add slow path for is_contiguous#77396
add slow path for is_contiguous#77396george-qi wants to merge 9 commits intogh/george-qi/33/basefrom
Conversation
[ghstack-poisoned]
🔗 Helpful links
✅ No Failures (50 Pending)As of commit 3d103ba (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. |
|
Looking over the implementation it looks like my outline was incomplete (also the outline predates policy consolidation), so there are a few more things to hit.
This also leaves me a question which is whether or not this is the best implementation strategy. An alternative implementation strategy would have been to add but have a test for "is Python subclass" here. But there are benefits to the approach in this PR: it is faster for the common case (since we only do one branch, not two) and it avoids having to deal with TorchScript related fallout from them having defined |
Implementation is done by roughly following the template from [Issue 65423](#65423) - Adding an argument `uses_python_dispatch` (defaulted to False) to `_make_subclass` and `_make_wrapper_subclass` - If True, then I'll `set_python_dispatch(true)` and set `sizes_strides_policy_` to `SizesStridesPolicy::CustomStrides` - In `is_contiguous`, if both of the above are true, then I'll call the new method on PyInterpreter This should avoid slowing down the fast path of `is_contiguous`. I don't have a ton of context around `python_dispatch`, so please let me know if this is the intended use. The other way I imagined doing this is adding another enum to `SizesStridesPolicy`, like `PythonCustomStrides`, and then instead of checking both `is_python_dispatch()` and `sizes_strides_policy_ >= SizesStridesPolicy::CustomStrides`, I would just check `sizes_strides_policy_ == SizesStridesPolicy::PythonCustomStrides` [ghstack-poisoned]
Implementation is done by roughly following the template from [Issue 65423](#65423) - Adding an argument `uses_python_dispatch` (defaulted to False) to `_make_subclass` and `_make_wrapper_subclass` - If True, then I'll `set_python_dispatch(true)` and set `sizes_strides_policy_` to `SizesStridesPolicy::CustomStrides` - In `is_contiguous`, if both of the above are true, then I'll call the new method on PyInterpreter This should avoid slowing down the fast path of `is_contiguous`. I don't have a ton of context around `python_dispatch`, so please let me know if this is the intended use. The other way I imagined doing this is adding another enum to `SizesStridesPolicy`, like `PythonCustomStrides`, and then instead of checking both `is_python_dispatch()` and `sizes_strides_policy_ >= SizesStridesPolicy::CustomStrides`, I would just check `sizes_strides_policy_ == SizesStridesPolicy::PythonCustomStrides` [ghstack-poisoned]
|
Thanks for the review and discussion in the meeting, super helpful!
As discussed in the meeting, I'm currently limiting this diff to
Good call, and as you point out, for us, not having the underlying strides field is indeed okay for us
Thanks for the explanation and the learnings :) After a quick discussion with Christian, I've changed it the minimal change -- that is, putting it in the virtual method and leaving this up to the devs of tensor subclasses to add the Python dispatch if they'd like. Please let me know if there are any other outstanding things! |
Implementation is done by roughly following the template from [Issue 65423](#65423) - Adding an argument `uses_python_dispatch` (defaulted to False) to `_make_subclass` and `_make_wrapper_subclass` - If True, then I'll `set_python_dispatch(true)` and set `sizes_strides_policy_` to `SizesStridesPolicy::CustomStrides` - In `is_contiguous`, if both of the above are true, then I'll call the new method on PyInterpreter This should avoid slowing down the fast path of `is_contiguous`. I don't have a ton of context around `python_dispatch`, so please let me know if this is the intended use. The other way I imagined doing this is adding another enum to `SizesStridesPolicy`, like `PythonCustomStrides`, and then instead of checking both `is_python_dispatch()` and `sizes_strides_policy_ >= SizesStridesPolicy::CustomStrides`, I would just check `sizes_strides_policy_ == SizesStridesPolicy::PythonCustomStrides` [ghstack-poisoned]
Implementation is done by roughly following the template from [Issue 65423](#65423) - Adding an argument `uses_python_dispatch` (defaulted to False) to `_make_subclass` and `_make_wrapper_subclass` - If True, then I'll `set_python_dispatch(true)` and set `sizes_strides_policy_` to `SizesStridesPolicy::CustomStrides` - In `is_contiguous`, if both of the above are true, then I'll call the new method on PyInterpreter This should avoid slowing down the fast path of `is_contiguous`. I don't have a ton of context around `python_dispatch`, so please let me know if this is the intended use. The other way I imagined doing this is adding another enum to `SizesStridesPolicy`, like `PythonCustomStrides`, and then instead of checking both `is_python_dispatch()` and `sizes_strides_policy_ >= SizesStridesPolicy::CustomStrides`, I would just check `sizes_strides_policy_ == SizesStridesPolicy::PythonCustomStrides` [ghstack-poisoned]
This reverts commit f6beda8. Reverted #77396 on behalf of https://github.com/malfet
|
By the way, look like this should have been marked as BC breaking? |
I don't think so, torchdistx is using private APIs. So this is not BC breaking. |
Hmm, are all APIs in C10 consider to be private? |
|
@george-qi has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
That's a good question. At least our FC/BC guarantees don't apply to them. Just like we're "breaking" aten APIs all the time without warnings. |
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). [ghstack-poisoned]
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). [ghstack-poisoned]
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). [ghstack-poisoned]
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). [ghstack-poisoned]
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). [ghstack-poisoned]
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). Differential Revision: [D36618465](https://our.internmc.facebook.com/intern/diff/D36618465) [ghstack-poisoned]
Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). Differential Revision: [D36618465](https://our.internmc.facebook.com/intern/diff/D36618465) [ghstack-poisoned]
Summary: Pull Request resolved: #77684 Similar to #77396, add a way to override `device` on Tensor Subclasses by adding a bit to call into a custom, virtual `device` function. This is necessary to allow extending devices with a `meta` device to also carry along a device so as to compute device propagation in addition to other properties (FakeTensors). Test Plan: Imported from OSS Reviewed By: Chillee Differential Revision: D36618465 Pulled By: eellison fbshipit-source-id: b9dcf480b9e78cbe46c776f1244e7259d871b379
This follows the template in #77396 [ghstack-poisoned]
This follows the template in #77396 [ghstack-poisoned]
This follows the template in #77396 [ghstack-poisoned]
This follows the template in #77396 Pull Request resolved: #78691 Approved by: https://github.com/ezyang
Summary: This follows the template in #77396 Pull Request resolved: #78691 Approved by: https://github.com/ezyang Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/22b10873f375cb0d582f4567525238f716c430ca Reviewed By: malfet, b0noI Differential Revision: D36882361 fbshipit-source-id: 67b95f50c40b09514d958526bc6126d314cce7c5
Stack from ghstack:
Implementation is done by roughly following the template from Issue 65423
uses_python_dispatch(defaulted to False) to_make_subclassand_make_wrapper_subclassset_python_dispatch(true)and setsizes_strides_policy_toSizesStridesPolicy::CustomStridesis_contiguous, if both of the above are true, then I'll call the new method on PyInterpreterThis should avoid slowing down the fast path of
is_contiguous.I don't have a ton of context around
python_dispatch, so please let me know if this is the intended use. The other way I imagined doing this is adding another enum toSizesStridesPolicy, likePythonCustomStrides, and then instead of checking bothis_python_dispatch()andsizes_strides_policy_ >= SizesStridesPolicy::CustomStrides, I would just checksizes_strides_policy_ == SizesStridesPolicy::PythonCustomStridesDifferential Revision: D36527481