Skip to content

Compute checkpoint replica ids over the module's own DP x CP group - #8044

Closed
Connor-XY wants to merge 5 commits into
NVIDIA:mainfrom
Connor-XY:yx/pstate-b2-ckpt-replica-groups
Closed

Connor-XY wants to merge 5 commits into
NVIDIA:mainfrom
Connor-XY:yx/pstate-b2-ckpt-replica-groups

Conversation

@Connor-XY

@Connor-XY Connor-XY commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Why. sharded_state_dict() called without metadata fills metadata['dp_cp_group'] from the global DP x CP group. A model on its own grid, as built by tools, converters, tests or exports, then computes replica ids from another grid's ranks, so several ranks or none write each shard. Separately, a tp_group passed to the sharded-tensor helpers without a dp_cp_group makes every data-parallel rank a main replica.

What.

  • ensure_metadata_has_dp_cp_group(metadata, dp_cp_group=None): a group already in the metadata still wins; otherwise the given group, then the global default.
  • MegatronModule, MLP (which keeps its pg_collection), TransformerBlock and LanguageModule pass their collection's dp_cp_gtp_remat, or dp_cp when unset: the group the global default stands for. One global read is removed.
  • The last commit makes make_sharded_tensors_for_checkpoint, make_tp_sharded_tensor_for_checkpoint and make_sharded_tensor_for_checkpoint raise ValueError for a tp_group without a dp_cp_group. A dp_cp_group alone still means "not tensor-parallel". No in-repo caller is affected; the commit can be dropped if the restriction is unwanted.

Tests. With the global DP x CP accessor patched to raise, new tests compare (key, global_offset, replica_id) with the global default for an MLP, a transformer block and a GPT model at TP=2 and on a GTP=2 grid, and check the new error. Before the sync they failed on main and passed here on 4 GPUs, and distributed-checkpointing GPT and MLP, MIMO checkpoint and GTP DCP tests matched main. In the integration run on 4 GPUs, the two new test files give 8 passed and 1 skipped: test_sharded_state_dict_dp_cp_group.py 6 passed, test_gpt_sharded_state_dict_dp_cp_group.py 2 passed and 1 skipped. The skipped case is the GPT model with GTP-sharded weights, because the container's Transformer Engine is older than GTP needs. Neither file exists on main. In the integration run, this PR's test files show no regressions against main.

Compatibility. Replica ids on the standard grid do not change. MoE experts, hybrid/SSM mixers and TE layers still fill the global group; they follow per owner.

Synced with main 77391e7 on 2026-11-01 by a merge commit, so existing commits and review links stay valid. The merge had no conflicts; its message records the one change made for main.

Part of #6307.

🤖 Generated with Claude Code

@Connor-XY

Copy link
Copy Markdown
Contributor Author

/ok to test 9a16919

@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Connor-XY and others added 4 commits October 26, 2026 10:58
sharded_state_dict() called without metadata filled in the global
get_data_parallel_group(with_context_parallel=True), and replica ids
were computed over it. A model on its own grid, saved by a tool, a
converter or a test that passes no metadata, then claimed replicas by
another grid's DP ranks: several ranks or none wrote each shard.

ensure_metadata_has_dp_cp_group takes an optional dp_cp_group that it
uses instead of the global group when the metadata has none; a group
already in the metadata still wins. MegatronModule, MLP and
TransformerBlock pass their collection's dp_cp_gtp_remat (dp_cp when
the collection has no GTP-inclusive group). That is the group the
global default stands for, so replica ids on the standard grid do not
change. MLP now keeps its pg_collection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
LanguageModule.sharded_state_dict fills missing metadata for GPT,
hybrid and BERT models before their submodules can, so a model built
on its own collection still got the global DP x CP group for every
replica id below it. Pass the model collection's dp_cp_gtp_remat
(dp_cp without GTP), the group the global default stands for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
make_sharded_tensors_for_checkpoint, make_tp_sharded_tensor_for_checkpoint
and make_sharded_tensor_for_checkpoint fell back to the global groups
only when both groups were None. A tp_group passed without its
dp_cp_group made the DP x CP group a singleton, so every data-parallel
rank claimed to be the main replica of each shard. That is now a
ValueError. No in-repo caller passes a TP group alone.

A dp_cp_group without a tp_group still means the tensors are not
tensor-parallel: the GTP checkpoint helper, MIMO's sharded_state_dict
for plain submodules and the GTP checkpoint tests rely on it, so the
docstrings now say so instead of raising.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
@Connor-XY
Connor-XY force-pushed the yx/pstate-b2-ckpt-replica-groups branch from 9a16919 to 482ceca Compare October 26, 2026 22:26
@Connor-XY

Copy link
Copy Markdown
Contributor Author

/ok to test 482ceca

Connor-XY added a commit to Connor-XY/Megatron-LM that referenced this pull request Nov 1, 2026
The SSM, MoE and TE layers that follow pass their own DP x CP group to
ensure_metadata_has_dp_cp_group, which takes that argument from NVIDIA#8044,
and their tests reuse NVIDIA#8044's sharded-state DP x CP test helpers, so
merge NVIDIA#8044 here. NVIDIA#8044's head already contains main, so the merge is
clean and its tree is NVIDIA#8044's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Connor-XY added a commit to Connor-XY/Megatron-LM that referenced this pull request Nov 1, 2026
NVIDIA#8044 lets modules fill missing sharded-state metadata with their own
DP x CP group and rejects a TP group passed without one to the
checkpoint helpers. The owners pass that group, and the checkpoint
helpers are to warn when they fall back to the global groups, in the
code NVIDIA#8044 changes, so merge NVIDIA#8044 here.
The merge is clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Connor-XY added a commit to Connor-XY/Megatron-LM that referenced this pull request Nov 1, 2026
The one-warning tests that follow check that a MoELayer built without a
collection gives its experts the GTP groups of the global grid, and
read them from experts.pg_collection. NVIDIA#8732's 645cd0d makes
SequentialMLP and TEGroupedMLP keep their collection; without it that
test case fails with "'SequentialMLP' object has no attribute
'pg_collection'". NVIDIA#8732 brings NVIDIA#8044.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
The process-group allowlist records the reads main added since this PR
was written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
@Connor-XY

Copy link
Copy Markdown
Contributor Author

Superseded by #8892, which carries this change as commit 446dc80 under the same title, with "Originally #8044." in its message. Closing so review happens in one place. The branch stays on the fork.

@Connor-XY Connor-XY closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant