32
32
from optimum .exporters .onnx .convert import check_dummy_inputs_are_allowed
33
33
from optimum .exporters .onnx .convert import export_pytorch as export_pytorch_to_onnx
34
34
from optimum .exporters .onnx .convert import export_tensorflow as export_tensorflow_onnx
35
+ from optimum .exporters .utils import _get_submodels_and_export_configs
35
36
from optimum .utils import DEFAULT_DUMMY_SHAPES , is_diffusers_available
36
37
from optimum .utils .save_utils import maybe_save_preprocessors
37
38
38
- from ...intel .utils .import_utils import is_nncf_available , is_optimum_version
39
+ from ...intel .utils .import_utils import is_nncf_available
39
40
from .model_patcher import patch_model_with_bettertransformer
40
41
from .stateful import ensure_export_task_support_stateful , ensure_stateful_is_available , patch_stateful
41
42
from .utils import (
48
49
)
49
50
50
51
51
- if is_optimum_version (">=" , "1.16.99" ):
52
- from optimum .exporters .onnx .utils import _get_submodels_and_onnx_configs
53
-
54
- else :
55
- from optimum .exporters .onnx .__main__ import _get_submodels_and_onnx_configs
56
-
57
-
58
52
UNSUPPORTED_TOKENIZER_CLASSES = (T5Tokenizer , T5TokenizerFast )
59
53
60
54
@@ -458,7 +452,7 @@ def ts_patched_forward(*args, **kwargs):
458
452
459
453
460
454
def export_models (
461
- models_and_onnx_configs : Dict [
455
+ models_and_export_configs : Dict [
462
456
str , Tuple [Union ["PreTrainedModel" , "TFPreTrainedModel" , "ModelMixin" ], "OnnxConfig" ]
463
457
],
464
458
output_dir : Path ,
@@ -475,7 +469,7 @@ def export_models(
475
469
Export the models to OpenVINO IR format
476
470
477
471
Args:
478
- models_and_onnx_configs (Dict[ str, Tuple[Union["PreTrainedModel", "TFPreTrainedModel", "ModelMixin"], "OnnxConfig"]):
472
+ models_and_export_configs (Dict[ str, Tuple[Union["PreTrainedModel", "TFPreTrainedModel", "ModelMixin"], "OnnxConfig"]):
479
473
output_dir (Path): output directory for saving models
480
474
opset (Optional[int], optional, Default to None): ONNX export opset
481
475
output_names (Optional[List[str]], optional, Defaults to None): model output names
@@ -504,20 +498,20 @@ def export_models(
504
498
# TODO : modify compression_option to quantization_config
505
499
outputs = []
506
500
507
- if output_names is not None and len (output_names ) != len (models_and_onnx_configs ):
501
+ if output_names is not None and len (output_names ) != len (models_and_export_configs ):
508
502
raise ValueError (
509
- f"Provided custom names { output_names } for the export of { len (models_and_onnx_configs )} models. Please provide the same number of names as models to export."
503
+ f"Provided custom names { output_names } for the export of { len (models_and_export_configs )} models. Please provide the same number of names as models to export."
510
504
)
511
505
512
- for i , model_name in enumerate (models_and_onnx_configs .keys ()):
513
- submodel , sub_onnx_config = models_and_onnx_configs [model_name ]
506
+ for i , model_name in enumerate (models_and_export_configs .keys ()):
507
+ submodel , sub_export_config = models_and_export_configs [model_name ]
514
508
output_name = output_names [i ] if output_names is not None else Path (model_name + ".xml" )
515
509
output_path = output_dir / output_name
516
510
output_path .parent .mkdir (parents = True , exist_ok = True )
517
511
outputs .append (
518
512
export (
519
513
model = submodel ,
520
- config = sub_onnx_config ,
514
+ config = sub_export_config ,
521
515
output = output_path ,
522
516
opset = opset ,
523
517
device = device ,
@@ -621,7 +615,7 @@ def export_from_model(
621
615
kwargs_shapes [input_name ] if input_name in kwargs_shapes else DEFAULT_DUMMY_SHAPES [input_name ]
622
616
)
623
617
624
- onnx_config , models_and_onnx_configs = _get_submodels_and_onnx_configs (
618
+ export_config , models_and_export_configs = _get_submodels_and_export_configs (
625
619
model = model ,
626
620
task = task ,
627
621
monolith = False ,
@@ -633,6 +627,7 @@ def export_from_model(
633
627
model_kwargs = model_kwargs ,
634
628
_variant = "default" ,
635
629
legacy = False ,
630
+ exporter = "openvino" ,
636
631
)
637
632
638
633
if compression_option is None :
@@ -661,18 +656,18 @@ def export_from_model(
661
656
model_name_or_path = model .config ._name_or_path
662
657
maybe_save_preprocessors (model_name_or_path , output )
663
658
664
- files_subpaths = ["openvino_" + model_name + ".xml" for model_name in models_and_onnx_configs .keys ()]
659
+ files_subpaths = ["openvino_" + model_name + ".xml" for model_name in models_and_export_configs .keys ()]
665
660
666
661
else :
667
662
# save the subcomponent configuration
668
- for model_name in models_and_onnx_configs :
669
- subcomponent = models_and_onnx_configs [model_name ][0 ]
663
+ for model_name in models_and_export_configs :
664
+ subcomponent = models_and_export_configs [model_name ][0 ]
670
665
if hasattr (subcomponent , "save_config" ):
671
666
subcomponent .save_config (output / model_name )
672
667
elif hasattr (subcomponent , "config" ) and hasattr (subcomponent .config , "save_pretrained" ):
673
668
subcomponent .config .save_pretrained (output / model_name )
674
669
675
- files_subpaths = [os .path .join (name_dir , OV_XML_FILE_NAME ) for name_dir in models_and_onnx_configs ]
670
+ files_subpaths = [os .path .join (name_dir , OV_XML_FILE_NAME ) for name_dir in models_and_export_configs ]
676
671
677
672
# Saving the additional components needed to perform inference.
678
673
model .scheduler .save_pretrained (output .joinpath ("scheduler" ))
@@ -692,7 +687,7 @@ def export_from_model(
692
687
model .save_config (output )
693
688
694
689
export_models (
695
- models_and_onnx_configs = models_and_onnx_configs ,
690
+ models_and_export_configs = models_and_export_configs ,
696
691
output_dir = output ,
697
692
output_names = files_subpaths ,
698
693
input_shapes = input_shapes ,
0 commit comments