optimum-intel 2.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {optimum_intel-2.2.0/optimum_intel.egg-info → optimum_intel-2.3.0}/PKG-INFO +9 -6
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/commands/export/openvino.py +38 -10
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/__main__.py +285 -19
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/convert.py +438 -53
- optimum_intel-2.3.0/optimum/exporters/openvino/dflash_utils.py +76 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/input_generators.py +822 -45
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/model_configs.py +1472 -189
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/model_patcher.py +2942 -760
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/stateful.py +3 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/utils.py +386 -2
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/__init__.py +12 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/__init__.py +8 -1
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/configuration.py +273 -23
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_base.py +30 -10
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_decoder.py +36 -13
- optimum_intel-2.3.0/optimum/intel/openvino/modeling_dflash.py +501 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_diffusion.py +905 -80
- optimum_intel-2.3.0/optimum/intel/openvino/modeling_funasr.py +1081 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_open_clip.py +5 -6
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_seq2seq.py +344 -44
- optimum_intel-2.3.0/optimum/intel/openvino/modeling_text2speech.py +2215 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_visual_language.py +1419 -126
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/quantization.py +28 -23
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/utils.py +14 -2
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/dummy_openvino_and_diffusers_objects.py +22 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/import_utils.py +44 -6
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/modeling_utils.py +104 -4
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/version.py +1 -1
- {optimum_intel-2.2.0 → optimum_intel-2.3.0/optimum_intel.egg-info}/PKG-INFO +9 -6
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum_intel.egg-info/SOURCES.txt +2 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum_intel.egg-info/requires.txt +3 -3
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/pyproject.toml +1 -1
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/setup.py +7 -5
- optimum_intel-2.2.0/optimum/intel/openvino/modeling_funasr.py +0 -443
- optimum_intel-2.2.0/optimum/intel/openvino/modeling_text2speech.py +0 -892
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/LICENSE +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/MANIFEST.in +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/README.md +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/commands/register/register_openvino.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/__init__.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/_ov_ops.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/_traceable_cache.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/_traceable_decorator.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/base.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/config.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/patching_utils.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/exporters/openvino/utils_annotations.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/loaders.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_sam.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_sentence_transformers.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/openvino/modeling_timm.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/pipelines/__init__.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/pipelines/accelerator_utils.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/pipelines/pipeline_base.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/__init__.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/constant.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/dummy_openvino_and_nncf_objects.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum/intel/utils/dummy_openvino_and_sentence_transformers_objects.py +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum_intel.egg-info/dependency_links.txt +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum_intel.egg-info/entry_points.txt +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum_intel.egg-info/not-zip-safe +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/optimum_intel.egg-info/top_level.txt +0 -0
- {optimum_intel-2.2.0 → optimum_intel-2.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: optimum-intel
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: Optimum Library is an extension of the Hugging Face Transformers library, providing a framework to integrate third-party libraries from Hardware Partners and interface with their specific functionality.
|
|
5
5
|
Home-page: https://www.intel.com
|
|
6
6
|
Author: HuggingFace Inc. Special Ops Team
|
|
@@ -13,17 +13,19 @@ Classifier: Intended Audience :: Developers
|
|
|
13
13
|
Classifier: Intended Audience :: Education
|
|
14
14
|
Classifier: Intended Audience :: Science/Research
|
|
15
15
|
Classifier: Operating System :: OS Independent
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
20
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.11
|
|
20
22
|
Description-Content-Type: text/markdown
|
|
21
23
|
License-File: LICENSE
|
|
22
24
|
Requires-Dist: torch>=2.1
|
|
23
25
|
Requires-Dist: optimum~=2.3.0
|
|
24
|
-
Requires-Dist: transformers<5.
|
|
26
|
+
Requires-Dist: transformers<5.16,>=4.51
|
|
25
27
|
Requires-Dist: setuptools
|
|
26
|
-
Requires-Dist: huggingface-hub<
|
|
28
|
+
Requires-Dist: huggingface-hub<2.0,>=0.23.2
|
|
27
29
|
Requires-Dist: nncf>=3.3.0
|
|
28
30
|
Requires-Dist: openvino>=2026.0
|
|
29
31
|
Requires-Dist: openvino-tokenizers>=2026.0
|
|
@@ -36,7 +38,7 @@ Requires-Dist: nncf>=2.19.0; extra == "openvino"
|
|
|
36
38
|
Requires-Dist: openvino>=2026.0; extra == "openvino"
|
|
37
39
|
Requires-Dist: openvino-tokenizers>=2026.0; extra == "openvino"
|
|
38
40
|
Provides-Extra: diffusers
|
|
39
|
-
Requires-Dist: diffusers; extra == "diffusers"
|
|
41
|
+
Requires-Dist: diffusers<0.42,>=0.32; extra == "diffusers"
|
|
40
42
|
Provides-Extra: quality
|
|
41
43
|
Requires-Dist: black~=23.1; extra == "quality"
|
|
42
44
|
Requires-Dist: ruff==0.4.4; extra == "quality"
|
|
@@ -82,6 +84,7 @@ Dynamic: license
|
|
|
82
84
|
Dynamic: license-file
|
|
83
85
|
Dynamic: provides-extra
|
|
84
86
|
Dynamic: requires-dist
|
|
87
|
+
Dynamic: requires-python
|
|
85
88
|
Dynamic: summary
|
|
86
89
|
|
|
87
90
|
<p align="center">
|
|
@@ -67,7 +67,7 @@ def parse_args_openvino(parser: "ArgumentParser"):
|
|
|
67
67
|
optional_group.add_argument(
|
|
68
68
|
"--weight-format",
|
|
69
69
|
type=str,
|
|
70
|
-
choices=["fp32", "fp16", "int8", "int4", "mxfp4", "nf4", "cb4"],
|
|
70
|
+
choices=["fp32", "fp16", "int8", "int4", "mxfp4", "nf4", "cb4", "int3", "int2"],
|
|
71
71
|
default=None,
|
|
72
72
|
help=(
|
|
73
73
|
"The weight format of the exported model. Option 'cb4' represents a codebook with 16 fixed fp8 values in E4M3 format."
|
|
@@ -139,7 +139,10 @@ def parse_args_openvino(parser: "ArgumentParser"):
|
|
|
139
139
|
"--group-size",
|
|
140
140
|
type=int,
|
|
141
141
|
default=None,
|
|
142
|
-
help=(
|
|
142
|
+
help=(
|
|
143
|
+
"The group size to use for quantization. Recommended value is 128 and -1 uses per-column quantization. "
|
|
144
|
+
"For --weight-format int8 the default is -1."
|
|
145
|
+
),
|
|
143
146
|
)
|
|
144
147
|
optional_group.add_argument(
|
|
145
148
|
"--group-size-fallback",
|
|
@@ -344,6 +347,8 @@ class OVExportCommand(BaseOptimumCLICommand):
|
|
|
344
347
|
def run(self):
|
|
345
348
|
from ...exporters.openvino.__main__ import _main_quantize, _merge_move, main_export
|
|
346
349
|
from ...intel.openvino.configuration import (
|
|
350
|
+
_DEFAULT_2BIT_WQ_CONFIG,
|
|
351
|
+
_DEFAULT_3BIT_WQ_CONFIG,
|
|
347
352
|
_DEFAULT_4BIT_WQ_CONFIG,
|
|
348
353
|
OVConfig,
|
|
349
354
|
_GPTOSSQuantizationConfig,
|
|
@@ -394,15 +399,27 @@ class OVExportCommand(BaseOptimumCLICommand):
|
|
|
394
399
|
)
|
|
395
400
|
if self.args.weight_format is not None:
|
|
396
401
|
quantization_config = prepare_wc_config(self.args, _DEFAULT_4BIT_WQ_CONFIG)
|
|
397
|
-
|
|
398
|
-
if no_compression_parameter_provided(self.args) and self.args.weight_format in [
|
|
402
|
+
|
|
403
|
+
if no_compression_parameter_provided(self.args) and self.args.weight_format in [
|
|
404
|
+
"int2",
|
|
405
|
+
"int3",
|
|
406
|
+
"int4",
|
|
407
|
+
"int8",
|
|
408
|
+
]:
|
|
409
|
+
# For int{2, 3, 4, 8} quantization, if no compression parameters are provided, use the model's default
|
|
410
|
+
# quantization config if one exists.
|
|
399
411
|
if default_quantization_config is not None:
|
|
400
412
|
quantization_config = default_quantization_config
|
|
401
413
|
logger.info(
|
|
402
414
|
f"Applying the default quantization config for {self.args.model}: {quantization_config}."
|
|
403
415
|
)
|
|
404
|
-
elif self.args.weight_format
|
|
405
|
-
quantization_config =
|
|
416
|
+
elif self.args.weight_format in ["int2", "int3", "int4"]:
|
|
417
|
+
quantization_config = {
|
|
418
|
+
"int2": _DEFAULT_2BIT_WQ_CONFIG,
|
|
419
|
+
"int3": _DEFAULT_3BIT_WQ_CONFIG,
|
|
420
|
+
"int4": _DEFAULT_4BIT_WQ_CONFIG,
|
|
421
|
+
}[self.args.weight_format]
|
|
422
|
+
|
|
406
423
|
logger.info(f"Applying a default quantization config: {quantization_config}.")
|
|
407
424
|
if self.args.quantization_statistics_path is not None:
|
|
408
425
|
quantization_config["statistics_path"] = self.args.quantization_statistics_path
|
|
@@ -503,11 +520,20 @@ class OVExportCommand(BaseOptimumCLICommand):
|
|
|
503
520
|
|
|
504
521
|
def prepare_wc_config(args, default_configs):
|
|
505
522
|
is_int8 = args.weight_format == "int8"
|
|
523
|
+
is_int2_or_int3 = args.weight_format == "int2" or args.weight_format == "int3"
|
|
524
|
+
|
|
525
|
+
weight_format_to_bits = {
|
|
526
|
+
"int2": 2,
|
|
527
|
+
"int3": 3,
|
|
528
|
+
"int4": 4,
|
|
529
|
+
"int8": 8,
|
|
530
|
+
}
|
|
531
|
+
|
|
506
532
|
return {
|
|
507
|
-
"bits":
|
|
533
|
+
"bits": weight_format_to_bits.get(args.weight_format, 4),
|
|
508
534
|
"ratio": 1.0 if is_int8 else (args.ratio or default_configs["ratio"]),
|
|
509
|
-
"sym": args.sym or False,
|
|
510
|
-
"group_size": -1 if is_int8 else args.group_size,
|
|
535
|
+
"sym": True if is_int2_or_int3 else (args.sym or False),
|
|
536
|
+
"group_size": -1 if is_int8 and args.group_size is None else args.group_size,
|
|
511
537
|
"all_layers": None if is_int8 else args.all_layers,
|
|
512
538
|
"dataset": args.dataset,
|
|
513
539
|
"num_samples": args.num_samples,
|
|
@@ -519,7 +545,9 @@ def prepare_wc_config(args, default_configs):
|
|
|
519
545
|
"dtype": args.weight_format,
|
|
520
546
|
"backup_precision": args.backup_precision,
|
|
521
547
|
"statistics_path": args.quantization_statistics_path,
|
|
522
|
-
"group_size_fallback": args.group_size_fallback
|
|
548
|
+
"group_size_fallback": args.group_size_fallback
|
|
549
|
+
if args.group_size_fallback
|
|
550
|
+
else default_configs["group_size_fallback"],
|
|
523
551
|
}
|
|
524
552
|
|
|
525
553
|
|
|
@@ -27,8 +27,9 @@ from requests.exceptions import ConnectionError as RequestsConnectionError
|
|
|
27
27
|
from transformers import AutoConfig, AutoTokenizer, PreTrainedTokenizerBase, ProcessorMixin
|
|
28
28
|
from transformers.utils import is_torch_available
|
|
29
29
|
|
|
30
|
-
from openvino import Core, Type, save_model
|
|
30
|
+
from openvino import Core, Model, Type, save_model
|
|
31
31
|
from optimum.exporters.openvino.base import OpenVINOConfig
|
|
32
|
+
from optimum.exporters.openvino.dflash_utils import DFLASH_ARCHITECTURES, DSPARK_ARCHITECTURES
|
|
32
33
|
from optimum.exporters.tasks import TasksManager
|
|
33
34
|
from optimum.intel.utils.import_utils import (
|
|
34
35
|
DIFFUSERS_IMPORT_ERROR,
|
|
@@ -36,19 +37,24 @@ from optimum.intel.utils.import_utils import (
|
|
|
36
37
|
is_diffusers_available,
|
|
37
38
|
is_nncf_available,
|
|
38
39
|
is_openvino_tokenizers_available,
|
|
40
|
+
is_openvino_version,
|
|
39
41
|
is_transformers_version,
|
|
40
42
|
)
|
|
41
43
|
from optimum.intel.utils.modeling_utils import (
|
|
42
44
|
_infer_library_from_model_name_or_path,
|
|
43
45
|
_KokoroForTextToSpeech,
|
|
44
46
|
_OpenClipForZeroShotImageClassification,
|
|
47
|
+
_Qwen3TTSForTextToSpeech,
|
|
45
48
|
)
|
|
46
49
|
|
|
47
50
|
from .utils import (
|
|
48
51
|
_MAX_UNCOMPRESSED_SIZE,
|
|
49
52
|
MULTI_MODAL_TEXT_GENERATION_MODELS,
|
|
53
|
+
check_transformers_version_compatibility,
|
|
50
54
|
clear_class_registry,
|
|
51
55
|
deduce_diffusers_dtype,
|
|
56
|
+
is_auto_compression_disabled,
|
|
57
|
+
keep_mixed_precision_parameters,
|
|
52
58
|
load_preprocessors,
|
|
53
59
|
patch_qwenvl_configs,
|
|
54
60
|
)
|
|
@@ -88,13 +94,21 @@ def infer_task(
|
|
|
88
94
|
if task == "auto":
|
|
89
95
|
if library_name == "open_clip":
|
|
90
96
|
task = "zero-shot-image-classification"
|
|
91
|
-
elif library_name
|
|
97
|
+
elif library_name in ("kokoro", "qwen3_tts"):
|
|
92
98
|
task = "text-to-audio"
|
|
93
99
|
elif library_name == "funasr":
|
|
94
100
|
# Use the with-past task so the encoder-decoder export is stateful (KV cache hidden in
|
|
95
101
|
# OpenVINO state). Without the `-with-past` suffix the decoder is exported stateless and
|
|
96
102
|
# incremental generation breaks (only the first token is correct).
|
|
97
|
-
|
|
103
|
+
from optimum.intel.openvino.modeling_funasr import _is_sensevoice_source
|
|
104
|
+
|
|
105
|
+
if _is_sensevoice_source(
|
|
106
|
+
model_name_or_path, cache_dir=cache_dir, token=token, subfolder=subfolder, revision=revision
|
|
107
|
+
):
|
|
108
|
+
# SenseVoiceSmall is a non-autoregressive (CTC encoder-only) model exported as a single stateless graph.
|
|
109
|
+
task = "automatic-speech-recognition"
|
|
110
|
+
else:
|
|
111
|
+
task = "automatic-speech-recognition-with-past"
|
|
98
112
|
else:
|
|
99
113
|
try:
|
|
100
114
|
task = TasksManager._infer_task_from_model_name_or_path(
|
|
@@ -163,6 +177,8 @@ def infer_task(
|
|
|
163
177
|
raise e
|
|
164
178
|
else:
|
|
165
179
|
raise
|
|
180
|
+
if original_task == "auto" and (config.architectures or [None])[0] in _NATIVE_DRAFT_MODEL_CLASSES:
|
|
181
|
+
task = "text-generation-with-past"
|
|
166
182
|
if hasattr(config, "export_model_type"):
|
|
167
183
|
model_type = config.export_model_type
|
|
168
184
|
else:
|
|
@@ -219,9 +235,27 @@ def _ensure_qwen3_omni_rope_scaling(config):
|
|
|
219
235
|
_CUSTOM_DRAFT_MODEL_MAP = {
|
|
220
236
|
"LlamaForCausalLMEagle3": ("LlamaEagle3Model", "LlamaEagle3ForCausalLM"),
|
|
221
237
|
"Eagle3LlamaForCausalLM": ("LlamaEagle3Model", "LlamaEagle3ForCausalLM"),
|
|
222
|
-
"DFlashDraftModel": ("Qwen3DFlashDraftModel", "Qwen3DFlashForCausalLM"),
|
|
223
238
|
}
|
|
224
239
|
|
|
240
|
+
# Maps config.architectures[0] to the model_patcher export class of DFlash draft models, or to a
|
|
241
|
+
# function building that class. They are loaded directly, so unlike `_CUSTOM_DRAFT_MODEL_MAP` they
|
|
242
|
+
# need no `auto_map` indirection (and no `trust_remote_code`).
|
|
243
|
+
_NATIVE_DRAFT_MODEL_CLASSES = {
|
|
244
|
+
"DFlashDraftModel": "Qwen3DFlashForCausalLM",
|
|
245
|
+
"Qwen3DSparkModel": "Qwen3DSparkForCausalLM",
|
|
246
|
+
"MuseGlimmerAssistantModel": "get_muse_glimmer_assistant_draft_model_class",
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def load_native_draft_model(architecture: str, model_name_or_path: str, **kwargs):
|
|
251
|
+
from optimum.exporters.openvino import model_patcher
|
|
252
|
+
|
|
253
|
+
model_class = getattr(model_patcher, _NATIVE_DRAFT_MODEL_CLASSES[architecture])
|
|
254
|
+
# The MuseGlimmer drafter class is built lazily because it needs transformers >= 5.15.
|
|
255
|
+
if not isinstance(model_class, type):
|
|
256
|
+
model_class = model_class()
|
|
257
|
+
return model_class.from_pretrained(model_name_or_path, **kwargs)
|
|
258
|
+
|
|
225
259
|
|
|
226
260
|
def update_config_for_custom_draft_model(config, auto_model, auto_model_for_causal_lm):
|
|
227
261
|
moduler_name = "optimum.exporters.openvino.model_patcher"
|
|
@@ -412,10 +446,28 @@ def main_export(
|
|
|
412
446
|
dtype = torch.bfloat16
|
|
413
447
|
loading_kwargs["quantization_config"] = Mxfp4Config(dequantize=True)
|
|
414
448
|
|
|
415
|
-
supported_quant_methods = ["gptq", "awq", "bitnet"]
|
|
449
|
+
supported_quant_methods = ["gptq", "awq", "bitnet", "compressed-tensors"]
|
|
416
450
|
do_quant_patching = quant_method in supported_quant_methods
|
|
417
451
|
do_gptq_patching = quant_method == "gptq"
|
|
418
452
|
do_bitnet_patching = quant_method == "bitnet"
|
|
453
|
+
do_ct_patching = quant_method == "compressed-tensors"
|
|
454
|
+
|
|
455
|
+
# compressed-tensors export relies on the OpenVINO PyTorch frontend
|
|
456
|
+
# compressed-tensors patcher, which is only available since 2026.3.
|
|
457
|
+
if do_ct_patching and is_openvino_version("<", "2026.3"):
|
|
458
|
+
raise RuntimeError(
|
|
459
|
+
"Exporting compressed-tensors quantized models requires OpenVINO 2026.3 or newer, "
|
|
460
|
+
"but the installed OpenVINO does not meet this requirement. "
|
|
461
|
+
"Please upgrade OpenVINO, e.g. `pip install --upgrade openvino`."
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
# Loading a compressed-tensors model and keeping its packed weights intact
|
|
465
|
+
# requires the `compressed_tensors` package.
|
|
466
|
+
if do_ct_patching and importlib.util.find_spec("compressed_tensors") is None:
|
|
467
|
+
raise RuntimeError(
|
|
468
|
+
"Exporting compressed-tensors quantized models requires the `compressed_tensors` "
|
|
469
|
+
"package, which is not installed. Please install it, e.g. `pip install compressed_tensors`."
|
|
470
|
+
)
|
|
419
471
|
|
|
420
472
|
if is_transformers_version(">=", "4.56") and config.model_type in {"qwen2_vl_text", "qwen2_5_vl_text"}:
|
|
421
473
|
patch_qwenvl_configs()
|
|
@@ -432,7 +484,7 @@ def main_export(
|
|
|
432
484
|
|
|
433
485
|
if original_task == "auto" and model_type in {"phi4mm", "phi4_multimodal"}:
|
|
434
486
|
task = "image-text-to-text"
|
|
435
|
-
elif model_type
|
|
487
|
+
elif model_type in ("qwen3_omni_moe", "lfm3_omni"):
|
|
436
488
|
task = "image-text-to-text"
|
|
437
489
|
|
|
438
490
|
if model_type not in TasksManager._SUPPORTED_MODEL_TYPE:
|
|
@@ -458,6 +510,11 @@ def main_export(
|
|
|
458
510
|
raise ValueError(
|
|
459
511
|
f"Asked to export a {model_type} model for the task {task}{autodetected_message}, but the Optimum OpenVINO exporter only supports the tasks {', '.join(model_tasks.keys())} for {model_type}. Please use a supported task. Please open an issue at https://github.com/huggingface/optimum-intel/issues if you would like the task {task} to be supported in the OpenVINO export for {model_type}."
|
|
460
512
|
)
|
|
513
|
+
if model_type in TasksManager._SUPPORTED_MODEL_TYPE:
|
|
514
|
+
export_config_constructor = TasksManager.get_exporter_config_constructor(
|
|
515
|
+
exporter="openvino", task=task, model_type=model_type, library_name=library_name
|
|
516
|
+
)
|
|
517
|
+
check_transformers_version_compatibility(export_config_constructor)
|
|
461
518
|
|
|
462
519
|
# some models force flash_attn attention by default that does not support load model on cpu
|
|
463
520
|
if model_type in FORCE_ATTN_MODEL_CLASSES:
|
|
@@ -484,6 +541,12 @@ def main_export(
|
|
|
484
541
|
if dtype == "auto":
|
|
485
542
|
dtype = getattr(config, "torch_dtype")
|
|
486
543
|
|
|
544
|
+
config_dtype = getattr(config, "torch_dtype", torch.float32)
|
|
545
|
+
if config_dtype is None:
|
|
546
|
+
# composite configs (e.g. LFM3-Omni) may keep the checkpoint dtype in some of their sub-configs only
|
|
547
|
+
sub_configs = [getattr(config, key, None) for key in getattr(config, "sub_configs", {})]
|
|
548
|
+
sub_dtypes = [getattr(sub_config, "torch_dtype", None) for sub_config in sub_configs]
|
|
549
|
+
config_dtype = next((sub_dtype for sub_dtype in sub_dtypes if sub_dtype is not None), None)
|
|
487
550
|
if (
|
|
488
551
|
dtype is None
|
|
489
552
|
and framework == "pt"
|
|
@@ -491,13 +554,13 @@ def main_export(
|
|
|
491
554
|
task.startswith("text-generation")
|
|
492
555
|
or getattr(config, "model_type", "") in MULTI_MODAL_TEXT_GENERATION_MODELS
|
|
493
556
|
)
|
|
494
|
-
and
|
|
557
|
+
and config_dtype in [torch.float16, torch.bfloat16]
|
|
495
558
|
):
|
|
496
559
|
if ov_config is not None and ov_config.dtype in {"fp16", "fp32"}:
|
|
497
560
|
dtype = torch.float16 if ov_config.dtype == "fp16" else torch.float32
|
|
498
|
-
elif
|
|
561
|
+
elif config_dtype == torch.float16:
|
|
499
562
|
dtype = torch.float16
|
|
500
|
-
elif
|
|
563
|
+
elif config_dtype == torch.bfloat16:
|
|
501
564
|
dtype = torch.bfloat16
|
|
502
565
|
|
|
503
566
|
if dtype is not None:
|
|
@@ -550,6 +613,32 @@ def main_export(
|
|
|
550
613
|
return state_dict
|
|
551
614
|
|
|
552
615
|
AutoBitLinear.load_hook = bitnet_load_hook
|
|
616
|
+
if do_ct_patching:
|
|
617
|
+
from transformers.quantizers.quantizer_compressed_tensors import (
|
|
618
|
+
CompressedTensorsHfQuantizer,
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
orig_ct_process = CompressedTensorsHfQuantizer._process_model_after_weight_loading
|
|
622
|
+
|
|
623
|
+
# Skip decompression so that weight_packed buffers remain intact for
|
|
624
|
+
# the OV PT frontend compressed-tensors patcher (quantized.py) to
|
|
625
|
+
# convert them to u4 constants during tracing.
|
|
626
|
+
CompressedTensorsHfQuantizer._process_model_after_weight_loading = lambda self, model, **kwargs: model
|
|
627
|
+
|
|
628
|
+
# In compressed-tensors >= 0.15, compress_model() installs a forward
|
|
629
|
+
# pre-hook (ct_decompress_hook) that lazily decompresses weights on
|
|
630
|
+
# the first forward pass. We must suppress it so that weight_packed
|
|
631
|
+
# buffers stay intact for the OV traced graph. Older versions do not
|
|
632
|
+
# define the method, so nothing needs to be patched there.
|
|
633
|
+
orig_add_decompress_hook = None
|
|
634
|
+
try:
|
|
635
|
+
from compressed_tensors import ModelCompressor
|
|
636
|
+
|
|
637
|
+
if hasattr(ModelCompressor, "add_decompress_hook"):
|
|
638
|
+
orig_add_decompress_hook = ModelCompressor.add_decompress_hook
|
|
639
|
+
ModelCompressor.add_decompress_hook = lambda self, model: None
|
|
640
|
+
except ImportError:
|
|
641
|
+
pass
|
|
553
642
|
elif library_name == "diffusers":
|
|
554
643
|
_loading_kwargs = {} if variant is None else {"variant": variant}
|
|
555
644
|
if dtype == "auto" or dtype is None:
|
|
@@ -572,6 +661,7 @@ def main_export(
|
|
|
572
661
|
if dtype in [torch.float16, torch.bfloat16]:
|
|
573
662
|
loading_kwargs["torch_dtype"] = dtype
|
|
574
663
|
patch_16bit = True
|
|
664
|
+
keep_mixed_precision_parameters()
|
|
575
665
|
if loading_kwargs.get("torch_dtype") == "auto":
|
|
576
666
|
loading_kwargs["torch_dtype"] = dtype
|
|
577
667
|
|
|
@@ -581,16 +671,62 @@ def main_export(
|
|
|
581
671
|
elif library_name == "kokoro":
|
|
582
672
|
model = _KokoroForTextToSpeech.from_pretrained(model_name_or_path, cache_dir=cache_dir, token=token)
|
|
583
673
|
elif library_name == "funasr":
|
|
584
|
-
from optimum.intel.openvino.modeling_funasr import
|
|
674
|
+
from optimum.intel.openvino.modeling_funasr import (
|
|
675
|
+
_FunASRForSpeechSeq2Seq,
|
|
676
|
+
_is_sensevoice_source,
|
|
677
|
+
_SenseVoiceForCTC,
|
|
678
|
+
)
|
|
585
679
|
|
|
586
|
-
|
|
680
|
+
if _is_sensevoice_source(
|
|
681
|
+
model_name_or_path, cache_dir=cache_dir, token=token, subfolder=subfolder, revision=revision
|
|
682
|
+
):
|
|
683
|
+
model = _SenseVoiceForCTC.from_pretrained(model_name_or_path, cache_dir=cache_dir, token=token)
|
|
684
|
+
else:
|
|
685
|
+
model = _FunASRForSpeechSeq2Seq.from_pretrained(model_name_or_path, cache_dir=cache_dir, token=token)
|
|
686
|
+
elif (
|
|
687
|
+
library_name == "transformers"
|
|
688
|
+
and (getattr(config, "architectures", None) or [None])[0] in _NATIVE_DRAFT_MODEL_CLASSES
|
|
689
|
+
):
|
|
690
|
+
model = load_native_draft_model(
|
|
691
|
+
config.architectures[0],
|
|
692
|
+
model_name_or_path,
|
|
693
|
+
subfolder=subfolder,
|
|
694
|
+
revision=revision,
|
|
695
|
+
cache_dir=cache_dir,
|
|
696
|
+
token=token,
|
|
697
|
+
local_files_only=local_files_only,
|
|
698
|
+
force_download=force_download,
|
|
699
|
+
**loading_kwargs,
|
|
700
|
+
)
|
|
701
|
+
elif library_name == "qwen3_tts":
|
|
702
|
+
# Without an explicit request the checkpoint's own precision is kept, so the IRs
|
|
703
|
+
# come out at the precision the model was published in rather than upcast. A
|
|
704
|
+
# floating-point --weight-format still pins the precision it names.
|
|
705
|
+
if ov_config is not None and ov_config.dtype in {"fp16", "fp32"}:
|
|
706
|
+
loading_kwargs.setdefault("torch_dtype", torch.float16 if ov_config.dtype == "fp16" else torch.float32)
|
|
707
|
+
model = _Qwen3TTSForTextToSpeech.from_pretrained(
|
|
708
|
+
model_name_or_path,
|
|
709
|
+
cache_dir=cache_dir,
|
|
710
|
+
token=token,
|
|
711
|
+
revision=revision,
|
|
712
|
+
local_files_only=local_files_only,
|
|
713
|
+
force_download=force_download,
|
|
714
|
+
**loading_kwargs,
|
|
715
|
+
)
|
|
587
716
|
else:
|
|
588
717
|
# remote code models like phi3_v internvl2, minicpmv, internvl2, nanollava, maira2 should be loaded using AutoModelForCausalLM and not AutoModelForImageTextToText
|
|
589
718
|
# TODO: use config.auto_map to load remote code models instead (for other models we can directly use config.architectures)
|
|
590
719
|
task_model_loading = task
|
|
591
720
|
if library_name == "transformers":
|
|
592
|
-
|
|
593
|
-
|
|
721
|
+
auto_map = getattr(config, "auto_map", None)
|
|
722
|
+
has_remote_code = auto_map is not None
|
|
723
|
+
# remote code that registers only AutoModelForImageTextToText (e.g. LFM3-Omni) is loaded with it
|
|
724
|
+
image_text_only = (
|
|
725
|
+
isinstance(auto_map, dict)
|
|
726
|
+
and "AutoModelForImageTextToText" in auto_map
|
|
727
|
+
and "AutoModelForCausalLM" not in auto_map
|
|
728
|
+
)
|
|
729
|
+
if has_remote_code and trust_remote_code and task == "image-text-to-text" and not image_text_only:
|
|
594
730
|
task_model_loading = "text-generation"
|
|
595
731
|
|
|
596
732
|
model = TasksManager.get_model_from_task(
|
|
@@ -643,6 +779,11 @@ def main_export(
|
|
|
643
779
|
preprocessors = load_preprocessors(
|
|
644
780
|
model_name_or_path, subfolder=subfolder, trust_remote_code=trust_remote_code, model_type=model_type
|
|
645
781
|
)
|
|
782
|
+
architectures = getattr(model.config, "architectures", None) or []
|
|
783
|
+
if architectures and architectures[0] in DFLASH_ARCHITECTURES | DSPARK_ARCHITECTURES:
|
|
784
|
+
# These drafts always run with the target model's tokenizer. Most are published without one, and
|
|
785
|
+
# transformers 5 then builds a placeholder tokenizer from the config.
|
|
786
|
+
preprocessors = [p for p in preprocessors if not isinstance(p, PreTrainedTokenizerBase)]
|
|
646
787
|
|
|
647
788
|
submodel_paths = export_from_model(
|
|
648
789
|
model=model,
|
|
@@ -663,6 +804,10 @@ def main_export(
|
|
|
663
804
|
if convert_tokenizer:
|
|
664
805
|
maybe_convert_tokenizers(library_name, output, model, preprocessors, task=task)
|
|
665
806
|
|
|
807
|
+
# Evaluated before `del model`: the size-based quantization below is skipped for some model
|
|
808
|
+
# types, and by the time it runs the object is gone.
|
|
809
|
+
skip_auto_compression = is_auto_compression_disabled(model)
|
|
810
|
+
|
|
666
811
|
clear_class_registry()
|
|
667
812
|
del model
|
|
668
813
|
gc.collect()
|
|
@@ -670,7 +815,12 @@ def main_export(
|
|
|
670
815
|
# TODO: Remove GPT-OSS workaround when possible
|
|
671
816
|
quantization_config = None if ov_config is None else ov_config.quantization_config
|
|
672
817
|
if not quantization_config or isinstance(quantization_config, _GPTOSSQuantizationConfig):
|
|
673
|
-
|
|
818
|
+
better_quality_config = (
|
|
819
|
+
_get_better_quality_config(model_name_or_path, skip_auto_compression) if ov_config is None else None
|
|
820
|
+
)
|
|
821
|
+
_apply_model_size_based_quantization(
|
|
822
|
+
submodel_paths, ov_config, output, skip_auto_compression, better_quality_config
|
|
823
|
+
)
|
|
674
824
|
finally:
|
|
675
825
|
# Unpatch modules after quantized model export
|
|
676
826
|
if do_quant_patching:
|
|
@@ -679,6 +829,10 @@ def main_export(
|
|
|
679
829
|
GPTQQuantizer.post_init_model = orig_post_init_model
|
|
680
830
|
if do_bitnet_patching:
|
|
681
831
|
AutoBitLinear.load_hook = orig_load_hook
|
|
832
|
+
if do_ct_patching:
|
|
833
|
+
CompressedTensorsHfQuantizer._process_model_after_weight_loading = orig_ct_process
|
|
834
|
+
if orig_add_decompress_hook is not None:
|
|
835
|
+
ModelCompressor.add_decompress_hook = orig_add_decompress_hook
|
|
682
836
|
|
|
683
837
|
|
|
684
838
|
def _main_quantize(
|
|
@@ -730,6 +884,8 @@ def _main_quantize(
|
|
|
730
884
|
`model_kwargs={"output_attentions": True}` is passed).
|
|
731
885
|
|
|
732
886
|
"""
|
|
887
|
+
from optimum.intel.openvino.configuration import OVWeightQuantizationConfig
|
|
888
|
+
from optimum.intel.openvino.modeling_dflash import is_dflash_draft_model
|
|
733
889
|
from optimum.intel.openvino.utils import _HEAD_TO_AUTOMODELS
|
|
734
890
|
|
|
735
891
|
# Step 0. Infer task and library name if needed
|
|
@@ -773,7 +929,7 @@ def _main_quantize(
|
|
|
773
929
|
# phi4mm is only misrouted by task inference, so keep its redirect limited to the auto case.
|
|
774
930
|
if original_task == "auto" and model_type in ["phi4mm", "phi4_multimodal"]:
|
|
775
931
|
task = "image-text-to-text"
|
|
776
|
-
elif model_type
|
|
932
|
+
elif model_type in ("qwen3_omni_moe", "lfm3_omni"):
|
|
777
933
|
task = "image-text-to-text"
|
|
778
934
|
|
|
779
935
|
# Step 1. Obtain the correct OpenVINO model class
|
|
@@ -795,6 +951,13 @@ def _main_quantize(
|
|
|
795
951
|
model_cls_name = _HEAD_TO_AUTOMODELS[task.replace("-with-past", "")]
|
|
796
952
|
if library_name == "sentence_transformers":
|
|
797
953
|
model_cls_name = "OVSentenceTransformer"
|
|
954
|
+
elif (
|
|
955
|
+
library_name == "transformers"
|
|
956
|
+
and task == "text-classification"
|
|
957
|
+
and model_type in MULTI_MODAL_TEXT_GENERATION_MODELS
|
|
958
|
+
):
|
|
959
|
+
# a VLM with a sequence classification head is exported as VLM parts
|
|
960
|
+
model_cls_name = "OVModelForVisualSequenceClassification"
|
|
798
961
|
model_cls = getattr(__import__("optimum.intel", fromlist=[model_cls_name]), model_cls_name)
|
|
799
962
|
except (AttributeError, ImportError, KeyError) as e:
|
|
800
963
|
raise RuntimeError(f"Wasn't able to locate OpenVINO class for task {original_task} ({task}).") from e
|
|
@@ -810,6 +973,16 @@ def _main_quantize(
|
|
|
810
973
|
)
|
|
811
974
|
|
|
812
975
|
# Step 3. Apply quantization and save the quantized model
|
|
976
|
+
if (
|
|
977
|
+
isinstance(quantization_config, OVWeightQuantizationConfig)
|
|
978
|
+
and quantization_config.bits == 4
|
|
979
|
+
and quantization_config.all_layers is None
|
|
980
|
+
and isinstance(getattr(model, "model", None), Model)
|
|
981
|
+
and is_dflash_draft_model(model.model)
|
|
982
|
+
):
|
|
983
|
+
# DFlash drafts have no embeddings or lm_head, so NNCF's "last MatMul stays int8" rule would hit a decoder layer.
|
|
984
|
+
quantization_config = quantization_config.clone()
|
|
985
|
+
quantization_config.all_layers = True
|
|
813
986
|
model._apply_quantization(
|
|
814
987
|
quantization_config,
|
|
815
988
|
compile_only=False,
|
|
@@ -840,7 +1013,28 @@ def maybe_convert_tokenizers(library_name: str, output: Path, model=None, prepro
|
|
|
840
1013
|
from optimum.exporters.openvino.convert import export_tokenizer
|
|
841
1014
|
|
|
842
1015
|
if is_openvino_tokenizers_available():
|
|
843
|
-
if
|
|
1016
|
+
if (
|
|
1017
|
+
library_name == "funasr"
|
|
1018
|
+
and model is not None
|
|
1019
|
+
and getattr(model.config, "export_model_type", None) == "sense_voice"
|
|
1020
|
+
):
|
|
1021
|
+
# SenseVoiceSmall ships a SentencePiece BPE model rather than a transformers tokenizer, so it
|
|
1022
|
+
# is not among ``preprocessors``. It has no text input, so build only the OV detokenizer IR from
|
|
1023
|
+
# that BPE model.
|
|
1024
|
+
from optimum.intel.openvino.modeling_funasr import export_sensevoice_tokenizers
|
|
1025
|
+
|
|
1026
|
+
source = getattr(model, "_sensevoice_source", None)
|
|
1027
|
+
if source is None:
|
|
1028
|
+
logger.warning("SenseVoice source path unknown; OpenVINO detokenizer model won't be generated.")
|
|
1029
|
+
else:
|
|
1030
|
+
try:
|
|
1031
|
+
export_sensevoice_tokenizers(source, output)
|
|
1032
|
+
except Exception as exception:
|
|
1033
|
+
logger.warning(
|
|
1034
|
+
"Could not convert the SenseVoice tokenizer. OpenVINO detokenizer "
|
|
1035
|
+
f"model won't be generated. Exception: {exception}"
|
|
1036
|
+
)
|
|
1037
|
+
elif library_name != "diffusers" and preprocessors:
|
|
844
1038
|
processor_chat_template = None
|
|
845
1039
|
tokenizer = next(filter(lambda it: isinstance(it, PreTrainedTokenizerBase), preprocessors), None)
|
|
846
1040
|
if len(preprocessors) > 1:
|
|
@@ -865,19 +1059,84 @@ def maybe_convert_tokenizers(library_name: str, output: Path, model=None, prepro
|
|
|
865
1059
|
tokenizer = getattr(model, tokenizer_name, None)
|
|
866
1060
|
if tokenizer:
|
|
867
1061
|
export_tokenizer(tokenizer, output / tokenizer_name, task=task)
|
|
1062
|
+
# Some diffusion pipelines (e.g. QwenImage2.1) register a `processor` instead of a bare
|
|
1063
|
+
# `tokenizer`; its tokenizer files are saved under the `processor` subfolder, so the OV
|
|
1064
|
+
# tokenizer/detokenizer IRs must be written there too.
|
|
1065
|
+
processor = getattr(model, "processor", None)
|
|
1066
|
+
processor_tokenizer = getattr(processor, "tokenizer", None) if processor is not None else None
|
|
1067
|
+
if processor_tokenizer is not None:
|
|
1068
|
+
processor_chat_template = getattr(processor, "chat_template", None)
|
|
1069
|
+
export_tokenizer(
|
|
1070
|
+
processor_tokenizer,
|
|
1071
|
+
output / "processor",
|
|
1072
|
+
task=task,
|
|
1073
|
+
processor_chat_template=processor_chat_template,
|
|
1074
|
+
)
|
|
868
1075
|
else:
|
|
869
1076
|
logger.warning("Tokenizer won't be converted.")
|
|
870
1077
|
|
|
871
1078
|
|
|
872
|
-
def
|
|
1079
|
+
def _get_better_quality_config(model_name_or_path: str, skip_auto_compression: bool) -> Optional[Dict[str, Any]]:
|
|
1080
|
+
"""
|
|
1081
|
+
Returns the config to compress the large submodels with when no weight format is given, instead of the generic
|
|
1082
|
+
int8_asym one, which costs too much quality for the models excluded from the automatic int8 compression (LTX-2).
|
|
1083
|
+
Only such models can have it: it is the int8 config registered for the model in `_DEFAULT_8BIT_WQ_CONFIGS`, which
|
|
1084
|
+
is tuned to keep the quality. If the installed NNCF version does not support it, the model is not compressed and a
|
|
1085
|
+
warning to install the latest NNCF version is printed.
|
|
1086
|
+
"""
|
|
1087
|
+
if not skip_auto_compression:
|
|
1088
|
+
return None
|
|
1089
|
+
|
|
1090
|
+
from optimum.intel.openvino.configuration import (
|
|
1091
|
+
_DEFAULT_8BIT_WQ_CONFIGS,
|
|
1092
|
+
_find_model_config,
|
|
1093
|
+
_get_missing_nncf_version,
|
|
1094
|
+
)
|
|
1095
|
+
|
|
1096
|
+
better_quality_config = _find_model_config(model_name_or_path, _DEFAULT_8BIT_WQ_CONFIGS)
|
|
1097
|
+
missing_nncf_version = _get_missing_nncf_version(better_quality_config)
|
|
1098
|
+
if missing_nncf_version is not None:
|
|
1099
|
+
logger.warning(
|
|
1100
|
+
"The model weights are not compressed, since the int8 config tuned to keep the quality of this model "
|
|
1101
|
+
f"needs nncf>={missing_nncf_version}. With it, the large submodels of the model are compressed to int8 by "
|
|
1102
|
+
"default, which roughly halves their size. Please install the latest nncf version, e.g. with "
|
|
1103
|
+
"`pip install -U nncf`."
|
|
1104
|
+
)
|
|
1105
|
+
return None
|
|
1106
|
+
return better_quality_config
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
def _apply_model_size_based_quantization(
|
|
1110
|
+
submodel_paths: List[str],
|
|
1111
|
+
ov_config: "OVConfig",
|
|
1112
|
+
output: Union[str, Path],
|
|
1113
|
+
skip_auto_compression: bool = False,
|
|
1114
|
+
better_quality_config: Optional[Dict[str, Any]] = None,
|
|
1115
|
+
):
|
|
873
1116
|
"""
|
|
874
1117
|
Apply weight-only quantization to int8_asym to submodels larger than 1B parameters.
|
|
1118
|
+
|
|
1119
|
+
Models for which `is_auto_compression_disabled` holds are left uncompressed: they are large
|
|
1120
|
+
enough to always cross the threshold, but lose too much quality at int8 for that to be a silent
|
|
1121
|
+
default. If such a model has an int8 config registered in `_DEFAULT_8BIT_WQ_CONFIGS`, given as
|
|
1122
|
+
`better_quality_config`, its submodels larger than 1B parameters that have an entry in it, matched by the
|
|
1123
|
+
submodel directory name, are quantized with that entry, which is tuned to keep the quality.
|
|
1124
|
+
An explicitly requested weight format is unaffected -- it does not reach this branch.
|
|
875
1125
|
"""
|
|
1126
|
+
if skip_auto_compression and ov_config is None and better_quality_config is None:
|
|
1127
|
+
logger.info(
|
|
1128
|
+
"Automatic int8 weight compression is skipped for this model. Export with "
|
|
1129
|
+
"`--weight-format int8` to compress the weights anyway."
|
|
1130
|
+
)
|
|
1131
|
+
return
|
|
1132
|
+
|
|
876
1133
|
# TODO: Refactor the code below in the following way:
|
|
877
1134
|
# 1. Create a OVPipelineQuantizationConfig based on each submodel size
|
|
878
1135
|
# 2. Run _main_quantize() with the created quantization config
|
|
879
1136
|
# TODO: Apply default int8 and ignored scope configs from configuration.py if matches
|
|
1137
|
+
# (not only for skip_auto_compressed models)
|
|
880
1138
|
for submodel_path in submodel_paths:
|
|
1139
|
+
submodel_name = Path(submodel_path).parent.name # the submodel directory of a diffusers pipeline
|
|
881
1140
|
submodel_path = Path(output) / submodel_path
|
|
882
1141
|
|
|
883
1142
|
if (not submodel_path.is_file()) or (submodel_path.stat().st_size == 0):
|
|
@@ -896,8 +1155,15 @@ def _apply_model_size_based_quantization(submodel_paths: List[str], ov_config: "
|
|
|
896
1155
|
del op
|
|
897
1156
|
if num_parameters >= _MAX_UNCOMPRESSED_SIZE:
|
|
898
1157
|
if is_nncf_available():
|
|
899
|
-
|
|
900
|
-
|
|
1158
|
+
if better_quality_config is None:
|
|
1159
|
+
quantization_config = {"bits": 8, "sym": False}
|
|
1160
|
+
logger.info("The model weights will be quantized to int8_asym.")
|
|
1161
|
+
else:
|
|
1162
|
+
quantization_config = better_quality_config.get("quantization_configs", {}).get(submodel_name)
|
|
1163
|
+
if quantization_config is not None:
|
|
1164
|
+
logger.info(
|
|
1165
|
+
f"The {submodel_name} weights will be quantized to int8 with config {quantization_config}."
|
|
1166
|
+
)
|
|
901
1167
|
else:
|
|
902
1168
|
logger.warning(
|
|
903
1169
|
"The model will be converted with no weights quantization. Quantization of the weights to int8 "
|