Repository navigation
[inductor] Reuse formatted origin nodes across kernel comments - #194010
Closed
anijain2305 wants to merge 7 commits into
Closed
anijain2305 wants to merge 7 commits into
anijain2305 wants to merge 7 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194010
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 2fb5e88 with merge base 9ebc67a ( 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 was referenced Aug 17, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
eellison
approved these changes
Aug 28, 2026
[ghstack-poisoned]
anijain2305
added a commit
that referenced
this pull request
Aug 28, 2026
Every generated kernel carries a comment naming the graph fragment it came from, and building it re-formats each of the kernel's origin nodes with Node.format_node(include_tensor_metadata=True). The same node is an origin of many kernels, so on a large graph this rebuilds the same strings over and over: 258k format_node calls to emit comments for 1266 kernels on one production model, which cProfile puts at a larger share of compile time than GraphLowering.run. The graph is fully built by the time we are emitting code, so a node's formatting cannot change. Cache the split lines on the graph, exactly as the topological index map a few lines above already does, so the lifetime is the graph's. Also memoize str(op._overloadpacket), which was called once per node per kernel - 271k times - on singleton op objects. Cold compile of a reduced training replay of model3 goes from 47.3s to 43.5s (median of three). Test plan: ``` python test/inductor/test_torchinductor.py -k GPU python test/inductor/test_provenance_tracing.py ``` The thing to establish is that the comments do not change, and the generated code cannot be diffed directly: two runs of unmodified code differ by 656 lines because the repro feeds random data and node numbering shifts. So the cache was checked from the inside instead - recompute on every hit and assert the cached lines match - and a full compile of that model passed with zero mismatches across all ~258k lookups. This PR was authored with the assistance of an AI coding agent. ghstack-source-id: efd1fe8 Pull-Request: #194010
anijain2305
added a commit
that referenced
this pull request
Aug 28, 2026
Every generated kernel carries a comment naming the graph fragment it came from, and building it re-formats each of the kernel's origin nodes with Node.format_node(include_tensor_metadata=True). The same node is an origin of many kernels, so on a large graph this rebuilds the same strings over and over: 258k format_node calls to emit comments for 1266 kernels on one production model, which cProfile puts at a larger share of compile time than GraphLowering.run. The graph is fully built by the time we are emitting code, so a node's formatting cannot change. Cache the split lines on the graph, exactly as the topological index map a few lines above already does, so the lifetime is the graph's. Also memoize str(op._overloadpacket), which was called once per node per kernel - 271k times - on singleton op objects. Cold compile of a reduced training replay of model3 goes from 47.3s to 43.5s (median of three). Test plan: ``` python test/inductor/test_torchinductor.py -k GPU python test/inductor/test_provenance_tracing.py ``` The thing to establish is that the comments do not change, and the generated code cannot be diffed directly: two runs of unmodified code differ by 656 lines because the repro feeds random data and node numbering shifts. So the cache was checked from the inside instead - recompute on every hit and assert the cached lines match - and a full compile of that model passed with zero mismatches across all ~258k lookups. This PR was authored with the assistance of an AI coding agent. ghstack-source-id: efd1fe8 Pull-Request: #194010
Contributor
Author
|
@pytorchbot merge |
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
orrangetabby17
pushed a commit
to orrangetabby17/pytorch
that referenced
this pull request
Sep 2, 2026
…ch#194010) Every generated kernel carries a comment naming the graph fragment it came from, and building it re-formats each of the kernel's origin nodes with Node.format_node(include_tensor_metadata=True). The same node is an origin of many kernels, so on a large graph this rebuilds the same strings over and over: 258k format_node calls to emit comments for 1266 kernels on one production model, which cProfile puts at a larger share of compile time than GraphLowering.run. The graph is fully built by the time we are emitting code, so a node's formatting cannot change. Cache the split lines on the graph, exactly as the topological index map a few lines above already does, so the lifetime is the graph's. Also memoize str(op._overloadpacket), which was called once per node per kernel - 271k times - on singleton op objects. Cold compile of a reduced training replay of model3 goes from 47.3s to 43.5s (median of three). Test plan: ``` python test/inductor/test_torchinductor.py -k GPU python test/inductor/test_provenance_tracing.py ``` The thing to establish is that the comments do not change, and the generated code cannot be diffed directly: two runs of unmodified code differ by 656 lines because the repro feeds random data and node numbering shifts. So the cache was checked from the inside instead - recompute on every hit and assert the cached lines match - and a full compile of that model passed with zero mismatches across all ~258k lookups. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#194010 Approved by: https://github.com/eellison
Sanskaaar1
pushed a commit
to Sanskaaar1/pytorch
that referenced
this pull request
Sep 8, 2026
…ch#194010) Every generated kernel carries a comment naming the graph fragment it came from, and building it re-formats each of the kernel's origin nodes with Node.format_node(include_tensor_metadata=True). The same node is an origin of many kernels, so on a large graph this rebuilds the same strings over and over: 258k format_node calls to emit comments for 1266 kernels on one production model, which cProfile puts at a larger share of compile time than GraphLowering.run. The graph is fully built by the time we are emitting code, so a node's formatting cannot change. Cache the split lines on the graph, exactly as the topological index map a few lines above already does, so the lifetime is the graph's. Also memoize str(op._overloadpacket), which was called once per node per kernel - 271k times - on singleton op objects. Cold compile of a reduced training replay of model3 goes from 47.3s to 43.5s (median of three). Test plan: ``` python test/inductor/test_torchinductor.py -k GPU python test/inductor/test_provenance_tracing.py ``` The thing to establish is that the comments do not change, and the generated code cannot be diffed directly: two runs of unmodified code differ by 656 lines because the repro feeds random data and node numbering shifts. So the cache was checked from the inside instead - recompute on every hit and assert the cached lines match - and a full compile of that model passed with zero mismatches across all ~258k lookups. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#194010 Approved by: https://github.com/eellison
pytorchmergebot
pushed a commit
that referenced
this pull request
Oct 14, 2026
https://www.internalfb.com/intern/paste/P2550697715/ #194010 memoized `str(op._overloadpacket)` in `get_kernel_metadata` with an `lru_cache` keyed on the `OpOverload`, assuming ops are singletons. They are not in `node.meta["original_aten"]`: FX copies that field with `copy.copy`, and `OpOverload` defines `__deepcopy__` but not `__copy__`, so every traced node carries its own copy of its op. The copies hash alike but compare unequal, so the cache fills with colliding keys and almost always misses. On a large training backward graph (1,544 kernels, up to 2,699 origin nodes per kernel) the cache recorded 2.53M misses and 18.8K hits, and `get_kernel_metadata` took 98s of a 293s cold compile. Computing the string directly costs about 0.25us; with this change the function takes 2.5s and the compile 201s. Pull Request resolved: #200953 Approved by: https://github.com/pytorchgreenlight
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):
Every generated kernel carries a comment naming the graph fragment it came
from, and building it re-formats each of the kernel's origin nodes with
Node.format_node(include_tensor_metadata=True). The same node is an origin of
many kernels, so on a large graph this rebuilds the same strings over and over:
258k format_node calls to emit comments for 1266 kernels on one production
model, which cProfile puts at a larger share of compile time than
GraphLowering.run.
The graph is fully built by the time we are emitting code, so a node's
formatting cannot change. Cache the split lines on the graph, exactly as the
topological index map a few lines above already does, so the lifetime is the
graph's. Also memoize str(op._overloadpacket), which was called once per node
per kernel - 271k times - on singleton op objects.
Cold compile of a reduced training replay of model3 goes from 47.3s to 43.5s
(median of three).
Test plan:
The thing to establish is that the comments do not change, and the generated
code cannot be diffed directly: two runs of unmodified code differ by 656 lines
because the repro feeds random data and node numbering shifts. So the cache was
checked from the inside instead - recompute on every hit and assert the cached
lines match - and a full compile of that model passed with zero mismatches
across all ~258k lookups.
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 @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo