From e88811d85d95c4037c555cc6b8c944b3bee2a803 Mon Sep 17 00:00:00 2001 From: Nikita Savelyev Date: Wed, 17 Apr 2024 17:03:43 +0200 Subject: [PATCH] Support NNCF 2.10 --- optimum/intel/openvino/configuration.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/optimum/intel/openvino/configuration.py b/optimum/intel/openvino/configuration.py index e75301729d..0850c2f828 100644 --- a/optimum/intel/openvino/configuration.py +++ b/optimum/intel/openvino/configuration.py @@ -20,6 +20,7 @@ import nncf import torch +from nncf.parameters import StrEnum from nncf.quantization.advanced_parameters import OverflowFix from transformers import PretrainedConfig from transformers.utils.quantization_config import QuantizationConfigMixin, QuantizationMethod @@ -351,11 +352,12 @@ def __init__( "Please check your configuration." ) super().__init__(ignored_scope, num_samples, False) - # TODO: remove checks below once NNCF is updated to 2.10 - if isinstance(overflow_fix, str): - overflow_fix = OverflowFix(overflow_fix) - if isinstance(preset, str): - preset = nncf.QuantizationPreset(preset) + # TODO: remove code below once NNCF < 2.10 support is dropped + if OverflowFix is not StrEnum: + if isinstance(overflow_fix, str): + overflow_fix = OverflowFix(overflow_fix) + if isinstance(preset, str): + preset = nncf.QuantizationPreset(preset) self.preset = preset self.model_type = model_type @@ -364,8 +366,8 @@ def __init__( self.post_init() def to_dict(self) -> Dict[str, Any]: - # TODO: remove code below once NNCF is updated to 2.10 - if isinstance(self.overflow_fix, Enum) or isinstance(self.preset, Enum): + # TODO: remove code below once NNCF < 2.10 support is dropped + if OverflowFix is not StrEnum and (isinstance(self.overflow_fix, Enum) or isinstance(self.preset, Enum)): overflow_fix_value = ( None if self.overflow_fix is None