|
24 | 24 | import re |
25 | 25 | from collections import OrderedDict |
26 | 26 | from pathlib import Path |
27 | | -from typing import Any, Optional, Union |
| 27 | +from typing import Any, Optional |
28 | 28 |
|
29 | 29 | import numpy as np |
30 | 30 | from huggingface_hub import DDUFEntry, create_repo, hf_hub_download |
@@ -143,7 +143,7 @@ def __getattr__(self, name: str) -> Any: |
143 | 143 |
|
144 | 144 | raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'") |
145 | 145 |
|
146 | | - def save_config(self, save_directory: Union[str, os.PathLike], push_to_hub: bool = False, **kwargs): |
| 146 | + def save_config(self, save_directory: str | os.PathLike, push_to_hub: bool = False, **kwargs): |
147 | 147 | """ |
148 | 148 | Save a configuration object to the directory specified in `save_directory` so that it can be reloaded using the |
149 | 149 | [`~ConfigMixin.from_config`] class method. |
@@ -189,8 +189,8 @@ def save_config(self, save_directory: Union[str, os.PathLike], push_to_hub: bool |
189 | 189 |
|
190 | 190 | @classmethod |
191 | 191 | def from_config( |
192 | | - cls, config: Union[FrozenDict, dict[str, Any]] = None, return_unused_kwargs=False, **kwargs |
193 | | - ) -> Union[Self, tuple[Self, dict[str, Any]]]: |
| 192 | + cls, config: FrozenDict | dict[str, Any] = None, return_unused_kwargs=False, **kwargs |
| 193 | + ) -> Self | tuple[Self, dict[str, Any]]: |
194 | 194 | r""" |
195 | 195 | Instantiate a Python class from a config dictionary. |
196 | 196 |
|
@@ -292,7 +292,7 @@ def get_config_dict(cls, *args, **kwargs): |
292 | 292 | @validate_hf_hub_args |
293 | 293 | def load_config( |
294 | 294 | cls, |
295 | | - pretrained_model_name_or_path: Union[str, os.PathLike], |
| 295 | + pretrained_model_name_or_path: str | os.PathLike, |
296 | 296 | return_unused_kwargs=False, |
297 | 297 | return_commit_hash=False, |
298 | 298 | **kwargs, |
@@ -563,9 +563,7 @@ def extract_init_dict(cls, config_dict, **kwargs): |
563 | 563 | return init_dict, unused_kwargs, hidden_config_dict |
564 | 564 |
|
565 | 565 | @classmethod |
566 | | - def _dict_from_json_file( |
567 | | - cls, json_file: Union[str, os.PathLike], dduf_entries: Optional[dict[str, DDUFEntry]] = None |
568 | | - ): |
| 566 | + def _dict_from_json_file(cls, json_file: str | os.PathLike, dduf_entries: Optional[dict[str, DDUFEntry]] = None): |
569 | 567 | if dduf_entries: |
570 | 568 | text = dduf_entries[json_file].read_text() |
571 | 569 | else: |
@@ -625,7 +623,7 @@ def to_json_saveable(value): |
625 | 623 |
|
626 | 624 | return json.dumps(config_dict, indent=2, sort_keys=True) + "\n" |
627 | 625 |
|
628 | | - def to_json_file(self, json_file_path: Union[str, os.PathLike]): |
| 626 | + def to_json_file(self, json_file_path: str | os.PathLike): |
629 | 627 | """ |
630 | 628 | Save the configuration instance's parameters to a JSON file. |
631 | 629 |
|
@@ -756,7 +754,7 @@ class LegacyConfigMixin(ConfigMixin): |
756 | 754 | """ |
757 | 755 |
|
758 | 756 | @classmethod |
759 | | - def from_config(cls, config: Union[FrozenDict, dict[str, Any]] = None, return_unused_kwargs=False, **kwargs): |
| 757 | + def from_config(cls, config: FrozenDict | dict[str, Any] = None, return_unused_kwargs=False, **kwargs): |
760 | 758 | # To prevent dependency import problem. |
761 | 759 | from .models.model_loading_utils import _fetch_remapped_cls_from_config |
762 | 760 |
|
|
0 commit comments