Repository navigation
[dynamo] Reuse the stack trace when consecutive fx nodes share one - #193764
anijain2305 wants to merge 9 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193764
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated Failure, 1 Unclassified FailureAs of commit 6ad8871 with merge base 6a0eb75 ( NEW FAILURE - The following job has failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Stack from ghstack (oldest at bottom):
Every fx node records the user stack that produced it, and producing it is not
cheap: a FrameSummary per frame on the tracing stack, then StackSummary.format(),
which reads the source line and works out the 3.11+ anchor columns for each one.
That is roughly ten frames for every node created.
Almost all of that is repeated. A transformer traces the same lines once per
layer, so the same stack recurs constantly - on a Qwen3-8B prefill trace, 4837
nodes produce far fewer distinct stacks, and 48k FrameSummary objects get built
and formatted to say the same handful of things.
Key on what the answer actually depends on - the frames' (file, line, name,
columns) - and build the string only when it is new. The key is read straight off
the tracing stack, so a hit skips constructing the FrameSummary objects as well
as formatting them. The cache lives on the SubgraphTracer, so it lasts exactly as
long as the graph being built.
Also hoists the torch/nn/modules regex in is_co_filename_from_nn_modules out of
the function; it was recompiled on every frame of every node.
Dynamo tracing on that model goes from 5.30s to 5.01s, and time attributed to
create_proxy from 0.72s to 0.44s.
Test plan:
865 tests, OK. Separately checked that the stack traces themselves do not
change: traced a small module with nested calls and a dynamic dimension, dumped
node.stack_trace for all 43 nodes with and without this change, and compared -
byte identical.
This PR was authored with the assistance of an AI coding agent.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98