huggingface-hub 1.0.0rc0__py3-none-any.whl → 1.0.0rc2__py3-none-any.whl
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.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +4 -4
- huggingface_hub/_commit_api.py +126 -66
- huggingface_hub/_commit_scheduler.py +4 -7
- huggingface_hub/_login.py +9 -15
- huggingface_hub/_tensorboard_logger.py +2 -5
- huggingface_hub/_webhooks_server.py +8 -20
- huggingface_hub/cli/__init__.py +0 -14
- huggingface_hub/cli/_cli_utils.py +79 -2
- huggingface_hub/cli/auth.py +104 -149
- huggingface_hub/cli/cache.py +97 -121
- huggingface_hub/cli/download.py +93 -110
- huggingface_hub/cli/hf.py +37 -41
- huggingface_hub/cli/jobs.py +687 -1014
- huggingface_hub/cli/lfs.py +116 -139
- huggingface_hub/cli/repo.py +290 -214
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -212
- huggingface_hub/cli/upload_large_folder.py +90 -105
- huggingface_hub/dataclasses.py +3 -12
- huggingface_hub/errors.py +1 -1
- huggingface_hub/fastai_utils.py +22 -32
- huggingface_hub/file_download.py +18 -21
- huggingface_hub/hf_api.py +258 -410
- huggingface_hub/hf_file_system.py +17 -44
- huggingface_hub/inference/_client.py +25 -47
- huggingface_hub/inference/_generated/_async_client.py +25 -47
- huggingface_hub/inference/_mcp/agent.py +2 -5
- huggingface_hub/inference/_mcp/mcp_client.py +2 -5
- huggingface_hub/inference/_providers/__init__.py +11 -0
- huggingface_hub/inference/_providers/_common.py +1 -0
- huggingface_hub/inference/_providers/publicai.py +6 -0
- huggingface_hub/inference/_providers/scaleway.py +28 -0
- huggingface_hub/lfs.py +14 -8
- huggingface_hub/repocard.py +12 -16
- huggingface_hub/serialization/_base.py +3 -6
- huggingface_hub/serialization/_torch.py +16 -34
- huggingface_hub/utils/__init__.py +1 -1
- huggingface_hub/utils/_cache_manager.py +41 -71
- huggingface_hub/utils/_chunk_utils.py +2 -3
- huggingface_hub/utils/_http.py +32 -35
- huggingface_hub/utils/logging.py +8 -11
- {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/METADATA +7 -2
- {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/RECORD +48 -46
- {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/LICENSE +0 -0
- {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/WHEEL +0 -0
- {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/top_level.txt +0 -0
|
@@ -15,118 +15,103 @@
|
|
|
15
15
|
"""Contains command to upload a large folder with the CLI."""
|
|
16
16
|
|
|
17
17
|
import os
|
|
18
|
-
from
|
|
19
|
-
|
|
18
|
+
from typing import Annotated, Optional
|
|
19
|
+
|
|
20
|
+
import typer
|
|
20
21
|
|
|
21
22
|
from huggingface_hub import logging
|
|
22
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
23
|
-
from huggingface_hub.hf_api import HfApi
|
|
24
23
|
from huggingface_hub.utils import disable_progress_bars
|
|
25
24
|
|
|
26
|
-
from ._cli_utils import ANSI
|
|
25
|
+
from ._cli_utils import ANSI, PrivateOpt, RepoIdArg, RepoType, RepoTypeOpt, RevisionOpt, TokenOpt, get_hf_api
|
|
27
26
|
|
|
28
27
|
|
|
29
28
|
logger = logging.get_logger(__name__)
|
|
30
29
|
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
help="
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
help="
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
" - Do not start several processes in parallel.\n"
|
|
102
|
-
" - You can interrupt and resume the process at any time. "
|
|
103
|
-
"The script will pick up where it left off except for partially uploaded files that would have to be entirely reuploaded.\n"
|
|
104
|
-
" - Do not upload the same folder to several repositories. If you need to do so, you must delete the `./.cache/huggingface/` folder first.\n"
|
|
105
|
-
"\n"
|
|
106
|
-
f"Some temporary metadata will be stored under `{self.local_path}/.cache/huggingface`.\n"
|
|
107
|
-
" - You must not modify those files manually.\n"
|
|
108
|
-
" - You must not delete the `./.cache/huggingface/` folder while a process is running.\n"
|
|
109
|
-
" - You can delete the `./.cache/huggingface/` folder to reinitialize the upload state when process is not running. Files will have to be hashed and preuploaded again, except for already committed files.\n"
|
|
110
|
-
"\n"
|
|
111
|
-
"If the process output is too verbose, you can disable the progress bars with `--no-bars`. "
|
|
112
|
-
"You can also entirely disable the status report with `--no-report`.\n"
|
|
113
|
-
"\n"
|
|
114
|
-
"For more details, run `hf upload-large-folder --help` or check the documentation at "
|
|
115
|
-
"https://huggingface.co/docs/huggingface_hub/guides/upload#upload-a-large-folder."
|
|
116
|
-
)
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
if self.no_bars:
|
|
120
|
-
disable_progress_bars()
|
|
121
|
-
|
|
122
|
-
self.api.upload_large_folder(
|
|
123
|
-
repo_id=self.repo_id,
|
|
124
|
-
folder_path=self.local_path,
|
|
125
|
-
repo_type=self.repo_type,
|
|
126
|
-
revision=self.revision,
|
|
127
|
-
private=self.private,
|
|
128
|
-
allow_patterns=self.include,
|
|
129
|
-
ignore_patterns=self.exclude,
|
|
130
|
-
num_workers=self.num_workers,
|
|
131
|
-
print_report=not self.no_report,
|
|
31
|
+
def upload_large_folder(
|
|
32
|
+
repo_id: RepoIdArg,
|
|
33
|
+
local_path: Annotated[
|
|
34
|
+
str,
|
|
35
|
+
typer.Argument(
|
|
36
|
+
help="Local path to the folder to upload.",
|
|
37
|
+
),
|
|
38
|
+
],
|
|
39
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
40
|
+
revision: RevisionOpt = None,
|
|
41
|
+
private: PrivateOpt = False,
|
|
42
|
+
include: Annotated[
|
|
43
|
+
Optional[list[str]],
|
|
44
|
+
typer.Option(
|
|
45
|
+
help="Glob patterns to match files to upload.",
|
|
46
|
+
),
|
|
47
|
+
] = None,
|
|
48
|
+
exclude: Annotated[
|
|
49
|
+
Optional[list[str]],
|
|
50
|
+
typer.Option(
|
|
51
|
+
help="Glob patterns to exclude from files to upload.",
|
|
52
|
+
),
|
|
53
|
+
] = None,
|
|
54
|
+
token: TokenOpt = None,
|
|
55
|
+
num_workers: Annotated[
|
|
56
|
+
Optional[int],
|
|
57
|
+
typer.Option(
|
|
58
|
+
help="Number of workers to use to hash, upload and commit files.",
|
|
59
|
+
),
|
|
60
|
+
] = None,
|
|
61
|
+
no_report: Annotated[
|
|
62
|
+
bool,
|
|
63
|
+
typer.Option(
|
|
64
|
+
help="Whether to disable regular status report.",
|
|
65
|
+
),
|
|
66
|
+
] = False,
|
|
67
|
+
no_bars: Annotated[
|
|
68
|
+
bool,
|
|
69
|
+
typer.Option(
|
|
70
|
+
help="Whether to disable progress bars.",
|
|
71
|
+
),
|
|
72
|
+
] = False,
|
|
73
|
+
) -> None:
|
|
74
|
+
"""Upload a large folder to the Hub. Recommended for resumable uploads."""
|
|
75
|
+
if not os.path.isdir(local_path):
|
|
76
|
+
raise typer.BadParameter("Large upload is only supported for folders.", param_hint="local_path")
|
|
77
|
+
|
|
78
|
+
print(
|
|
79
|
+
ANSI.yellow(
|
|
80
|
+
"You are about to upload a large folder to the Hub using `hf upload-large-folder`. "
|
|
81
|
+
"This is a new feature so feedback is very welcome!\n"
|
|
82
|
+
"\n"
|
|
83
|
+
"A few things to keep in mind:\n"
|
|
84
|
+
" - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations\n"
|
|
85
|
+
" - Do not start several processes in parallel.\n"
|
|
86
|
+
" - You can interrupt and resume the process at any time. "
|
|
87
|
+
"The script will pick up where it left off except for partially uploaded files that would have to be entirely reuploaded.\n"
|
|
88
|
+
" - Do not upload the same folder to several repositories. If you need to do so, you must delete the `./.cache/huggingface/` folder first.\n"
|
|
89
|
+
"\n"
|
|
90
|
+
f"Some temporary metadata will be stored under `{local_path}/.cache/huggingface`.\n"
|
|
91
|
+
" - You must not modify those files manually.\n"
|
|
92
|
+
" - You must not delete the `./.cache/huggingface/` folder while a process is running.\n"
|
|
93
|
+
" - You can delete the `./.cache/huggingface/` folder to reinitialize the upload state when process is not running. Files will have to be hashed and preuploaded again, except for already committed files.\n"
|
|
94
|
+
"\n"
|
|
95
|
+
"If the process output is too verbose, you can disable the progress bars with `--no-bars`. "
|
|
96
|
+
"You can also entirely disable the status report with `--no-report`.\n"
|
|
97
|
+
"\n"
|
|
98
|
+
"For more details, run `hf upload-large-folder --help` or check the documentation at "
|
|
99
|
+
"https://huggingface.co/docs/huggingface_hub/guides/upload#upload-a-large-folder."
|
|
132
100
|
)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
if no_bars:
|
|
104
|
+
disable_progress_bars()
|
|
105
|
+
|
|
106
|
+
api = get_hf_api(token=token)
|
|
107
|
+
api.upload_large_folder(
|
|
108
|
+
repo_id=repo_id,
|
|
109
|
+
folder_path=local_path,
|
|
110
|
+
repo_type=repo_type.value,
|
|
111
|
+
revision=revision,
|
|
112
|
+
private=private,
|
|
113
|
+
allow_patterns=include,
|
|
114
|
+
ignore_patterns=exclude,
|
|
115
|
+
num_workers=num_workers,
|
|
116
|
+
print_report=not no_report,
|
|
117
|
+
)
|
huggingface_hub/dataclasses.py
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
from dataclasses import _MISSING_TYPE, MISSING, Field, field, fields
|
|
3
3
|
from functools import wraps
|
|
4
|
-
from typing import
|
|
5
|
-
Any,
|
|
6
|
-
Callable,
|
|
7
|
-
Literal,
|
|
8
|
-
Optional,
|
|
9
|
-
Type,
|
|
10
|
-
TypeVar,
|
|
11
|
-
Union,
|
|
12
|
-
get_args,
|
|
13
|
-
get_origin,
|
|
14
|
-
overload,
|
|
15
|
-
)
|
|
4
|
+
from typing import Any, Callable, ForwardRef, Literal, Optional, Type, TypeVar, Union, get_args, get_origin, overload
|
|
16
5
|
|
|
17
6
|
from .errors import (
|
|
18
7
|
StrictDataclassClassValidationError,
|
|
@@ -322,6 +311,8 @@ def type_validator(name: str, value: Any, expected_type: Any) -> None:
|
|
|
322
311
|
validator(name, value, args)
|
|
323
312
|
elif isinstance(expected_type, type): # simple types
|
|
324
313
|
_validate_simple_type(name, value, expected_type)
|
|
314
|
+
elif isinstance(expected_type, ForwardRef) or isinstance(expected_type, str):
|
|
315
|
+
return
|
|
325
316
|
else:
|
|
326
317
|
raise TypeError(f"Unsupported type for field '{name}': {expected_type}")
|
|
327
318
|
|
huggingface_hub/errors.py
CHANGED
|
@@ -37,7 +37,7 @@ class OfflineModeIsEnabled(ConnectionError):
|
|
|
37
37
|
"""Raised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable."""
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
class HfHubHTTPError(HTTPError):
|
|
40
|
+
class HfHubHTTPError(HTTPError, OSError):
|
|
41
41
|
"""
|
|
42
42
|
HTTPError to inherit from for any custom HTTP Error raised in HF Hub.
|
|
43
43
|
|
huggingface_hub/fastai_utils.py
CHANGED
|
@@ -34,13 +34,11 @@ def _check_fastai_fastcore_versions(
|
|
|
34
34
|
fastcore_min_version (`str`, *optional*):
|
|
35
35
|
The minimum fastcore version supported.
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
Raises the following error:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
</Tip>
|
|
37
|
+
> [!TIP]
|
|
38
|
+
> Raises the following error:
|
|
39
|
+
>
|
|
40
|
+
> - [`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
|
|
41
|
+
> if the fastai or fastcore libraries are not available or are of an invalid version.
|
|
44
42
|
"""
|
|
45
43
|
|
|
46
44
|
if (get_fastcore_version() or get_fastai_version()) == "N/A":
|
|
@@ -88,15 +86,13 @@ def _check_fastai_fastcore_pyproject_versions(
|
|
|
88
86
|
fastcore_min_version (`str`, *optional*):
|
|
89
87
|
The minimum fastcore version supported.
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
Raises the following errors:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
</Tip>
|
|
89
|
+
> [!TIP]
|
|
90
|
+
> Raises the following errors:
|
|
91
|
+
>
|
|
92
|
+
> - [`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
|
|
93
|
+
> if the `toml` module is not installed.
|
|
94
|
+
> - [`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
|
|
95
|
+
> if the `pyproject.toml` indicates a lower than minimum supported version of fastai or fastcore.
|
|
100
96
|
"""
|
|
101
97
|
|
|
102
98
|
try:
|
|
@@ -253,14 +249,11 @@ def _save_pretrained_fastai(
|
|
|
253
249
|
config (`dict`, *optional*):
|
|
254
250
|
Configuration object. Will be uploaded as a .json file. Example: 'https://huggingface.co/espejelomar/fastai-pet-breeds-classification/blob/main/config.json'.
|
|
255
251
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if the config file provided is not a dictionary.
|
|
262
|
-
|
|
263
|
-
</Tip>
|
|
252
|
+
> [!TIP]
|
|
253
|
+
> Raises the following error:
|
|
254
|
+
>
|
|
255
|
+
> - [`RuntimeError`](https://docs.python.org/3/library/exceptions.html#RuntimeError)
|
|
256
|
+
> if the config file provided is not a dictionary.
|
|
264
257
|
"""
|
|
265
258
|
_check_fastai_fastcore_versions()
|
|
266
259
|
|
|
@@ -394,14 +387,11 @@ def push_to_hub_fastai(
|
|
|
394
387
|
Returns:
|
|
395
388
|
The url of the commit of your model in the given repository.
|
|
396
389
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if the user is not log on to the Hugging Face Hub.
|
|
403
|
-
|
|
404
|
-
</Tip>
|
|
390
|
+
> [!TIP]
|
|
391
|
+
> Raises the following error:
|
|
392
|
+
>
|
|
393
|
+
> - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
394
|
+
> if the user is not log on to the Hugging Face Hub.
|
|
405
395
|
"""
|
|
406
396
|
_check_fastai_fastcore_versions()
|
|
407
397
|
api = HfApi(endpoint=api_endpoint)
|
huggingface_hub/file_download.py
CHANGED
|
@@ -191,26 +191,23 @@ def hf_hub_url(
|
|
|
191
191
|
'https://huggingface.co/julien-c/EsperBERTo-small/resolve/main/pytorch_model.bin'
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if stored in git, or its sha256 if stored in git-lfs.
|
|
212
|
-
|
|
213
|
-
</Tip>
|
|
194
|
+
> [!TIP]
|
|
195
|
+
> Notes:
|
|
196
|
+
>
|
|
197
|
+
> Cloudfront is replicated over the globe so downloads are way faster for
|
|
198
|
+
> the end user (and it also lowers our bandwidth costs).
|
|
199
|
+
>
|
|
200
|
+
> Cloudfront aggressively caches files by default (default TTL is 24
|
|
201
|
+
> hours), however this is not an issue here because we implement a
|
|
202
|
+
> git-based versioning system on huggingface.co, which means that we store
|
|
203
|
+
> the files on S3/Cloudfront in a content-addressable way (i.e., the file
|
|
204
|
+
> name is its hash). Using content-addressable filenames means cache can't
|
|
205
|
+
> ever be stale.
|
|
206
|
+
>
|
|
207
|
+
> In terms of client-side caching from this library, we base our caching
|
|
208
|
+
> on the objects' entity tag (`ETag`), which is an identifier of a
|
|
209
|
+
> specific version of a resource [1]_. An object's ETag is: its git-sha1
|
|
210
|
+
> if stored in git, or its sha256 if stored in git-lfs.
|
|
214
211
|
|
|
215
212
|
References:
|
|
216
213
|
|
|
@@ -243,7 +240,7 @@ def _httpx_follow_relative_redirects(method: HTTP_METHOD_T, url: str, **httpx_kw
|
|
|
243
240
|
|
|
244
241
|
This is useful to follow a redirection to a renamed repository without following redirection to a CDN.
|
|
245
242
|
|
|
246
|
-
A backoff mechanism retries the HTTP call on
|
|
243
|
+
A backoff mechanism retries the HTTP call on 5xx errors and network errors.
|
|
247
244
|
|
|
248
245
|
Args:
|
|
249
246
|
method (`str`):
|