Skip to content

Commit a3bbaff

Browse files
committed
refactoring
1 parent 88b017c commit a3bbaff

File tree

6 files changed

+22
-53
lines changed

6 files changed

+22
-53
lines changed

optimum/intel/openvino/modeling_base.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,9 @@ def _from_transformers(
619619
)
620620
compile_only = False
621621

622-
ov_config = kwargs.get("ov_config")
623-
if ov_config is None:
624-
# If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size
625-
if load_in_8bit is None and not quantization_config:
626-
ov_config = None
627-
else:
628-
ov_config = OVConfig(dtype="fp32")
622+
ov_config = kwargs.get("ov_export_config")
623+
if ov_config is None and load_in_8bit is not None or quantization_config is not None:
624+
ov_config = OVConfig(dtype="fp32")
629625

630626
variant = kwargs.pop("variant", None)
631627

optimum/intel/openvino/modeling_decoder.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,9 @@ def _from_transformers(
306306
if use_cache:
307307
task = task + "-with-past"
308308

309-
ov_export_config = kwargs.get("ov_config")
310-
if ov_export_config is None:
311-
# If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size
312-
if load_in_8bit is None and not quantization_config:
313-
ov_export_config = None
314-
else:
315-
ov_export_config = OVConfig(dtype="auto")
309+
ov_export_config = kwargs.get("ov_export_config")
310+
if ov_export_config is None and load_in_8bit is not None or quantization_config is not None:
311+
ov_export_config = OVConfig(dtype="auto")
316312

317313
stateful = kwargs.pop("stateful", ensure_stateful_is_available(warn=False) and use_cache)
318314

optimum/intel/openvino/modeling_diffusion.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,9 @@ def _from_transformers(
605605
)
606606
compile_only = False
607607

608-
ov_config = kwargs.get("ov_config")
609-
610-
if ov_config is None:
611-
# If load_in_8bit and quantization_config not specified then ov_config is set
612-
# to None and will be set by default in convert depending on the model size
613-
if load_in_8bit is None and not quantization_config:
614-
ov_config = None
615-
else:
616-
ov_config = OVConfig(dtype="auto")
608+
ov_config = kwargs.get("ov_export_config")
609+
if ov_config is None and load_in_8bit is not None or quantization_config is not None:
610+
ov_config = OVConfig(dtype="auto")
617611

618612
torch_dtype = kwargs.pop("torch_dtype", None)
619613

optimum/intel/openvino/modeling_open_clip.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,9 @@ def _from_transformers(
243243
# would end-up removing the directory containing the underlying OpenVINO model
244244
cls._model_save_dir_tempdirectory_instance = save_dir
245245

246-
ov_config = kwargs.get("ov_config")
247-
if ov_config is None:
248-
# If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size
249-
if load_in_8bit is None and not quantization_config:
250-
ov_config = None
251-
else:
252-
ov_config = OVConfig(dtype="fp32")
246+
ov_config = kwargs.get("ov_export_config")
247+
if ov_config is None and load_in_8bit is not None or quantization_config is not None:
248+
ov_config = OVConfig(dtype="fp32")
253249

254250
def fn_get_submodels(model):
255251
return {"model_text": model.text}
@@ -370,14 +366,9 @@ def _from_transformers(
370366
# would end-up removing the directory containing the underlying OpenVINO model
371367
cls._model_save_dir_tempdirectory_instance = save_dir
372368

373-
ov_config = kwargs.get("ov_config")
374-
375-
if ov_config is None:
376-
# If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size
377-
if load_in_8bit is None and not quantization_config:
378-
ov_config = None
379-
else:
380-
ov_config = OVConfig(dtype="fp32")
369+
ov_config = kwargs.get("ov_export_config")
370+
if ov_config is None and load_in_8bit is not None or quantization_config is not None:
371+
ov_config = OVConfig(dtype="fp32")
381372

382373
def fn_get_submodels(model):
383374
return {"model_vision": model.visual}

optimum/intel/openvino/modeling_seq2seq.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,9 @@ def _from_transformers(
602602
"Please provide openvino model obtained using optimum-cli or saved on disk using `save_pretrained`"
603603
)
604604
compile_only = False
605-
ov_config = kwargs.get("ov_config")
606-
if ov_config is None:
607-
# If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size
608-
if load_in_8bit is None and not quantization_config:
609-
ov_config = None
610-
else:
611-
ov_config = OVConfig(dtype="fp32")
605+
ov_config = kwargs.get("ov_export_config")
606+
if ov_config is None and (load_in_8bit is not None or quantization_config is not None):
607+
ov_config = OVConfig(dtype="fp32")
612608
stateful = kwargs.get("stateful", True)
613609
variant = kwargs.pop("variant", None)
614610

optimum/intel/openvino/modeling_visual_language.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,10 @@ def _from_transformers(
660660
if task is None:
661661
task = cls.export_feature
662662

663-
ov_config = kwargs.get("ov_config")
664-
if ov_config is None:
665-
# If load_in_8bit and quantization_config not specified then ov_config is set to None and will be set by default in convert depending on the model size
666-
if load_in_8bit is None and not quantization_config:
667-
ov_config = None
668-
else:
669-
# Export in fp32 if compression won't be applied later
670-
ov_config = OVConfig(dtype="fp32" if load_in_8bit is False else "auto")
663+
ov_config = kwargs.get("ov_export_config")
664+
if ov_config is None and (load_in_8bit is not None or quantization_config is None):
665+
# Export in fp32 if compression won't be applied later
666+
ov_config = OVConfig(dtype="fp32" if load_in_8bit is False else "auto")
671667

672668
stateful = kwargs.pop("stateful", ensure_stateful_is_available(warn=False) and use_cache)
673669
variant = kwargs.pop("variant", None)

0 commit comments

Comments
 (0)