-
Notifications
You must be signed in to change notification settings - Fork 492
workarounds for all2all autograd issues that Ruisi ran into #1604
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
Open
bdhirsh
wants to merge
2
commits into
gh/bdhirsh/4/base
Choose a base branch
from
gh/bdhirsh/4/head
base: gh/bdhirsh/4/base
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.
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
[ghstack-poisoned]
The idea behind this PR is that there appears to be an issue in the way that dynamo is inlining the `_A2A.apply` used in EP: (1) ruisizhang123 / anijain2305 noticed that the MoE code wasn't getting a proper backward graph generated for it when being run with compile (notes here: https://docs.google.com/document/d/1l1PfSrhJRXRLa1usBsEh4YSidgJiDU_eVNJ01p7PetM/edit?tab=t.0), running on tip-of-main with this [PR](https://github.com/pytorch/torchtitan/pull/1529/files), and this command: `CONFIG_FILE="./torchtitan/models/deepseek_v3/train_configs/debug_model.toml" ./run_train.sh --model.name deepseekv3_simple_fsdp --profiling.enable_profiling --parallelism.expert_parallel_degree 2 --training.compile` (2) old tlparse showed that there are no `aten._grouped_mm` calls in the backward graph, showing that we are not properly differentiating the MoE code ([tlparse](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpxMfgwf/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000)) if you look at the dynamo graph in that tlparse, though, you'll see nodes for `_c10d_functional.all_to_all_single` and `_c10d_functional.wait_tensor`. This is a problem - the dynamo graph should be capturing the entire autograd.Function as a HOP, since those two ops are not differentiable. (3) I didn't root cause why dynamo is "ignoring" the `autograd.Function`. I have some suspicion about the fact that the autograd.Function in question accepts a `ProcessGroup`. Instead, I just (a) wrote a slightly different version of the autograd.Function that doesn't accept ProcessGroup, and (b) allow-in-graph'd it for good measure, to guarantee that dynamo won't incorrectly inline it. As a followup, we should either debug why dynamo is not constructing a HOP for the autograd.Function, or kill the _A2A.apply code entirely as per this [comment](#1467 (comment)) Here's a good tlparse with my changes, where you can see proper `aten._grouped_mm` nodes in the backward graph: https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/hirsheybar/9b03e768-73a1-4154-b7af-dcd79cfc754d/custom/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000 [ghstack-poisoned]
@bdhirsh I have a fix for the root cause here: pytorch/pytorch#161036 |
pytorchmergebot
pushed a commit
to pytorch/pytorch
that referenced
this pull request
Aug 22, 2025
…1036) Fixes silent incorrectness for autograd function tracing, where we rely on FakeTensor metadata (requires_grad) to determine whether to HOP or not: https://github.com/pytorch/pytorch/blob/5ee464db5c4293ac09521f9069fa7d2106680a7f/torch/_dynamo/variables/misc.py#L671 Stared at this with @anijain2305 yesterday, `Tensor.__setitem__` can update tensor metadata, and we can just run the fake prop and extract the output metadata from the updated FakeTensor. FIXES #160901 It should also be the root cause behind the issue in pytorch/torchtitan#1604 @bdhirsh @ruisizhang123 Pull Request resolved: #161036 Approved by: https://github.com/anijain2305 ghstack dependencies: #160805
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.
The idea behind this PR is that there appears to be an issue in the way that dynamo is inlining the
_A2A.apply
used in EP:(1) @ruisizhang123 / @anijain2305 noticed that the MoE code wasn't getting a proper backward graph generated for it when being run with compile (notes here: https://docs.google.com/document/d/1l1PfSrhJRXRLa1usBsEh4YSidgJiDU_eVNJ01p7PetM/edit?tab=t.0), running on tip-of-main with this PR, and this command:
CONFIG_FILE="./torchtitan/models/deepseek_v3/train_configs/debug_model.toml" ./run_train.sh --model.name deepseekv3_simple_fsdp --profiling.enable_profiling --parallelism.expert_parallel_degree 2 --training.compile
(2) old tlparse showed that there are no
aten._grouped_mm
calls in the backward graph, showing that we are not properly differentiating the MoE code (tlparse)if you look at the dynamo graph in that tlparse, though, you'll see nodes for
_c10d_functional.all_to_all_single
and_c10d_functional.wait_tensor
. This is a problem - the dynamo graph should be capturing the entire autograd.Function as a HOP, since those two ops are not differentiable.(3) I didn't root cause why dynamo is "ignoring" the
autograd.Function
. I have some suspicion about the fact that the autograd.Function in question accepts aProcessGroup
.Instead, I just (a) wrote a slightly different version of the autograd.Function that doesn't accept ProcessGroup, and (b) allow-in-graph'd it for good measure, to guarantee that dynamo won't incorrectly inline it.
As a followup, we should either debug why dynamo is not constructing a HOP for the autograd.Function, or kill the _A2A.apply code entirely as per this comment
Here's a good tlparse with my changes, where you can see proper
aten._grouped_mm
nodes in the backward graph: https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/hirsheybar/9b03e768-73a1-4154-b7af-dcd79cfc754d/custom/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000Stack from ghstack (oldest at bottom):