Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions docs/source/de/guides/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Obwohl dieser Ansatz flexibel ist, hat er einige Nachteile, insbesondere in Bezu
- `token`: zum Herunterladen aus einem privaten Repository
- `revision`: zum Herunterladen von einem spezifischen Branch
- `cache_dir`: um Dateien in einem spezifischen Verzeichnis zu cachen
- `force_download`/`resume_download`/`local_files_only`: um den Cache wieder zu verwenden oder nicht
- `force_download`/`local_files_only`: um den Cache wieder zu verwenden oder nicht
- `api_endpoint`/`proxies`: HTTP-Session konfigurieren

Beim Pushen von Modellen werden ähnliche Parameter unterstützt:
Expand Down Expand Up @@ -203,7 +203,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
cache_dir: str,
force_download: bool,
proxies: Optional[dict],
resume_download: bool,
local_files_only: bool,
token: Union[str, bool, None],
map_location: str = "cpu", # zusätzliches Argument
Expand All @@ -221,8 +220,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
revision=revision,
cache_dir=cache_dir,
force_download=force_download,
proxies=proxies,
resume_download=resume_download,
token=token,
local_files_only=local_files_only,
)
Expand All @@ -242,9 +239,9 @@ Und das war's! Ihre Bibliothek ermöglicht es Benutzern nun, Dateien vom und zum
Lassen Sie uns die beiden Ansätze, die wir gesehen haben, schnell mit ihren Vor- und Nachteilen zusammenfassen. Die untenstehende Tabelle ist nur indikativ. Ihr Framework könnte einige Besonderheiten haben, die Sie berücksichtigen müssen. Dieser Leitfaden soll nur Richtlinien und Ideen geben, wie Sie die Integration handhaben können. Kontaktieren Sie uns in jedem Fall, wenn Sie Fragen haben!

<!-- Generated using https://www.tablesgenerator.com/markdown_tables -->
| Integration | Mit Helfern | Mit [`ModelHubMixin`] |
|:---:|:---:|:---:|
| Benutzererfahrung | `model = load_from_hub(...)`<br>`push_to_hub(model, ...)` | `model = MyModel.from_pretrained(...)`<br>`model.push_to_hub(...)` |
| Flexibilität | Sehr flexibel.<br>Sie haben die volle Kontrolle über die Implementierung. | Weniger flexibel.<br>Ihr Framework muss eine Modellklasse haben. |
| Wartung | Mehr Wartung, um Unterstützung für Konfiguration und neue Funktionen hinzuzufügen. Könnte auch das Beheben von Benutzerproblemen erfordern. | Weniger Wartung, da die meisten Interaktionen mit dem Hub in `huggingface_hub` implementiert sind. |
| Dokumentation/Typ-Annotation| Manuell zu schreiben. | Teilweise durch `huggingface_hub` behandelt. |
| Integration | Mit Helfern | Mit [`ModelHubMixin`] |
| :--------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------: |
| Benutzererfahrung | `model = load_from_hub(...)`<br>`push_to_hub(model, ...)` | `model = MyModel.from_pretrained(...)`<br>`model.push_to_hub(...)` |
| Flexibilität | Sehr flexibel.<br>Sie haben die volle Kontrolle über die Implementierung. | Weniger flexibel.<br>Ihr Framework muss eine Modellklasse haben. |
| Wartung | Mehr Wartung, um Unterstützung für Konfiguration und neue Funktionen hinzuzufügen. Könnte auch das Beheben von Benutzerproblemen erfordern. | Weniger Wartung, da die meisten Interaktionen mit dem Hub in `huggingface_hub` implementiert sind. |
| Dokumentation/Typ-Annotation | Manuell zu schreiben. | Teilweise durch `huggingface_hub` behandelt. |
20 changes: 8 additions & 12 deletions docs/source/en/guides/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
revision: str,
cache_dir: str,
force_download: bool,
proxies: Optional[dict],
resume_download: bool,
local_files_only: bool,
token: Union[str, bool, None],
map_location: str = "cpu", # additional argument
Expand All @@ -265,8 +263,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
revision=revision,
cache_dir=cache_dir,
force_download=force_download,
proxies=proxies,
resume_download=resume_download,
token=token,
local_files_only=local_files_only,
)
Expand Down Expand Up @@ -428,11 +424,11 @@ Your framework might have some specificities that you need to address. This guid
ideas on how to handle integration. In any case, feel free to contact us if you have any questions!

<!-- Generated using https://www.tablesgenerator.com/markdown_tables -->
| Integration | Using helpers | Using [`ModelHubMixin`] |
|:---:|:---:|:---:|
| User experience | `model = load_from_hub(...)`<br>`push_to_hub(model, ...)` | `model = MyModel.from_pretrained(...)`<br>`model.push_to_hub(...)` |
| Flexibility | Very flexible.<br>You fully control the implementation. | Less flexible.<br>Your framework must have a model class. |
| Maintenance | More maintenance to add support for configuration, and new features. Might also require fixing issues reported by users. | Less maintenance as most of the interactions with the Hub are implemented in `huggingface_hub`. |
| Documentation / Type annotation | To be written manually. | Partially handled by `huggingface_hub`. |
| Download counter | To be handled manually. | Enabled by default if class has a `config` attribute. |
| Model card | To be handled manually | Generated by default with library_name, tags, etc. |
| Integration | Using helpers | Using [`ModelHubMixin`] |
| :-----------------------------: | :----------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: |
| User experience | `model = load_from_hub(...)`<br>`push_to_hub(model, ...)` | `model = MyModel.from_pretrained(...)`<br>`model.push_to_hub(...)` |
| Flexibility | Very flexible.<br>You fully control the implementation. | Less flexible.<br>Your framework must have a model class. |
| Maintenance | More maintenance to add support for configuration, and new features. Might also require fixing issues reported by users. | Less maintenance as most of the interactions with the Hub are implemented in `huggingface_hub`. |
| Documentation / Type annotation | To be written manually. | Partially handled by `huggingface_hub`. |
| Download counter | To be handled manually. | Enabled by default if class has a `config` attribute. |
| Model card | To be handled manually | Generated by default with library_name, tags, etc. |
18 changes: 2 additions & 16 deletions docs/source/en/package_reference/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,6 @@ huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in rep

>>> my_cool_method(repo_id="other..repo..id")
huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in repo_id: 'other..repo..id'.

>>> @validate_hf_hub_args
... def my_cool_auth_method(token: str):
... print(token)

>>> my_cool_auth_method(token="a token")
"a token"

>>> my_cool_auth_method(use_auth_token="a use_auth_token")
"a use_auth_token"

>>> my_cool_auth_method(token="a token", use_auth_token="a use_auth_token")
UserWarning: Both `token` and `use_auth_token` are passed (...). `use_auth_token` value will be ignored.
"a token"
```

#### validate_hf_hub_args
Expand All @@ -288,8 +274,8 @@ validated.

[[autodoc]] utils.validate_repo_id

#### smoothly_deprecate_use_auth_token
#### smoothly_deprecate_legacy_arguments

Not exactly a validator, but ran as well.

[[autodoc]] utils.smoothly_deprecate_use_auth_token
[[autodoc]] utils.smoothly_deprecate_legacy_arguments
4 changes: 0 additions & 4 deletions docs/source/fr/guides/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
revision: str,
cache_dir: str,
force_download: bool,
proxies: Optional[dict],
resume_download: bool,
local_files_only: bool,
token: Union[str, bool, None],
map_location: str = "cpu", # argument supplémentaire
Expand All @@ -242,8 +240,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
revision=revision,
cache_dir=cache_dir,
force_download=force_download,
proxies=proxies,
resume_download=resume_download,
token=token,
local_files_only=local_files_only,
)
Expand Down
5 changes: 1 addition & 4 deletions docs/source/ko/guides/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def push_to_hub(model: MyModelClass, repo_name: str) -> None:
- `token`: 개인 리포지토리에서 다운로드하기 위한 토큰
- `revision`: 특정 브랜치에서 다운로드하기 위한 리비전
- `cache_dir`: 특정 디렉터리에 파일을 캐시하기 위한 디렉터리
- `force_download`/`resume_download`/`local_files_only`: 캐시를 재사용할 것인지 여부를 결정하는 매개변수
- `force_download`/`local_files_only`: 캐시를 재사용할 것인지 여부를 결정하는 매개변수
- `proxies`: HTTP 세션 구성

모델을 푸시할 때는 유사한 매개변수가 지원됩니다:
Expand Down Expand Up @@ -212,7 +212,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
cache_dir: str,
force_download: bool,
proxies: Optional[dict],
resume_download: bool,
local_files_only: bool,
token: Union[str, bool, None],
map_location: str = "cpu", # 추가 인자
Expand All @@ -232,8 +231,6 @@ class PyTorchModelHubMixin(ModelHubMixin):
revision=revision,
cache_dir=cache_dir,
force_download=force_download,
proxies=proxies,
resume_download=resume_download,
token=token,
local_files_only=local_files_only,
)
Expand Down
20 changes: 0 additions & 20 deletions docs/source/ko/package_reference/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,6 @@ huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in rep

>>> my_cool_method(repo_id="other..repo..id")
huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in repo_id: 'other..repo..id'.

>>> @validate_hf_hub_args
... def my_cool_auth_method(token: str):
... print(token)

>>> my_cool_auth_method(token="a token")
"a token"

>>> my_cool_auth_method(use_auth_token="a use_auth_token")
"a use_auth_token"

>>> my_cool_auth_method(token="a token", use_auth_token="a use_auth_token")
UserWarning: Both `token` and `use_auth_token` are passed (...). `use_auth_token` value will be ignored.
"a token"
```

#### validate_hf_hub_args[[huggingface_hub.utils.validate_hf_hub_args]]
Expand All @@ -230,9 +216,3 @@ UserWarning: Both `token` and `use_auth_token` are passed (...). `use_auth_token
#### repo_id[[huggingface_hub.utils.validate_repo_id]]

[[autodoc]] utils.validate_repo_id

#### smoothly_deprecate_use_auth_token[[huggingface_hub.utils.smoothly_deprecate_use_auth_token]]

정확히 검증기는 아니지만, 잘 실행됩니다.

[[autodoc]] utils.smoothly_deprecate_use_auth_token
6 changes: 0 additions & 6 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
"get_safetensors_metadata",
"get_space_runtime",
"get_space_variables",
"get_token_permission",
"get_user_overview",
"get_webhook",
"grant_access",
Expand Down Expand Up @@ -278,7 +277,6 @@
"update_collection_metadata",
"update_inference_endpoint",
"update_repo_settings",
"update_repo_visibility",
"update_webhook",
"upload_file",
"upload_folder",
Expand Down Expand Up @@ -885,7 +883,6 @@
"get_space_variables",
"get_tf_storage_size",
"get_token",
"get_token_permission",
"get_torch_storage_id",
"get_torch_storage_size",
"get_user_overview",
Expand Down Expand Up @@ -977,7 +974,6 @@
"update_collection_metadata",
"update_inference_endpoint",
"update_repo_settings",
"update_repo_visibility",
"update_webhook",
"upload_file",
"upload_folder",
Expand Down Expand Up @@ -1247,7 +1243,6 @@ def __dir__():
get_safetensors_metadata, # noqa: F401
get_space_runtime, # noqa: F401
get_space_variables, # noqa: F401
get_token_permission, # noqa: F401
get_user_overview, # noqa: F401
get_webhook, # noqa: F401
grant_access, # noqa: F401
Expand Down Expand Up @@ -1308,7 +1303,6 @@ def __dir__():
update_collection_metadata, # noqa: F401
update_inference_endpoint, # noqa: F401
update_repo_settings, # noqa: F401
update_repo_visibility, # noqa: F401
update_webhook, # noqa: F401
upload_file, # noqa: F401
upload_folder, # noqa: F401
Expand Down
50 changes: 14 additions & 36 deletions src/huggingface_hub/_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
_save_token,
get_stored_tokens,
)
from .utils._deprecation import _deprecate_arguments, _deprecate_positional_args
from .utils._deprecation import _deprecate_positional_args


logger = logging.get_logger(__name__)
Expand All @@ -55,18 +55,12 @@
"""


@_deprecate_arguments(
version="1.0",
deprecated_args="write_permission",
custom_message="Fine-grained tokens added complexity to the permissions, making it irrelevant to check if a token has 'write' access.",
)
@_deprecate_positional_args(version="1.0")
def login(
token: Optional[str] = None,
*,
add_to_git_credential: bool = False,
new_session: bool = True,
write_permission: bool = False,
skip_if_logged_in: bool = False,
) -> None:
"""Login the machine to access the Hub.

Expand Down Expand Up @@ -102,10 +96,8 @@ def login(
is configured, a warning will be displayed to the user. If `token` is `None`,
the value of `add_to_git_credential` is ignored and will be prompted again
to the end user.
new_session (`bool`, defaults to `True`):
If `True`, will request a token even if one is already saved on the machine.
write_permission (`bool`):
Ignored and deprecated argument.
skip_if_logged_in (`bool`, defaults to `False`):
If `True`, do not prompt for token if user is already logged in.
Raises:
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
If an organization token is passed. Only personal account tokens are valid
Expand All @@ -125,9 +117,9 @@ def login(
)
_login(token, add_to_git_credential=add_to_git_credential)
elif is_notebook():
notebook_login(new_session=new_session)
notebook_login(skip_if_logged_in=skip_if_logged_in)
else:
interpreter_login(new_session=new_session)
interpreter_login(skip_if_logged_in=skip_if_logged_in)


def logout(token_name: Optional[str] = None) -> None:
Expand Down Expand Up @@ -242,13 +234,8 @@ def auth_list() -> None:
###


@_deprecate_arguments(
version="1.0",
deprecated_args="write_permission",
custom_message="Fine-grained tokens added complexity to the permissions, making it irrelevant to check if a token has 'write' access.",
)
@_deprecate_positional_args(version="1.0")
def interpreter_login(*, new_session: bool = True, write_permission: bool = False) -> None:
def interpreter_login(*, skip_if_logged_in: bool = False) -> None:
"""
Displays a prompt to log in to the HF website and store the token.

Expand All @@ -259,12 +246,10 @@ def interpreter_login(*, new_session: bool = True, write_permission: bool = Fals
For more details, see [`login`].

Args:
new_session (`bool`, defaults to `True`):
If `True`, will request a token even if one is already saved on the machine.
write_permission (`bool`):
Ignored and deprecated argument.
skip_if_logged_in (`bool`, defaults to `False`):
If `True`, do not prompt for token if user is already logged in.
"""
if not new_session and get_token() is not None:
if not skip_if_logged_in and get_token() is not None:
logger.info("User is already logged in.")
return

Expand Down Expand Up @@ -314,13 +299,8 @@ def interpreter_login(*, new_session: bool = True, write_permission: bool = Fals
notebooks. </center>"""


@_deprecate_arguments(
version="1.0",
deprecated_args="write_permission",
custom_message="Fine-grained tokens added complexity to the permissions, making it irrelevant to check if a token has 'write' access.",
)
@_deprecate_positional_args(version="1.0")
def notebook_login(*, new_session: bool = True, write_permission: bool = False) -> None:
def notebook_login(*, skip_if_logged_in: bool = False) -> None:
"""
Displays a widget to log in to the HF website and store the token.

Expand All @@ -331,10 +311,8 @@ def notebook_login(*, new_session: bool = True, write_permission: bool = False)
For more details, see [`login`].

Args:
new_session (`bool`, defaults to `True`):
If `True`, will request a token even if one is already saved on the machine.
write_permission (`bool`):
Ignored and deprecated argument.
skip_if_logged_in (`bool`, defaults to `False`):
If `True`, do not prompt for token if user is already logged in.
"""
try:
import ipywidgets.widgets as widgets # type: ignore
Expand All @@ -344,7 +322,7 @@ def notebook_login(*, new_session: bool = True, write_permission: bool = False)
"The `notebook_login` function can only be used in a notebook (Jupyter or"
" Colab) and you need the `ipywidgets` module: `pip install ipywidgets`."
)
if not new_session and get_token() is not None:
if not skip_if_logged_in and get_token() is not None:
logger.info("User is already logged in.")
return

Expand Down
7 changes: 1 addition & 6 deletions src/huggingface_hub/_snapshot_download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
from typing import Iterable, Literal, Optional, Union
from typing import Iterable, Optional, Union

import httpx
from tqdm.auto import tqdm as base_tqdm
Expand Down Expand Up @@ -46,9 +46,6 @@ def snapshot_download(
tqdm_class: Optional[type[base_tqdm]] = None,
headers: Optional[dict[str, str]] = None,
endpoint: Optional[str] = None,
# Deprecated args
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
resume_download: Optional[bool] = None,
) -> str:
"""Download repo files.

Expand Down Expand Up @@ -303,12 +300,10 @@ def _inner_hf_hub_download(repo_file: str):
endpoint=endpoint,
cache_dir=cache_dir,
local_dir=local_dir,
local_dir_use_symlinks=local_dir_use_symlinks,
library_name=library_name,
library_version=library_version,
user_agent=user_agent,
etag_timeout=etag_timeout,
resume_download=resume_download,
force_download=force_download,
token=token,
headers=headers,
Expand Down
Loading
Loading