Fix Megatron-FSDP DTensor checkpoint save/load compatibility - #9976
Open
addsubmuldiv wants to merge 9 commits into
Open
Fix Megatron-FSDP DTensor checkpoint save/load compatibility#9976addsubmuldiv wants to merge 9 commits into
addsubmuldiv wants to merge 9 commits into
Conversation
addsubmuldiv
marked this pull request as ready for review
August 26, 2026 01:29
addsubmuldiv
marked this pull request as draft
August 26, 2026 02:47
addsubmuldiv
marked this pull request as ready for review
August 26, 2026 08:13
addsubmuldiv
marked this pull request as draft
August 26, 2026 08:24
addsubmuldiv
marked this pull request as ready for review
August 27, 2026 08:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
This PR adds a dedicated save/load path for Megatron-FSDP DTensor checkpoints.
The existing Megatron checkpoint path uses MCore sharded state dictionaries. Megatron-FSDP exposes DTensor state through
state_dict_for_save_checkpoint(), which must be preprocessed and saved with PyTorch Distributed Checkpoint (DCP).Main changes
swift/megatron/utils/megatron_fsdp_checkpoint.pyto identify FSDP DCP checkpoints, run MCorepreprocess_fsdp_dtensor_state_dict(), and save/load DTensor state with PyTorch DCP, following Megatron-Core's configurable partial/strict load behavior.use_megatron_fsdp=truethrough the DCP path while preserving the existing non-FSDP checkpoint path.(PP rank, TP rank), with per-DP-rank state gathered whendata_parallel_random_init=true.warmup_jit_function()before checkpoint loading so JIT warmup cannot consume restored RNG state.PR scope and limitations
gradient_accumulation_fusion=truecan fail when BF16 gradients are accumulated into FP32main_grad; validation therefore uses--gradient_accumulation_fusion false. Further 0.18 stack adaptation is outside this PR.Validation
optim_grads_params.loss=6.79597759,grad_norm=446.08346558, andlearning_rate=0.0.git diff --checkpassed.