huggingface-hub 0.36.0__py3-none-any.whl → 1.0.0__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 +33 -45
- huggingface_hub/_commit_api.py +39 -43
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +20 -20
- huggingface_hub/_login.py +17 -43
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +135 -50
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +5 -5
- huggingface_hub/_upload_large_folder.py +18 -32
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/__init__.py +0 -14
- huggingface_hub/cli/_cli_utils.py +143 -39
- huggingface_hub/cli/auth.py +105 -171
- huggingface_hub/cli/cache.py +594 -361
- huggingface_hub/cli/download.py +120 -112
- huggingface_hub/cli/hf.py +38 -41
- huggingface_hub/cli/jobs.py +689 -1017
- huggingface_hub/cli/lfs.py +120 -143
- huggingface_hub/cli/repo.py +282 -216
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -220
- huggingface_hub/cli/upload_large_folder.py +91 -106
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +17 -52
- huggingface_hub/dataclasses.py +135 -21
- huggingface_hub/errors.py +47 -30
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +351 -303
- huggingface_hub/hf_api.py +398 -570
- huggingface_hub/hf_file_system.py +101 -66
- huggingface_hub/hub_mixin.py +32 -54
- huggingface_hub/inference/_client.py +177 -162
- huggingface_hub/inference/_common.py +38 -54
- huggingface_hub/inference/_generated/_async_client.py +218 -258
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
- 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/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +10 -10
- 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/agent.py +3 -3
- huggingface_hub/inference/_mcp/constants.py +1 -2
- huggingface_hub/inference/_mcp/mcp_client.py +33 -22
- huggingface_hub/inference/_mcp/types.py +10 -10
- huggingface_hub/inference/_mcp/utils.py +4 -4
- huggingface_hub/inference/_providers/__init__.py +12 -4
- huggingface_hub/inference/_providers/_common.py +62 -24
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cohere.py +3 -3
- huggingface_hub/inference/_providers/fal_ai.py +25 -25
- huggingface_hub/inference/_providers/featherless_ai.py +4 -4
- huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
- huggingface_hub/inference/_providers/hf_inference.py +13 -13
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +10 -10
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +4 -4
- huggingface_hub/inference/_providers/replicate.py +15 -15
- huggingface_hub/inference/_providers/sambanova.py +6 -6
- huggingface_hub/inference/_providers/together.py +7 -7
- huggingface_hub/lfs.py +21 -94
- huggingface_hub/repocard.py +15 -16
- huggingface_hub/repocard_data.py +57 -57
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +9 -9
- huggingface_hub/serialization/_dduf.py +7 -7
- huggingface_hub/serialization/_torch.py +28 -28
- huggingface_hub/utils/__init__.py +11 -6
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +49 -74
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +3 -3
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +3 -3
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +371 -208
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_parsing.py +98 -0
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +59 -23
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -9
- huggingface_hub/utils/_typing.py +3 -3
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +1 -1
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/METADATA +16 -35
- huggingface_hub-1.0.0.dist-info/RECORD +152 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/entry_points.txt +0 -1
- huggingface_hub/commands/__init__.py +0 -27
- huggingface_hub/commands/delete_cache.py +0 -476
- huggingface_hub/commands/download.py +0 -204
- huggingface_hub/commands/env.py +0 -39
- huggingface_hub/commands/huggingface_cli.py +0 -65
- huggingface_hub/commands/lfs.py +0 -200
- huggingface_hub/commands/repo.py +0 -151
- huggingface_hub/commands/repo_files.py +0 -132
- huggingface_hub/commands/scan_cache.py +0 -183
- huggingface_hub/commands/tag.py +0 -161
- huggingface_hub/commands/upload.py +0 -318
- huggingface_hub/commands/upload_large_folder.py +0 -131
- huggingface_hub/commands/user.py +0 -208
- huggingface_hub/commands/version.py +0 -40
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -497
- huggingface_hub/repository.py +0 -1471
- huggingface_hub/serialization/_tensorflow.py +0 -92
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.36.0.dist-info/RECORD +0 -170
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/top_level.txt +0 -0
huggingface_hub/cli/lfs.py
CHANGED
|
@@ -20,10 +20,10 @@ import json
|
|
|
20
20
|
import os
|
|
21
21
|
import subprocess
|
|
22
22
|
import sys
|
|
23
|
-
from
|
|
24
|
-
|
|
23
|
+
from typing import Annotated, Optional
|
|
24
|
+
|
|
25
|
+
import typer
|
|
25
26
|
|
|
26
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
27
27
|
from huggingface_hub.lfs import LFS_MULTIPART_UPLOAD_COMMAND
|
|
28
28
|
|
|
29
29
|
from ..utils import get_session, hf_raise_for_status, logging
|
|
@@ -33,68 +33,45 @@ from ..utils._lfs import SliceFileObj
|
|
|
33
33
|
logger = logging.get_logger(__name__)
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
def lfs_enable_largefiles(
|
|
37
|
+
path: Annotated[
|
|
38
|
+
str,
|
|
39
|
+
typer.Argument(
|
|
40
|
+
help="Local path to repository you want to configure.",
|
|
41
|
+
),
|
|
42
|
+
],
|
|
43
|
+
) -> None:
|
|
37
44
|
"""
|
|
38
|
-
|
|
39
|
-
for git-lfs. This lets users upload large files >5GB 🔥. Spec for LFS custom
|
|
40
|
-
transfer agent is:
|
|
41
|
-
https://github.com/git-lfs/git-lfs/blob/master/docs/custom-transfers.md
|
|
42
|
-
|
|
43
|
-
This introduces two commands to the CLI:
|
|
44
|
-
|
|
45
|
-
1. $ hf lfs-enable-largefiles
|
|
46
|
-
|
|
47
|
-
This should be executed once for each model repo that contains a model file
|
|
48
|
-
>5GB. It's documented in the error message you get if you just try to git
|
|
49
|
-
push a 5GB file without having enabled it before.
|
|
50
|
-
|
|
51
|
-
2. $ hf lfs-multipart-upload
|
|
45
|
+
Configure a local git repository to use the multipart transfer agent for large files.
|
|
52
46
|
|
|
53
|
-
This command
|
|
54
|
-
|
|
47
|
+
This command sets up git-lfs to use the custom multipart transfer agent
|
|
48
|
+
which enables efficient uploading of large files in chunks.
|
|
55
49
|
"""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if not os.path.isdir(local_path):
|
|
75
|
-
print("This does not look like a valid git repo.")
|
|
76
|
-
exit(1)
|
|
77
|
-
subprocess.run(
|
|
78
|
-
"git config lfs.customtransfer.multipart.path hf".split(),
|
|
79
|
-
check=True,
|
|
80
|
-
cwd=local_path,
|
|
81
|
-
)
|
|
82
|
-
subprocess.run(
|
|
83
|
-
f"git config lfs.customtransfer.multipart.args {LFS_MULTIPART_UPLOAD_COMMAND}".split(),
|
|
84
|
-
check=True,
|
|
85
|
-
cwd=local_path,
|
|
86
|
-
)
|
|
87
|
-
print("Local repo set up for largefiles")
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def write_msg(msg: Dict):
|
|
50
|
+
local_path = os.path.abspath(path)
|
|
51
|
+
if not os.path.isdir(local_path):
|
|
52
|
+
print("This does not look like a valid git repo.")
|
|
53
|
+
raise typer.Exit(code=1)
|
|
54
|
+
subprocess.run(
|
|
55
|
+
"git config lfs.customtransfer.multipart.path hf".split(),
|
|
56
|
+
check=True,
|
|
57
|
+
cwd=local_path,
|
|
58
|
+
)
|
|
59
|
+
subprocess.run(
|
|
60
|
+
f"git config lfs.customtransfer.multipart.args {LFS_MULTIPART_UPLOAD_COMMAND}".split(),
|
|
61
|
+
check=True,
|
|
62
|
+
cwd=local_path,
|
|
63
|
+
)
|
|
64
|
+
print("Local repo set up for largefiles")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def write_msg(msg: dict):
|
|
91
68
|
"""Write out the message in Line delimited JSON."""
|
|
92
69
|
msg_str = json.dumps(msg) + "\n"
|
|
93
70
|
sys.stdout.write(msg_str)
|
|
94
71
|
sys.stdout.flush()
|
|
95
72
|
|
|
96
73
|
|
|
97
|
-
def read_msg() -> Optional[
|
|
74
|
+
def read_msg() -> Optional[dict]:
|
|
98
75
|
"""Read Line delimited JSON from stdin."""
|
|
99
76
|
msg = json.loads(sys.stdin.readline().strip())
|
|
100
77
|
|
|
@@ -109,90 +86,90 @@ def read_msg() -> Optional[Dict]:
|
|
|
109
86
|
return msg
|
|
110
87
|
|
|
111
88
|
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
89
|
+
def lfs_multipart_upload() -> None:
|
|
90
|
+
"""Internal git-lfs custom transfer agent for multipart uploads.
|
|
91
|
+
|
|
92
|
+
This function implements the custom transfer protocol for git-lfs multipart uploads.
|
|
93
|
+
Handles chunked uploads of large files to Hugging Face Hub.
|
|
94
|
+
"""
|
|
95
|
+
# Immediately after invoking a custom transfer process, git-lfs
|
|
96
|
+
# sends initiation data to the process over stdin.
|
|
97
|
+
# This tells the process useful information about the configuration.
|
|
98
|
+
init_msg = json.loads(sys.stdin.readline().strip())
|
|
99
|
+
if not (init_msg.get("event") == "init" and init_msg.get("operation") == "upload"):
|
|
100
|
+
write_msg({"error": {"code": 32, "message": "Wrong lfs init operation"}})
|
|
101
|
+
sys.exit(1)
|
|
102
|
+
|
|
103
|
+
# The transfer process should use the information it needs from the
|
|
104
|
+
# initiation structure, and also perform any one-off setup tasks it
|
|
105
|
+
# needs to do. It should then respond on stdout with a simple empty
|
|
106
|
+
# confirmation structure, as follows:
|
|
107
|
+
write_msg({})
|
|
108
|
+
|
|
109
|
+
# After the initiation exchange, git-lfs will send any number of
|
|
110
|
+
# transfer requests to the stdin of the transfer process, in a serial sequence.
|
|
111
|
+
while True:
|
|
112
|
+
msg = read_msg()
|
|
113
|
+
if msg is None:
|
|
114
|
+
# When all transfers have been processed, git-lfs will send
|
|
115
|
+
# a terminate event to the stdin of the transfer process.
|
|
116
|
+
# On receiving this message the transfer process should
|
|
117
|
+
# clean up and terminate. No response is expected.
|
|
118
|
+
sys.exit(0)
|
|
119
|
+
|
|
120
|
+
oid = msg["oid"]
|
|
121
|
+
filepath = msg["path"]
|
|
122
|
+
completion_url = msg["action"]["href"]
|
|
123
|
+
header = msg["action"]["header"]
|
|
124
|
+
chunk_size = int(header.pop("chunk_size"))
|
|
125
|
+
presigned_urls: list[str] = list(header.values())
|
|
126
|
+
|
|
127
|
+
# Send a "started" progress event to allow other workers to start.
|
|
128
|
+
# Otherwise they're delayed until first "progress" event is reported,
|
|
129
|
+
# i.e. after the first 5GB by default (!)
|
|
130
|
+
write_msg(
|
|
131
|
+
{
|
|
132
|
+
"event": "progress",
|
|
133
|
+
"oid": oid,
|
|
134
|
+
"bytesSoFar": 1,
|
|
135
|
+
"bytesSinceLast": 0,
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
parts = []
|
|
140
|
+
with open(filepath, "rb") as file:
|
|
141
|
+
for i, presigned_url in enumerate(presigned_urls):
|
|
142
|
+
with SliceFileObj(
|
|
143
|
+
file,
|
|
144
|
+
seek_from=i * chunk_size,
|
|
145
|
+
read_limit=chunk_size,
|
|
146
|
+
) as data:
|
|
147
|
+
r = get_session().put(presigned_url, data=data)
|
|
148
|
+
hf_raise_for_status(r)
|
|
149
|
+
parts.append(
|
|
150
|
+
{
|
|
151
|
+
"etag": r.headers.get("etag"),
|
|
152
|
+
"partNumber": i + 1,
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
# In order to support progress reporting while data is uploading / downloading,
|
|
156
|
+
# the transfer process should post messages to stdout
|
|
157
|
+
write_msg(
|
|
158
|
+
{
|
|
159
|
+
"event": "progress",
|
|
160
|
+
"oid": oid,
|
|
161
|
+
"bytesSoFar": (i + 1) * chunk_size,
|
|
162
|
+
"bytesSinceLast": chunk_size,
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
r = get_session().post(
|
|
167
|
+
completion_url,
|
|
168
|
+
json={
|
|
169
|
+
"oid": oid,
|
|
170
|
+
"parts": parts,
|
|
171
|
+
},
|
|
172
|
+
)
|
|
173
|
+
hf_raise_for_status(r)
|
|
174
|
+
|
|
175
|
+
write_msg({"event": "complete", "oid": oid})
|