Skip to content

Commit e15053d

Browse files
Fix and uniformize hub kwargs (#2276)
* fix and uniformize hub kwargs * fix
1 parent 16618fc commit e15053d

5 files changed

Lines changed: 61 additions & 84 deletions

File tree

optimum/exporters/onnx/__main__.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""Entry point to the optimum.exporters.onnx command line."""
1616

1717
import argparse
18-
import warnings
1918
from pathlib import Path
2019

2120
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
@@ -63,15 +62,16 @@ def main_export(
6362
no_post_process: bool = False,
6463
framework: Optional[str] = None,
6564
atol: Optional[float] = None,
66-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
67-
trust_remote_code: bool = False,
6865
pad_token_id: Optional[int] = None,
66+
# hub options
6967
subfolder: str = "",
7068
revision: str = "main",
7169
force_download: bool = False,
7270
local_files_only: bool = False,
73-
use_auth_token: Optional[Union[bool, str]] = None,
71+
trust_remote_code: bool = False,
72+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
7473
token: Optional[Union[bool, str]] = None,
74+
########################################
7575
for_ort: bool = False,
7676
do_validation: bool = True,
7777
model_kwargs: Optional[Dict[str, Any]] = None,
@@ -185,15 +185,6 @@ def main_export(
185185
```
186186
"""
187187

188-
if use_auth_token is not None:
189-
warnings.warn(
190-
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
191-
FutureWarning,
192-
)
193-
if token is not None:
194-
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
195-
token = use_auth_token
196-
197188
if fp16:
198189
if dtype is not None:
199190
raise ValueError(

optimum/modeling_base.py

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,15 @@ def git_config_username_and_email(self, git_user: str = None, git_email: str = N
241241
def _load_config(
242242
cls,
243243
config_name_or_path: Union[str, os.PathLike],
244-
revision: Optional[str] = None,
245-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
246-
use_auth_token: Optional[Union[bool, str]] = None,
247-
token: Optional[Union[bool, str]] = None,
248-
force_download: bool = False,
244+
# hub options
249245
subfolder: str = "",
246+
revision: str = "main",
247+
force_download: bool = False,
248+
local_files_only: bool = False,
250249
trust_remote_code: bool = False,
250+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
251+
token: Optional[Union[bool, str]] = None,
251252
) -> PretrainedConfig:
252-
if use_auth_token is not None:
253-
warnings.warn(
254-
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
255-
FutureWarning,
256-
)
257-
if token is not None:
258-
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
259-
token = use_auth_token
260-
261253
try:
262254
config = AutoConfig.from_pretrained(
263255
pretrained_model_name_or_path=config_name_or_path,
@@ -290,14 +282,14 @@ def _load_config(
290282
def _from_pretrained(
291283
cls,
292284
model_id: Union[str, Path],
293-
config: PretrainedConfig,
294-
use_auth_token: Optional[Union[bool, str]] = None,
295-
token: Optional[Union[bool, str]] = None,
296-
revision: Optional[str] = None,
297-
force_download: bool = False,
298-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
285+
# hub options
299286
subfolder: str = "",
287+
revision: str = "main",
288+
force_download: bool = False,
300289
local_files_only: bool = False,
290+
trust_remote_code: bool = False,
291+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
292+
token: Optional[Union[bool, str]] = None,
301293
**kwargs,
302294
) -> "OptimizedModel":
303295
"""Overwrite this method in subclass to define how to load your model from pretrained"""
@@ -308,14 +300,14 @@ def _export(
308300
cls,
309301
model_id: Union[str, Path],
310302
config: PretrainedConfig,
311-
use_auth_token: Optional[Union[bool, str]] = None,
312-
token: Optional[Union[bool, str]] = None,
313-
revision: Optional[str] = None,
314-
force_download: bool = False,
315-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
303+
# hub options
316304
subfolder: str = "",
305+
revision: str = "main",
306+
force_download: bool = False,
317307
local_files_only: bool = False,
318308
trust_remote_code: bool = False,
309+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
310+
token: Optional[Union[bool, str]] = None,
319311
**kwargs,
320312
) -> "OptimizedModel":
321313
"""Overwrite this method in subclass to define how to load your model from vanilla hugging face model"""
@@ -328,32 +320,23 @@ def _export(
328320
def from_pretrained(
329321
cls,
330322
model_id: Union[str, Path],
323+
config: Optional[PretrainedConfig] = None,
331324
export: bool = False,
332-
force_download: bool = False,
333-
use_auth_token: Optional[Union[bool, str]] = None,
334-
token: Optional[Union[bool, str]] = None,
335-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
325+
# hub options
336326
subfolder: str = "",
337-
config: Optional[PretrainedConfig] = None,
327+
revision: str = "main",
328+
force_download: bool = False,
338329
local_files_only: bool = False,
339330
trust_remote_code: bool = False,
340-
revision: Optional[str] = None,
331+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
332+
token: Optional[Union[bool, str]] = None,
341333
**kwargs,
342334
) -> "OptimizedModel":
343335
"""
344336
Returns:
345337
`OptimizedModel`: The loaded optimized model.
346338
"""
347339

348-
if use_auth_token is not None:
349-
warnings.warn(
350-
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
351-
FutureWarning,
352-
)
353-
if token is not None:
354-
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
355-
token = use_auth_token
356-
357340
if isinstance(model_id, Path):
358341
model_id = model_id.as_posix()
359342

@@ -425,6 +408,7 @@ def from_pretrained(
425408
return from_pretrained_method(
426409
model_id=model_id,
427410
config=config,
411+
# hub options
428412
revision=revision,
429413
cache_dir=cache_dir,
430414
force_download=force_download,

optimum/onnxruntime/modeling_decoder.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,13 @@ def _from_pretrained(
405405
model_id: Union[str, Path],
406406
config: "PretrainedConfig",
407407
# hub options
408-
token: Optional[Union[bool, str]] = None,
409-
revision: Optional[str] = None,
410-
force_download: bool = False,
411-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
412408
subfolder: str = "",
413-
trust_remote_code: bool = False, # forced by OptimizedModel.from_pretrained
409+
revision: str = "main",
410+
force_download: bool = False,
414411
local_files_only: bool = False,
412+
trust_remote_code: bool = False,
413+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
414+
token: Optional[Union[bool, str]] = None,
415415
# file options
416416
file_name: Optional[str] = None,
417417
# session options
@@ -654,13 +654,13 @@ def _export(
654654
model_id: Union[str, Path],
655655
config: "PretrainedConfig",
656656
# hub options
657-
token: Optional[Union[bool, str]] = None,
658-
revision: str = "main",
659-
force_download: bool = True,
660-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
661657
subfolder: str = "",
658+
revision: str = "main",
659+
force_download: bool = False,
662660
local_files_only: bool = False,
663661
trust_remote_code: bool = False,
662+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
663+
token: Optional[Union[bool, str]] = None,
664664
# inference options
665665
use_cache: bool = True,
666666
**kwargs,

optimum/onnxruntime/modeling_ort.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,13 @@ def _from_pretrained(
281281
model_id: Union[str, Path],
282282
config: "PretrainedConfig",
283283
# hub options
284-
token: Optional[Union[bool, str]] = None,
285-
revision: Optional[str] = None,
286-
force_download: bool = False,
287-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
288284
subfolder: str = "",
285+
revision: str = "main",
286+
force_download: bool = False,
289287
local_files_only: bool = False,
290-
trust_remote_code: bool = False, # forced by OptimizedModel.from_pretrained
288+
trust_remote_code: bool = False,
289+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
290+
token: Optional[Union[bool, str]] = None,
291291
# file options
292292
file_name: Optional[str] = None,
293293
# session options
@@ -395,13 +395,13 @@ def _export(
395395
model_id: Union[str, Path],
396396
config: "PretrainedConfig",
397397
# hub options
398-
token: Optional[Union[bool, str]] = None,
399-
revision: Optional[str] = None,
400-
force_download: bool = False,
401-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
402398
subfolder: str = "",
399+
revision: str = "main",
400+
force_download: bool = False,
403401
local_files_only: bool = False,
404402
trust_remote_code: bool = False,
403+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
404+
token: Optional[Union[bool, str]] = None,
405405
# other arguments
406406
**kwargs,
407407
) -> "ORTModel":
@@ -441,16 +441,17 @@ def _export(
441441
def from_pretrained(
442442
cls,
443443
model_id: Union[str, Path],
444+
config: Optional["PretrainedConfig"] = None,
444445
# export options
445446
export: bool = False,
446447
# hub options
447-
token: Optional[Union[bool, str]] = None,
448-
revision: str = "main",
449-
force_download: bool = True,
450-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
451448
subfolder: str = "",
449+
revision: str = "main",
450+
force_download: bool = False,
452451
local_files_only: bool = False,
453452
trust_remote_code: bool = False,
453+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
454+
token: Optional[Union[bool, str]] = None,
454455
# session options
455456
provider: str = "CPUExecutionProvider",
456457
providers: Optional[Sequence[str]] = None,
@@ -548,6 +549,7 @@ def from_pretrained(
548549

549550
return super().from_pretrained(
550551
model_id,
552+
config=config,
551553
export=_export,
552554
force_download=force_download,
553555
token=token,

optimum/onnxruntime/modeling_seq2seq.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,13 +1043,13 @@ def _from_pretrained(
10431043
model_id: Union[str, Path],
10441044
config: "PretrainedConfig",
10451045
# hub options
1046-
token: Optional[Union[bool, str]] = None,
1047-
revision: Optional[str] = None,
1048-
trust_remote_code: bool = False, # forced by OptimizedModel.from_pretrained
1049-
local_files_only: bool = False,
1050-
force_download: bool = False,
10511046
subfolder: str = "",
1047+
revision: str = "main",
1048+
force_download: bool = False,
1049+
local_files_only: bool = False,
1050+
trust_remote_code: bool = False,
10521051
cache_dir: str = HUGGINGFACE_HUB_CACHE,
1052+
token: Optional[Union[bool, str]] = None,
10531053
# file options
10541054
encoder_file_name: str = ONNX_ENCODER_NAME,
10551055
decoder_file_name: str = ONNX_DECODER_NAME,
@@ -1297,13 +1297,13 @@ def _export(
12971297
model_id: Union[str, Path],
12981298
config: "PretrainedConfig",
12991299
# hub options
1300-
token: Optional[Union[bool, str]] = None,
1301-
revision: str = "main",
1302-
force_download: bool = True,
1303-
cache_dir: str = HUGGINGFACE_HUB_CACHE,
13041300
subfolder: str = "",
1301+
revision: str = "main",
1302+
force_download: bool = False,
13051303
local_files_only: bool = False,
13061304
trust_remote_code: bool = False,
1305+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
1306+
token: Optional[Union[bool, str]] = None,
13071307
# inference options
13081308
use_cache: bool = True,
13091309
use_merged: bool = False,

0 commit comments

Comments
 (0)