Revert "[dynamo] Graph break on torch.Tensor.data assignment with mismatched dtype (#156623)"

This reverts commit c1ad4b8e7a16f54c35a3908b56ed7d9f95eef586.

Reverted https://github.com/pytorch/pytorch/pull/156623 on behalf of https://github.com/albanD due to Breaks Dynamo tests in trunk ([comment](https://github.com/pytorch/pytorch/pull/156623#issuecomment-3001806841))
This commit is contained in:
PyTorch MergeBot
2025-06-24 20:44:42 +00:00
parent aa280ea19f
commit 1dc1eedd43
3 changed files with 0 additions and 25 deletions

View File

@ -4460,20 +4460,6 @@ class ReproTests(torch._dynamo.test_case.TestCase):
# frame_count should stay at 1.
self.assertEqual(cnt.frame_count, 1)
def test_tensor_set_data_mismatched_dtype(self):
def func(x, y):
x.data = y.to(dtype=torch.bfloat16)
x1 = torch.tensor([], dtype=torch.float32)
x2 = torch.tensor([], dtype=torch.float32)
y1 = torch.tensor([1, 2, 3], dtype=torch.float32)
y2 = torch.tensor([1, 2, 3], dtype=torch.float32)
func(x1, y1)
torch.compile(func, backend="eager")(x2, y2)
self.assertEqual(x1, x2)
self.assertEqual(x1.data, x2.data)
self.assertEqual(y1, y2)
def test_user_ctor_ctx_manager(self):
class UserCtxManager:
def __enter__(self):

View File

@ -2175,17 +2175,6 @@ class BuiltinVariable(VariableTracker):
"the mutation out of `torch.compile` region",
],
)
elif obj.dtype != val.dtype: # type: ignore[attr-defined]
unimplemented_v2(
gb_type="Failed to mutate tensor data attribute",
context=f"setattr({obj}, {name}, {val})",
explanation="Dyanmo only supports mutating `.data`"
" of tensor to a new one with the same dtype",
hints=[
"Don't mutate `.data` on this tensor, or move "
"the mutation out of `torch.compile` region",
],
)
# Remove the old reference in tracked fakes - if we don't do this
# new .data value size and shape differences will cause