Skip to content

Add C++ function for torch.distributed.tensor._op_schema.is_view_op#161595

Closed
swolchok wants to merge 6 commits intogh/swolchok/814/basefrom
gh/swolchok/814/head
Closed

Add C++ function for torch.distributed.tensor._op_schema.is_view_op#161595
swolchok wants to merge 6 commits intogh/swolchok/814/basefrom
gh/swolchok/814/head

Conversation

@swolchok
Copy link
Copy Markdown
Contributor

@swolchok swolchok commented Aug 27, 2025

Stack from ghstack (oldest at bottom):

This seems to have been an especially slow one because of the repeated pybind access (schema is a pybind, as is arguments, and then we hit each argument). It's still ~~1% of total benchmark runtime because of the repeated single pybind function call, but that's a lot better.

Differential Revision: D81530095

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @ezyang @msaroufim @EikanWang @jgong5 @wenzhe-nrv @sanchitintel

This seems to have been an especially slow one because of the repeated pybind access (schema is a pybind, as is arguments, and then we hit each argument). It's still ~~1% of total benchmark runtime because of the repeated single pybind function call, but that's a lot better.

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Aug 27, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/161595

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 90190d0 with merge base dcf3853 (image):

BROKEN TRUNK - The following jobs 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.

@pytorch-bot pytorch-bot Bot added ciflow/inductor oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: jit release notes category labels Aug 27, 2025
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 27, 2025
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
These seem to have been costing us 5-10 usec per detach (out of ~~95 usec total).  If they need to ship let's talk about requirements and how we can make this more efficient given that we would prefer if an entire DTensor op could finish in 10 usec.

Differential Revision: [D81530106](https://our.internmc.facebook.com/intern/diff/D81530106)
Pull Request resolved: pytorch#161596
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
…162337)

We control DTensor, so we can just guarantee there isn't a programming error with __torch_dispatch__. (The guard is already less-than-perfect; see the note that the deleted comment refers to.)
Pull Request resolved: pytorch#162337
Approved by: https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218, pytorch#161596
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
…ytorch#161595)

This seems to have been an especially slow one because of the repeated pybind access (schema is a pybind, as is arguments, and then we hit each argument). It's still ~~1% of total benchmark runtime because of the repeated single pybind function call, but that's a lot better.

Differential Revision: [D81530095](https://our.internmc.facebook.com/intern/diff/D81530095)

Pull Request resolved: pytorch#161595
Approved by: https://github.com/ezyang, https://github.com/bdhirsh
ghstack dependencies: pytorch#161466, pytorch#161586, pytorch#161590, pytorch#161591
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
…ytorch#161633)

py::args::size() calls PyTuple_GetSize. Compiler can't know the two calls will always return the same result, so we have to consolidate them ourselves.

Differential Revision: [D81530096](https://our.internmc.facebook.com/intern/diff/D81530096)

Pull Request resolved: pytorch#161633
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
It is cheap to do an exact check against Tensor and much faster when it works (PyType_IsSubtype does not have this fastpath, I checked [source](https://github.com/python/cpython/blob/9ee0214b5dd982ac9fbe18dcce0e8787456e29af/Objects/typeobject.c#L2889)). Spot-checked in perf on detach-DTensor-in-a-loop benchmark; small win but clear.

Differential Revision: [D81530101](https://our.internmc.facebook.com/intern/diff/D81530101)
Pull Request resolved: pytorch#161634
Approved by: https://github.com/Skylion007, https://github.com/albanD
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Calling this first minimizes overhead for plain old ints, making cheap things cheap.

Differential Revision: [D81530098](https://our.internmc.facebook.com/intern/diff/D81530098)
Pull Request resolved: pytorch#161692
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Optimize for common case and remove a pair of refcount operations (see new comments.)

Pull Request resolved: pytorch#162220
Approved by: https://github.com/jansel, https://github.com/williamwen42
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
These seem to have been costing us 5-10 usec per detach (out of ~~95 usec total).  If they need to ship let's talk about requirements and how we can make this more efficient given that we would prefer if an entire DTensor op could finish in 10 usec.

Differential Revision: [D81530106](https://our.internmc.facebook.com/intern/diff/D81530106)
Pull Request resolved: pytorch#161596
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
…162337)

We control DTensor, so we can just guarantee there isn't a programming error with __torch_dispatch__. (The guard is already less-than-perfect; see the note that the deleted comment refers to.)
Pull Request resolved: pytorch#162337
Approved by: https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218, pytorch#161596
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
…ytorch#161595)

This seems to have been an especially slow one because of the repeated pybind access (schema is a pybind, as is arguments, and then we hit each argument). It's still ~~1% of total benchmark runtime because of the repeated single pybind function call, but that's a lot better.

Differential Revision: [D81530095](https://our.internmc.facebook.com/intern/diff/D81530095)

Pull Request resolved: pytorch#161595
Approved by: https://github.com/ezyang, https://github.com/bdhirsh
ghstack dependencies: pytorch#161466, pytorch#161586, pytorch#161590, pytorch#161591
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
…ytorch#161633)

py::args::size() calls PyTuple_GetSize. Compiler can't know the two calls will always return the same result, so we have to consolidate them ourselves.

Differential Revision: [D81530096](https://our.internmc.facebook.com/intern/diff/D81530096)

Pull Request resolved: pytorch#161633
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
It is cheap to do an exact check against Tensor and much faster when it works (PyType_IsSubtype does not have this fastpath, I checked [source](https://github.com/python/cpython/blob/9ee0214b5dd982ac9fbe18dcce0e8787456e29af/Objects/typeobject.c#L2889)). Spot-checked in perf on detach-DTensor-in-a-loop benchmark; small win but clear.

Differential Revision: [D81530101](https://our.internmc.facebook.com/intern/diff/D81530101)
Pull Request resolved: pytorch#161634
Approved by: https://github.com/Skylion007, https://github.com/albanD
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Calling this first minimizes overhead for plain old ints, making cheap things cheap.

Differential Revision: [D81530098](https://our.internmc.facebook.com/intern/diff/D81530098)
Pull Request resolved: pytorch#161692
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Optimize for common case and remove a pair of refcount operations (see new comments.)

Pull Request resolved: pytorch#162220
Approved by: https://github.com/jansel, https://github.com/williamwen42
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
These seem to have been costing us 5-10 usec per detach (out of ~~95 usec total).  If they need to ship let's talk about requirements and how we can make this more efficient given that we would prefer if an entire DTensor op could finish in 10 usec.

Differential Revision: [D81530106](https://our.internmc.facebook.com/intern/diff/D81530106)
Pull Request resolved: pytorch#161596
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
…162337)

We control DTensor, so we can just guarantee there isn't a programming error with __torch_dispatch__. (The guard is already less-than-perfect; see the note that the deleted comment refers to.)
Pull Request resolved: pytorch#162337
Approved by: https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218, pytorch#161596
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
…ytorch#161595)

This seems to have been an especially slow one because of the repeated pybind access (schema is a pybind, as is arguments, and then we hit each argument). It's still ~~1% of total benchmark runtime because of the repeated single pybind function call, but that's a lot better.

Differential Revision: [D81530095](https://our.internmc.facebook.com/intern/diff/D81530095)

Pull Request resolved: pytorch#161595
Approved by: https://github.com/ezyang, https://github.com/bdhirsh
ghstack dependencies: pytorch#161466, pytorch#161586, pytorch#161590, pytorch#161591
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
…ytorch#161633)

py::args::size() calls PyTuple_GetSize. Compiler can't know the two calls will always return the same result, so we have to consolidate them ourselves.

Differential Revision: [D81530096](https://our.internmc.facebook.com/intern/diff/D81530096)

Pull Request resolved: pytorch#161633
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
It is cheap to do an exact check against Tensor and much faster when it works (PyType_IsSubtype does not have this fastpath, I checked [source](https://github.com/python/cpython/blob/9ee0214b5dd982ac9fbe18dcce0e8787456e29af/Objects/typeobject.c#L2889)). Spot-checked in perf on detach-DTensor-in-a-loop benchmark; small win but clear.

Differential Revision: [D81530101](https://our.internmc.facebook.com/intern/diff/D81530101)
Pull Request resolved: pytorch#161634
Approved by: https://github.com/Skylion007, https://github.com/albanD
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Calling this first minimizes overhead for plain old ints, making cheap things cheap.

Differential Revision: [D81530098](https://our.internmc.facebook.com/intern/diff/D81530098)
Pull Request resolved: pytorch#161692
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Optimize for common case and remove a pair of refcount operations (see new comments.)

Pull Request resolved: pytorch#162220
Approved by: https://github.com/jansel, https://github.com/williamwen42
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
These seem to have been costing us 5-10 usec per detach (out of ~~95 usec total).  If they need to ship let's talk about requirements and how we can make this more efficient given that we would prefer if an entire DTensor op could finish in 10 usec.

Differential Revision: [D81530106](https://our.internmc.facebook.com/intern/diff/D81530106)
Pull Request resolved: pytorch#161596
Approved by: https://github.com/ezyang, https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
…162337)

We control DTensor, so we can just guarantee there isn't a programming error with __torch_dispatch__. (The guard is already less-than-perfect; see the note that the deleted comment refers to.)
Pull Request resolved: pytorch#162337
Approved by: https://github.com/Skylion007
ghstack dependencies: pytorch#161591, pytorch#161595, pytorch#161633, pytorch#161634, pytorch#161692, pytorch#162219, pytorch#162220, pytorch#162218, pytorch#161596
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged oncall: distributed Add this issue/PR to distributed oncall triage queue oncall: jit Add this issue/PR to JIT oncall triage queue release notes: jit release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants