Add load-time GPT-to-Hybrid checkpoint translation (#5675) - #5792
Conversation
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
|
/ok to test 6cd111c |
6cd111c to
bda9121
Compare
Allow HybridModel runs to load GPT (pure transformer) torch_dist checkpoints directly, without an offline conversion step. Instead of rewriting the checkpoint on disk, load_checkpoint retargets the hybrid model's own sharded state dict at the GPT checkpoint: attention and MLP entries are rewritten to the checkpoint's homogeneous layer format (layer index dropped from the storage key and prepended as a sharding axis), the final norm key is renamed, and layers without a GPT counterpart (e.g. Mamba) keep their fresh initialization via LocalNonpersistentObject. The regular dist-checkpointing machinery then reads the GPT checkpoint directly and reshards across any TP/PP/EP/ETP layout change. Requires --finetune and --no-load-optim, and validates that the hybrid layer pattern pairs one-to-one with the checkpoint's layers (no MTP, no GDN/DSA positions, uniform dense or MoE MLP kind). Tests cover the pure layer-map/retarget logic and distributed round-trips across TP/PP/EP/ETP reconfigurations, including gated-MLP (swiglu factory) and grouped-GEMM MoE variants. Signed-off-by: guihong-nv <guihongl@nvidia.com>
bda9121 to
562b4f4
Compare
|
/ok to test 20ca49f |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30155062432 |
|
/ok to test 0f73838 |
Signed-off-by: guihong-nv <guihongl@nvidia.com>
Signed-off-by: guihong-nv <guihongl@nvidia.com>
|
/ok to test 716875a |
Signed-off-by: guihong-nv <guihongl@nvidia.com>
|
/ok to test 49a44bd |
1 similar comment
|
/ok to test 49a44bd |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30313936889 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30315004225 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30317255643 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30332765580 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30337950766 |
Allow HybridModel runs to load GPT (pure transformer) distributed checkpoints directly, without an offline conversion step. This supports both
torch_distand Megatron-FSDP (fsdp_dtensor) checkpoints, including model weights and distributed optimizer state. Instead of rewriting the checkpoint on disk,load_checkpointretargets the hybrid model's own sharded state dict at the GPT checkpoint: attention and MLP entries are rewritten to the checkpoint's homogeneous layer format (layer index dropped from the storage key and prepended as a sharding axis), the final norm key is renamed, and layers without a GPT counterpart (for example Mamba) keep their fresh initialization viaLocalNonpersistentObject. The regular distributed-checkpointing machinery then reads the GPT checkpoint directly and reshards across parallel-layout changes.--hybrid-layer-patternis required for GPT-to-Hybrid translation.--finetuneis optional and keeps its normal meaning: a direct--loadwithout it resumes iteration, optimizer, scheduler, RNG, and rerun state under normal compatibility rules; using--finetuneresets training progress while still allowing translated optimizer state to load.--no-load-optimremains available for a weights-only load. The layer pattern must pair one-to-one with the checkpoint's layers (no MTP, no GDN/DSA positions, uniform dense or MoE MLP kind).Also add
--use-legacy-modelso the hybrid entrypoint can keep training a GPT checkpoint asGPTModelwithout any translation.Tests cover the pure layer-map/retarget logic and distributed model-plus-optimizer round trips across DP, Megatron FSDP, TP, PP, CP, EP, and ETP reconfigurations, including gated-MLP (SwiGLU factory) and grouped-GEMM MoE variants. Dedicated cases verify resume without
--finetunefor bothtorch_distandfsdp_dtensorcheckpoints.This PR is required by #5675.
What does this PR do?
Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.