-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add a miniature backend select implementation for prims #82311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It turns out that for factory function prims (prims with no Tensor arguments), we were always going to the ATen implementation of the operator. Prior to the next PR in this stack, the change is a bit hard to test, but you can indirectly observe the impact by running arange with trace dispatching on (well, you need #82277 patched in too.) ``` $ TORCH_SHOW_DISPATCH_TRACE=1 python -c "import torch._refs; torch._refs.arange(4, device='meta')" [callBoxed] op=[prims::arange], key=[BackendSelect] [call] op=[aten::empty_strided], key=[BackendSelect] [redispatch] op=[aten::empty_strided], key=[Meta] ``` Previously, the prims::arange call was dispatching to Undefined. For maximum fidelity, technically we're supposed to redispatch to a specific dispatch key, but the Python bindings to do this don't exist and it was easy to route to the implementations which we already intended to go to. We would have to fix this if we wanted external backends to register custom implementations to OTHER dispatch keys via Python op registration. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
🔗 Helpful links
✅ No Failures (0 Pending)As of commit 59d859c (more details on the Dr. CI page): Expand to see more💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
It turns out that for factory function prims (prims with no Tensor arguments), we were always going to the ATen implementation of the operator. Prior to the next PR in this stack, the change is a bit hard to test, but you can indirectly observe the impact by running arange with trace dispatching on (well, you need #82277 patched in too.) ``` $ TORCH_SHOW_DISPATCH_TRACE=1 python -c "import torch._refs; torch._refs.arange(4, device='meta')" [callBoxed] op=[prims::arange], key=[BackendSelect] [call] op=[aten::empty_strided], key=[BackendSelect] [redispatch] op=[aten::empty_strided], key=[Meta] ``` Previously, the prims::arange call was dispatching to Undefined. For maximum fidelity, technically we're supposed to redispatch to a specific dispatch key, but the Python bindings to do this don't exist and it was easy to route to the implementations which we already intended to go to. We would have to fix this if we wanted external backends to register custom implementations to OTHER dispatch keys via Python op registration. Signed-off-by: Edward Z. Yang <ezyangfb.com> [ghstack-poisoned]
|
|
||
| from torch._subclasses.fake_tensor import contains_tensor_types | ||
|
|
||
| if not any(contains_tensor_types(a.type) for a in _prim._schema.arguments): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this map 1-to-1 with the logic that codegen uses to determine when to generate backend select kernels?
Line 859 in 1231194
| def needs_backend_select(f: NativeFunction, selector: SelectiveBuilder) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hypothetically yes, but prims are simpler than native_functions.yaml so I guessed a simplified version would work.
|
@pytorchbot merge |
|
@pytorchbot successfully started a merge job. Check the current status here |
|
Hey @ezyang. |
) Summary: It turns out that for factory function prims (prims with no Tensor arguments), we were always going to the ATen implementation of the operator. Prior to the next PR in this stack, the change is a bit hard to test, but you can indirectly observe the impact by running arange with trace dispatching on (well, you need #82277 patched in too.) ``` $ TORCH_SHOW_DISPATCH_TRACE=1 python -c "import torch._refs; torch._refs.arange(4, device='meta')" [callBoxed] op=[prims::arange], key=[BackendSelect] [call] op=[aten::empty_strided], key=[BackendSelect] [redispatch] op=[aten::empty_strided], key=[Meta] ``` Previously, the prims::arange call was dispatching to Undefined. For maximum fidelity, technically we're supposed to redispatch to a specific dispatch key, but the Python bindings to do this don't exist and it was easy to route to the implementations which we already intended to go to. We would have to fix this if we wanted external backends to register custom implementations to OTHER dispatch keys via Python op registration. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Pull Request resolved: #82311 Approved by: https://github.com/ngimel, https://github.com/bdhirsh Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/3b6b27e9d7ad3951b23364f31c19b1d3ebbeaf7c Reviewed By: osalpekar Differential Revision: D38234285 Pulled By: ezyang fbshipit-source-id: e73b770529d3e221dd85f8c7b1607da975d1f211
Stack from ghstack (oldest at bottom):
It turns out that for factory function prims (prims with no Tensor
arguments), we were always going to the ATen implementation of
the operator.
Prior to the next PR in this stack, the change is a bit hard to
test, but you can indirectly observe the impact by running arange
with trace dispatching on (well, you need
#82277 patched in too.)
Previously, the prims::arange call was dispatching to Undefined.
For maximum fidelity, technically we're supposed to redispatch to a
specific dispatch key, but the Python bindings to do this don't exist
and it was easy to route to the implementations which we already
intended to go to. We would have to fix this if we wanted external
backends to register custom implementations to OTHER dispatch keys
via Python op registration.
Signed-off-by: Edward Z. Yang ezyang@fb.com