huggingface-hub 0.29.0rc2__py3-none-any.whl → 1.1.3__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.
- huggingface_hub/__init__.py +160 -46
- huggingface_hub/_commit_api.py +277 -71
- huggingface_hub/_commit_scheduler.py +15 -15
- huggingface_hub/_inference_endpoints.py +33 -22
- huggingface_hub/_jobs_api.py +301 -0
- huggingface_hub/_local_folder.py +18 -3
- huggingface_hub/_login.py +31 -63
- huggingface_hub/_oauth.py +460 -0
- huggingface_hub/_snapshot_download.py +241 -81
- huggingface_hub/_space_api.py +18 -10
- huggingface_hub/_tensorboard_logger.py +15 -19
- huggingface_hub/_upload_large_folder.py +196 -76
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +15 -25
- huggingface_hub/{commands → cli}/__init__.py +1 -15
- huggingface_hub/cli/_cli_utils.py +173 -0
- huggingface_hub/cli/auth.py +147 -0
- huggingface_hub/cli/cache.py +841 -0
- huggingface_hub/cli/download.py +189 -0
- huggingface_hub/cli/hf.py +60 -0
- huggingface_hub/cli/inference_endpoints.py +377 -0
- huggingface_hub/cli/jobs.py +772 -0
- huggingface_hub/cli/lfs.py +175 -0
- huggingface_hub/cli/repo.py +315 -0
- huggingface_hub/cli/repo_files.py +94 -0
- huggingface_hub/{commands/env.py → cli/system.py} +10 -13
- huggingface_hub/cli/upload.py +294 -0
- huggingface_hub/cli/upload_large_folder.py +117 -0
- huggingface_hub/community.py +20 -12
- huggingface_hub/constants.py +83 -59
- huggingface_hub/dataclasses.py +609 -0
- huggingface_hub/errors.py +99 -30
- huggingface_hub/fastai_utils.py +30 -41
- huggingface_hub/file_download.py +606 -346
- huggingface_hub/hf_api.py +2445 -1132
- huggingface_hub/hf_file_system.py +269 -152
- huggingface_hub/hub_mixin.py +61 -66
- huggingface_hub/inference/_client.py +501 -630
- huggingface_hub/inference/_common.py +133 -121
- huggingface_hub/inference/_generated/_async_client.py +536 -722
- huggingface_hub/inference/_generated/types/__init__.py +6 -1
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +5 -6
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +77 -31
- huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
- huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
- huggingface_hub/inference/_generated/types/image_to_image.py +8 -2
- huggingface_hub/inference/_generated/types/image_to_text.py +2 -3
- huggingface_hub/inference/_generated/types/image_to_video.py +60 -0
- huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +5 -5
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +11 -11
- huggingface_hub/inference/_generated/types/text_to_audio.py +1 -2
- huggingface_hub/inference/_generated/types/text_to_speech.py +1 -2
- huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
- huggingface_hub/inference/_generated/types/token_classification.py +2 -2
- huggingface_hub/inference/_generated/types/translation.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
- huggingface_hub/inference/_mcp/__init__.py +0 -0
- huggingface_hub/inference/_mcp/_cli_hacks.py +88 -0
- huggingface_hub/inference/_mcp/agent.py +100 -0
- huggingface_hub/inference/_mcp/cli.py +247 -0
- huggingface_hub/inference/_mcp/constants.py +81 -0
- huggingface_hub/inference/_mcp/mcp_client.py +395 -0
- huggingface_hub/inference/_mcp/types.py +45 -0
- huggingface_hub/inference/_mcp/utils.py +128 -0
- huggingface_hub/inference/_providers/__init__.py +149 -20
- huggingface_hub/inference/_providers/_common.py +160 -37
- huggingface_hub/inference/_providers/black_forest_labs.py +12 -9
- huggingface_hub/inference/_providers/cerebras.py +6 -0
- huggingface_hub/inference/_providers/clarifai.py +13 -0
- huggingface_hub/inference/_providers/cohere.py +32 -0
- huggingface_hub/inference/_providers/fal_ai.py +231 -22
- huggingface_hub/inference/_providers/featherless_ai.py +38 -0
- huggingface_hub/inference/_providers/fireworks_ai.py +22 -1
- huggingface_hub/inference/_providers/groq.py +9 -0
- huggingface_hub/inference/_providers/hf_inference.py +143 -33
- huggingface_hub/inference/_providers/hyperbolic.py +9 -5
- huggingface_hub/inference/_providers/nebius.py +47 -5
- huggingface_hub/inference/_providers/novita.py +48 -5
- huggingface_hub/inference/_providers/nscale.py +44 -0
- huggingface_hub/inference/_providers/openai.py +25 -0
- huggingface_hub/inference/_providers/publicai.py +6 -0
- huggingface_hub/inference/_providers/replicate.py +46 -9
- huggingface_hub/inference/_providers/sambanova.py +37 -1
- huggingface_hub/inference/_providers/scaleway.py +28 -0
- huggingface_hub/inference/_providers/together.py +34 -5
- huggingface_hub/inference/_providers/wavespeed.py +138 -0
- huggingface_hub/inference/_providers/zai_org.py +17 -0
- huggingface_hub/lfs.py +33 -100
- huggingface_hub/repocard.py +34 -38
- huggingface_hub/repocard_data.py +79 -59
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +12 -15
- huggingface_hub/serialization/_dduf.py +8 -8
- huggingface_hub/serialization/_torch.py +69 -69
- huggingface_hub/utils/__init__.py +27 -8
- huggingface_hub/utils/_auth.py +7 -7
- huggingface_hub/utils/_cache_manager.py +92 -147
- huggingface_hub/utils/_chunk_utils.py +2 -3
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +55 -0
- huggingface_hub/utils/_experimental.py +7 -5
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +5 -5
- huggingface_hub/utils/_headers.py +8 -30
- huggingface_hub/utils/_http.py +399 -237
- huggingface_hub/utils/_pagination.py +6 -6
- huggingface_hub/utils/_parsing.py +98 -0
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +74 -22
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +13 -11
- huggingface_hub/utils/_telemetry.py +4 -4
- huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -4
- huggingface_hub/utils/_typing.py +25 -5
- huggingface_hub/utils/_validators.py +55 -74
- huggingface_hub/utils/_verification.py +167 -0
- huggingface_hub/utils/_xet.py +235 -0
- huggingface_hub/utils/_xet_progress_reporting.py +162 -0
- huggingface_hub/utils/insecure_hashlib.py +3 -5
- huggingface_hub/utils/logging.py +8 -11
- huggingface_hub/utils/tqdm.py +33 -4
- {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info}/METADATA +94 -82
- huggingface_hub-1.1.3.dist-info/RECORD +155 -0
- {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info}/WHEEL +1 -1
- huggingface_hub-1.1.3.dist-info/entry_points.txt +6 -0
- huggingface_hub/commands/delete_cache.py +0 -428
- huggingface_hub/commands/download.py +0 -200
- huggingface_hub/commands/huggingface_cli.py +0 -61
- huggingface_hub/commands/lfs.py +0 -200
- huggingface_hub/commands/repo_files.py +0 -128
- huggingface_hub/commands/scan_cache.py +0 -181
- huggingface_hub/commands/tag.py +0 -159
- huggingface_hub/commands/upload.py +0 -299
- huggingface_hub/commands/upload_large_folder.py +0 -129
- huggingface_hub/commands/user.py +0 -304
- huggingface_hub/commands/version.py +0 -37
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -500
- huggingface_hub/repository.py +0 -1477
- huggingface_hub/serialization/_tensorflow.py +0 -95
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.29.0rc2.dist-info/RECORD +0 -131
- huggingface_hub-0.29.0rc2.dist-info/entry_points.txt +0 -6
- {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info/licenses}/LICENSE +0 -0
- {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info}/top_level.txt +0 -0
huggingface_hub/errors.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from typing import Optional, Union
|
|
5
5
|
|
|
6
|
-
from
|
|
6
|
+
from httpx import HTTPError, Response
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
# CACHE ERRORS
|
|
@@ -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
|
|
|
@@ -51,7 +51,7 @@ class HfHubHTTPError(HTTPError):
|
|
|
51
51
|
|
|
52
52
|
Example:
|
|
53
53
|
```py
|
|
54
|
-
import
|
|
54
|
+
import httpx
|
|
55
55
|
from huggingface_hub.utils import get_session, hf_raise_for_status, HfHubHTTPError
|
|
56
56
|
|
|
57
57
|
response = get_session().post(...)
|
|
@@ -67,24 +67,27 @@ class HfHubHTTPError(HTTPError):
|
|
|
67
67
|
```
|
|
68
68
|
"""
|
|
69
69
|
|
|
70
|
-
def __init__(
|
|
71
|
-
self
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
def __init__(
|
|
71
|
+
self,
|
|
72
|
+
message: str,
|
|
73
|
+
*,
|
|
74
|
+
response: Response,
|
|
75
|
+
server_message: Optional[str] = None,
|
|
76
|
+
):
|
|
77
|
+
self.request_id = response.headers.get("x-request-id") or response.headers.get("X-Amzn-Trace-Id")
|
|
76
78
|
self.server_message = server_message
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
response=response, # type: ignore [arg-type]
|
|
81
|
-
request=response.request if response is not None else None, # type: ignore [arg-type]
|
|
82
|
-
)
|
|
79
|
+
self.response = response
|
|
80
|
+
self.request = response.request
|
|
81
|
+
super().__init__(message)
|
|
83
82
|
|
|
84
83
|
def append_to_message(self, additional_message: str) -> None:
|
|
85
84
|
"""Append additional information to the `HfHubHTTPError` initial message."""
|
|
86
85
|
self.args = (self.args[0] + additional_message,) + self.args[1:]
|
|
87
86
|
|
|
87
|
+
def __reduce_ex__(self, protocol):
|
|
88
|
+
"""Fix pickling of Exception subclass with kwargs. We need to override __reduce_ex__ of the parent class"""
|
|
89
|
+
return (self.__class__, (str(self),), {"response": self.response, "server_message": self.server_message})
|
|
90
|
+
|
|
88
91
|
|
|
89
92
|
# INFERENCE CLIENT ERRORS
|
|
90
93
|
|
|
@@ -161,6 +164,10 @@ class HFValidationError(ValueError):
|
|
|
161
164
|
# FILE METADATA ERRORS
|
|
162
165
|
|
|
163
166
|
|
|
167
|
+
class DryRunError(OSError):
|
|
168
|
+
"""Error triggered when a dry run is requested but cannot be performed (e.g. invalid repo)."""
|
|
169
|
+
|
|
170
|
+
|
|
164
171
|
class FileMetadataError(OSError):
|
|
165
172
|
"""Error triggered when the metadata of a file on the Hub cannot be retrieved (missing ETag or commit_hash).
|
|
166
173
|
|
|
@@ -182,7 +189,7 @@ class RepositoryNotFoundError(HfHubHTTPError):
|
|
|
182
189
|
>>> from huggingface_hub import model_info
|
|
183
190
|
>>> model_info("<non_existent_repository>")
|
|
184
191
|
(...)
|
|
185
|
-
huggingface_hub.
|
|
192
|
+
huggingface_hub.errors.RepositoryNotFoundError: 401 Client Error. (Request ID: PvMw_VjBMjVdMz53WKIzP)
|
|
186
193
|
|
|
187
194
|
Repository Not Found for url: https://huggingface.co/api/models/%3Cnon_existent_repository%3E.
|
|
188
195
|
Please make sure you specified the correct `repo_id` and `repo_type`.
|
|
@@ -205,7 +212,7 @@ class GatedRepoError(RepositoryNotFoundError):
|
|
|
205
212
|
>>> from huggingface_hub import model_info
|
|
206
213
|
>>> model_info("<gated_repository>")
|
|
207
214
|
(...)
|
|
208
|
-
huggingface_hub.
|
|
215
|
+
huggingface_hub.errors.GatedRepoError: 403 Client Error. (Request ID: ViT1Bf7O_026LGSQuVqfa)
|
|
209
216
|
|
|
210
217
|
Cannot access gated repo for url https://huggingface.co/api/models/ardent-figment/gated-model.
|
|
211
218
|
Access to model ardent-figment/gated-model is restricted and you are not in the authorized list.
|
|
@@ -224,7 +231,7 @@ class DisabledRepoError(HfHubHTTPError):
|
|
|
224
231
|
>>> from huggingface_hub import dataset_info
|
|
225
232
|
>>> dataset_info("laion/laion-art")
|
|
226
233
|
(...)
|
|
227
|
-
huggingface_hub.
|
|
234
|
+
huggingface_hub.errors.DisabledRepoError: 403 Client Error. (Request ID: Root=1-659fc3fa-3031673e0f92c71a2260dbe2;bc6f4dfb-b30a-4862-af0a-5cfe827610d8)
|
|
228
235
|
|
|
229
236
|
Cannot access repository for url https://huggingface.co/api/datasets/laion/laion-art.
|
|
230
237
|
Access to this resource is disabled.
|
|
@@ -246,7 +253,7 @@ class RevisionNotFoundError(HfHubHTTPError):
|
|
|
246
253
|
>>> from huggingface_hub import hf_hub_download
|
|
247
254
|
>>> hf_hub_download('bert-base-cased', 'config.json', revision='<non-existent-revision>')
|
|
248
255
|
(...)
|
|
249
|
-
huggingface_hub.
|
|
256
|
+
huggingface_hub.errors.RevisionNotFoundError: 404 Client Error. (Request ID: Mwhe_c3Kt650GcdKEFomX)
|
|
250
257
|
|
|
251
258
|
Revision Not Found for url: https://huggingface.co/bert-base-cased/resolve/%3Cnon-existent-revision%3E/config.json.
|
|
252
259
|
```
|
|
@@ -254,7 +261,25 @@ class RevisionNotFoundError(HfHubHTTPError):
|
|
|
254
261
|
|
|
255
262
|
|
|
256
263
|
# ENTRY ERRORS
|
|
257
|
-
class EntryNotFoundError(
|
|
264
|
+
class EntryNotFoundError(Exception):
|
|
265
|
+
"""
|
|
266
|
+
Raised when entry not found, either locally or remotely.
|
|
267
|
+
|
|
268
|
+
Example:
|
|
269
|
+
|
|
270
|
+
```py
|
|
271
|
+
>>> from huggingface_hub import hf_hub_download
|
|
272
|
+
>>> hf_hub_download('bert-base-cased', '<non-existent-file>')
|
|
273
|
+
(...)
|
|
274
|
+
huggingface_hub.errors.RemoteEntryNotFoundError (...)
|
|
275
|
+
>>> hf_hub_download('bert-base-cased', '<non-existent-file>', local_files_only=True)
|
|
276
|
+
(...)
|
|
277
|
+
huggingface_hub.utils.errors.LocalEntryNotFoundError (...)
|
|
278
|
+
```
|
|
279
|
+
"""
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class RemoteEntryNotFoundError(HfHubHTTPError, EntryNotFoundError):
|
|
258
283
|
"""
|
|
259
284
|
Raised when trying to access a hf.co URL with a valid repository and revision
|
|
260
285
|
but an invalid filename.
|
|
@@ -265,34 +290,30 @@ class EntryNotFoundError(HfHubHTTPError):
|
|
|
265
290
|
>>> from huggingface_hub import hf_hub_download
|
|
266
291
|
>>> hf_hub_download('bert-base-cased', '<non-existent-file>')
|
|
267
292
|
(...)
|
|
268
|
-
huggingface_hub.
|
|
293
|
+
huggingface_hub.errors.EntryNotFoundError: 404 Client Error. (Request ID: 53pNl6M0MxsnG5Sw8JA6x)
|
|
269
294
|
|
|
270
295
|
Entry Not Found for url: https://huggingface.co/bert-base-cased/resolve/main/%3Cnon-existent-file%3E.
|
|
271
296
|
```
|
|
272
297
|
"""
|
|
273
298
|
|
|
274
299
|
|
|
275
|
-
class LocalEntryNotFoundError(
|
|
300
|
+
class LocalEntryNotFoundError(FileNotFoundError, EntryNotFoundError):
|
|
276
301
|
"""
|
|
277
302
|
Raised when trying to access a file or snapshot that is not on the disk when network is
|
|
278
303
|
disabled or unavailable (connection issue). The entry may exist on the Hub.
|
|
279
304
|
|
|
280
|
-
Note: `ValueError` type is to ensure backward compatibility.
|
|
281
|
-
Note: `LocalEntryNotFoundError` derives from `HTTPError` because of `EntryNotFoundError`
|
|
282
|
-
even when it is not a network issue.
|
|
283
|
-
|
|
284
305
|
Example:
|
|
285
306
|
|
|
286
307
|
```py
|
|
287
308
|
>>> from huggingface_hub import hf_hub_download
|
|
288
309
|
>>> hf_hub_download('bert-base-cased', '<non-cached-file>', local_files_only=True)
|
|
289
310
|
(...)
|
|
290
|
-
huggingface_hub.
|
|
311
|
+
huggingface_hub.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.
|
|
291
312
|
```
|
|
292
313
|
"""
|
|
293
314
|
|
|
294
315
|
def __init__(self, message: str):
|
|
295
|
-
super().__init__(message
|
|
316
|
+
super().__init__(message)
|
|
296
317
|
|
|
297
318
|
|
|
298
319
|
# REQUEST ERROR
|
|
@@ -303,9 +324,9 @@ class BadRequestError(HfHubHTTPError, ValueError):
|
|
|
303
324
|
Example:
|
|
304
325
|
|
|
305
326
|
```py
|
|
306
|
-
>>> resp =
|
|
327
|
+
>>> resp = httpx.post("hf.co/api/check", ...)
|
|
307
328
|
>>> hf_raise_for_status(resp, endpoint_name="check")
|
|
308
|
-
huggingface_hub.
|
|
329
|
+
huggingface_hub.errors.BadRequestError: Bad request for check endpoint: {details} (Request ID: XXX)
|
|
309
330
|
```
|
|
310
331
|
"""
|
|
311
332
|
|
|
@@ -327,3 +348,51 @@ class DDUFExportError(DDUFError):
|
|
|
327
348
|
|
|
328
349
|
class DDUFInvalidEntryNameError(DDUFExportError):
|
|
329
350
|
"""Exception thrown when the entry name is invalid."""
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
# STRICT DATACLASSES ERRORS
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
class StrictDataclassError(Exception):
|
|
357
|
+
"""Base exception for strict dataclasses."""
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
class StrictDataclassDefinitionError(StrictDataclassError):
|
|
361
|
+
"""Exception thrown when a strict dataclass is defined incorrectly."""
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
class StrictDataclassFieldValidationError(StrictDataclassError):
|
|
365
|
+
"""Exception thrown when a strict dataclass fails validation for a given field."""
|
|
366
|
+
|
|
367
|
+
def __init__(self, field: str, cause: Exception):
|
|
368
|
+
error_message = f"Validation error for field '{field}':"
|
|
369
|
+
error_message += f"\n {cause.__class__.__name__}: {cause}"
|
|
370
|
+
super().__init__(error_message)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
class StrictDataclassClassValidationError(StrictDataclassError):
|
|
374
|
+
"""Exception thrown when a strict dataclass fails validation on a class validator."""
|
|
375
|
+
|
|
376
|
+
def __init__(self, validator: str, cause: Exception):
|
|
377
|
+
error_message = f"Class validation error for validator '{validator}':"
|
|
378
|
+
error_message += f"\n {cause.__class__.__name__}: {cause}"
|
|
379
|
+
super().__init__(error_message)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
# XET ERRORS
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
class XetError(Exception):
|
|
386
|
+
"""Base exception for errors related to Xet Storage."""
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
class XetAuthorizationError(XetError):
|
|
390
|
+
"""Exception thrown when the user does not have the right authorization to use Xet Storage."""
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
class XetRefreshTokenError(XetError):
|
|
394
|
+
"""Exception thrown when the refresh token is invalid."""
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
class XetDownloadError(Exception):
|
|
398
|
+
"""Exception thrown when the download from Xet Storage fails."""
|
huggingface_hub/fastai_utils.py
CHANGED
|
@@ -2,7 +2,7 @@ import json
|
|
|
2
2
|
import os
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from pickle import DEFAULT_PROTOCOL, PicklingError
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Optional, Union
|
|
6
6
|
|
|
7
7
|
from packaging import version
|
|
8
8
|
|
|
@@ -16,7 +16,6 @@ from huggingface_hub.utils import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
from .utils import logging, validate_hf_hub_args
|
|
19
|
-
from .utils._runtime import _PY_VERSION # noqa: F401 # for backward compatibility...
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
logger = logging.get_logger(__name__)
|
|
@@ -35,13 +34,11 @@ def _check_fastai_fastcore_versions(
|
|
|
35
34
|
fastcore_min_version (`str`, *optional*):
|
|
36
35
|
The minimum fastcore version supported.
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
Raises the following error:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
</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.
|
|
45
42
|
"""
|
|
46
43
|
|
|
47
44
|
if (get_fastcore_version() or get_fastai_version()) == "N/A":
|
|
@@ -89,15 +86,13 @@ def _check_fastai_fastcore_pyproject_versions(
|
|
|
89
86
|
fastcore_min_version (`str`, *optional*):
|
|
90
87
|
The minimum fastcore version supported.
|
|
91
88
|
|
|
92
|
-
|
|
93
|
-
Raises the following errors:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
</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.
|
|
101
96
|
"""
|
|
102
97
|
|
|
103
98
|
try:
|
|
@@ -241,7 +236,7 @@ def _create_model_pyproject(repo_dir: Path):
|
|
|
241
236
|
def _save_pretrained_fastai(
|
|
242
237
|
learner,
|
|
243
238
|
save_directory: Union[str, Path],
|
|
244
|
-
config: Optional[
|
|
239
|
+
config: Optional[dict[str, Any]] = None,
|
|
245
240
|
):
|
|
246
241
|
"""
|
|
247
242
|
Saves a fastai learner to `save_directory` in pickle format using the default pickle protocol for the version of python used.
|
|
@@ -254,14 +249,11 @@ def _save_pretrained_fastai(
|
|
|
254
249
|
config (`dict`, *optional*):
|
|
255
250
|
Configuration object. Will be uploaded as a .json file. Example: 'https://huggingface.co/espejelomar/fastai-pet-breeds-classification/blob/main/config.json'.
|
|
256
251
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if the config file provided is not a dictionary.
|
|
263
|
-
|
|
264
|
-
</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.
|
|
265
257
|
"""
|
|
266
258
|
_check_fastai_fastcore_versions()
|
|
267
259
|
|
|
@@ -350,9 +342,9 @@ def push_to_hub_fastai(
|
|
|
350
342
|
config: Optional[dict] = None,
|
|
351
343
|
branch: Optional[str] = None,
|
|
352
344
|
create_pr: Optional[bool] = None,
|
|
353
|
-
allow_patterns: Optional[Union[
|
|
354
|
-
ignore_patterns: Optional[Union[
|
|
355
|
-
delete_patterns: Optional[Union[
|
|
345
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
346
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
347
|
+
delete_patterns: Optional[Union[list[str], str]] = None,
|
|
356
348
|
api_endpoint: Optional[str] = None,
|
|
357
349
|
):
|
|
358
350
|
"""
|
|
@@ -385,24 +377,21 @@ def push_to_hub_fastai(
|
|
|
385
377
|
Defaults to `False`.
|
|
386
378
|
api_endpoint (`str`, *optional*):
|
|
387
379
|
The API endpoint to use when pushing the model to the hub.
|
|
388
|
-
allow_patterns (`
|
|
380
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
389
381
|
If provided, only files matching at least one pattern are pushed.
|
|
390
|
-
ignore_patterns (`
|
|
382
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
391
383
|
If provided, files matching any of the patterns are not pushed.
|
|
392
|
-
delete_patterns (`
|
|
384
|
+
delete_patterns (`list[str]` or `str`, *optional*):
|
|
393
385
|
If provided, remote files matching any of the patterns will be deleted from the repo.
|
|
394
386
|
|
|
395
387
|
Returns:
|
|
396
388
|
The url of the commit of your model in the given repository.
|
|
397
389
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if the user is not log on to the Hugging Face Hub.
|
|
404
|
-
|
|
405
|
-
</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.
|
|
406
395
|
"""
|
|
407
396
|
_check_fastai_fastcore_versions()
|
|
408
397
|
api = HfApi(endpoint=api_endpoint)
|