Skip to content
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

HalfCauchy should ValueError if _validate_args #50403

Closed
wants to merge 2 commits into from

Conversation

feynmanliang
Copy link
Contributor

@feynmanliang feynmanliang commented Jan 12, 2021

Expected: When I run torch.distributions.HalfCauchy(torch.tensor(1.0), validate_args=True).log_prob(-1), I expect a ValueErro because that is the behavior of other distributions (e.g. Beta, Bernoulli).

Actual: No run-time error is thrown, but a -inf log prob is returned.

Fixes #50404


This change is Reviewable

**Expected**: When I run `torch.distributions.HalfCauchy(1.0, validate_args=True).log_prob(-1)`, I expect a `ValueErro` because that is the behavior of other distributions (e.g. Beta, Bernoulli).

**Actual**: No run-time error is thrown, but a `-inf` log prob is returned.
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jan 12, 2021

💊 CI failures summary and remediations

As of commit edd20ab (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Copy link
Contributor

@neerajprad neerajprad left a comment

Choose a reason for hiding this comment

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

Thank you fixing this, @feynmanliang!

@feynmanliang
Copy link
Contributor Author

Let me fix CI; I think the tests may need a bump

@neerajprad
Copy link
Contributor

Hmm..there is a test failure in test_distributions which is genuine.

Jan 12 01:08:33 ERROR [0.004s]: test_halfcauchy_shape_scalar_params (__main__.TestDistributionShapes)
Jan 12 01:08:33 ----------------------------------------------------------------------
Jan 12 01:08:33 Traceback (most recent call last):
Jan 12 01:08:33   File "distributions/test_distributions.py", line 3234, in test_halfcauchy_shape_scalar_params
Jan 12 01:08:33     self.assertEqual(halfcauchy.log_prob(self.scalar_sample).size(),
Jan 12 01:08:33   File "/Users/distiller/workspace/miniconda3/lib/python3.7/site-packages/torch/distributions/half_cauchy.py", line 54, in log_prob
Jan 12 01:08:33     self._validate_sample(value)
Jan 12 01:08:33   File "/Users/distiller/workspace/miniconda3/lib/python3.7/site-packages/torch/distributions/distribution.py", line 255, in _validate_sample
Jan 12 01:08:33     raise ValueError('The value argument to log_prob must be a Tensor')
Jan 12 01:08:33 ValueError: The value argument to log_prob must be a Tensor

@codecov
Copy link

codecov bot commented Jan 13, 2021

Codecov Report

Merging #50403 (edd20ab) into master (bb97503) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #50403      +/-   ##
==========================================
- Coverage   80.70%   80.70%   -0.01%     
==========================================
  Files        1905     1905              
  Lines      206755   206757       +2     
==========================================
  Hits       166859   166859              
- Misses      39896    39898       +2     

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@neerajprad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@neerajprad merged this pull request in fc9f013.

facebook-github-bot pushed a commit that referenced this pull request Jan 14, 2021
Summary:
Fixes #50404
Complementary to #50403

This also fixes `HalfCauchy.cdf()`, `HalfNormal.log_prob()`, `HalfNormal.cdf()` and ensures validation is not done twice.

cc feynmanliang

Pull Request resolved: #50492

Reviewed By: mrshenli

Differential Revision: D25909541

Pulled By: neerajprad

fbshipit-source-id: 35859633bf5c4fd20995182c599cbcaeb863cf29
@feynmanliang feynmanliang deleted the patch-2 branch January 14, 2021 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HalfCauchy does not respect _validate_args
3 participants