Skip to content

Commit 8362718

Browse files
committed
feat: Allow for multiple parallelism methods in get_parallel_degree
1 parent e89f4b8 commit 8362718

5 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎config_files/training/config_lorem_ipsum_long_fsdp2.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ device_mesh:
183183
world_size: ${settings.cuda_env.world_size}
184184

185185
dp_degree:
186-
component_key: device_mesh
186+
component_key: number_conversion
187187
variant_key: parallel_degree
188188
config: # get the parallel degree from the device mesh
189189
device_mesh:
190190
instance_key: device_mesh
191191
pass_type: BY_REFERENCE
192-
parallelism_method: dp_shard
192+
parallelism_methods: [dp_shard, dp_replicate]
193193

194194
app_state:
195195
component_key: app_state

‎src/modalities/config/config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ class GPT2MFUCalculatorConfig(BaseModel):
485485

486486
class ParallelDegreeConfig(BaseModel):
487487
device_mesh: PydanticDeviceMeshIFType
488-
parallelism_method: ParallelismDegrees
488+
parallelism_methods: list[ParallelismDegrees]
489489

490490

491491
def load_app_config_dict(

‎src/modalities/main.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def run(self, components: TrainingComponentsInstantiationModel):
141141

142142
# Trainer
143143
dp_degree = get_parallel_degree(
144-
device_mesh=components.device_mesh, parallelism_method=ParallelismDegrees.DP_SHARD
144+
device_mesh=components.device_mesh,
145+
parallelism_methods=[ParallelismDegrees.DP_SHARD, ParallelismDegrees.DP_REPLICATE],
145146
)
146147
global_num_tokens_per_train_step = (
147148
components.settings.step_profile.local_train_micro_batch_size

‎src/modalities/registry/components.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class ComponentEntity:
177177
),
178178
# Device mesh
179179
ComponentEntity("device_mesh", "default", get_device_mesh, DeviceMeshConfig),
180-
ComponentEntity("device_mesh", "parallel_degree", get_parallel_degree, ParallelDegreeConfig),
180+
ComponentEntity("number_conversion", "parallel_degree", get_parallel_degree, ParallelDegreeConfig),
181181
# weight initializers
182182
ComponentEntity(
183183
"model_initialization",

‎src/modalities/running_env/fsdp/device_mesh.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from math import prod
23
from typing import Annotated, Optional
34

45
from pydantic import BaseModel, Field, model_validator
@@ -129,19 +130,20 @@ def get_device_mesh(
129130
return device_mesh
130131

131132

132-
def get_parallel_degree(device_mesh: DeviceMesh, parallelism_method: ParallelismDegrees) -> int:
133+
def get_parallel_degree(device_mesh: DeviceMesh, parallelism_methods: list[ParallelismDegrees]) -> int:
133134
"""Gets the number of parallel ranks (i.e., the parallelism degree)
134135
from the device mesh for a specific parallelism method.
135136
Args:
136137
device_mesh (DeviceMesh): The device mesh.
137-
parallelism_method (ParallelismDegrees): The parallelism method.
138+
parallelism_methods (list[ParallelismDegrees]): The parallelism methods.
138139
Returns:
139140
int: The number of parallel ranks for the specified parallelism method.
140141
"""
141142
if device_mesh.mesh_dim_names is None:
142143
raise ValueError("device_mesh.mesh_dim_names is None")
143144

144-
if parallelism_method.value not in device_mesh.mesh_dim_names:
145-
return 1
146-
else:
147-
return device_mesh.size(device_mesh.mesh_dim_names.index(parallelism_method.value))
145+
return prod(
146+
device_mesh.size(device_mesh.mesh_dim_names.index(method.value))
147+
for method in parallelism_methods
148+
if method.value in device_mesh.mesh_dim_names
149+
)

0 commit comments

Comments
 (0)