KEMBAR78
Added a UserWarning when using torch.{std,var,std_mean,std_var} with dof<=0 by tringwald · Pull Request #109824 · pytorch/pytorch · GitHub
Skip to content

Conversation

@tringwald
Copy link
Collaborator

Fixes #109696.

This PR adds a UserWarning when calling

  • torch.var
  • torch.var_mean
  • torch.std
  • torch.std_mean

with an effective dof<=0. Until now, only torch.cov warned about this. The code also handles edge cases, such as torch.empty

>>> import torch; torch.std_mean(torch.empty(0), correction=0)
<stdin>:1: UserWarning: std_mean(): degrees of freedom is <= 0 (Triggered internally at /app/aten/src/ATen/native/ReduceOps.cpp:1671.)
(tensor(nan), tensor(nan))

multi-dim reductions

>>> import torch; torch.std_mean(torch.empty(10, 30, 20, 50), correction=600, dim=(1, 2))
<stdin>:1: UserWarning: std_mean(): degrees of freedom is <= 0 (Triggered internally at /app/aten/src/ATen/native/ReduceOps.cpp:1671.)
[... snip ...]

and a negative correction.

>>> import torch; torch.std_mean(torch.randn(0), correction=-5)
(tensor(nan), tensor(nan))

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 21, 2023

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit d8c410d with merge base 6ca964b (image):

UNSTABLE - The following job failed but was 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.

@cpuhrsch cpuhrsch requested a review from soulitzer September 23, 2023 01:21
@cpuhrsch cpuhrsch added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 23, 2023
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Will let @soulitzer review this one

Copy link
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

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

Thanks!
Could we add a small test in test/test_reductions.py?

 with warnings.catch_warnings(record=True) as w:
        # stuff

self.assertIn('blah', str(w[0].message))

@soulitzer soulitzer added the release notes: python_frontend python frontend release notes category label Oct 5, 2023
@pytorch pytorch deleted a comment from github-actions bot Oct 5, 2023
Copy link
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the update!

@soulitzer soulitzer added the topic: improvements topic category label Oct 5, 2023
@soulitzer
Copy link
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 5, 2023
@pytorchmergebot
Copy link
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

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 open source release notes: python_frontend python frontend release notes category topic: improvements topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize UserWarnings for torch.cov, torch.{std,var} and torch.{std,var}_mean

6 participants