-
Notifications
You must be signed in to change notification settings - Fork 699
[FSDP2] enable per-param mesh FSDP2 for MoE #2281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
weifengpy
wants to merge
2
commits into
pytorch:main
Choose a base branch
from
weifengpy:per-param-mesh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
345bbdd to
6e5dcf2
Compare
bd87f68 to
3c36e53
Compare
Add deepseek_v3_16b.toml config for local testing with 4 GPUs.
3c36e53 to
3bf7e27
Compare
b5932fa to
3bf7e27
Compare
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 9, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 10, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
weifengpy
added a commit
to pytorch/pytorch
that referenced
this pull request
Feb 10, 2026
this PR applies fully_shard on transformer_block, sharding experts on edp_mesh, and other params on dp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on experts see torchtitan for AG/RS schedules and numeric experiments: pytorch/torchtitan#2281 existing fsdp2 callsite won't be affected because _shard_placement_fn -> ShardPlacementResult is a new code path checked backward-compatiblibility * pytorch: fsdp2_mem_tracker.py is affected, but only if people use it with per-param mesh. I don't think it's a hard blocker * torchtitan: No usages of _fsdp_param_group (singular). Safe. * torchao: No usages of _fsdp_param_group (singular). Safe. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
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.
command:
CUDA_VISIBLE_DEVICES=4,5,6,7 NGPU=4 CONFIG_FILE="./torchtitan/models/deepseek_v3/train_configs/deepseek_v3_16b.toml" ./run_train.shfsdp2 support per-param mesh: pytorch/pytorch#173509
this PR applies fully_shard on transformer_block, sharding experts on
edp_mesh, and other params ondp_mesh. FSDPModule schedule 2 all-gather sequentially: 1st on transformer blocks, 2nd on expertsthis make it possible for apply torch.compile on each transformer_block. I didn't enable compile per block yet becuase there is still a gap in torch.compile + ac + MoE: #2341
AG order in forward are exactly the same before and after this change

AG order in backward are different but is better

Numerics remains bitwise equal with/without this change