-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Add amax/amin #43092
Add amax/amin #43092
Conversation
💊 CI failures summary and remediationsAs of commit 422e870 (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages: pytorch_windows_vs2019_py36_cuda10.1_test2 (1/2)Step: "Attaching workspace" (full log | diagnosis details | 🔁 rerun)
|
Thinking seems good, but PRs introducing new functions typically do add the out variants and derivatives, and they should be straightforward to include. I do have a question, though: What's the difference between min_values (max_values) and amin (amax)? Should we leave min_values and max_values unchanged and deprecate them? |
Overall looking good but you need to update tensors.rst and torch.rst with the new doc entries. |
@mruberry Yes, I missed that point. Added now. |
@@ -336,6 +336,10 @@ Reduction Ops | |||
|
|||
argmax | |||
argmin | |||
amax | |||
amin | |||
max |
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.
This is a better place for max and min but would you please remove them from the "Comparison Ops," too, then? People should be using maximum and minimum, anyway, for comparisons.
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.
done
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.
One last nit about removing the redundant max and min torch.rst entries under Comparison Ops.
Other than that I am satisfied. Let's let @ngimel make her final determination, too.
torch/_torch_docs.py
Outdated
r""" | ||
amax(input, dim, keepdim=False, *, out=None) -> Tensor | ||
|
||
Returns the maximum value of each row of the :attr:`input` tensor in the given |
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.
Given that there are potentially multiple dimensions, it's slice
, not row
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.
fixed
torch/_torch_docs.py
Outdated
The difference between ``max``/``min`` and ``amax``/``amin`` is: | ||
1. ``amax``/``amin`` supports reducing on multiple dimensions, | ||
2. ``amax``/``amin`` does not return indices, | ||
3. ``amax``/``amin`` produces deterministic (sub)gradients unlike |
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.
max
and min
will produce deterministic (but different) gradients soon, so it makes sense to say that amax
evenly distributes gradient between equal values, while max
propagates gradient only to a single index in the source tensor.
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.
fixed
Just fixed the failures in doc build and doc test. |
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@zasdfgbnm Would you rebase this? |
@mruberry rebased |
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: This is to align with the naming in numpy and in #43092 Test Plan: ``` python test/test_torch.py TestTorchDeviceTypeCPU.test_aminmax_cpu_float32 python test/test_torch.py TestTorchDeviceTypeCUDA.test_aminmax_cuda_float32 ``` Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: This is to align with the naming in numpy and in #43092 Test Plan: ``` python test/test_torch.py TestTorchDeviceTypeCPU.test_aminmax_cpu_float32 python test/test_torch.py TestTorchDeviceTypeCUDA.test_aminmax_cuda_float32 ``` Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23465298](https://our.internmc.facebook.com/intern/diff/D23465298) [ghstack-poisoned]
Summary: Pull Request resolved: #44001 This is to align with the naming in numpy and in #43092 Test Plan: ``` python test/test_torch.py TestTorchDeviceTypeCPU.test_aminmax_cpu_float32 python test/test_torch.py TestTorchDeviceTypeCUDA.test_aminmax_cuda_float32 ``` Imported from OSS Reviewed By: jerryzh168 Differential Revision: D23465298 fbshipit-source-id: b599035507156cefa53942db05f93242a21c8d06
This was reverted because it triggered a preexisting CUDA bug, relevant log snippet:
|
Add a max/min operator that only return values.
Some important decision to discuss
Numpy compatibility
Reference: https://numpy.org/doc/stable/reference/generated/numpy.amax.html
axis
: None or int or tuple of ints, optional. Axis or axes along which to operate. By default, flattened input is used. If this is a tuple of ints, the maximum is selected over multiple axes, instead of a single axis or all the axes as before.dim
, behavior same astorch.sum
(#29137)out
: ndarray, optional. Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.keepdims
: bool, optional. If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.keepdim
initial
: scalar, optional. The minimum value of an output element. Must be present to allow computation on empty slice.where
: array_like of bool, optional. Elements to compare for the maximum.Note from numpy:
PyTorch has the same behavior