Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions exir/tests/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,76 +307,6 @@ def f(x: torch.Tensor, y: List[torch.Tensor]) -> Dict[str, torch.Tensor]:

self.assertEqual(prog(*inp), f(*inp))

def test_aot_buffer_mutation(self) -> None:
class Module(torch.nn.Module):
def __init__(self):
super().__init__()
self.register_buffer(
"_bin_num_examples",
torch.empty([42]).fill_(
0.0,
),
)

def forward(self, x, y, z):
self._bin_num_examples.index_copy_(
dim=0,
index=y,
source=z,
)
self._bin_num_examples.index_add_(
dim=0, index=torch.arange(4), source=x
)
return self._bin_num_examples - 1, x * z

model = Module()
example_inputs = (
torch.randn(4, requires_grad=True),
torch.tensor(0),
torch.tensor(3.14),
)

with self.assertRaisesRegex(
RuntimeError,
"Found a graph input that requires gradients, and received a mutation.",
):
_ = exir.capture(
model,
example_inputs,
exir.CaptureConfig(
enable_aot=True,
),
)

# Note that model._bin_num_examples is mutated during exir.capture
# We need to create a new_model
new_model = Module()
example_inputs = (
torch.randn(4),
torch.tensor(0),
torch.tensor(3.14),
)

ep = exir.capture(
new_model,
example_inputs,
exir.CaptureConfig(
enable_aot=True,
),
)

test_inputs = (
torch.randn(4),
torch.tensor(0),
torch.tensor(2.1),
)
graph_outputs = ep(*test_inputs)
eager_outputs = Module()(*test_inputs)
self.assertEqual(len(graph_outputs), 2)
self.assertEqual(len(eager_outputs), 2)
self.assertTrue(torch.allclose(graph_outputs[0], eager_outputs[0]))
self.assertTrue(torch.allclose(graph_outputs[1], eager_outputs[1]))

def test_assume_constant_by_default_prop(self) -> None:
def foo(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
if x.shape[0] > 3:
Expand Down
Loading