Skip to content

Update docs for quantile to be clearer for nearest#162423

Closed
janeyx99 wants to merge 2 commits intomainfrom
quantile-docs
Closed

Update docs for quantile to be clearer for nearest#162423
janeyx99 wants to merge 2 commits intomainfrom
quantile-docs

Conversation

@janeyx99
Copy link
Copy Markdown
Contributor

@janeyx99 janeyx99 commented Sep 8, 2025

Correct the rounding scheme for nearest in quantile.

@pytorch-bot pytorch-bot Bot added the release notes: python_frontend python frontend release notes category label Sep 8, 2025
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Sep 8, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/162423

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 2 Pending

As of commit ff697a8 with merge base fecd968 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Comment thread torch/_torch_docs.py Outdated
- ``lower``: ``a``.
- ``higher``: ``b``.
- ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (rounding down for .5 fractions).
- ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index
Copy link
Copy Markdown
Contributor

@soulitzer soulitzer Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the current docs are wrong? If we follow the "round to even" rules like torch.round, it would mean that 1.5 is rounded up and 2.5 is rounded down, and not always rounded down like the current docs suggest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you mention that in your description, but title suggests it just makes things clearer

Copy link
Copy Markdown
Contributor

@trirpi trirpi Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's a discrepancy.

x = torch.tensor([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
quantiles = torch.tensor([0.25])
result = torch.quantile(x, quantiles, interpolation="nearest")
print(result)

Rounds 1.5 up to 2 instead of 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This was prompted from a pytorch q&a post

@janeyx99
Copy link
Copy Markdown
Contributor Author

janeyx99 commented Sep 9, 2025

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 9, 2025
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
Correct the rounding scheme for nearest in quantile.

Pull Request resolved: pytorch#162423
Approved by: https://github.com/soulitzer
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Correct the rounding scheme for nearest in quantile.

Pull Request resolved: pytorch#162423
Approved by: https://github.com/soulitzer
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Correct the rounding scheme for nearest in quantile.

Pull Request resolved: pytorch#162423
Approved by: https://github.com/soulitzer
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Correct the rounding scheme for nearest in quantile.

Pull Request resolved: pytorch#162423
Approved by: https://github.com/soulitzer
@github-actions github-actions Bot deleted the quantile-docs branch October 10, 2025 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: python_frontend python frontend release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants