From 5e71f07216c2f5cc25292157dcc56e6a3dab558d Mon Sep 17 00:00:00 2001 From: eaidova Date: Thu, 24 Oct 2024 14:23:37 +0400 Subject: [PATCH] fix config saving when check on misplaced args broken --- optimum/exporters/openvino/convert.py | 7 ++++++- optimum/intel/neural_compressor/modeling_base.py | 2 ++ optimum/intel/openvino/modeling_base_seq2seq.py | 6 +++++- optimum/intel/openvino/modeling_visual_language.py | 8 ++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/optimum/exporters/openvino/convert.py b/optimum/exporters/openvino/convert.py index 2c076827d2..0f203bd04b 100644 --- a/optimum/exporters/openvino/convert.py +++ b/optimum/exporters/openvino/convert.py @@ -70,6 +70,7 @@ _get_open_clip_submodels_fn_and_export_configs, clear_class_registry, remove_none_from_dummy_inputs, + save_config, ) @@ -658,7 +659,11 @@ def export_from_model( files_subpaths = ["openvino_" + model_name + ".xml" for model_name in models_and_export_configs.keys()] elif library_name != "diffusers": if is_transformers_version(">=", "4.44.99"): - misplaced_generation_parameters = model.config._get_non_default_generation_parameters() + # some model configs may have issues with loading without parameters initialization + try: + misplaced_generation_parameters = model.config._get_non_default_generation_parameters() + except Exception: + misplaced_generation_parameters = {} if isinstance(model, GenerationMixin) and len(misplaced_generation_parameters) > 0: logger.warning( "Moving the following attributes in the config to the generation config: " diff --git a/optimum/intel/neural_compressor/modeling_base.py b/optimum/intel/neural_compressor/modeling_base.py index 6f6c700d87..8a9c4339a6 100644 --- a/optimum/intel/neural_compressor/modeling_base.py +++ b/optimum/intel/neural_compressor/modeling_base.py @@ -97,6 +97,8 @@ def __init__( if is_transformers_version(">=", "4.44.99"): misplaced_generation_parameters = self.config._get_non_default_generation_parameters() + except Exception: + misplaced_generation_parameters = {} if len(misplaced_generation_parameters) > 0: logger.warning( "Moving the following attributes in the config to the generation config: " diff --git a/optimum/intel/openvino/modeling_base_seq2seq.py b/optimum/intel/openvino/modeling_base_seq2seq.py index 06c6011488..20a5afdca7 100644 --- a/optimum/intel/openvino/modeling_base_seq2seq.py +++ b/optimum/intel/openvino/modeling_base_seq2seq.py @@ -84,7 +84,11 @@ def __init__( self.generation_config = generation_config or GenerationConfig.from_model_config(config) if is_transformers_version(">=", "4.44.99"): - misplaced_generation_parameters = self.config._get_non_default_generation_parameters() + # some model configs may have issues with loading without parameters initialization + try: + misplaced_generation_parameters = self.config._get_non_default_generation_parameters() + except Exception: + misplaced_generation_parameters = {} if len(misplaced_generation_parameters) > 0: logger.warning( "Moving the following attributes in the config to the generation config: " diff --git a/optimum/intel/openvino/modeling_visual_language.py b/optimum/intel/openvino/modeling_visual_language.py index 141abeb87f..32cda33861 100644 --- a/optimum/intel/openvino/modeling_visual_language.py +++ b/optimum/intel/openvino/modeling_visual_language.py @@ -14,6 +14,7 @@ from transformers.modeling_outputs import BaseModelOutputWithPooling from ...exporters.openvino import main_export +from ...exporters.openvino.utils import save_config from ...exporters.openvino.stateful import ensure_stateful_is_available from .configuration import OVConfig, OVWeightQuantizationConfig from .modeling_base import OVBaseModel, OVModelPart @@ -272,6 +273,13 @@ def compile(self): if part_model is not None: part_model._compile() + def _save_config(self, save_directory): + """ + Saves a model configuration into a directory, so that it can be re-loaded using the + [`from_pretrained`] class method. + """ + save_config(self.config, save_directory) + def _save_pretrained(self, save_directory: Union[str, Path]): """ Saves the model to the OpenVINO IR format so that it can be re-loaded using the