Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion megatron/core/dist_checkpointing/strategies/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ def register_default_torch_strategies():

logger = getLogger(__name__)

_COORDINATION_PROCESS_GROUP = None


def _get_coordination_process_group():
"""Gloo group for checkpoint plan/metadata object collectives. On an
NCCL-only default group these would be staged through GPU and leave
permanent per-peer NCCL channel buffers on the coordinator rank."""
global _COORDINATION_PROCESS_GROUP
if not torch.distributed.is_initialized():
return None
if _COORDINATION_PROCESS_GROUP is None:
_COORDINATION_PROCESS_GROUP = torch.distributed.new_group(backend="gloo")
return _COORDINATION_PROCESS_GROUP


def flatten_state_dict(
state_dict: ShardedStateDict,
Expand Down Expand Up @@ -701,7 +715,7 @@ def async_save(
) = save_state_dict_async_plan(
pyt_state_dict,
writer,
None,
_get_coordination_process_group(),
coordinator,
planner=MCoreSavePlanner(
dedup_replicated_tensors=not self.keep_only_main_replica, flatten_state_dict=False
Expand Down Expand Up @@ -805,6 +819,7 @@ def load(self, sharded_state_dict: ShardedStateDict, checkpoint_dir: Path) -> St
checkpoint.load_state_dict(
pyt_state_dict,
fsr,
process_group=_get_coordination_process_group(),
planner=MCoreLoadPlanner(
shapes_validation_sharded_tensors=flexible_shape_sharded_tensors,
allow_shape_mismatch_sharded_tensors=allow_shape_mismatch_sharded_tensors,
Expand Down