Skip to content

Commit f75d18d

Browse files
authored
Merge branch 'main' into ea/mpt_sdpa
2 parents 2f960af + 805335c commit f75d18d

17 files changed

+387
-64
lines changed

optimum/exporters/openvino/__main__.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import logging
16+
import warnings
1617
from pathlib import Path
1718
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union
1819

@@ -57,6 +58,7 @@ def main_export(
5758
force_download: bool = False,
5859
local_files_only: bool = False,
5960
use_auth_token: Optional[Union[bool, str]] = None,
61+
token: Optional[Union[bool, str]] = None,
6062
model_kwargs: Optional[Dict[str, Any]] = None,
6163
custom_export_configs: Optional[Dict[str, "OnnxConfig"]] = None,
6264
fn_get_submodels: Optional[Callable] = None,
@@ -107,9 +109,11 @@ def main_export(
107109
cached versions if they exist.
108110
local_files_only (`Optional[bool]`, defaults to `False`):
109111
Whether or not to only look at local files (i.e., do not try to download the model).
110-
use_auth_token (`Optional[str]`, defaults to `None`):
112+
use_auth_token (Optional[Union[bool, str]], defaults to `None`):
113+
Deprecated. Please use `token` instead.
114+
token (Optional[Union[bool, str]], defaults to `None`):
111115
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
112-
when running `transformers-cli login` (stored in `~/.huggingface`).
116+
when running `huggingface-cli login` (stored in `~/.huggingface`).
113117
model_kwargs (`Optional[Dict[str, Any]]`, defaults to `None`):
114118
Experimental usage: keyword arguments to pass to the model during
115119
the export. This argument should be used along the `custom_export_configs` argument
@@ -138,6 +142,15 @@ def main_export(
138142
```
139143
"""
140144

145+
if use_auth_token is not None:
146+
warnings.warn(
147+
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
148+
FutureWarning,
149+
)
150+
if token is not None:
151+
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
152+
token = use_auth_token
153+
141154
if compression_option is not None:
142155
logger.warning(
143156
"The `compression_option` argument is deprecated and will be removed in optimum-intel v1.17.0. "
@@ -196,7 +209,7 @@ def main_export(
196209
subfolder=subfolder,
197210
revision=revision,
198211
cache_dir=cache_dir,
199-
use_auth_token=use_auth_token,
212+
token=token,
200213
local_files_only=local_files_only,
201214
force_download=force_download,
202215
trust_remote_code=trust_remote_code,
@@ -268,7 +281,7 @@ class StoreAttr(object):
268281
subfolder=subfolder,
269282
revision=revision,
270283
cache_dir=cache_dir,
271-
use_auth_token=use_auth_token,
284+
token=token,
272285
local_files_only=local_files_only,
273286
force_download=force_download,
274287
trust_remote_code=trust_remote_code,

optimum/exporters/openvino/model_configs.py

+59
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
LlamaOnnxConfig,
2626
MPTOnnxConfig,
2727
PhiOnnxConfig,
28+
UNetOnnxConfig,
29+
VaeDecoderOnnxConfig,
30+
VaeEncoderOnnxConfig,
2831
)
2932
from optimum.exporters.tasks import TasksManager
3033
from optimum.utils import DEFAULT_DUMMY_SHAPES
@@ -533,3 +536,59 @@ class FalconOpenVINOConfig(FalconOnnxConfig):
533536
OVFalconDummyPastKeyValuesGenerator,
534537
) + TextDecoderOnnxConfig.DUMMY_INPUT_GENERATOR_CLASSES
535538
DUMMY_PKV_GENERATOR_CLASS = OVFalconDummyPastKeyValuesGenerator
539+
540+
541+
@register_in_tasks_manager("unet", *["semantic-segmentation"], library_name="diffusers")
542+
class UNetOpenVINOConfig(UNetOnnxConfig):
543+
@property
544+
def inputs(self) -> Dict[str, Dict[int, str]]:
545+
common_inputs = {
546+
"sample": {0: "batch_size", 2: "height", 3: "width"},
547+
"timestep": {0: "steps"},
548+
"encoder_hidden_states": {0: "batch_size", 1: "sequence_length"},
549+
}
550+
551+
# TODO : add text_image, image and image_embeds
552+
if getattr(self._normalized_config, "addition_embed_type", None) == "text_time":
553+
common_inputs["text_embeds"] = {0: "batch_size"}
554+
common_inputs["time_ids"] = {0: "batch_size"}
555+
556+
if getattr(self._normalized_config, "time_cond_proj_dim", None) is not None:
557+
common_inputs["timestep_cond"] = {0: "batch_size"}
558+
return common_inputs
559+
560+
@property
561+
def outputs(self) -> Dict[str, Dict[int, str]]:
562+
return {
563+
"out_sample": {0: "batch_size", 2: "height", 3: "width"},
564+
}
565+
566+
567+
@register_in_tasks_manager("vae-encoder", *["semantic-segmentation"], library_name="diffusers")
568+
class VaeEncoderOpenVINOConfig(VaeEncoderOnnxConfig):
569+
@property
570+
def inputs(self) -> Dict[str, Dict[int, str]]:
571+
return {
572+
"sample": {0: "batch_size", 2: "height", 3: "width"},
573+
}
574+
575+
@property
576+
def outputs(self) -> Dict[str, Dict[int, str]]:
577+
return {
578+
"latent_sample": {0: "batch_size", 2: "height_latent", 3: "width_latent"},
579+
}
580+
581+
582+
@register_in_tasks_manager("vae-decoder", *["semantic-segmentation"], library_name="diffusers")
583+
class VaeDecoderOpenVINOConfig(VaeDecoderOnnxConfig):
584+
@property
585+
def inputs(self) -> Dict[str, Dict[int, str]]:
586+
return {
587+
"latent_sample": {0: "batch_size", 2: "height_latent", 3: "width_latent"},
588+
}
589+
590+
@property
591+
def outputs(self) -> Dict[str, Dict[int, str]]:
592+
return {
593+
"sample": {0: "batch_size", 2: "height", 3: "width"},
594+
}

optimum/intel/generation/modeling.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import inspect
1616
import logging
1717
import os
18+
import warnings
1819
from pathlib import Path
1920
from tempfile import TemporaryDirectory
2021
from typing import Optional, Tuple, Union
@@ -363,15 +364,25 @@ def _from_pretrained(
363364
cls,
364365
model_id: Union[str, Path],
365366
config: PretrainedConfig,
366-
use_auth_token: Optional[Union[bool, str, None]] = None,
367-
revision: Optional[Union[str, None]] = None,
367+
use_auth_token: Optional[Union[bool, str]] = None,
368+
token: Optional[Union[bool, str]] = None,
369+
revision: Optional[str] = None,
368370
force_download: bool = False,
369371
cache_dir: str = HUGGINGFACE_HUB_CACHE,
370372
file_name: Optional[str] = WEIGHTS_NAME,
371373
local_files_only: bool = False,
372374
use_cache: bool = True,
373375
**kwargs,
374376
):
377+
if use_auth_token is not None:
378+
warnings.warn(
379+
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
380+
FutureWarning,
381+
)
382+
if token is not None:
383+
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
384+
token = use_auth_token
385+
375386
if not getattr(config, "torchscript", False):
376387
raise ValueError("`torchscript` should be set to True to load TorchScript model")
377388

@@ -385,7 +396,7 @@ def _from_pretrained(
385396
model_cache_path = hf_hub_download(
386397
repo_id=model_id,
387398
filename=file_name,
388-
use_auth_token=use_auth_token,
399+
token=token,
389400
revision=revision,
390401
cache_dir=cache_dir,
391402
force_download=force_download,
@@ -408,6 +419,7 @@ def _from_transformers(
408419
model_id: str,
409420
config: PretrainedConfig,
410421
use_auth_token: Optional[Union[bool, str]] = None,
422+
token: Optional[Union[bool, str]] = None,
411423
revision: Optional[str] = None,
412424
force_download: bool = False,
413425
cache_dir: str = HUGGINGFACE_HUB_CACHE,
@@ -417,13 +429,22 @@ def _from_transformers(
417429
torch_dtype: Optional[Union[str, "torch.dtype"]] = None,
418430
**kwargs,
419431
):
432+
if use_auth_token is not None:
433+
warnings.warn(
434+
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
435+
FutureWarning,
436+
)
437+
if token is not None:
438+
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
439+
token = use_auth_token
440+
420441
if is_torch_version("<", "2.1.0"):
421442
raise ImportError("`torch>=2.0.0` is needed to trace your model")
422443

423444
task = cls.export_feature
424445
model_kwargs = {
425446
"revision": revision,
426-
"use_auth_token": use_auth_token,
447+
"token": token,
427448
"cache_dir": cache_dir,
428449
"subfolder": subfolder,
429450
"local_files_only": local_files_only,
@@ -445,7 +466,7 @@ def _from_transformers(
445466
model_id=save_dir_path,
446467
config=config,
447468
use_cache=use_cache,
448-
use_auth_token=use_auth_token,
469+
token=token,
449470
revision=revision,
450471
force_download=force_download,
451472
cache_dir=cache_dir,

optimum/intel/ipex/modeling_base.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import logging
1717
import os
18+
import warnings
1819
from pathlib import Path
1920
from tempfile import TemporaryDirectory
2021
from typing import Optional, Tuple, Union
@@ -152,6 +153,7 @@ def _from_transformers(
152153
config: PretrainedConfig,
153154
use_cache: bool = True,
154155
use_auth_token: Optional[Union[bool, str]] = None,
156+
token: Optional[Union[bool, str]] = None,
155157
revision: Optional[str] = None,
156158
force_download: bool = False,
157159
cache_dir: str = HUGGINGFACE_HUB_CACHE,
@@ -160,13 +162,24 @@ def _from_transformers(
160162
torch_dtype: Optional[Union[str, "torch.dtype"]] = None,
161163
trust_remote_code: bool = False,
162164
):
165+
if use_auth_token is not None:
166+
warnings.warn(
167+
"The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
168+
FutureWarning,
169+
)
170+
if token is not None:
171+
raise ValueError(
172+
"Both the arguments `use_auth_token` and `token` were specified, which is not supported. Please specify only `token`."
173+
)
174+
token = use_auth_token
175+
163176
if is_torch_version("<", "2.1.0"):
164177
raise ImportError("`torch>=2.0.0` is needed to trace your model")
165178

166179
task = cls.export_feature
167180
model_kwargs = {
168181
"revision": revision,
169-
"use_auth_token": use_auth_token,
182+
"token": token,
170183
"cache_dir": cache_dir,
171184
"subfolder": subfolder,
172185
"local_files_only": local_files_only,
@@ -188,15 +201,27 @@ def _from_pretrained(
188201
cls,
189202
model_id: Union[str, Path],
190203
config: PretrainedConfig,
191-
use_auth_token: Optional[Union[bool, str, None]] = None,
192-
revision: Optional[Union[str, None]] = None,
204+
use_auth_token: Optional[Union[bool, str]] = None,
205+
token: Optional[Union[bool, str]] = None,
206+
revision: Optional[str] = None,
193207
force_download: bool = False,
194208
cache_dir: str = HUGGINGFACE_HUB_CACHE,
195209
file_name: Optional[str] = WEIGHTS_NAME,
196210
local_files_only: bool = False,
197211
subfolder: str = "",
198212
**kwargs,
199213
):
214+
if use_auth_token is not None:
215+
warnings.warn(
216+
"The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
217+
FutureWarning,
218+
)
219+
if token is not None:
220+
raise ValueError(
221+
"Both the arguments `use_auth_token` and `token` were specified, which is not supported. Please specify only `token`."
222+
)
223+
token = use_auth_token
224+
200225
if not getattr(config, "torchscript", False):
201226
raise ValueError(
202227
"`config.torchscript` should be set to `True`, if your model is not a TorchScript model and needs to be traced please set `export=True` when loading it with `.from_pretrained()`"
@@ -211,7 +236,7 @@ def _from_pretrained(
211236
model_cache_path = hf_hub_download(
212237
repo_id=model_id,
213238
filename=file_name,
214-
use_auth_token=use_auth_token,
239+
token=token,
215240
revision=revision,
216241
cache_dir=cache_dir,
217242
force_download=force_download,

optimum/intel/neural_compressor/modeling_base.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import logging
1616
import os
17+
import warnings
1718
from pathlib import Path
1819
from tempfile import TemporaryDirectory
1920
from typing import Dict, Optional, Union
@@ -98,8 +99,9 @@ def _from_pretrained(
9899
cls,
99100
model_id: Union[str, Path],
100101
config: PretrainedConfig,
101-
use_auth_token: Optional[Union[bool, str, None]] = None,
102-
revision: Optional[Union[str, None]] = None,
102+
use_auth_token: Optional[Union[bool, str]] = None,
103+
token: Optional[Union[bool, str]] = None,
104+
revision: Optional[str] = None,
103105
force_download: bool = False,
104106
cache_dir: str = HUGGINGFACE_HUB_CACHE,
105107
file_name: str = WEIGHTS_NAME,
@@ -108,6 +110,15 @@ def _from_pretrained(
108110
trust_remote_code: bool = False,
109111
**kwargs,
110112
):
113+
if use_auth_token is not None:
114+
warnings.warn(
115+
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
116+
FutureWarning,
117+
)
118+
if token is not None:
119+
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
120+
token = use_auth_token
121+
111122
model_name_or_path = kwargs.pop("model_name_or_path", None)
112123
if model_name_or_path is not None:
113124
logger.warning("`model_name_or_path` is deprecated please use `model_id`")
@@ -122,7 +133,7 @@ def _from_pretrained(
122133
repo_id=model_id,
123134
filename=file_name,
124135
subfolder=subfolder,
125-
use_auth_token=use_auth_token,
136+
token=token,
126137
revision=revision,
127138
cache_dir=cache_dir,
128139
force_download=force_download,
@@ -145,7 +156,7 @@ def _from_pretrained(
145156

146157
return _BaseQBitsAutoModelClass.from_pretrained(
147158
pretrained_model_name_or_path=model_id,
148-
use_auth_token=use_auth_token,
159+
token=token,
149160
revision=revision,
150161
force_download=force_download,
151162
cache_dir=cache_dir,

0 commit comments

Comments
 (0)