Skip to content

Conversation

@shino16
Copy link
Collaborator

@shino16 shino16 commented Nov 26, 2025

Fixes #2773. It clones the first argument into op so that jitted op and eager-mode op will mutate different tensors.

Alongside, I removed _inplace_to_out_of_place[tanhshrink] = tanhshrink, -1, because tanhshrink is not in-place (e.g. compare with relu_). And I couldn't find an in-place version of tanhshrink.

Copy link
Collaborator

@kshitij12345 kshitij12345 left a 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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Collaborator

@riccardofelluga riccardofelluga left a 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?

Copy link
Collaborator

@beverlylytle beverlylytle left a comment

Choose a reason for hiding this comment

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

Nice!

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)
Copy link
Collaborator

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]?

Copy link
Collaborator Author

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.

@shino16
Copy link
Collaborator Author

shino16 commented Dec 1, 2025

I added assert id(actual) == id(args[0]) to the test. I think this resolves @riccardofelluga's question.

Is there a way to test this? Should we add a test to check that this is always the case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_update_aliases does not correctly test function outputs

5 participants