3
from __future__ import annotations
6
from torch.fx import symbolic_trace
9
def __call__(self, x: torch.Tensor):
10
return torch.add(x, x)
13
class M1(torch.nn.Module):
14
def forward(self, x: torch.Tensor, a: A) -> torch.Tensor:
18
class M2(torch.nn.Module):
19
def forward(self, x: torch.Tensor, a: A) -> torch.Tensor:
23
class M3(torch.nn.Module):
24
def forward(self, x: typing.List[torch.Tensor], a: A) -> torch.Tensor:
28
class M4(torch.nn.Module):
29
def forward(self, x: typing.List[torch.Tensor], a: A) -> torch.Tensor:
36
traced1 = symbolic_trace(M1())
38
assert torch.all(torch.eq(ref, res1))
40
traced2 = symbolic_trace(M2())
42
assert torch.all(torch.eq(ref, res2))
44
traced3 = symbolic_trace(M3())
45
res3 = traced3([x], A())
46
assert torch.all(torch.eq(ref, res3))
48
traced4 = symbolic_trace(M4())
49
res4 = traced4([x], A())
50
assert torch.all(torch.eq(ref, res4))