mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[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:
parent
5b2ad9279c
commit
447e300d55
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user