-
Notifications
You must be signed in to change notification settings - Fork 26.3k
clamp Categorical logit from -inf to min_fifo when calculating entropy #41002
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
Conversation
💊 CI failures summary and remediationsAs of commit e3148bb (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 on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 16 times. |
|
Flake errors are real. |
torch/distributions/categorical.py
Outdated
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 will normalize but won't convert -inf to real.
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 meant "real" as "non-inf".
| # Convert -inf to a real number | |
| # Normalize -inf to min_real |
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 meant that normalization below would retain -inf (indices with 0 prob).
>>> t = torch.tensor([float('-inf'), 2])
>>> t - t.logsumexp(dim=-1, keepdim=True)
tensor([-inf, 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.
So the comment should be merely "Normalize", right?
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.
That's right, I just wanted to also make sure that we aren't assuming that the logits will get clipped here, but as far as I can see, entropy is the only place where -inf values could cause issues and that has been fixed separately.
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.
What would you prefer the comment read? "Normalize -inf in logit"?
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.
Simply "Normalize"
torch/distributions/categorical.py
Outdated
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 will be a good place to use xlogy when available.
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 xlogy calculates x * log(y) where here we want x * y
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.
That's right, we are using the precomputed probs / logits attributes directly.
fritzo
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.
LGTM except for the comment on line 54
facebook-github-bot
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.
@ngimel has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
I see a related error on internal tests: This is a jit version of test_entropy which was likely touched by this diff, I don't know why OSS CI did not catch it. |
|
Do you understand why that error is being triggered? It looks as if |
|
@mattip can you please add the following to your diff This solves internal test failures, but I want to make sure that OSS CI is ok with this too. Thanks! |
@ngimel From my limited understanding the changes seem OK. I applied the patch. It would be good if we could also at some point add a test for this code path, maybe there are more like this lurking around |
|
It seems there are merge conflicts. Rebased to clear them. |
|
These failures were coming from running regular tests under ASAN, we have an asan build in OSS CI, but for some reason it's not triggering those. |
facebook-github-bot
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.
@ngimel has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Fixes gh-40553 by clamping logit values when calculating Categorical.entropy