-
Notifications
You must be signed in to change notification settings - Fork 108
Clone tensor before mutation for in-place tests #2774
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
base: main
Are you sure you want to change the base?
Conversation
kshitij12345
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, thanks @shino16
|
|
||
|
|
||
| _inplace_to_out_of_place[tanhshrink] = tanhshrink, -1 | ||
|
|
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.
Nice catch!
riccardofelluga
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.
Nice!
Is there a way to test this? Should we add a test to check that this is always the case?
beverlylytle
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.
Nice!
thunder/tests/test_update_aliases.py
Outdated
| actual = j_op(*args, **sample.kwargs) | ||
| expected = op.torch_reference(*args, **sample.kwargs) | ||
| expected = op.torch_reference(*args_ref, **sample.kwargs) | ||
| assert id(actual) != id(expected) |
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 assert checks that our testing infrastructure is correct, not that the source code is correct. It's an inexpensive check, but we need to always keep in mind what these inexpensive checks add up to when run for every in-place op. Isn't the more interesting thing to test that the id of actual matches the id of args[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.
Interesting! That makes a lot of sense.
|
I added
|
Fixes #2773. It clones the first argument into
opso that jitted op and eager-mode op will mutate different tensors.Alongside, I removed
_inplace_to_out_of_place[tanhshrink] = tanhshrink, -1, becausetanhshrinkis not in-place (e.g. compare withrelu_). And I couldn't find an in-place version oftanhshrink.