Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Quant tool] Ensure MSFT opset for Q/DQ models #19335

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions onnxruntime/python/tools/quantization/qdq_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def quantize_model(self):

self.model.model.producer_name = __producer__
self.model.model.producer_version = __version__
if self.qdq_op_domain == ms_domain:
self.model.set_opset_import(ms_domain, 1)

return self.model.model

Expand Down
7 changes: 7 additions & 0 deletions onnxruntime/test/python/quantization/test_qdq.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ def verify_qdq(self, per_channel, activation_type, weight_type, extra_options=No
)
check_model_correctness(self, model_fp32_path, model_qdq_path, data_reader.get_next())

# If the model uses Q/DQ ops with "com.microsoft" domain (e.g., for int16 support),
# then ensure the model has the appropriate opset import.
if extra_options and extra_options.get("UseQDQContribOps", False):
qdq_model = onnx.load_model(model_qdq_path)
ms_opset = next((opset for opset in qdq_model.opset_import if opset.domain == "com.microsoft"), None)
self.assertIsNot(ms_opset, None)

def verify_qop(self, per_channel, is_quant_type_int8):
np.random.seed(1)
model_fp32_path = str(Path(self._tmp_model_dir.name) / f"conv_relu_fp32.{per_channel}.onnx")
Expand Down
Loading