bridge.models.megatron_mimo.megatron_mimo_builder#
Module Contents#
Functions#
Return new NCCL options that create a MegatronMIMO group’s communicator on first use. |
|
Create HyperCommGrid objects per module from MegatronMIMO parallelism config. |
|
Create embedding-related process groups from globally enumerated PP ranks. |
|
Check if current rank is first stage in pipeline. |
|
Check if current rank is last stage in pipeline. |
Data#
API#
- bridge.models.megatron_mimo.megatron_mimo_builder.EXPERT_VIEW_NAME#
‘expert’
- bridge.models.megatron_mimo.megatron_mimo_builder._lazy_nccl_pg_options() torch.distributed.ProcessGroupNCCL.Options | None#
Return new NCCL options that create a MegatronMIMO group’s communicator on first use.
PyTorch builds whose
ncclbackend is ProcessGroupNCCL2 bind the default process group to a device, so every laternew_groupsplits its NCCL communicator eagerly, even if the group never communicates. MegatronMIMO creates every parallelism group of every module on every rank, so eager splitting holds NCCL buffers for groups the rank never uses.lazy_initinstead creates a group’s communicator at the group’s first operation. That creation is collective over all members, so every member must take part in the first operation: MIMO groups are used by collectives over the whole group, and every pipeline stage issues its point-to-point operations on its pipeline group during the warm-up phase.- Returns:
Options with
lazy_init=Truewhen the default process group is a ProcessGroupNCCL2 group bound to a device and PyTorch has the option, else None (default options).lazy_initis specific to ProcessGroupNCCL2; on the legacy backend it would only replace the split with an eager per-group initialization. Each call returns a new object because PyTorch writes per-group settings into the options it is given.
- bridge.models.megatron_mimo.megatron_mimo_builder.build_hypercomm_grids(
- megatron_mimo_parallelism_config: megatron.bridge.models.megatron_mimo.megatron_mimo_config.MegatronMIMOParallelismConfig,
Create HyperCommGrid objects per module from MegatronMIMO parallelism config.
Creates grids on ALL ranks (required for consistent collective calls), but only ranks in each grid’s range will participate in its operations.
Each grid is built with a dense
baseview plus a registeredexpertview over the same rank span. Dense process groups (tp/cp/dp/pp) come from the base view; expert-parallel groups (expt_tp/ep/expt_dp) come from the expert view, matching the contract mcore’sget_mimo_optimizerexpects.The groups are created with lazy NCCL initialization when the backend would otherwise split every group eagerly (see
_lazy_nccl_pg_options), so a group allocates NCCL resources only once it communicates.- Parameters:
megatron_mimo_parallelism_config – MegatronMIMOParallelismConfig specifying parallelism per module.
- Returns:
Dict mapping module names to their HyperCommGrids.
- bridge.models.megatron_mimo.megatron_mimo_builder.populate_embedding_and_position_groups(
- pp_rank_groups: list[list[int]] | None,
Create embedding-related process groups from globally enumerated PP ranks.
Following MCore semantics:
pos_embd_pg: Only rank 0 of PP (first stage) - for position embeddings
embd_pg: Ranks 0 and -1 of PP (first and last stages) - for tied word embeddings
IMPORTANT: This calls dist.new_group which is a collective operation. Must be called on all ranks that could participate.
- Parameters:
pp_rank_groups – Every pipeline-parallel rank group in global creation order.
- Returns:
Tuple of process groups for the current rank. Returns (None, None) when no pipeline-parallel rank groups are provided.
- bridge.models.megatron_mimo.megatron_mimo_builder.is_pp_first_stage(
- pp_group: Optional[torch.distributed.ProcessGroup],
Check if current rank is first stage in pipeline.
- bridge.models.megatron_mimo.megatron_mimo_builder.is_pp_last_stage(
- pp_group: Optional[torch.distributed.ProcessGroup],
Check if current rank is last stage in pipeline.