Repository navigation
[fake tensor] Don't derive a view's size and stride twice on a dispatch cache hit - #192821
anijain2305 wants to merge 5 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192821
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit be908cd with merge base 2760264 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
…ch cache hit 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. ghstack-source-id: 7895de1 Pull-Request: #192821
[ghstack-poisoned]
…ch cache hit 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. ghstack-source-id: 5241fd2 Pull-Request: #192821
…ch cache hit 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. ghstack-source-id: 5241fd2 Pull-Request: #192821
…ch cache hit 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. ghstack-source-id: 5241fd2 Pull-Request: #192821
|
@claude review this PR and explain how it reduces the compile time |
|
Claude finished @anijain2305's task in 29m 44s —— View job Reviewed — LGTM. The change removes a redundant symbolic-shape derivation on the view cache-hit path; my only ask is a regression test that actually covers view synthesis under a
|
[ghstack-poisoned]
…ch cache hit 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. ghstack-source-id: 26842ad Pull-Request: #192821
…ch cache hit 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. ghstack-source-id: 26842ad Pull-Request: #192821
…ch cache hit 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. ghstack-source-id: 4d5f387 Pull-Request: #192821
|
@pytorchbot merge |
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 |
…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
…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
Stack from ghstack (oldest at bottom):
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:
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:
This PR was authored with the assistance of an AI coding agent.