Skip to content

Commit 5269e93

Browse files
adrianlizarragarachguo
authored and
rachguo
committed
[Quant tool] Ensure MSFT opset for Q/DQ models (#19335)
### Description Updates qdq quantization to ensure the final model has the `com.microsoft` opset import if the model uses Q/DQ ops with the `com.microsoft` domain (e.g., for int16 quantization) ### Motivation and Context Need to ensure the MSFT domain is correctly set for all relevant cases. Otherwise, shape inferencing tools will raise an exception.
1 parent a77ee4a commit 5269e93

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

onnxruntime/python/tools/quantization/qdq_quantizer.py

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ def quantize_model(self):
270270

271271
self.model.model.producer_name = __producer__
272272
self.model.model.producer_version = __version__
273+
if self.qdq_op_domain == ms_domain:
274+
self.model.set_opset_import(ms_domain, 1)
273275

274276
return self.model.model
275277

onnxruntime/test/python/quantization/test_qdq.py

+7
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ def verify_qdq(self, per_channel, activation_type, weight_type, extra_options=No
601601
)
602602
check_model_correctness(self, model_fp32_path, model_qdq_path, data_reader.get_next())
603603

604+
# If the model uses Q/DQ ops with "com.microsoft" domain (e.g., for int16 support),
605+
# then ensure the model has the appropriate opset import.
606+
if extra_options and extra_options.get("UseQDQContribOps", False):
607+
qdq_model = onnx.load_model(model_qdq_path)
608+
ms_opset = next((opset for opset in qdq_model.opset_import if opset.domain == "com.microsoft"), None)
609+
self.assertIsNot(ms_opset, None)
610+
604611
def verify_qop(self, per_channel, is_quant_type_int8):
605612
np.random.seed(1)
606613
model_fp32_path = str(Path(self._tmp_model_dir.name) / f"conv_relu_fp32.{per_channel}.onnx")

0 commit comments

Comments
 (0)