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.

Files changed (48) hide show
  1. huggingface_hub/__init__.py +4 -4
  2. huggingface_hub/_commit_api.py +126 -66
  3. huggingface_hub/_commit_scheduler.py +4 -7
  4. huggingface_hub/_login.py +9 -15
  5. huggingface_hub/_tensorboard_logger.py +2 -5
  6. huggingface_hub/_webhooks_server.py +8 -20
  7. huggingface_hub/cli/__init__.py +0 -14
  8. huggingface_hub/cli/_cli_utils.py +79 -2
  9. huggingface_hub/cli/auth.py +104 -149
  10. huggingface_hub/cli/cache.py +97 -121
  11. huggingface_hub/cli/download.py +93 -110
  12. huggingface_hub/cli/hf.py +37 -41
  13. huggingface_hub/cli/jobs.py +687 -1014
  14. huggingface_hub/cli/lfs.py +116 -139
  15. huggingface_hub/cli/repo.py +290 -214
  16. huggingface_hub/cli/repo_files.py +50 -84
  17. huggingface_hub/cli/system.py +6 -25
  18. huggingface_hub/cli/upload.py +198 -212
  19. huggingface_hub/cli/upload_large_folder.py +90 -105
  20. huggingface_hub/dataclasses.py +3 -12
  21. huggingface_hub/errors.py +1 -1
  22. huggingface_hub/fastai_utils.py +22 -32
  23. huggingface_hub/file_download.py +18 -21
  24. huggingface_hub/hf_api.py +258 -410
  25. huggingface_hub/hf_file_system.py +17 -44
  26. huggingface_hub/inference/_client.py +25 -47
  27. huggingface_hub/inference/_generated/_async_client.py +25 -47
  28. huggingface_hub/inference/_mcp/agent.py +2 -5
  29. huggingface_hub/inference/_mcp/mcp_client.py +2 -5
  30. huggingface_hub/inference/_providers/__init__.py +11 -0
  31. huggingface_hub/inference/_providers/_common.py +1 -0
  32. huggingface_hub/inference/_providers/publicai.py +6 -0
  33. huggingface_hub/inference/_providers/scaleway.py +28 -0
  34. huggingface_hub/lfs.py +14 -8
  35. huggingface_hub/repocard.py +12 -16
  36. huggingface_hub/serialization/_base.py +3 -6
  37. huggingface_hub/serialization/_torch.py +16 -34
  38. huggingface_hub/utils/__init__.py +1 -1
  39. huggingface_hub/utils/_cache_manager.py +41 -71
  40. huggingface_hub/utils/_chunk_utils.py +2 -3
  41. huggingface_hub/utils/_http.py +32 -35
  42. huggingface_hub/utils/logging.py +8 -11
  43. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/METADATA +7 -2
  44. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/RECORD +48 -46
  45. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/LICENSE +0 -0
  46. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/WHEEL +0 -0
  47. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/entry_points.txt +0 -0
  48. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/top_level.txt +0 -0
@@ -20,10 +20,10 @@ import json
20
20
  import os
21
21
  import subprocess
22
22
  import sys
23
- from argparse import _SubParsersAction
24
- from typing import Optional
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,58 +33,35 @@ from ..utils._lfs import SliceFileObj
33
33
  logger = logging.get_logger(__name__)
34
34
 
35
35
 
36
- class LfsCommands(BaseHuggingfaceCLICommand):
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
- Implementation of a custom transfer agent for the transfer type "multipart"
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.
45
+ Configure a local git repository to use the multipart transfer agent for large files.
50
46
 
51
- 2. $ hf lfs-multipart-upload
52
-
53
- This command is called by lfs directly and is not meant to be called by the
54
- user.
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
- @staticmethod
58
- def register_subcommand(parser: _SubParsersAction):
59
- enable_parser = parser.add_parser("lfs-enable-largefiles", add_help=False)
60
- enable_parser.add_argument("path", type=str, help="Local path to repository you want to configure.")
61
- enable_parser.set_defaults(func=lambda args: LfsEnableCommand(args))
62
-
63
- # Command will get called by git-lfs, do not call it directly.
64
- upload_parser = parser.add_parser(LFS_MULTIPART_UPLOAD_COMMAND, add_help=False)
65
- upload_parser.set_defaults(func=lambda args: LfsUploadCommand(args))
66
-
67
-
68
- class LfsEnableCommand:
69
- def __init__(self, args):
70
- self.args = args
71
-
72
- def run(self):
73
- local_path = os.path.abspath(self.args.path)
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")
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")
88
65
 
89
66
 
90
67
  def write_msg(msg: dict):
@@ -109,90 +86,90 @@ def read_msg() -> Optional[dict]:
109
86
  return msg
110
87
 
111
88
 
112
- class LfsUploadCommand:
113
- def __init__(self, args) -> None:
114
- self.args = args
115
-
116
- def run(self) -> None:
117
- # Immediately after invoking a custom transfer process, git-lfs
118
- # sends initiation data to the process over stdin.
119
- # This tells the process useful information about the configuration.
120
- init_msg = json.loads(sys.stdin.readline().strip())
121
- if not (init_msg.get("event") == "init" and init_msg.get("operation") == "upload"):
122
- write_msg({"error": {"code": 32, "message": "Wrong lfs init operation"}})
123
- sys.exit(1)
124
-
125
- # The transfer process should use the information it needs from the
126
- # initiation structure, and also perform any one-off setup tasks it
127
- # needs to do. It should then respond on stdout with a simple empty
128
- # confirmation structure, as follows:
129
- write_msg({})
130
-
131
- # After the initiation exchange, git-lfs will send any number of
132
- # transfer requests to the stdin of the transfer process, in a serial sequence.
133
- while True:
134
- msg = read_msg()
135
- if msg is None:
136
- # When all transfers have been processed, git-lfs will send
137
- # a terminate event to the stdin of the transfer process.
138
- # On receiving this message the transfer process should
139
- # clean up and terminate. No response is expected.
140
- sys.exit(0)
141
-
142
- oid = msg["oid"]
143
- filepath = msg["path"]
144
- completion_url = msg["action"]["href"]
145
- header = msg["action"]["header"]
146
- chunk_size = int(header.pop("chunk_size"))
147
- presigned_urls: list[str] = list(header.values())
148
-
149
- # Send a "started" progress event to allow other workers to start.
150
- # Otherwise they're delayed until first "progress" event is reported,
151
- # i.e. after the first 5GB by default (!)
152
- write_msg(
153
- {
154
- "event": "progress",
155
- "oid": oid,
156
- "bytesSoFar": 1,
157
- "bytesSinceLast": 0,
158
- }
159
- )
160
-
161
- parts = []
162
- with open(filepath, "rb") as file:
163
- for i, presigned_url in enumerate(presigned_urls):
164
- with SliceFileObj(
165
- file,
166
- seek_from=i * chunk_size,
167
- read_limit=chunk_size,
168
- ) as data:
169
- r = get_session().put(presigned_url, data=data)
170
- hf_raise_for_status(r)
171
- parts.append(
172
- {
173
- "etag": r.headers.get("etag"),
174
- "partNumber": i + 1,
175
- }
176
- )
177
- # In order to support progress reporting while data is uploading / downloading,
178
- # the transfer process should post messages to stdout
179
- write_msg(
180
- {
181
- "event": "progress",
182
- "oid": oid,
183
- "bytesSoFar": (i + 1) * chunk_size,
184
- "bytesSinceLast": chunk_size,
185
- }
186
- )
187
- # Not precise but that's ok.
188
-
189
- r = get_session().post(
190
- completion_url,
191
- json={
192
- "oid": oid,
193
- "parts": parts,
194
- },
195
- )
196
- hf_raise_for_status(r)
197
-
198
- write_msg({"event": "complete", "oid": oid})
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})