[Dynamo] Frozen dataclass attr access test (#159513)

Verifies https://github.com/pytorch/pytorch/issues/159424, but perhaps the issue is not fixed yet.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/159513
Approved by: https://github.com/oulgen
This commit is contained in:
Michael Lazos 2025-07-30 16:44:34 -07:00 committed by PyTorch MergeBot
parent 5b2ad9279c
commit 447e300d55

View File

@ -10568,6 +10568,28 @@ def ___make_guard_fn():
self.assertEqual(actual, expected)
def test_frozen_dataclass_attr_access(self):
@dataclasses.dataclass(frozen=True)
class TestDataClass:
x: torch.Tensor
y: torch.Tensor
z: int
a: int
def inner_fn(dc):
return dc.x + dc.y + dc.a + dc.z
def fn(x, y):
dc = TestDataClass(x, y, z=5, a=2)
return inner_fn(dc)
fn_opt = torch.compile(fullgraph=True)(fn)
inps = (torch.ones(2, 2), torch.ones(2, 2))
actual = fn_opt(*inps)
expected = fn(*inps)
self.assertEqual(actual, expected)
def test_pytree_tree_leaves(self):
implementations = [("python", python_pytree)]
if cxx_pytree is not None: