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
18 changes: 10 additions & 8 deletions backends/nxp/tests/test_batch_norm_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ def test_batch_norm_conv_fusing(bias: bool, input_shape: list[int]):
og_nodes = list(program.graph.nodes)
transformed_nodes = list(graph_module_out.graph.nodes)

assert len(og_nodes) == (11 if bias else 10)
assert og_nodes[9 if bias else 8].target.__name__ == "batch_norm.default"
assert any(
node.op == "call_function" and node.target.__name__ == "batch_norm.default"
for node in og_nodes
)

assert len(transformed_nodes) == 5
assert not any(
node.op == "call_function" and "batch_norm" in node.target.__name__
for node in transformed_nodes
Expand All @@ -118,7 +119,7 @@ def test_batch_norm_conv_fusing(bias: bool, input_shape: list[int]):
input_data = torch.randn(input_shape, dtype=torch.float32)
out1 = og_module(input_data).detach().numpy()
out2 = graph_module_out(input_data).detach().numpy()
assert np.allclose(out1, out2, atol=3.0e-7)
torch.testing.assert_close(out1, out2)


@pytest.mark.parametrize(
Expand All @@ -139,10 +140,11 @@ def test_batch_norm_linear_fusing(bias: bool):
og_nodes = list(og_module.graph.nodes)
transformed_nodes = list(graph_module_out.graph.nodes)

assert len(og_nodes) == (11 if bias else 10)
assert og_nodes[8 if bias else 7].target.__name__ == "linear.default"
assert any(
node.op == "call_function" and node.target.__name__ == "linear.default"
for node in og_nodes
)

assert len(transformed_nodes) == 5
assert not any(
node.op == "call_function" and "batch_norm" in node.target.__name__
for node in transformed_nodes
Expand All @@ -152,7 +154,7 @@ def test_batch_norm_linear_fusing(bias: bool):
input_data = torch.randn(input_shape, dtype=torch.float32)
out1 = og_module(input_data).detach().numpy()
out2 = graph_module_out(input_data).detach().numpy()
assert np.allclose(out1, out2, atol=1.2e-7)
torch.testing.assert_close(out1, out2)


@pytest.mark.parametrize(
Expand Down
Loading