Use metadata dp_cp_group for the tied-embeddings replica_id - #6888
Use metadata dp_cp_group for the tied-embeddings replica_id#6888going-song wants to merge 2 commits into
Conversation
The tied output-layer replica id read the global parallel_state.get_data_parallel_rank, which crashes checkpoint save for models running on per-module process groups without the global MPU (e.g. MimoModel) with tied embeddings and PP >= 2. Read it from metadata['dp_cp_group'] instead: the key is always present, and with the global MPU initialized it is the same group, so nothing changes for existing setups. Add a tied case to the MIMO checkpoint tests. Co-Authored-By: Kayeon Song <kayeon.song@navercorp.com> Co-Authored-By: Yoonsik Kim <yoonsik.kim90@navercorp.com> Co-Authored-By: Yechan Kim <yechan.78@navercorp.com> Signed-off-by: Kayeon Song <kayeon.song@navercorp.com> Signed-off-by: Yoonsik Kim <yoonsik.kim90@navercorp.com> Signed-off-by: Yechan Kim <yechan.78@navercorp.com>
| 1, # copy of first stage embedding | ||
| 0, | ||
| parallel_state.get_data_parallel_rank(with_context_parallel=True), | ||
| get_pg_rank(metadata['dp_cp_group']), |
There was a problem hiding this comment.
Same source as the first-stage copy: when replica_id is not given, make_tp_sharded_tensor_for_checkpoint (megatron/core/utils.py) computes this component as get_pg_rank(dp_cp_group) from its dp_cp_group argument, which the standard path fills from metadata['dp_cp_group'].
|
/claude fix |
Signed-off-by: svcnvidia-nemo-ci <svcnvidia-nemo-ci@nvidia.com>
|
🛠️ Claude fix commit
What changed Files changed by Claude
Why DCO Sanitized and posted by |
|
/ok to test 88163fa |
|
❌ Claude fix stopped because the pull request head or base changed. View exact-SHA CI. |
Motivation
MimoModelruns each submodule on its own process groups (per-moduleHyperCommGrids with different parallel layouts), so the global MPU maynever be initialized. In that setup, saving a checkpoint of a language
module with
share_embeddings_and_output_weights=Trueand PP >= 2 fails onthe last pipeline stage:
The failing line is the tied output-layer copy's replica id in
LanguageModule.tie_embeddings_and_output_weights_state_dict, which readsthe global
parallel_state.get_data_parallel_rank(with_context_parallel=True).Change
In
megatron/core/models/common/language_module/language_module.py, computethe DP replica index from the process group threaded through
metadata['dp_cp_group']:The key is guaranteed to be present:
LanguageModule.sharded_state_dictcalls
ensure_metadata_has_dp_cp_groupat its entry, before the tying step,and the
make_tp_sharded_tensor_for_checkpointcall registering this sametensor a few lines below already consumes
metadata['dp_cp_group'].MimoModel.sharded_state_dictfills the key with each module'sdp_cpgroup (
megatron/core/models/mimo/model/base.py), which makes the savework without the global MPU.
This follows #2053, which moved this file's other reads (the
sharded_state_dictentry guard and the MTP tying path) to the metadatagroup — this was the file's remaining direct
parallel_stateread — andthe guideline to prefer caller-provided process groups over global
parallel_statereads inmegatron/core.Behavior for existing setups
metadata['dp_cp_group']holds the samegroup the removed call reads —
ensure_metadata_has_dp_cp_groupfills itfrom
get_data_parallel_group(with_context_parallel=True), and thetrainer's
_build_sharded_state_dict_metadata(
megatron/training/checkpointing.py) threads the same group — so thecomputed rank is unchanged.
leading
1("copy of first stage embedding") already makesis_main_replicaFalse regardless of the third component, and_sharded_tensor_shard_iddoes not includereplica_id.Why this hasn't surfaced before
yield the same value.
save; with PP == 1 the function returns early (the stage holding the
embedding never registers a tied copy).
(
share_embeddings_and_output_weightsdefaults to False), so thiscombination is not covered there yet.
Testing
Verified on 3 ranks with per-module HyperCommGrids and no global MPU
(llm tp1/pp2/dp1 + one encoder rank): unpatched,
sharded_state_dict()raises the assertion on the last language PP stage; with this change, save
(
validate_access_integrity=True) and a load round trip pass, and theloaded tied weight equals the first-stage embedding. Adds a tied-embeddings
case to
tests/unit_tests/models/mimo/test_mimo_checkpoint.py.