From 3bea1a22acf0ca401fc8994056670f8e715d6cc7 Mon Sep 17 00:00:00 2001 From: Ella Charlaix Date: Thu, 21 Sep 2023 16:01:19 +0200 Subject: [PATCH] fix quantization for onnxruntime v1.16.0 --- optimum/onnxruntime/quantization.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/optimum/onnxruntime/quantization.py b/optimum/onnxruntime/quantization.py index 31140c5b747..730abae1dfb 100644 --- a/optimum/onnxruntime/quantization.py +++ b/optimum/onnxruntime/quantization.py @@ -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( @@ -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