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
Dispatch numpy.take_along_axis
to torch.take_along_dim
#108880
Dispatch numpy.take_along_axis
to torch.take_along_dim
#108880
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/108880
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 1173859 with merge base bde75eb (): UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ghstack-source-id: 30d64fd6c78488e5efa3abaae0f86e3a01a2a59b Pull Request resolved: #108880
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: 0cd0450ae03d96cd56b8fdc03ab68c2faba65748 Pull Request resolved: #108880
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: 034d7f244bf1f60d6e82946bfcf95ceb9af605d6 Pull Request resolved: #108880
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: 9a8119830a33f8f4a0747b59dfedc7fc0fa750cb Pull Request resolved: #108880
test/dynamo/test_misc.py
Outdated
torch.float32, | ||
requires_grad=False, | ||
include_0d=False, | ||
include_empty=False, |
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.
What's the issue with the empty one?
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.
It fails in a test case on test_misc.py
as the indices has dtype uint8_t
:
...
torch/_dynamo/utils.py:1339: in <lambda>
lambda: run_node(tx.output, node, args, kwargs, nnmodule)
torch/_dynamo/utils.py:1411: in run_node
raise RuntimeError(fn_str + str(e)).with_traceback(e.__traceback__) from e
torch/_dynamo/utils.py:1398: in run_node
return node.target(*args, **kwargs)
torch/_dynamo/utils.py:1699: in __call__
out = self.f(*args, **kwargs)
torch/_numpy/_normalizations.py:213: in wrapped
result = func(*args, **kwds)
torch/_numpy/_funcs_impl.py:889: in take_along_axis
return torch.take_along_dim(arr, indices, axis)
E torch._dynamo.exc.TorchRuntimeError: Failed running call_function <Wrapped function <original take_along_axis>>(*(FakeTensor(..., size=(s0,)), FakeTensor(..., size=(0,), dtype=torch.uint8), 0), **{}):
E torch.take_along_dim(): dtype of indices should be Long but got Byte
E
E from user code:
E File "/home/guilhermeleobas/git/pytorch/test/dynamo/test_misc.py", line 1283, in fn
E return np.take_along_axis(x, i, a)
E
E Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
E
E
E You can suppress this exception and fall back to eager by setting:
E import torch._dynamo
E torch._dynamo.config.suppress_errors = True
E
E
E To execute this test, run the following from the base repo dir:
E python test/dynamo/test_misc.py -k test_numpy_take_along_axis
E
E This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
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.
Makes sense. Actually, it may be best to use sample_inputs_take_along_dim
. Note that the order of the args for indices and dims is swapped wrt. gather.
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.
Are you ok if I skip the tests from sample_inputs_take_along_dim
that don't include dim
?
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.
What do you mean exactly?
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.
Sorry for not including more information in my previous comment. There are two tests that don't include the dim
argument in sample_inputs_take_along_dim
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.
Actually, Numpy also has this behaviour, so we should also implement it. Can you modify the decomposition accordingly?
Also, could you send a separate PR fixing the docs of this operation noting that dim
can also be None?
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: 94c656703ca0cd8ada89cc3e1f2c361a6301c60c Pull Request resolved: #108880
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: 051f2784b04dd91c5a01073393b027858d416c8c Pull Request resolved: #108880
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.
Just a small note, feel free to merge once you change the sampling function.
You can even clean-up the include_0d
and the include_empty
args for sample_inputs_gather
as these will not be used anywhere any more.
Feel free to merge once you change this. In a stack, if you call pytorchbot merge
on a given PR, it'll merge that PR and all the previous ones.
test/dynamo/test_misc.py
Outdated
torch.float32, | ||
requires_grad=False, | ||
include_0d=False, | ||
include_empty=False, |
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.
Makes sense. Actually, it may be best to use sample_inputs_take_along_dim
. Note that the order of the args for indices and dims is swapped wrt. gather.
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: a069ca22b64f1b560780680ce38ddd31d91a2ed7 Pull Request resolved: #108880
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: e9fab7e192d878647768f0caacefd7cf9d324224 Pull Request resolved: #108880
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
ghstack-source-id: 1574f0efaf181c9a903f47a5068744bb71cc5a48 Pull Request resolved: #108880
Also, note that you can even clean-up the include_0d and the include_empty args for sample_inputs_gather as these will not be used anywhere any more. |
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx chenyang78 aakhundov kadeng [ghstack-poisoned]
Pull Request resolved: #109120 Approved by: https://github.com/lezcano ghstack dependencies: #108879, #108880
Pull Request resolved: #109125 Approved by: https://github.com/lezcano ghstack dependencies: #108879, #108880, #109120
Stack from ghstack (oldest at bottom):
dim=None
case #109120numpy.take_along_axis
totorch.take_along_dim
#108880SymInt
support totorch.take_along_dim
#108879cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng