-
Notifications
You must be signed in to change notification settings - Fork 25.7k
make assert_equal an example how to partial torch.testing.assert_close
#58918
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
Instead of a distinct `torch.testing.assert_close` and `torch.testing.assert_equal`, this makes `torch.testing.assert_equal` a special case of `torch.testing.assert_close` for `rtol=atol=0`. In this case the closeness definition `abs(actual - expected) <= atol + rtol * abs(expected)` boils down to `abs(actual - expected) <= 0`. Since `abs(x)` can never be `<0`, this is equivalent to `abs(a - b) == 0` and this again boils down to `a == b`. This makes maintaing the module a lot easier, because we don't need to keep two functions in sync. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 0f9e7b8 (more details on the Dr. CI page and at hud.pytorch.org/pr/58918): 💚 💚 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. |
|
Instead of defining |
|
Is there logic like pytorch/torch/testing/_core.py Line 107 in 3607478
somewhere, where this will short-circuit to a bitwise equivalence test? |
|
Lint failures are real |
Nope, in the current state we will always use We could also use an equal check if |
Instead of a distinct `torch.testing.assert_close` and `torch.testing.assert_equal`, this makes `torch.testing.assert_equal` a special case of `torch.testing.assert_close` for `rtol=atol=0`. In this case the closeness definition `abs(actual - expected) <= atol + rtol * abs(expected)` boils down to `abs(actual - expected) <= 0`. Since `abs(x)` can never be `<0`, this is equivalent to `abs(a - b) == 0` and this again boils down to `a == b`. This makes maintaing the module a lot easier, because we don't need to keep two functions in sync. [ghstack-poisoned]
….assert_close`" ~Instead of a distinct `torch.testing.assert_close` and `torch.testing.assert_equal`, this makes `torch.testing.assert_equal` a special case of `torch.testing.assert_close` for `rtol=atol=0`. In this case the closeness definition `abs(actual - expected) <= atol + rtol * abs(expected)` boils down to `abs(actual - expected) <= 0`. Since `abs(x)` can never be `<0`, this is equivalent to `abs(a - b) == 0` and this again boils down to `a == b`.~ Following #58918 (comment) and some offline discussions, we opted to use `assert_equal` as an example how to `partial` it. This makes maintaing the module a lot easier, because we don't need to keep two functions in sync. [ghstack-poisoned]
torch.testing.assert_close
…l `torch.testing.assert_close`" ~Instead of a distinct `torch.testing.assert_close` and `torch.testing.assert_equal`, this makes `torch.testing.assert_equal` a special case of `torch.testing.assert_close` for `rtol=atol=0`. In this case the closeness definition `abs(actual - expected) <= atol + rtol * abs(expected)` boils down to `abs(actual - expected) <= 0`. Since `abs(x)` can never be `<0`, this is equivalent to `abs(a - b) == 0` and this again boils down to `a == b`.~ Following #58918 (comment) and some offline discussions, we opted to use `assert_equal` as an example how to `partial` it. This makes maintaing the module a lot easier, because we don't need to keep two functions in sync. [ghstack-poisoned]
| AssertionError: Tensors are not close! | ||
| Mismatched elements: 1 / 1 (100.0%) | ||
| Greatest absolute difference: 8.999999703829253e-10 at 0 (up to 0 allowed) | ||
| Greatest relative difference: 8.999999583666371 at 0 (up to 0 allowed) |
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 make much more sense after #60091 from later in this stack is in. The error will read:
AssertionError: Scalars are not equal!
Absolute difference: 8.999999703829253e-10
Relative difference: 8.999999583666371
….assert_close`" ~Instead of a distinct `torch.testing.assert_close` and `torch.testing.assert_equal`, this makes `torch.testing.assert_equal` a special case of `torch.testing.assert_close` for `rtol=atol=0`. In this case the closeness definition `abs(actual - expected) <= atol + rtol * abs(expected)` boils down to `abs(actual - expected) <= 0`. Since `abs(x)` can never be `<0`, this is equivalent to `abs(a - b) == 0` and this again boils down to `a == b`.~ Following #58918 (comment) and some offline discussions, we opted to use `assert_equal` as an example how to `partial` it. This makes maintaing the module a lot easier, because we don't need to keep two functions in sync. [ghstack-poisoned]
…l `torch.testing.assert_close`" ~Instead of a distinct `torch.testing.assert_close` and `torch.testing.assert_equal`, this makes `torch.testing.assert_equal` a special case of `torch.testing.assert_close` for `rtol=atol=0`. In this case the closeness definition `abs(actual - expected) <= atol + rtol * abs(expected)` boils down to `abs(actual - expected) <= 0`. Since `abs(x)` can never be `<0`, this is equivalent to `abs(a - b) == 0` and this again boils down to `a == b`.~ Following #58918 (comment) and some offline discussions, we opted to use `assert_equal` as an example how to `partial` it. This makes maintaing the module a lot easier, because we don't need to keep two functions in sync. [ghstack-poisoned]
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.
Cool
|
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Stack from ghstack:
msgintorch.testing.assert_close#60254 tests for diagnostics in callablemsgintorch.testing.assert_closetorch.testing.assert_close#60163 update docstring examples oftorch.testing.assert_closetorch.testing.assert_closein case of mismatching values #60091 Improve error messages oftorch.testing.assert_closein case of mismatching valuestorch.testing.assert_close#58918 make assert_equal an example how to partialtorch.testing.assert_closeInstead of a distincttorch.testing.assert_closeandtorch.testing.assert_equal, this makestorch.testing.assert_equala special case oftorch.testing.assert_closeforrtol=atol=0. In this case the closeness definitionabs(actual - expected) <= atol + rtol * abs(expected)boils down toabs(actual - expected) <= 0. Sinceabs(x)can never be<0, this is equivalent toabs(a - b) == 0and this again boils down toa == b.Following #58918 (comment) and some offline discussions, we opted to use
assert_equalas an example how topartialit.This makes maintaing the module a lot easier, because we don't need to keep two functions in sync.
Differential Revision: D29259404