Skip to content

Commit 63f41ea

Browse files
authored
Adding test for CadenceWakeWordQuantizer
Differential Revision: D88898933 Pull Request resolved: #16356
1 parent a1665c5 commit 63f41ea

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

backends/cadence/aot/tests/test_quantizer_ops.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
CadenceNopQuantizer, # No-op quantizer, doesn't annotate anything
5959
CadenceW8A32MixedQuantizer, # TODO: T247438158 Add test coverage
6060
CadenceRmsNormNopQuantizer, # No-op quantizer, doesn't annotate anything, preserves rms_norm from decomposition
61-
CadenceWakeWordQuantizer, # TODO: T247438162 Add test coverage
6261
}
6362

6463

@@ -129,6 +128,15 @@
129128
# For layer_norm: only input_activation (weights/bias are passed as others)
130129
[qconfig_A8W8.input_activation],
131130
),
131+
(
132+
"add_A8W8",
133+
lambda self: self._build_add_graph(),
134+
CadenceWakeWordQuantizer(),
135+
torch.ops.aten.add.Tensor,
136+
qconfig_A8W8.output_activation,
137+
# For add: both inputs are activations
138+
[qconfig_A8W8.input_activation, qconfig_A8W8.input_activation],
139+
),
132140
]
133141

134142
# Derive the set of tested quantizer classes from the test cases.
@@ -279,6 +287,28 @@ def _build_layer_norm_graph(self) -> tuple[torch.fx.GraphModule, torch.fx.Node]:
279287
]
280288
return gm, layer_norm_nodes[0]
281289

290+
def _build_add_graph(self) -> tuple[torch.fx.GraphModule, torch.fx.Node]:
291+
"""Build a simple graph with an add operation."""
292+
builder = GraphBuilder()
293+
x = builder.placeholder("x", torch.randn(1, 10))
294+
y = builder.placeholder("y", torch.randn(1, 10))
295+
add = builder.call_operator(
296+
op=torch.ops.aten.add.Tensor,
297+
args=(x, y),
298+
meta=NodeMetadata(
299+
{"source_fn_stack": [("add", torch.ops.aten.add.Tensor)]}
300+
),
301+
)
302+
builder.output([add])
303+
gm = builder.get_graph_module()
304+
305+
add_nodes = gm.graph.find_nodes(
306+
op="call_function",
307+
target=torch.ops.aten.add.Tensor,
308+
)
309+
self.assertEqual(len(add_nodes), 1, "Should find exactly one add node")
310+
return gm, add_nodes[0]
311+
282312
@parameterized.expand(QUANTIZER_ANNOTATION_TEST_CASES)
283313
def test_quantizer_annotation(
284314
self,

0 commit comments

Comments
 (0)