-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Update median doc to note return value of even-sized input #44562
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
Update median doc to note return value of even-sized input #44562
Conversation
[ghstack-poisoned]
albanD
left a comment
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.
Thanks!
Codecov Report
@@ Coverage Diff @@
## gh/heitorschueroff/13/base #44562 +/- ##
===========================================================
Coverage 68.00% 68.00%
===========================================================
Files 384 384
Lines 49599 49599
===========================================================
Hits 33728 33728
Misses 15871 15871
Continue to review full report at Codecov.
|
| :func:`torch.quantile` with ``q=0.5`` instead. | ||
| .. warning:: | ||
| This function produces deterministic (sub)gradients unlike ``median(dim=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.
Aside: it's very surprising to me that this version of median produces deterministic gradients but the other version, which actually computes indices, doesn't. We should probably fix "median_with_indices" to consistently return the FIRST valid median, just like we fixed argmin and argmax.
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.
I think, as you mention, that the other function returns non-deterministic indices and thus non-deterministic subgradients.
This one evenly distribute the gradient to all the inputs with the value used. So it always is deterministic.
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.
The reason it returns non-deterministic indices is because it uses quickselect to partition which is not stable. One way to solve it is to use 3-way quickselect that partitions input into <, = and >. Then choose the smallest index from the = segment.
Add a note that torch.median returns the smaller of the two middle elements for even-sized input and refer user to torch.quantile for the mean of the middle values. fixes #39520 Differential Revision: [D23657208](https://our.internmc.facebook.com/intern/diff/D23657208) [ghstack-poisoned]
|
@heitorschueroff merged this pull request in 199435a. |
Summary: Pull Request resolved: #44562 Add a note that torch.median returns the smaller of the two middle elements for even-sized input and refer user to torch.quantile for the mean of the middle values. fixes #39520 Test Plan: Imported from OSS Reviewed By: albanD Differential Revision: D23657208 Pulled By: heitorschueroff fbshipit-source-id: 2747aa652d1e7f10229d9299b089295aeae092c2
Stack from ghstack:
Add a note that torch.median returns the smaller of the two middle elements for even-sized input and refer user to torch.quantile for the mean of the middle values.
fixes #39520
Differential Revision: D23657208