huggingface-hub 0.24.7__py3-none-any.whl → 0.25.0rc0__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 +21 -1
- huggingface_hub/_commit_api.py +4 -4
- huggingface_hub/_inference_endpoints.py +13 -1
- huggingface_hub/_local_folder.py +191 -4
- huggingface_hub/_login.py +6 -6
- huggingface_hub/_snapshot_download.py +8 -17
- huggingface_hub/_space_api.py +5 -0
- huggingface_hub/_tensorboard_logger.py +29 -13
- huggingface_hub/_upload_large_folder.py +573 -0
- huggingface_hub/_webhooks_server.py +1 -1
- huggingface_hub/commands/_cli_utils.py +5 -0
- huggingface_hub/commands/download.py +8 -0
- huggingface_hub/commands/huggingface_cli.py +6 -1
- huggingface_hub/commands/lfs.py +2 -1
- huggingface_hub/commands/repo_files.py +2 -2
- huggingface_hub/commands/scan_cache.py +99 -57
- huggingface_hub/commands/tag.py +1 -1
- huggingface_hub/commands/upload.py +2 -1
- huggingface_hub/commands/upload_large_folder.py +129 -0
- huggingface_hub/commands/version.py +37 -0
- huggingface_hub/community.py +2 -2
- huggingface_hub/errors.py +218 -1
- huggingface_hub/fastai_utils.py +2 -3
- huggingface_hub/file_download.py +61 -62
- huggingface_hub/hf_api.py +758 -314
- huggingface_hub/hf_file_system.py +15 -23
- huggingface_hub/hub_mixin.py +27 -25
- huggingface_hub/inference/_client.py +78 -127
- huggingface_hub/inference/_generated/_async_client.py +169 -144
- huggingface_hub/inference/_generated/types/base.py +0 -9
- huggingface_hub/inference/_templating.py +2 -3
- huggingface_hub/inference_api.py +2 -2
- huggingface_hub/keras_mixin.py +2 -2
- huggingface_hub/lfs.py +7 -98
- huggingface_hub/repocard.py +6 -5
- huggingface_hub/repository.py +5 -5
- huggingface_hub/serialization/_torch.py +64 -11
- huggingface_hub/utils/__init__.py +13 -14
- huggingface_hub/utils/_cache_manager.py +97 -14
- huggingface_hub/utils/_fixes.py +18 -2
- huggingface_hub/utils/_http.py +228 -2
- huggingface_hub/utils/_lfs.py +110 -0
- huggingface_hub/utils/_runtime.py +7 -1
- huggingface_hub/utils/_token.py +3 -2
- {huggingface_hub-0.24.7.dist-info → huggingface_hub-0.25.0rc0.dist-info}/METADATA +2 -2
- {huggingface_hub-0.24.7.dist-info → huggingface_hub-0.25.0rc0.dist-info}/RECORD +50 -48
- huggingface_hub/inference/_types.py +0 -52
- huggingface_hub/utils/_errors.py +0 -397
- {huggingface_hub-0.24.7.dist-info → huggingface_hub-0.25.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.24.7.dist-info → huggingface_hub-0.25.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.24.7.dist-info → huggingface_hub-0.25.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.24.7.dist-info → huggingface_hub-0.25.0rc0.dist-info}/top_level.txt +0 -0
|
@@ -80,60 +80,102 @@ class ScanCacheCommand(BaseHuggingfaceCLICommand):
|
|
|
80
80
|
print(ANSI.gray(message + " Use -vvv to print details."))
|
|
81
81
|
|
|
82
82
|
def _print_hf_cache_info_as_table(self, hf_cache_info: HFCacheInfo) -> None:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
83
|
+
print(get_table(hf_cache_info, verbosity=self.verbosity))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def get_table(hf_cache_info: HFCacheInfo, *, verbosity: int = 0) -> str:
|
|
87
|
+
"""Generate a table from the [`HFCacheInfo`] object.
|
|
88
|
+
|
|
89
|
+
Pass `verbosity=0` to get a table with a single row per repo, with columns
|
|
90
|
+
"repo_id", "repo_type", "size_on_disk", "nb_files", "last_accessed", "last_modified", "refs", "local_path".
|
|
91
|
+
|
|
92
|
+
Pass `verbosity=1` to get a table with a row per repo and revision (thus multiple rows can appear for a single repo), with columns
|
|
93
|
+
"repo_id", "repo_type", "revision", "size_on_disk", "nb_files", "last_modified", "refs", "local_path".
|
|
94
|
+
|
|
95
|
+
Example:
|
|
96
|
+
```py
|
|
97
|
+
>>> from huggingface_hub.utils import scan_cache_dir
|
|
98
|
+
>>> from huggingface_hub.commands.scan_cache import get_table
|
|
99
|
+
|
|
100
|
+
>>> hf_cache_info = scan_cache_dir()
|
|
101
|
+
HFCacheInfo(...)
|
|
102
|
+
|
|
103
|
+
>>> print(get_table(hf_cache_info, verbosity=0))
|
|
104
|
+
REPO ID REPO TYPE SIZE ON DISK NB FILES LAST_ACCESSED LAST_MODIFIED REFS LOCAL PATH
|
|
105
|
+
--------------------------------------------------- --------- ------------ -------- ------------- ------------- ---- --------------------------------------------------------------------------------------------------
|
|
106
|
+
roberta-base model 2.7M 5 1 day ago 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--roberta-base
|
|
107
|
+
suno/bark model 8.8K 1 1 week ago 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--suno--bark
|
|
108
|
+
t5-base model 893.8M 4 4 days ago 7 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-base
|
|
109
|
+
t5-large model 3.0G 4 5 weeks ago 5 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-large
|
|
110
|
+
|
|
111
|
+
>>> print(get_table(hf_cache_info, verbosity=1))
|
|
112
|
+
REPO ID REPO TYPE REVISION SIZE ON DISK NB FILES LAST_MODIFIED REFS LOCAL PATH
|
|
113
|
+
--------------------------------------------------- --------- ---------------------------------------- ------------ -------- ------------- ---- -----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
114
|
+
roberta-base model e2da8e2f811d1448a5b465c236feacd80ffbac7b 2.7M 5 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--roberta-base\\snapshots\\e2da8e2f811d1448a5b465c236feacd80ffbac7b
|
|
115
|
+
suno/bark model 70a8a7d34168586dc5d028fa9666aceade177992 8.8K 1 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--suno--bark\\snapshots\\70a8a7d34168586dc5d028fa9666aceade177992
|
|
116
|
+
t5-base model a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1 893.8M 4 7 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-base\\snapshots\\a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1
|
|
117
|
+
t5-large model 150ebc2c4b72291e770f58e6057481c8d2ed331a 3.0G 4 5 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-large\\snapshots\\150ebc2c4b72291e770f58e6057481c8d2ed331a ```
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
hf_cache_info ([`HFCacheInfo`]):
|
|
122
|
+
The HFCacheInfo object to print.
|
|
123
|
+
verbosity (`int`, *optional*):
|
|
124
|
+
The verbosity level. Defaults to 0.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
`str`: The table as a string.
|
|
128
|
+
"""
|
|
129
|
+
if verbosity == 0:
|
|
130
|
+
return tabulate(
|
|
131
|
+
rows=[
|
|
132
|
+
[
|
|
133
|
+
repo.repo_id,
|
|
134
|
+
repo.repo_type,
|
|
135
|
+
"{:>12}".format(repo.size_on_disk_str),
|
|
136
|
+
repo.nb_files,
|
|
137
|
+
repo.last_accessed_str,
|
|
138
|
+
repo.last_modified_str,
|
|
139
|
+
", ".join(sorted(repo.refs)),
|
|
140
|
+
str(repo.repo_path),
|
|
141
|
+
]
|
|
142
|
+
for repo in sorted(hf_cache_info.repos, key=lambda repo: repo.repo_path)
|
|
143
|
+
],
|
|
144
|
+
headers=[
|
|
145
|
+
"REPO ID",
|
|
146
|
+
"REPO TYPE",
|
|
147
|
+
"SIZE ON DISK",
|
|
148
|
+
"NB FILES",
|
|
149
|
+
"LAST_ACCESSED",
|
|
150
|
+
"LAST_MODIFIED",
|
|
151
|
+
"REFS",
|
|
152
|
+
"LOCAL PATH",
|
|
153
|
+
],
|
|
154
|
+
)
|
|
155
|
+
else:
|
|
156
|
+
return tabulate(
|
|
157
|
+
rows=[
|
|
158
|
+
[
|
|
159
|
+
repo.repo_id,
|
|
160
|
+
repo.repo_type,
|
|
161
|
+
revision.commit_hash,
|
|
162
|
+
"{:>12}".format(revision.size_on_disk_str),
|
|
163
|
+
revision.nb_files,
|
|
164
|
+
revision.last_modified_str,
|
|
165
|
+
", ".join(sorted(revision.refs)),
|
|
166
|
+
str(revision.snapshot_path),
|
|
167
|
+
]
|
|
168
|
+
for repo in sorted(hf_cache_info.repos, key=lambda repo: repo.repo_path)
|
|
169
|
+
for revision in sorted(repo.revisions, key=lambda revision: revision.commit_hash)
|
|
170
|
+
],
|
|
171
|
+
headers=[
|
|
172
|
+
"REPO ID",
|
|
173
|
+
"REPO TYPE",
|
|
174
|
+
"REVISION",
|
|
175
|
+
"SIZE ON DISK",
|
|
176
|
+
"NB FILES",
|
|
177
|
+
"LAST_MODIFIED",
|
|
178
|
+
"REFS",
|
|
179
|
+
"LOCAL PATH",
|
|
180
|
+
],
|
|
181
|
+
)
|
huggingface_hub/commands/tag.py
CHANGED
|
@@ -40,7 +40,7 @@ from huggingface_hub.constants import (
|
|
|
40
40
|
)
|
|
41
41
|
from huggingface_hub.hf_api import HfApi
|
|
42
42
|
|
|
43
|
-
from ..
|
|
43
|
+
from ..errors import HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
|
|
44
44
|
from ._cli_utils import ANSI
|
|
45
45
|
|
|
46
46
|
|
|
@@ -53,8 +53,9 @@ from huggingface_hub import logging
|
|
|
53
53
|
from huggingface_hub._commit_scheduler import CommitScheduler
|
|
54
54
|
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
55
55
|
from huggingface_hub.constants import HF_HUB_ENABLE_HF_TRANSFER
|
|
56
|
+
from huggingface_hub.errors import RevisionNotFoundError
|
|
56
57
|
from huggingface_hub.hf_api import HfApi
|
|
57
|
-
from huggingface_hub.utils import
|
|
58
|
+
from huggingface_hub.utils import disable_progress_bars, enable_progress_bars
|
|
58
59
|
|
|
59
60
|
|
|
60
61
|
logger = logging.get_logger(__name__)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2023-present, the HuggingFace Inc. team.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""Contains command to upload a large folder with the CLI."""
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
from argparse import Namespace, _SubParsersAction
|
|
19
|
+
from typing import List, Optional
|
|
20
|
+
|
|
21
|
+
from huggingface_hub import logging
|
|
22
|
+
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
23
|
+
from huggingface_hub.hf_api import HfApi
|
|
24
|
+
from huggingface_hub.utils import disable_progress_bars
|
|
25
|
+
|
|
26
|
+
from ._cli_utils import ANSI
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
logger = logging.get_logger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class UploadLargeFolderCommand(BaseHuggingfaceCLICommand):
|
|
33
|
+
@staticmethod
|
|
34
|
+
def register_subcommand(parser: _SubParsersAction):
|
|
35
|
+
subparser = parser.add_parser("upload-large-folder", help="Upload a large folder to a repo on the Hub")
|
|
36
|
+
subparser.add_argument(
|
|
37
|
+
"repo_id", type=str, help="The ID of the repo to upload to (e.g. `username/repo-name`)."
|
|
38
|
+
)
|
|
39
|
+
subparser.add_argument("local_path", type=str, help="Local path to the file or folder to upload.")
|
|
40
|
+
subparser.add_argument(
|
|
41
|
+
"--repo-type",
|
|
42
|
+
choices=["model", "dataset", "space"],
|
|
43
|
+
help="Type of the repo to upload to (e.g. `dataset`).",
|
|
44
|
+
)
|
|
45
|
+
subparser.add_argument(
|
|
46
|
+
"--revision",
|
|
47
|
+
type=str,
|
|
48
|
+
help=("An optional Git revision to push to. It can be a branch name or a PR reference."),
|
|
49
|
+
)
|
|
50
|
+
subparser.add_argument(
|
|
51
|
+
"--private",
|
|
52
|
+
action="store_true",
|
|
53
|
+
help=(
|
|
54
|
+
"Whether to create a private repo if repo doesn't exist on the Hub. Ignored if the repo already exists."
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
subparser.add_argument("--include", nargs="*", type=str, help="Glob patterns to match files to upload.")
|
|
58
|
+
subparser.add_argument("--exclude", nargs="*", type=str, help="Glob patterns to exclude from files to upload.")
|
|
59
|
+
subparser.add_argument(
|
|
60
|
+
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
61
|
+
)
|
|
62
|
+
subparser.add_argument(
|
|
63
|
+
"--num-workers", type=int, help="Number of workers to use to hash, upload and commit files."
|
|
64
|
+
)
|
|
65
|
+
subparser.add_argument("--no-report", action="store_true", help="Whether to disable regular status report.")
|
|
66
|
+
subparser.add_argument("--no-bars", action="store_true", help="Whether to disable progress bars.")
|
|
67
|
+
subparser.set_defaults(func=UploadLargeFolderCommand)
|
|
68
|
+
|
|
69
|
+
def __init__(self, args: Namespace) -> None:
|
|
70
|
+
self.repo_id: str = args.repo_id
|
|
71
|
+
self.local_path: str = args.local_path
|
|
72
|
+
self.repo_type: str = args.repo_type
|
|
73
|
+
self.revision: Optional[str] = args.revision
|
|
74
|
+
self.private: bool = args.private
|
|
75
|
+
|
|
76
|
+
self.include: Optional[List[str]] = args.include
|
|
77
|
+
self.exclude: Optional[List[str]] = args.exclude
|
|
78
|
+
|
|
79
|
+
self.api: HfApi = HfApi(token=args.token, library_name="huggingface-cli")
|
|
80
|
+
|
|
81
|
+
self.num_workers: Optional[int] = args.num_workers
|
|
82
|
+
self.no_report: bool = args.no_report
|
|
83
|
+
self.no_bars: bool = args.no_bars
|
|
84
|
+
|
|
85
|
+
if not os.path.isdir(self.local_path):
|
|
86
|
+
raise ValueError("Large upload is only supported for folders.")
|
|
87
|
+
|
|
88
|
+
def run(self) -> None:
|
|
89
|
+
logging.set_verbosity_info()
|
|
90
|
+
|
|
91
|
+
print(
|
|
92
|
+
ANSI.yellow(
|
|
93
|
+
"You are about to upload a large folder to the Hub using `huggingface-cli upload-large-folder`. "
|
|
94
|
+
"This is a new feature so feedback is very welcome!\n"
|
|
95
|
+
"\n"
|
|
96
|
+
"A few things to keep in mind:\n"
|
|
97
|
+
" - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations\n"
|
|
98
|
+
" - Do not start several processes in parallel.\n"
|
|
99
|
+
" - You can interrupt and resume the process at any time. "
|
|
100
|
+
"The script will pick up where it left off except for partially uploaded files that would have to be entirely reuploaded.\n"
|
|
101
|
+
" - Do not upload the same folder to several repositories. If you need to do so, you must delete the `./.cache/huggingface/` folder first.\n"
|
|
102
|
+
"\n"
|
|
103
|
+
f"Some temporary metadata will be stored under `{self.local_path}/.cache/huggingface`.\n"
|
|
104
|
+
" - You must not modify those files manually.\n"
|
|
105
|
+
" - You must not delete the `./.cache/huggingface/` folder while a process is running.\n"
|
|
106
|
+
" - 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"
|
|
107
|
+
"\n"
|
|
108
|
+
"If the process output is to verbose, you can disable the progress bars with `--no-bars`. "
|
|
109
|
+
"You can also entirely disable the status report with `--no-report`.\n"
|
|
110
|
+
"\n"
|
|
111
|
+
"For more details, run `huggingface-cli upload-large-folder --help` or check the documentation at "
|
|
112
|
+
"https://huggingface.co/docs/huggingface_hub/guides/upload#upload-a-large-folder."
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if self.no_bars:
|
|
117
|
+
disable_progress_bars()
|
|
118
|
+
|
|
119
|
+
self.api.upload_large_folder(
|
|
120
|
+
repo_id=self.repo_id,
|
|
121
|
+
folder_path=self.local_path,
|
|
122
|
+
repo_type=self.repo_type,
|
|
123
|
+
revision=self.revision,
|
|
124
|
+
private=self.private,
|
|
125
|
+
allow_patterns=self.include,
|
|
126
|
+
ignore_patterns=self.exclude,
|
|
127
|
+
num_workers=self.num_workers,
|
|
128
|
+
print_report=not self.no_report,
|
|
129
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Copyright 2022 The HuggingFace Team. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Contains command to print information about the version.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
huggingface-cli version
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from argparse import _SubParsersAction
|
|
21
|
+
|
|
22
|
+
from huggingface_hub import __version__
|
|
23
|
+
|
|
24
|
+
from . import BaseHuggingfaceCLICommand
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class VersionCommand(BaseHuggingfaceCLICommand):
|
|
28
|
+
def __init__(self, args):
|
|
29
|
+
self.args = args
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def register_subcommand(parser: _SubParsersAction):
|
|
33
|
+
version_parser = parser.add_parser("version", help="Print information about the huggingface-cli version.")
|
|
34
|
+
version_parser.set_defaults(func=VersionCommand)
|
|
35
|
+
|
|
36
|
+
def run(self) -> None:
|
|
37
|
+
print(f"huggingface_hub version: {__version__}")
|
huggingface_hub/community.py
CHANGED
|
@@ -9,7 +9,7 @@ from dataclasses import dataclass
|
|
|
9
9
|
from datetime import datetime
|
|
10
10
|
from typing import List, Literal, Optional, Union
|
|
11
11
|
|
|
12
|
-
from .
|
|
12
|
+
from . import constants
|
|
13
13
|
from .utils import parse_datetime
|
|
14
14
|
|
|
15
15
|
|
|
@@ -79,7 +79,7 @@ class Discussion:
|
|
|
79
79
|
@property
|
|
80
80
|
def url(self) -> str:
|
|
81
81
|
"""Returns the URL of the discussion on the Hub."""
|
|
82
|
-
if self.repo_type is None or self.repo_type == REPO_TYPE_MODEL:
|
|
82
|
+
if self.repo_type is None or self.repo_type == constants.REPO_TYPE_MODEL:
|
|
83
83
|
return f"{self.endpoint}/{self.repo_id}/discussions/{self.num}"
|
|
84
84
|
return f"{self.endpoint}/{self.repo_type}s/{self.repo_id}/discussions/{self.num}"
|
|
85
85
|
|
huggingface_hub/errors.py
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"""Contains all custom errors."""
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional, Union
|
|
5
|
+
|
|
6
|
+
from requests import HTTPError, Response
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# CACHE ERRORS
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CacheNotFound(Exception):
|
|
13
|
+
"""Exception thrown when the Huggingface cache is not found."""
|
|
14
|
+
|
|
15
|
+
cache_dir: Union[str, Path]
|
|
16
|
+
|
|
17
|
+
def __init__(self, msg: str, cache_dir: Union[str, Path], *args, **kwargs):
|
|
18
|
+
super().__init__(msg, *args, **kwargs)
|
|
19
|
+
self.cache_dir = cache_dir
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CorruptedCacheException(Exception):
|
|
23
|
+
"""Exception for any unexpected structure in the Huggingface cache-system."""
|
|
4
24
|
|
|
5
25
|
|
|
6
26
|
# HEADERS ERRORS
|
|
@@ -17,6 +37,51 @@ class OfflineModeIsEnabled(ConnectionError):
|
|
|
17
37
|
"""Raised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable."""
|
|
18
38
|
|
|
19
39
|
|
|
40
|
+
class HfHubHTTPError(HTTPError):
|
|
41
|
+
"""
|
|
42
|
+
HTTPError to inherit from for any custom HTTP Error raised in HF Hub.
|
|
43
|
+
|
|
44
|
+
Any HTTPError is converted at least into a `HfHubHTTPError`. If some information is
|
|
45
|
+
sent back by the server, it will be added to the error message.
|
|
46
|
+
|
|
47
|
+
Added details:
|
|
48
|
+
- Request id from "X-Request-Id" header if exists.
|
|
49
|
+
- Server error message from the header "X-Error-Message".
|
|
50
|
+
- Server error message if we can found one in the response body.
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
```py
|
|
54
|
+
import requests
|
|
55
|
+
from huggingface_hub.utils import get_session, hf_raise_for_status, HfHubHTTPError
|
|
56
|
+
|
|
57
|
+
response = get_session().post(...)
|
|
58
|
+
try:
|
|
59
|
+
hf_raise_for_status(response)
|
|
60
|
+
except HfHubHTTPError as e:
|
|
61
|
+
print(str(e)) # formatted message
|
|
62
|
+
e.request_id, e.server_message # details returned by server
|
|
63
|
+
|
|
64
|
+
# Complete the error message with additional information once it's raised
|
|
65
|
+
e.append_to_message("\n`create_commit` expects the repository to exist.")
|
|
66
|
+
raise
|
|
67
|
+
```
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
def __init__(self, message: str, response: Optional[Response] = None, *, server_message: Optional[str] = None):
|
|
71
|
+
self.request_id = response.headers.get("x-request-id") if response is not None else None
|
|
72
|
+
self.server_message = server_message
|
|
73
|
+
|
|
74
|
+
super().__init__(
|
|
75
|
+
message,
|
|
76
|
+
response=response, # type: ignore [arg-type]
|
|
77
|
+
request=response.request if response is not None else None, # type: ignore [arg-type]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def append_to_message(self, additional_message: str) -> None:
|
|
81
|
+
"""Append additional information to the `HfHubHTTPError` initial message."""
|
|
82
|
+
self.args = (self.args[0] + additional_message,) + self.args[1:]
|
|
83
|
+
|
|
84
|
+
|
|
20
85
|
# INFERENCE CLIENT ERRORS
|
|
21
86
|
|
|
22
87
|
|
|
@@ -94,3 +159,155 @@ class HFValidationError(ValueError):
|
|
|
94
159
|
|
|
95
160
|
Inherits from [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError).
|
|
96
161
|
"""
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# FILE METADATA ERRORS
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class FileMetadataError(OSError):
|
|
168
|
+
"""Error triggered when the metadata of a file on the Hub cannot be retrieved (missing ETag or commit_hash).
|
|
169
|
+
|
|
170
|
+
Inherits from `OSError` for backward compatibility.
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# REPOSITORY ERRORS
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class RepositoryNotFoundError(HfHubHTTPError):
|
|
178
|
+
"""
|
|
179
|
+
Raised when trying to access a hf.co URL with an invalid repository name, or
|
|
180
|
+
with a private repo name the user does not have access to.
|
|
181
|
+
|
|
182
|
+
Example:
|
|
183
|
+
|
|
184
|
+
```py
|
|
185
|
+
>>> from huggingface_hub import model_info
|
|
186
|
+
>>> model_info("<non_existent_repository>")
|
|
187
|
+
(...)
|
|
188
|
+
huggingface_hub.utils._errors.RepositoryNotFoundError: 401 Client Error. (Request ID: PvMw_VjBMjVdMz53WKIzP)
|
|
189
|
+
|
|
190
|
+
Repository Not Found for url: https://huggingface.co/api/models/%3Cnon_existent_repository%3E.
|
|
191
|
+
Please make sure you specified the correct `repo_id` and `repo_type`.
|
|
192
|
+
If the repo is private, make sure you are authenticated.
|
|
193
|
+
Invalid username or password.
|
|
194
|
+
```
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class GatedRepoError(RepositoryNotFoundError):
|
|
199
|
+
"""
|
|
200
|
+
Raised when trying to access a gated repository for which the user is not on the
|
|
201
|
+
authorized list.
|
|
202
|
+
|
|
203
|
+
Note: derives from `RepositoryNotFoundError` to ensure backward compatibility.
|
|
204
|
+
|
|
205
|
+
Example:
|
|
206
|
+
|
|
207
|
+
```py
|
|
208
|
+
>>> from huggingface_hub import model_info
|
|
209
|
+
>>> model_info("<gated_repository>")
|
|
210
|
+
(...)
|
|
211
|
+
huggingface_hub.utils._errors.GatedRepoError: 403 Client Error. (Request ID: ViT1Bf7O_026LGSQuVqfa)
|
|
212
|
+
|
|
213
|
+
Cannot access gated repo for url https://huggingface.co/api/models/ardent-figment/gated-model.
|
|
214
|
+
Access to model ardent-figment/gated-model is restricted and you are not in the authorized list.
|
|
215
|
+
Visit https://huggingface.co/ardent-figment/gated-model to ask for access.
|
|
216
|
+
```
|
|
217
|
+
"""
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class DisabledRepoError(HfHubHTTPError):
|
|
221
|
+
"""
|
|
222
|
+
Raised when trying to access a repository that has been disabled by its author.
|
|
223
|
+
|
|
224
|
+
Example:
|
|
225
|
+
|
|
226
|
+
```py
|
|
227
|
+
>>> from huggingface_hub import dataset_info
|
|
228
|
+
>>> dataset_info("laion/laion-art")
|
|
229
|
+
(...)
|
|
230
|
+
huggingface_hub.utils._errors.DisabledRepoError: 403 Client Error. (Request ID: Root=1-659fc3fa-3031673e0f92c71a2260dbe2;bc6f4dfb-b30a-4862-af0a-5cfe827610d8)
|
|
231
|
+
|
|
232
|
+
Cannot access repository for url https://huggingface.co/api/datasets/laion/laion-art.
|
|
233
|
+
Access to this resource is disabled.
|
|
234
|
+
```
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
# REVISION ERROR
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class RevisionNotFoundError(HfHubHTTPError):
|
|
242
|
+
"""
|
|
243
|
+
Raised when trying to access a hf.co URL with a valid repository but an invalid
|
|
244
|
+
revision.
|
|
245
|
+
|
|
246
|
+
Example:
|
|
247
|
+
|
|
248
|
+
```py
|
|
249
|
+
>>> from huggingface_hub import hf_hub_download
|
|
250
|
+
>>> hf_hub_download('bert-base-cased', 'config.json', revision='<non-existent-revision>')
|
|
251
|
+
(...)
|
|
252
|
+
huggingface_hub.utils._errors.RevisionNotFoundError: 404 Client Error. (Request ID: Mwhe_c3Kt650GcdKEFomX)
|
|
253
|
+
|
|
254
|
+
Revision Not Found for url: https://huggingface.co/bert-base-cased/resolve/%3Cnon-existent-revision%3E/config.json.
|
|
255
|
+
```
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
# ENTRY ERRORS
|
|
260
|
+
class EntryNotFoundError(HfHubHTTPError):
|
|
261
|
+
"""
|
|
262
|
+
Raised when trying to access a hf.co URL with a valid repository and revision
|
|
263
|
+
but an invalid filename.
|
|
264
|
+
|
|
265
|
+
Example:
|
|
266
|
+
|
|
267
|
+
```py
|
|
268
|
+
>>> from huggingface_hub import hf_hub_download
|
|
269
|
+
>>> hf_hub_download('bert-base-cased', '<non-existent-file>')
|
|
270
|
+
(...)
|
|
271
|
+
huggingface_hub.utils._errors.EntryNotFoundError: 404 Client Error. (Request ID: 53pNl6M0MxsnG5Sw8JA6x)
|
|
272
|
+
|
|
273
|
+
Entry Not Found for url: https://huggingface.co/bert-base-cased/resolve/main/%3Cnon-existent-file%3E.
|
|
274
|
+
```
|
|
275
|
+
"""
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
class LocalEntryNotFoundError(EntryNotFoundError, FileNotFoundError, ValueError):
|
|
279
|
+
"""
|
|
280
|
+
Raised when trying to access a file or snapshot that is not on the disk when network is
|
|
281
|
+
disabled or unavailable (connection issue). The entry may exist on the Hub.
|
|
282
|
+
|
|
283
|
+
Note: `ValueError` type is to ensure backward compatibility.
|
|
284
|
+
Note: `LocalEntryNotFoundError` derives from `HTTPError` because of `EntryNotFoundError`
|
|
285
|
+
even when it is not a network issue.
|
|
286
|
+
|
|
287
|
+
Example:
|
|
288
|
+
|
|
289
|
+
```py
|
|
290
|
+
>>> from huggingface_hub import hf_hub_download
|
|
291
|
+
>>> hf_hub_download('bert-base-cased', '<non-cached-file>', local_files_only=True)
|
|
292
|
+
(...)
|
|
293
|
+
huggingface_hub.utils._errors.LocalEntryNotFoundError: Cannot find the requested files in the disk cache and outgoing traffic has been disabled. To enable hf.co look-ups and downloads online, set 'local_files_only' to False.
|
|
294
|
+
```
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
def __init__(self, message: str):
|
|
298
|
+
super().__init__(message, response=None)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
# REQUEST ERROR
|
|
302
|
+
class BadRequestError(HfHubHTTPError, ValueError):
|
|
303
|
+
"""
|
|
304
|
+
Raised by `hf_raise_for_status` when the server returns a HTTP 400 error.
|
|
305
|
+
|
|
306
|
+
Example:
|
|
307
|
+
|
|
308
|
+
```py
|
|
309
|
+
>>> resp = requests.post("hf.co/api/check", ...)
|
|
310
|
+
>>> hf_raise_for_status(resp, endpoint_name="check")
|
|
311
|
+
huggingface_hub.utils._errors.BadRequestError: Bad request for check endpoint: {details} (Request ID: XXX)
|
|
312
|
+
```
|
|
313
|
+
"""
|
huggingface_hub/fastai_utils.py
CHANGED
|
@@ -6,8 +6,7 @@ from typing import Any, Dict, List, Optional, Union
|
|
|
6
6
|
|
|
7
7
|
from packaging import version
|
|
8
8
|
|
|
9
|
-
from huggingface_hub import snapshot_download
|
|
10
|
-
from huggingface_hub.constants import CONFIG_NAME
|
|
9
|
+
from huggingface_hub import constants, snapshot_download
|
|
11
10
|
from huggingface_hub.hf_api import HfApi
|
|
12
11
|
from huggingface_hub.utils import (
|
|
13
12
|
SoftTemporaryDirectory,
|
|
@@ -272,7 +271,7 @@ def _save_pretrained_fastai(
|
|
|
272
271
|
if config is not None:
|
|
273
272
|
if not isinstance(config, dict):
|
|
274
273
|
raise RuntimeError(f"Provided config should be a dict. Got: '{type(config)}'")
|
|
275
|
-
path = os.path.join(save_directory, CONFIG_NAME)
|
|
274
|
+
path = os.path.join(save_directory, constants.CONFIG_NAME)
|
|
276
275
|
with open(path, "w") as f:
|
|
277
276
|
json.dump(config, f)
|
|
278
277
|
|