Skip to content

Commit

Permalink
fix quantization for onnxruntime v1.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
echarlaix committed Sep 21, 2023
1 parent 8383fb3 commit 3bea1a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions optimum/onnxruntime/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ def compute_ranges(self) -> Dict[str, Tuple[float, float]]:
)

LOGGER.info("Computing calibration ranges")

if parse(ort_version) >= Version("1.16.0"):
return self._calibrator.compute_data()

return self._calibrator.compute_range()

def quantize(
Expand Down Expand Up @@ -351,8 +355,13 @@ def quantize(
has_subgraphs = True
break

if quantization_config.is_static and has_subgraphs:
raise NotImplementedError("Static quantization is currently not supported for models with" " subgraphs.")
if has_subgraphs:
if quantization_config.is_static:
raise NotImplementedError("Static quantization is currently not supported for models with subgraphs.")
if parse(ort_version) >= Version("1.16.0"):
raise ValueError(
"Onnxruntime version v1.16.0 not compatible with quantization for models with subgraphs, please downgrade to an earlier version."
)

quantizer_factory = QDQQuantizer if use_qdq else ONNXQuantizer

Expand Down

0 comments on commit 3bea1a2

Please sign in to comment.