fix(fsdp): add CLI argument for outer_dp_sharding_strategy - #3053
Merged
shjwudp merged 2 commits intoJan 26, 2026
Conversation
This commit adds the missing --outer-dp-sharding-strategy CLI argument to enable HSDP (Hybrid-Sharded Data Parallelism) with outer-layer optimizer sharding in Megatron-LM training scripts. Fixes NVIDIA#3038
shjwudp
approved these changes
Jan 23, 2026
shjwudp
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks for your contribution!
Contributor
|
/ok to test dde6725 |
shjwudp
enabled auto-merge
January 23, 2026 04:58
Contributor
|
Thank you for your contribution! NVIDIA Megatron-LM is currently transitioning to development on Github. We will aim to review your PR after we complete our transition and stabilize our Github development process. Thank you for your understanding. |
Contributor
|
/ok to test 3f903f9 |
daiyaanarfeen
pushed a commit
to daiyaanarfeen/Megatron-LM
that referenced
this pull request
Feb 23, 2026
Co-authored-by: Jianbin Chang <shjwudp@gmail.com>
yangbofun
pushed a commit
to xlm-research/Megatron-LM
that referenced
this pull request
May 22, 2026
Co-authored-by: Jianbin Chang <shjwudp@gmail.com>
terminator123
pushed a commit
to 021ai/Megatron-LM
that referenced
this pull request
Aug 3, 2026
Co-authored-by: Jianbin Chang <shjwudp@gmail.com>
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.
Summary
This PR adds the missing
--outer-dp-sharding-strategyCLI argument to enable HSDP (Hybrid-Sharded Data Parallelism) with outer-layer optimizer sharding in Megatron-LM training scripts.Changes
--outer-dp-sharding-strategyCLI argument inmegatron/training/arguments.py'no_shard'(default) and'optim''optim'option requires--data-parallel-sharding-strategy optim_grads_paramsMotivation
The underlying Megatron-FSDP codebase already supports
outer_dp_sharding_strategyparameter:DistributedDataParallelConfig.outer_dp_sharding_strategyexists (default:'no_shard')fully_shard_model()API acceptsouter_dp_sharding_strategyparametermcore_fsdp_adapter.pychecks forouter_dp_sharding_strategy != "no_shard"However, users could not configure this via command-line arguments, preventing them from utilizing HSDP with outer optimizer sharding, which can provide significant memory savings (up to 4x reduction in optimizer state memory for outer-DP size of 4).
Usage Example
python pretrain_gpt.py \ --use-megatron-fsdp \ --data-parallel-sharding-strategy optim_grads_params \ --outer-dp-sharding-strategy optim \ --num-distributed-optimizer-instances 4 \ ...Implementation Details
The implementation leverages the existing automatic parameter passing mechanism in
training.py(lines 1281-1283), which automatically extracts allDistributedDataParallelConfigfields fromargs. Therefore, only adding the CLI argument is needed - no changes totraining.pyare required.Validation logic already exists in
fully_shard.py:'no_shard'and'optim'are supported forouter_dp_sharding_strategy'optim',data_parallel_sharding_strategymust be'optim_grads_params'Testing
--data-parallel-sharding-strategy)DistributedDataParallelConfigvia existing mechanismfully_shard.pyFixes #3038