Repository navigation
[FSDP2] enable per-param mesh FSDP2 for MoE - #2281
Conversation
345bbdd to
6e5dcf2
Compare
3c36e53 to
3bf7e27
Compare
b5932fa to
3bf7e27
Compare
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
|
those CI errors because we need to land pytorch/pytorch#173509 first |
|
@tianyu-l We're still gonna need the fine-grained workarounds at least for mxfp8, due to #2250 (comment). Until that issue is fixed (dynamo bwd tracing of autograd functions), we will trace wrong bwd graph. |
|
@xmfan oh, I didn't know. I marked it as high priority for now. |
I didn't change apply_compile because of #2341. #2250 (comment) is new to me |
| efsdp_config["mesh"] = edp_mesh | ||
| assert edp_mesh is not None | ||
| efsdp_ep_size = edp_mesh["efsdp"].size() * ep_degree | ||
| else: |
There was a problem hiding this comment.
NOTE: there's some recent logic change (fix), which applies to when ep_degree=1. Please adapt.
There was a problem hiding this comment.
good catch! I am adding those logic back
There was a problem hiding this comment.
I am taking a look at ci errors if it's related
There was a problem hiding this comment.
CI error is gone after rebasing on top of #2723
|
I am merging now. I assume rocm CI are still down, since another PR also didn't get result: #2707 |

command:
NGPU=8 MODULE=deepseek_v3 CONFIG=deepseek_v3_16b ./run_train.sh --training.steps 20 --parallelism.expert_parallel_degree 4fsdp2 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. rebased on latest main and handles ep size == 1 carefullyloss and grad_norm are identical using 10 decimal

Each layer issues 2 AGs and 2 RS, back-to-back. AG and RS overlapps if one is on dp mesh and another on efsdp mesh

active memory are exactly the same. reserved memory are tiny tiny higher
