Compare commits

...

1 Commits

Author SHA1 Message Date
a87ac298a5 [Dynamo] Frozen dataclass attr access test
ghstack-source-id: 5844a30db4c185e80a8902b657a84da03c9933e7
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159513
2025-07-30 14:27:50 -07:00

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 = dataclasses.field(kw_only=True)
a: int = dataclasses.field(kw_only=True)
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: