Merged
Conversation
Increase tolerance from 1e-5 (default) to 1e-4 when checking sum_to_one
Dref360
reviewed
Dec 3, 2025
| not_bounded = np.min(probabilities) < 0 or np.max(probabilities) > 1.0 | ||
| multiclass = probabilities.shape[1] > 1 | ||
| sum_to_one = np.allclose(probabilities.sum(1), 1) | ||
| sum_to_one = np.allclose(probabilities.sum(1), 1, rtol=1e-4) |
Member
There was a problem hiding this comment.
Based on your explanation, should this uses atol instead of rtol? I guess in this case since b==1, it doesn't matter.
Contributor
Author
There was a problem hiding this comment.
Thank you for the response. You are correct it does not matter in this case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Increase tolerance from 1e-5 (default) to 1e-4 when checking sum_to_one
Summary:
The PR relaxes the tolerance used to check whether an input vector is a valid probability distribution. The current check uses np.allclose(probabilities.sum(1), 1), which relies on the default rtol=1e-5. Vectors produced by torch.nn.Softmax in float32 often sum to around 1 ± 1e-4, so valid probability vectors are incorrectly rejected.
Features:
To avoid complicating the existing code, this pr simply increases the tolerance to 1e-4 so that softmax outputs are correctly treated as probability distributions.
Checklist:
tests/documentation_test.py).