mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
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:
@ -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):
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user