Repository navigation
[graph_trainer] Prefer live SimpleFSDP unshard chains - #4934
Merged
Merged
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
This was referenced Sep 29, 2026
[ghstack-poisoned]
aditvenk
reviewed
Sep 30, 2026
…lized SimpleFSDP weights" I reviewed this one-file fix (BAD HACK) and its existing MXFP8 and GraphPP validation; it preserves eager fused WGrad accumulation while removing duplicate SimpleFSDP materialization. > The following technical description was prepared with Codex assistance and reviewed before posting. > > ### Summary > > `Linear.forward()` already materializes and flattens the weight before calling `MXFP8Linear._linear()`. Reading `self.weight` again is harmless for an ordinary module but reruns SimpleFSDP's dynamic parametrization, issuing a second all-gather and MXFP8 quantization for the same forward. Under GraphTrainer this also creates duplicate unshard chains whose extracted forward can receive an invalid scaled-mm operand. > > Reuse the supplied non-leaf `_UnshardedFSDPTensor` for SimpleFSDP and make_fx, where WGrad accumulation remains functional. Keep the module-attribute path for Dynamo and ordinary/FSDP2 eager execution, preserving leaf-owned fused WGrad accumulation and stacked-weight gradient shape. > > Fixes #4933. > > ### Test plan > > ```bash > python -m pytest -q \ > tests/unit_tests/gpu/test_mxfp8_fsdp.py \ > tests/unit_tests/gpu/test_mxfp8_linear.py > ``` > > Result: `31 passed, 1 expected xfail`. > > ```bash > python -m tests.integration_tests.run_tests \ > /tmp/tt_graph_pp_distmoe_mxfp8_post_rebase_fix_v2_20260928 \ > --test_suite b200 \ > --test_name graph_trainer_dist_moe_mxfp8_fsdp_ep_pp_cudagraph \ > --ngpu 4 --gpu_arch b200 --no-parallel > ``` > > Result: the four-rank PP2/FSDP2/EP2 run completed four steps with whole-step CUDA-graph capture and replay. [ghstack-poisoned]
… weights" I reviewed this one-file fix (BAD HACK) and its existing MXFP8 and GraphPP validation; it preserves eager fused WGrad accumulation while removing duplicate SimpleFSDP materialization. > The following technical description was prepared with Codex assistance and reviewed before posting. > > ### Summary > > `Linear.forward()` already materializes and flattens the weight before calling `MXFP8Linear._linear()`. Reading `self.weight` again is harmless for an ordinary module but reruns SimpleFSDP's dynamic parametrization, issuing a second all-gather and MXFP8 quantization for the same forward. Under GraphTrainer this also creates duplicate unshard chains whose extracted forward can receive an invalid scaled-mm operand. > > Reuse the supplied non-leaf `_UnshardedFSDPTensor` for SimpleFSDP and make_fx, where WGrad accumulation remains functional. Keep the module-attribute path for Dynamo and ordinary/FSDP2 eager execution, preserving leaf-owned fused WGrad accumulation and stacked-weight gradient shape. > > Fixes #4933. > > ### Test plan > > ```bash > python -m pytest -q \ > tests/unit_tests/gpu/test_mxfp8_fsdp.py \ > tests/unit_tests/gpu/test_mxfp8_linear.py > ``` > > Result: `31 passed, 1 expected xfail`. > > ```bash > python -m tests.integration_tests.run_tests \ > /tmp/tt_graph_pp_distmoe_mxfp8_post_rebase_fix_v2_20260928 \ > --test_suite b200 \ > --test_name graph_trainer_dist_moe_mxfp8_fsdp_ep_pp_cudagraph \ > --ngpu 4 --gpu_arch b200 --no-parallel > ``` > > Result: the four-rank PP2/FSDP2/EP2 run completed four steps with whole-step CUDA-graph capture and replay. [ghstack-poisoned]
sanketpurandare
marked this pull request as ready for review
September 30, 2026 03:40
sanketpurandare
requested review from
IvanKobzarev,
SherlockNoMad and
tianyu-l
as code owners
September 30, 2026 03:40
Contributor
|
This is now a dupe of #4966 |
Contributor
|
#4949 is a better root fix. |
IvanKobzarev
pushed a commit
that referenced
this pull request
Oct 1, 2026
Summary: SimpleFSDP intentionally materializes a parameter on each property access, so tracing may produce duplicate annotated all-gather and post-gather preparation chains for one parameter. GraphTrainer already canonicalizes those chains before partitioning and FSDP extraction. Prefer an unshard endpoint that still has consumers when choosing the canonical chain. Dead-code elimination removes an unused preparation tail but retains its effectful collective; choosing that dead raw endpoint can otherwise replace a live prepared MXFP8 value with a BF16 gathered tensor. Remove dead duplicate chains without substituting their unused endpoints. This keeps SimpleFSDP functional and compiler-safe. It adds no module hooks, Python cache state, MXFP8 execution-mode branches, or changes to eager FSDP behavior. Test Plan: - `python -m pytest -q 'torchtitan/experiments/graph_trainer/tests/test_passes.py::TestFSDPUnshardDedupPass' 'torchtitan/experiments/graph_trainer/tests/test_passes.py::TestReassignCollectivePgsPass::test_overlap_preserves_total_ag_count' 'torchtitan/experiments/graph_trainer/tests/test_passes.py::TestReassignCollectivePgsPass::test_overlap_rewrites_ag_nodes' 'torchtitan/experiments/graph_trainer/tests/test_passes.py::TestReassignCollectivePgsPass::test_overlap_rewrites_multiple_pgs'` (`6 passed`). - Four-rank MXFP8 GraphPP with PP2/FSDP2/EP2 and Interleaved1F1B completed four steps with CUDA-graph capture/replay; the pass reported 7 and 14 canonicalized duplicate chains for the local stages. ghstack-source-id: 1ef78ef Pull Request resolved: #4934
[ghstack-poisoned]
[ghstack-poisoned]
Contributor
Author
@SherlockNoMad and @aditvenk #4949 doesn't entirely address the issue. I get the same issue in the dist-moe PR integration above |
aditvenk
approved these changes
Oct 2, 2026
SherlockNoMad
approved these changes
Oct 2, 2026
[ghstack-poisoned]
[ghstack-poisoned]
sanketpurandare
changed the base branch from
gh/sanketpurandare/47/base
to
main
October 2, 2026 17:25
submartingales
pushed a commit
to botcanlearn/torchtitan-upstream
that referenced
this pull request
Oct 2, 2026
Summary: SimpleFSDP intentionally materializes a parameter on each property access, so tracing may produce duplicate annotated all-gather and post-gather preparation chains for one parameter. GraphTrainer already canonicalizes those chains before partitioning and FSDP extraction. Prefer an unshard endpoint that still has consumers when choosing the canonical chain. Dead-code elimination removes an unused preparation tail but retains its effectful collective; choosing that dead raw endpoint can otherwise replace a live prepared MXFP8 value with a BF16 gathered tensor. Remove dead duplicate chains without substituting their unused endpoints. This keeps SimpleFSDP functional and compiler-safe. It adds no module hooks, Python cache state, MXFP8 execution-mode branches, or changes to eager FSDP behavior. Test Plan: - The six focused FSDP unshard-deduplication and overlap tests pass on the current base. - The final changed-surface suite passes with 315 tests and 1 skip. ghstack-source-id: 1638b10 Pull Request resolved: pytorch/torchtitan#4934
AlbedoWang
added a commit
to AlbedoWang/torchtitan
that referenced
this pull request
Oct 7, 2026
…torch#4934) Backport of upstream torchtitan 0a3e5e0 (main) without chunk ownership handling, which this base does not have (590624c not present). deduplicate_fsdp_unshard_chains_pass picked unshard_outputs[0] as canonical. For Shard(1) expert params (efsdp*ep > num_experts), the first chain's post-gather chunk/cat tail is dead after DCE, so its raw wait_tensor was substituted for the live reconstructed value and _grouped_mm saw a (8, 352, 2048) gathered shard instead of (2, 1408, 2048).
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.
Stack from ghstack (oldest at bottom):
Summary:
SimpleFSDP intentionally materializes a parameter on each property access, so tracing may produce duplicate annotated all-gather and post-gather preparation chains for one parameter. GraphTrainer already canonicalizes those chains before partitioning and FSDP extraction.
Prefer an unshard endpoint that still has consumers when choosing the canonical chain. Dead-code elimination removes an unused preparation tail but retains its effectful collective; choosing that dead raw endpoint can otherwise replace a live prepared MXFP8 value with a BF16 gathered tensor. Remove dead duplicate chains without substituting their unused endpoints.
This keeps SimpleFSDP functional and compiler-safe. It adds no module hooks, Python cache state, MXFP8 execution-mode branches, or changes to eager FSDP behavior.
Test Plan: