Skip to content

Commit f11a56b

Browse files
jerryzh168facebook-github-bot
authored andcommitted
Enable quantization for inception_v3 (#426)
Summary: quantized model: https://www.internalfb.com/intern/everpaste/?handle=GFU5kxapMcFIxvgCAN39FPLWemAibsIXAAAB Note: this diverges from fx quant since we quantize mul op with Scalar inputs in different ways, and xnnpack quantizer won't align with the old flow xnnpack: differnt input and output qparams qnnpack in fx: same input and output qparams Reviewed By: kimishpatel Differential Revision: D49474108
1 parent af370c2 commit f11a56b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

examples/quantization/example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def verify_xnnpack_quantizer_matching_fx_quant_model(model_name, model, example_
5555
m = prepare_pt2e(m, quantizer)
5656
# calibration
5757
after_prepare_result = m(*example_inputs)
58+
logging.info(f"prepare_pt2e: {m}")
5859
m = convert_pt2e(m)
5960
after_quant_result = m(*example_inputs)
6061

@@ -66,11 +67,18 @@ def verify_xnnpack_quantizer_matching_fx_quant_model(model_name, model, example_
6667
m_copy, qconfig_mapping, example_inputs, backend_config=backend_config
6768
)
6869
after_prepare_result_fx = m_fx(*example_inputs)
70+
logging.info(f"prepare_fx: {m_fx}")
6971
m_fx = _convert_to_reference_decomposed_fx(m_fx, backend_config=backend_config)
7072
after_quant_result_fx = m_fx(*example_inputs)
7173

7274
# 3. compare results
75+
if model_name == "ic3":
76+
# we don't want to compare results of inception_v3 with fx, since mul op with Scalar
77+
# input is quantized differently in fx, and we don't want to replicate the behavior
78+
# in XNNPACKQuantizer
79+
return
7380
if model_name == "dl3":
81+
# dl3 output format: {"out": a, "aux": b}
7482
after_prepare_result = after_prepare_result["out"]
7583
after_prepare_result_fx = after_prepare_result_fx["out"]
7684
after_quant_result = after_quant_result["out"]

examples/recipes/xnnpack_optimization/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class OptimizationOptions(object):
1919
"add_mul": OptimizationOptions(True, True),
2020
"mv2": OptimizationOptions(True, True),
2121
"mv3": OptimizationOptions(False, True),
22+
"ic3": OptimizationOptions(True, False),
2223
"ic4": OptimizationOptions(
2324
True, False
2425
), # TODO[T163161310]: takes a long time to export to exec prog and save inception_v4 quantized model

0 commit comments

Comments
 (0)