Skip to content

Commit 4219de3

Browse files
eigen-kfacebook-github-bot
authored andcommitted
Make test_replace_quant_view_dequant_with_requantize use GraphBuilder. (pytorch#10928)
Summary: Pull Request resolved: pytorch#10928 Use GraphBuilder to create the model for unit testing. Differential Revision: D74843628
1 parent 8953279 commit 4219de3

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

backends/cadence/aot/tests/test_fusion_ops_passes.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,30 +312,28 @@ def forward(self, x):
312312
)
313313

314314
def test_replace_quant_view_dequant_with_requantize(self):
315-
class M(torch.nn.Module):
316-
def __init__(self):
317-
super().__init__()
318-
319-
def forward(self, x):
320-
x = torch.ops.quantized_decomposed.quantize_per_tensor(
321-
x, 1.2, 3, 0, 127, torch.int8
322-
)
323-
x = x.view(-1)
324-
x = torch.ops.quantized_decomposed.dequantize_per_tensor(
325-
x, 4.5, 6, 0, 127, torch.int8
326-
)
327-
return x
328-
329-
inputs = torch.randn(2, 12, 1, 6)
330-
model = M()
331-
graph_module = export_to_edge(model, (inputs,)).exported_program().graph_module
332-
graph_module = FuseQuantDequantToRequantizePass()(graph_module).graph_module
315+
builder = GraphBuilder()
316+
x = builder.placeholder("x", torch.randn(2, 12, 1, 6, dtype=torch.float32))
317+
quant = builder.call_operator(
318+
op=exir_ops.edge.quantized_decomposed.quantize_per_tensor.default,
319+
args=(x, 1.2, 3, 0, 127, torch.int8),
320+
)
321+
view = builder.call_operator(
322+
op=exir_ops.edge.aten.view_copy.default, args=(quant, [-1])
323+
)
324+
dequant = builder.call_operator(
325+
op=exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,
326+
args=(view, 4.5, 6, 0, 127, torch.int8),
327+
)
328+
builder.output(dequant)
329+
graph_module = FuseQuantDequantToRequantizePass()(
330+
builder.get_graph_module()
331+
).graph_module
333332

334333
self.check_op_counts(
335334
graph_module,
336335
expected_op_counts={
337-
# Verify that no dequant/quant pair was replaced with requantize.
338-
# quantize -> permute -> dequantize should not be replaced with requantize.
336+
# Verify that dequant/quant pair was replaced with requantize.
339337
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default: 0,
340338
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default: 0,
341339
exir_ops.edge.cadence.requantize.default: 1,

0 commit comments

Comments
 (0)