-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import torch | ||
import torch_ttnn | ||
import pytest | ||
import ttnn | ||
|
||
|
||
class AliasModule(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, x): | ||
return torch.ops.aten.alias.default(x) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_shape", | ||
[(4, 4)], | ||
) | ||
def test_alias(device, input_shape): | ||
m = AliasModule() | ||
input = torch.rand(input_shape, dtype=torch.bfloat16) | ||
result_before = m.forward(input) | ||
|
||
option = torch_ttnn.TorchTtnnOption(device=device, gen_graphviz=True) | ||
# The compilation is lazy, so we need to run forward once to trigger the compilation | ||
m = torch.compile(m, backend=torch_ttnn.backend, options=option) | ||
result_after = m.forward(input) | ||
option._out_fx_graphs[0].print_tabular() | ||
|
||
# Check the graph has be rewritten | ||
nodes = list(option._out_fx_graphs[0].nodes) | ||
# There should be no op | ||
assert [node.op for node in nodes].count("call_function") == 0 | ||
# Check inference result | ||
assert torch.allclose(result_before, result_after) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters