|
6 | 6 |
|
7 | 7 | import torch |
8 | 8 | from executorch.backends.arm.test.common import parametrize, xfail_type |
| 9 | +from executorch.backends.cortex_m.quantizer.quantizer import CortexMQuantizer |
9 | 10 | from executorch.backends.cortex_m.test.tester import ( |
10 | 11 | CortexMTester, |
11 | 12 | McuTestCase, |
12 | 13 | ramp_tensor, |
13 | 14 | ) |
| 15 | +from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e |
14 | 16 |
|
15 | 17 |
|
16 | 18 | class CortexMSoftmax(torch.nn.Module): |
@@ -80,6 +82,26 @@ def test_dialect_softmax(test_case, cortex_m_target): |
80 | 82 | ) |
81 | 83 |
|
82 | 84 |
|
| 85 | +def test_softmax_output_does_not_requantize(): |
| 86 | + inputs = (ramp_tensor(-8, 8, (4, 8)),) |
| 87 | + exported = torch.export.export(CortexMSoftmax(dim=-1), inputs, strict=True) |
| 88 | + prepared = prepare_pt2e(exported.module(), CortexMQuantizer()) |
| 89 | + prepared(*inputs) |
| 90 | + converted = convert_pt2e(prepared) |
| 91 | + |
| 92 | + quantize = torch.ops.quantized_decomposed.quantize_per_tensor.default |
| 93 | + dequantize = torch.ops.quantized_decomposed.dequantize_per_tensor.default |
| 94 | + requantize_nodes = [ |
| 95 | + node |
| 96 | + for node in converted.graph.nodes |
| 97 | + if node.target == quantize |
| 98 | + and isinstance(node.args[0], torch.fx.Node) |
| 99 | + and node.args[0].target == dequantize |
| 100 | + and any(user.target == dequantize for user in node.users) |
| 101 | + ] |
| 102 | + assert not requantize_nodes |
| 103 | + |
| 104 | + |
83 | 105 | @parametrize("test_case", test_cases, xfails=xfail_cases_impl) |
84 | 106 | def test_implementation_softmax(test_case, cortex_m_target): |
85 | 107 | tester = CortexMTester( |
|
0 commit comments