Skip to content
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

try removing ltorch.copy_ #1209

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions thunder/tests/test_inplace_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from torch.testing import assert_close, make_tensor

import thunder
from thunder.core import prims
import thunder.core.dtypes as datatypes
import thunder.torch as ttorch
from thunder.tests.framework import instantiate, nvFuserExecutor
Expand Down Expand Up @@ -158,9 +159,9 @@ def func3(x, y):
def test_inplace_copy_dst_copy_returned_issue_1109(executor, device, dtype):
def func(T0):
T1 = torch.sin(T0)
T0.copy_(T1) # destination.copy_(source)
prims.copy_(T1, T0)
crcrpar marked this conversation as resolved.
Show resolved Hide resolved
T2 = torch.cos(T1)
T0.copy_(T2)
prims.copy_(T2, T0)
# T1 & T2 should be returned as separate buffer, instead of sharing
# storage with T0
return T1, T2
Expand All @@ -169,12 +170,16 @@ def func(T0):
# This pattern is unsafe in general. Disabling sanity check to silence
# exception for testing
traced_foo = executor.make_callable(func, disable_inplace_copy_check=True)
a = make_tensor((4, 4), device=device, dtype=tdtype)
a_ref = a.clone()
t0 = make_tensor((4, 4), device=device, dtype=tdtype)
t0_ref = t0.clone()

o_thunder = traced_foo(a)
o_eager = func(a_ref)
actual_t1, actual_t2 = traced_foo(t0)

assert_close(a_ref, a)
for o, o_ref in zip(o_thunder, o_eager):
assert_close(o, o_ref)
expected = t0_ref.sin().cos()
expected_t1 = t0_ref.sin()
expected_t2 = expected_t1.cos()
expected = expected_t2

assert_close(t0, expected)
assert_close(actual_t2, expected_t2)
assert_close(actual_t1, expected_t1)
5 changes: 0 additions & 5 deletions thunder/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,11 +1958,6 @@ def copysign_(a, b, /):
return prims.copy_(copysign(a, b), a)


@torchsymbol(torch.Tensor.copy_, is_method=True) # , tags=(prims.OpTags.IN_PLACE,))
def copy_(a, b, /):
return prims.copy_(b, a)


# TODO Implement div
@torchsymbol(torch.div, is_method=True)
def div(
Expand Down
Loading