Skip to content

Commit

Permalink
Fix missing parallelisms (#9725)
Browse files Browse the repository at this point in the history
* pass cp and ep cfg to init mp

Signed-off-by: Maanu Grover <maanug@nvidia.com>

* update test

Signed-off-by: Maanu Grover <maanug@nvidia.com>

---------

Signed-off-by: Maanu Grover <maanug@nvidia.com>
Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
  • Loading branch information
maanug-nv authored and akoumpa committed Jul 25, 2024
1 parent ca94e03 commit 48f1dce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion nemo/lightning/_strategy_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ def init_parallel_ranks(
global_rank=init_global_rank,
local_rank=init_local_rank,
tensor_model_parallel_size=parallel_config.tensor_model_parallel_size,
expert_model_parallel_size=parallel_config.expert_model_parallel_size,
pipeline_model_parallel_size=parallel_config.pipeline_model_parallel_size,
virtual_pipeline_model_parallel_size=parallel_config.virtual_pipeline_model_parallel_size,
context_parallel_size=parallel_config.context_parallel_size,
seed=seed,
pipeline_model_parallel_split_rank=getattr(parallel_config, "pipeline_model_parallel_split_rank", None),
use_fp8=fp8,
init_mpi_proc_group=getattr(parallel_config, "ub_tp_comm_overlap", False),
init_mpi_proc_group=getattr(parallel_config, "tp_comm_overlap", False),
# apex_transformer_log_level=self.cfg.get('apex_transformer_log_level', 30),
)

Expand All @@ -92,6 +94,8 @@ def init_model_parallel(model: Optional[nn.Module] = None) -> None:
pipeline_model_parallel_size=app_state.pipeline_model_parallel_size,
virtual_pipeline_model_parallel_size=app_state.virtual_pipeline_model_parallel_size,
pipeline_model_parallel_split_rank=app_state.pipeline_model_parallel_split_rank,
context_parallel_size=app_state.context_parallel_size,
expert_model_parallel_size=app_state.expert_model_parallel_size,
)

# assert that fake tp and pp rank match after model parallel init
Expand Down
19 changes: 17 additions & 2 deletions tests/lightning/test_strategy_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ def test_init_parallel_ranks(mock_initialize_model_parallel) -> None:

app_state.tensor_model_parallel_size = 2
app_state.pipeline_model_parallel_size = 3
app_state.context_parallel_size = 2
app_state.expert_model_parallel_size = 2
app_state.global_rank = 1
app_state.local_rank = 0

mock_parallel_config = MagicMock()
mock_parallel_config.tensor_model_parallel_size = 2
mock_parallel_config.pipeline_model_parallel_size = 3
mock_parallel_config.virtual_pipeline_model_parallel_size = 4
mock_parallel_config.ub_tp_comm_overlap = False
mock_parallel_config.context_parallel_size = 2
mock_parallel_config.expert_model_parallel_size = 2
mock_parallel_config.tp_comm_overlap = False
mock_parallel_config.pipeline_model_parallel_split_rank = None

_strategy_lib.init_parallel_ranks(
world_size=2, global_rank=1, local_rank=0, parallel_config=mock_parallel_config, seed=1234, fp8=False,
world_size=2,
global_rank=1,
local_rank=0,
parallel_config=mock_parallel_config,
seed=1234,
fp8=False,
)
mock_initialize_model_parallel.assert_called_once_with(
world_size=2,
Expand All @@ -43,6 +52,8 @@ def test_init_parallel_ranks(mock_initialize_model_parallel) -> None:
tensor_model_parallel_size=2,
pipeline_model_parallel_size=3,
virtual_pipeline_model_parallel_size=4,
context_parallel_size=2,
expert_model_parallel_size=2,
seed=1234,
pipeline_model_parallel_split_rank=None,
use_fp8=False,
Expand All @@ -60,6 +71,8 @@ def test_init_model_parallel(mock_mpu, *args):
app_state.tensor_model_parallel_size = 2
app_state.pipeline_model_parallel_size = 1
app_state.pipeline_model_parallel_split_rank = None
app_state.context_parallel_size = 2
app_state.expert_model_parallel_size = 2
app_state.init_mpi_proc_group = False
app_state.tensor_model_parallel_rank = 2
app_state.pipeline_model_parallel_rank = 0
Expand All @@ -72,6 +85,8 @@ def test_init_model_parallel(mock_mpu, *args):
pipeline_model_parallel_size=1,
virtual_pipeline_model_parallel_size=None,
pipeline_model_parallel_split_rank=None,
context_parallel_size=2,
expert_model_parallel_size=2,
)


Expand Down

0 comments on commit 48f1dce

Please sign in to comment.