Repository navigation
[inductor] Cache optimization_hint across lowering - #192817
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/192817
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit ddac2ab with merge base 2760264 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 10, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
eellison
approved these changes
Aug 11, 2026
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 |
pytorchmergebot
pushed a commit
that referenced
this pull request
Aug 11, 2026
…ch cache hit (#192821) When the fake tensor dispatch cache hits for a view op, the output is synthesized by allocating a meta tensor with empty_strided and then calling set_ on it to point at the input's storage. set_ overwrites the size, stride and storage that empty_strided just established, so on symbolic shapes we pay twice for the part that dominates both calls: deriving the storage size and the contiguity flags from symbolic sizes and strides, which calls back into Python for every SymInt add, mul and comparison. Allocate the placeholder with an empty size and stride when the op is a view, and let set_ install the real ones. Measured on a FairChem UMA compile, where 7288 of 16551 cache hits are views: empty_strided in the cache hit path 192us/call, 3.19s total set_ in the cache hit path 283us/call, 2.06s total Interleaved cold compile runs: 53.93s -> 52.43s. Test Plan: ``` python test/test_fake_tensor.py ``` Failure set identical to baseline (4 pre-existing cudnn RNN errors). Also exercised the view synthesis path end to end under both dynamic=True and dynamic=False with view/permute/T/slice/expand/as_strided plus backward: ``` python -c "... torch.compile(f, dynamic=dyn) over view, permute, .T, x[1:], expand, as_strided ..." ``` This PR was authored with the assistance of an AI coding agent. Pull Request resolved: #192821 Approved by: https://github.com/zou3519 ghstack dependencies: #192817
ankitbhrdwj
pushed a commit
to ankitbhrdwj/pytorch
that referenced
this pull request
Aug 12, 2026
SizeVarAllocator.optimization_hint is asked for the same expression over and over while lowering: on FairChem UMA, 75784 calls over 388 distinct expressions, with one expression accounting for 18917 of them. Each miss runs sympy substitution plus the unbacked-hint heuristics, none of which sympy caches internally. Route it through the existing _lru_cache helper, which already backs stride_vars and simplify_with_ranges and drops the cache whenever replacements change. Measured on UMA, interleaved runs: cold compile 55.32s -> 54.36s. Test Plan: ``` python test/inductor/test_torchinductor.py python test/inductor/test_torchinductor_dynamic_shapes.py ``` Failure sets unchanged. The cache was also checked by computing both the cached and uncached value on every call for a full compile: 43906 comparisons, 0 mismatches. I also tried caching SizeVarAllocator.simplify, which looked more promising still (149938 calls over 1396 distinct expressions) but measured slower: it is sympy.expand plus xreplace, and sympy already memoizes expand, so an lru_cache only adds hashing of large expressions on top. Not included. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#192817 Approved by: https://github.com/eellison
ankitbhrdwj
pushed a commit
to ankitbhrdwj/pytorch
that referenced
this pull request
Aug 12, 2026
…ch cache hit (pytorch#192821) When the fake tensor dispatch cache hits for a view op, the output is synthesized by allocating a meta tensor with empty_strided and then calling set_ on it to point at the input's storage. set_ overwrites the size, stride and storage that empty_strided just established, so on symbolic shapes we pay twice for the part that dominates both calls: deriving the storage size and the contiguity flags from symbolic sizes and strides, which calls back into Python for every SymInt add, mul and comparison. Allocate the placeholder with an empty size and stride when the op is a view, and let set_ install the real ones. Measured on a FairChem UMA compile, where 7288 of 16551 cache hits are views: empty_strided in the cache hit path 192us/call, 3.19s total set_ in the cache hit path 283us/call, 2.06s total Interleaved cold compile runs: 53.93s -> 52.43s. Test Plan: ``` python test/test_fake_tensor.py ``` Failure set identical to baseline (4 pre-existing cudnn RNN errors). Also exercised the view synthesis path end to end under both dynamic=True and dynamic=False with view/permute/T/slice/expand/as_strided plus backward: ``` python -c "... torch.compile(f, dynamic=dyn) over view, permute, .T, x[1:], expand, as_strided ..." ``` This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#192821 Approved by: https://github.com/zou3519 ghstack dependencies: pytorch#192817
gavinwang269
pushed a commit
to gavinwang269/pytorch
that referenced
this pull request
Aug 13, 2026
SizeVarAllocator.optimization_hint is asked for the same expression over and over while lowering: on FairChem UMA, 75784 calls over 388 distinct expressions, with one expression accounting for 18917 of them. Each miss runs sympy substitution plus the unbacked-hint heuristics, none of which sympy caches internally. Route it through the existing _lru_cache helper, which already backs stride_vars and simplify_with_ranges and drops the cache whenever replacements change. Measured on UMA, interleaved runs: cold compile 55.32s -> 54.36s. Test Plan: ``` python test/inductor/test_torchinductor.py python test/inductor/test_torchinductor_dynamic_shapes.py ``` Failure sets unchanged. The cache was also checked by computing both the cached and uncached value on every call for a full compile: 43906 comparisons, 0 mismatches. I also tried caching SizeVarAllocator.simplify, which looked more promising still (149938 calls over 1396 distinct expressions) but measured slower: it is sympy.expand plus xreplace, and sympy already memoizes expand, so an lru_cache only adds hashing of large expressions on top. Not included. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#192817 Approved by: https://github.com/eellison
gavinwang269
pushed a commit
to gavinwang269/pytorch
that referenced
this pull request
Aug 13, 2026
…ch cache hit (pytorch#192821) When the fake tensor dispatch cache hits for a view op, the output is synthesized by allocating a meta tensor with empty_strided and then calling set_ on it to point at the input's storage. set_ overwrites the size, stride and storage that empty_strided just established, so on symbolic shapes we pay twice for the part that dominates both calls: deriving the storage size and the contiguity flags from symbolic sizes and strides, which calls back into Python for every SymInt add, mul and comparison. Allocate the placeholder with an empty size and stride when the op is a view, and let set_ install the real ones. Measured on a FairChem UMA compile, where 7288 of 16551 cache hits are views: empty_strided in the cache hit path 192us/call, 3.19s total set_ in the cache hit path 283us/call, 2.06s total Interleaved cold compile runs: 53.93s -> 52.43s. Test Plan: ``` python test/test_fake_tensor.py ``` Failure set identical to baseline (4 pre-existing cudnn RNN errors). Also exercised the view synthesis path end to end under both dynamic=True and dynamic=False with view/permute/T/slice/expand/as_strided plus backward: ``` python -c "... torch.compile(f, dynamic=dyn) over view, permute, .T, x[1:], expand, as_strided ..." ``` This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#192821 Approved by: https://github.com/zou3519 ghstack dependencies: pytorch#192817
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):
SizeVarAllocator.optimization_hint is asked for the same expression over and
over while lowering: on FairChem UMA, 75784 calls over 388 distinct
expressions, with one expression accounting for 18917 of them. Each miss runs
sympy substitution plus the unbacked-hint heuristics, none of which sympy
caches internally.
Route it through the existing _lru_cache helper, which already backs
stride_vars and simplify_with_ranges and drops the cache whenever replacements
change.
Measured on UMA, interleaved runs: cold compile 55.32s -> 54.36s.
Test Plan:
Failure sets unchanged. The cache was also checked by computing both the cached
and uncached value on every call for a full compile: 43906 comparisons, 0
mismatches.
I also tried caching SizeVarAllocator.simplify, which looked more promising
still (149938 calls over 1396 distinct expressions) but measured slower: it is
sympy.expand plus xreplace, and sympy already memoizes expand, so an lru_cache
only adds hashing of large expressions on top. Not included.
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