huggingface-hub 0.25.0rc0__py3-none-any.whl → 0.25.1__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.

@@ -46,7 +46,7 @@ import sys
46
46
  from typing import TYPE_CHECKING
47
47
 
48
48
 
49
- __version__ = "0.25.0.rc0"
49
+ __version__ = "0.25.1"
50
50
 
51
51
  # Alphabetical order of definitions is ensured in tests
52
52
  # WARNING: any comment added in this dictionary definition will be lost when
@@ -41,6 +41,8 @@ if TYPE_CHECKING:
41
41
  logger = logging.getLogger(__name__)
42
42
 
43
43
  WAITING_TIME_IF_NO_TASKS = 10 # seconds
44
+ MAX_NB_REGULAR_FILES_PER_COMMIT = 75
45
+ MAX_NB_LFS_FILES_PER_COMMIT = 150
44
46
 
45
47
 
46
48
  def upload_large_folder_internal(
@@ -373,17 +375,18 @@ def _determine_next_job(status: LargeUploadStatus) -> Optional[Tuple[WorkerJob,
373
375
  if (
374
376
  status.nb_workers_commit == 0
375
377
  and status.queue_commit.qsize() > 0
376
- and (status.last_commit_attempt is None or time.time() - status.last_commit_attempt > 5 * 60)
378
+ and status.last_commit_attempt is not None
379
+ and time.time() - status.last_commit_attempt > 5 * 60
377
380
  ):
378
381
  status.nb_workers_commit += 1
379
382
  logger.debug("Job: commit (more than 5 minutes since last commit attempt)")
380
- return (WorkerJob.COMMIT, _get_n(status.queue_commit, 25))
383
+ return (WorkerJob.COMMIT, _get_items_to_commit(status.queue_commit))
381
384
 
382
- # 2. Commit if at least 25 files are ready to commit
383
- elif status.nb_workers_commit == 0 and status.queue_commit.qsize() >= 25:
385
+ # 2. Commit if at least 100 files are ready to commit
386
+ elif status.nb_workers_commit == 0 and status.queue_commit.qsize() >= 150:
384
387
  status.nb_workers_commit += 1
385
- logger.debug("Job: commit (>25 files ready)")
386
- return (WorkerJob.COMMIT, _get_n(status.queue_commit, 25))
388
+ logger.debug("Job: commit (>100 files ready)")
389
+ return (WorkerJob.COMMIT, _get_items_to_commit(status.queue_commit))
387
390
 
388
391
  # 3. Get upload mode if at least 10 files
389
392
  elif status.queue_get_upload_mode.qsize() >= 10:
@@ -430,18 +433,39 @@ def _determine_next_job(status: LargeUploadStatus) -> Optional[Tuple[WorkerJob,
430
433
  logger.debug("Job: get upload mode")
431
434
  return (WorkerJob.GET_UPLOAD_MODE, _get_n(status.queue_get_upload_mode, 50))
432
435
 
433
- # 10. Commit if at least 1 file
434
- elif status.nb_workers_commit == 0 and status.queue_commit.qsize() > 0:
436
+ # 10. Commit if at least 1 file and 1 min since last commit attempt
437
+ elif (
438
+ status.nb_workers_commit == 0
439
+ and status.queue_commit.qsize() > 0
440
+ and status.last_commit_attempt is not None
441
+ and time.time() - status.last_commit_attempt > 1 * 60
442
+ ):
443
+ status.nb_workers_commit += 1
444
+ logger.debug("Job: commit (1 min since last commit attempt)")
445
+ return (WorkerJob.COMMIT, _get_items_to_commit(status.queue_commit))
446
+
447
+ # 11. Commit if at least 1 file all other queues are empty and all workers are waiting
448
+ # e.g. when it's the last commit
449
+ elif (
450
+ status.nb_workers_commit == 0
451
+ and status.queue_commit.qsize() > 0
452
+ and status.queue_sha256.qsize() == 0
453
+ and status.queue_get_upload_mode.qsize() == 0
454
+ and status.queue_preupload_lfs.qsize() == 0
455
+ and status.nb_workers_sha256 == 0
456
+ and status.nb_workers_get_upload_mode == 0
457
+ and status.nb_workers_preupload_lfs == 0
458
+ ):
435
459
  status.nb_workers_commit += 1
436
460
  logger.debug("Job: commit")
437
- return (WorkerJob.COMMIT, _get_n(status.queue_commit, 25))
461
+ return (WorkerJob.COMMIT, _get_items_to_commit(status.queue_commit))
438
462
 
439
- # 11. If all queues are empty, exit
463
+ # 12. If all queues are empty, exit
440
464
  elif all(metadata.is_committed or metadata.should_ignore for _, metadata in status.items):
441
465
  logger.info("All files have been processed! Exiting worker.")
442
466
  return None
443
467
 
444
- # 12. If no task is available, wait
468
+ # 13. If no task is available, wait
445
469
  else:
446
470
  status.nb_workers_waiting += 1
447
471
  logger.debug(f"No task available, waiting... ({WAITING_TIME_IF_NO_TASKS}s)")
@@ -547,6 +571,30 @@ def _get_n(queue: "queue.Queue[JOB_ITEM_T]", n: int) -> List[JOB_ITEM_T]:
547
571
  return [queue.get() for _ in range(min(queue.qsize(), n))]
548
572
 
549
573
 
574
+ def _get_items_to_commit(queue: "queue.Queue[JOB_ITEM_T]") -> List[JOB_ITEM_T]:
575
+ """Special case for commit job: the number of items to commit depends on the type of files."""
576
+ # Can take at most 50 regular files and/or 100 LFS files in a single commit
577
+ items: List[JOB_ITEM_T] = []
578
+ nb_lfs, nb_regular = 0, 0
579
+ while True:
580
+ # If empty queue => commit everything
581
+ if queue.qsize() == 0:
582
+ return items
583
+
584
+ # If we have enough items => commit them
585
+ if nb_lfs >= MAX_NB_LFS_FILES_PER_COMMIT or nb_regular >= MAX_NB_REGULAR_FILES_PER_COMMIT:
586
+ return items
587
+
588
+ # Else, get a new item and increase counter
589
+ item = queue.get()
590
+ items.append(item)
591
+ _, metadata = item
592
+ if metadata.upload_mode == "lfs":
593
+ nb_lfs += 1
594
+ else:
595
+ nb_regular += 1
596
+
597
+
550
598
  def _print_overwrite(report: str) -> None:
551
599
  """Print a report, overwriting the previous lines.
552
600
 
huggingface_hub/hf_api.py CHANGED
@@ -136,6 +136,7 @@ from .utils import (
136
136
  validate_hf_hub_args,
137
137
  )
138
138
  from .utils import tqdm as hf_tqdm
139
+ from .utils._deprecation import _deprecate_method
139
140
  from .utils._typing import CallableT
140
141
  from .utils.endpoint_helpers import _is_emission_within_threshold
141
142
 
@@ -1405,6 +1406,10 @@ class User:
1405
1406
  Number of upvotes received by the user.
1406
1407
  num_likes (`int`, *optional*):
1407
1408
  Number of likes given by the user.
1409
+ num_following (`int`, *optional*):
1410
+ Number of users this user is following.
1411
+ num_followers (`int`, *optional*):
1412
+ Number of users following this user.
1408
1413
  orgs (list of [`Organization`]):
1409
1414
  List of organizations the user is part of.
1410
1415
  """
@@ -1423,6 +1428,8 @@ class User:
1423
1428
  num_papers: Optional[int] = None
1424
1429
  num_upvotes: Optional[int] = None
1425
1430
  num_likes: Optional[int] = None
1431
+ num_following: Optional[int] = None
1432
+ num_followers: Optional[int] = None
1426
1433
  orgs: List[Organization] = field(default_factory=list)
1427
1434
 
1428
1435
  def __init__(self, **kwargs) -> None:
@@ -1439,6 +1446,8 @@ class User:
1439
1446
  self.num_papers = kwargs.pop("numPapers", None)
1440
1447
  self.num_upvotes = kwargs.pop("numUpvotes", None)
1441
1448
  self.num_likes = kwargs.pop("numLikes", None)
1449
+ self.num_following = kwargs.pop("numFollowing", None)
1450
+ self.num_followers = kwargs.pop("numFollowers", None)
1442
1451
  self.user_type = kwargs.pop("type", None)
1443
1452
  self.orgs = [Organization(**org) for org in kwargs.pop("orgs", [])]
1444
1453
 
@@ -4010,6 +4019,9 @@ class HfApi:
4010
4019
 
4011
4020
  @experimental
4012
4021
  @validate_hf_hub_args
4022
+ @_deprecate_method(
4023
+ version="0.27", message="This is an experimental feature. Please use `upload_large_folder` instead."
4024
+ )
4013
4025
  def create_commits_on_pr(
4014
4026
  self,
4015
4027
  *,
@@ -4848,8 +4860,10 @@ class HfApi:
4848
4860
  new files. This is useful if you don't know which files have already been uploaded.
4849
4861
  Note: to avoid discrepancies the `.gitattributes` file is not deleted even if it matches the pattern.
4850
4862
  multi_commits (`bool`):
4863
+ Deprecated. For large uploads, use `upload_large_folder` instead.
4851
4864
  If True, changes are pushed to a PR using a multi-commit process. Defaults to `False`.
4852
4865
  multi_commits_verbose (`bool`):
4866
+ Deprecated. For large uploads, use `upload_large_folder` instead.
4853
4867
  If True and `multi_commits` is used, more information will be displayed to the user.
4854
4868
  run_as_future (`bool`, *optional*):
4855
4869
  Whether or not to run this method in the background. Background jobs are run sequentially without
@@ -5342,7 +5356,7 @@ class HfApi:
5342
5356
 
5343
5357
  Order of priority:
5344
5358
  1. Commit if more than 5 minutes since last commit attempt (and at least 1 file).
5345
- 2. Commit if at least 25 files are ready to commit.
5359
+ 2. Commit if at least 150 files are ready to commit.
5346
5360
  3. Get upload mode if at least 10 files have been hashed.
5347
5361
  4. Pre-upload LFS file if at least 1 file and no worker is pre-uploading.
5348
5362
  5. Hash file if at least 1 file and no worker is hashing.
@@ -5350,7 +5364,8 @@ class HfApi:
5350
5364
  7. Pre-upload LFS file if at least 1 file (exception: if hf_transfer is enabled, only 1 worker can preupload LFS at a time).
5351
5365
  8. Hash file if at least 1 file to hash.
5352
5366
  9. Get upload mode if at least 1 file to get upload mode.
5353
- 10. Commit if at least 1 file to commit.
5367
+ 10. Commit if at least 1 file to commit and at least 1 min since last commit attempt.
5368
+ 11. Commit if at least 1 file to commit and all other queues are empty.
5354
5369
 
5355
5370
  Special rules:
5356
5371
  - If `hf_transfer` is enabled, only 1 LFS uploader at a time. Otherwise the CPU would be bloated by `hf_transfer`.
@@ -9463,14 +9478,24 @@ class HfApi:
9463
9478
  repo_type=repo_type,
9464
9479
  token=token,
9465
9480
  )
9481
+ if len(filtered_repo_objects) > 30:
9482
+ logger.info(
9483
+ "It seems you are trying to upload a large folder at once. This might take some time and then fail if "
9484
+ "the folder is too large. For such cases, it is recommended to upload in smaller batches or to use "
9485
+ "`HfApi().upload_large_folder(...)`/`huggingface-cli upload-large-folder` instead. For more details, "
9486
+ "check out https://huggingface.co/docs/huggingface_hub/main/en/guides/upload#upload-a-large-folder."
9487
+ )
9466
9488
 
9467
- return [
9489
+ logger.info(f"Start hashing {len(filtered_repo_objects)} files.")
9490
+ operations = [
9468
9491
  CommitOperationAdd(
9469
9492
  path_or_fileobj=relpath_to_abspath[relpath], # absolute path on disk
9470
9493
  path_in_repo=prefix + relpath, # "absolute" path in repo
9471
9494
  )
9472
9495
  for relpath in filtered_repo_objects
9473
9496
  ]
9497
+ logger.info(f"Finished hashing {len(filtered_repo_objects)} files.")
9498
+ return operations
9474
9499
 
9475
9500
  def _validate_yaml(self, content: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None):
9476
9501
  """
@@ -350,6 +350,12 @@ def _format_chat_completion_stream_output(
350
350
  # Decode payload
351
351
  payload = byte_payload.decode("utf-8")
352
352
  json_payload = json.loads(payload.lstrip("data:").rstrip("/n"))
353
+
354
+ # Either an error as being returned
355
+ if json_payload.get("error") is not None:
356
+ raise _parse_text_generation_error(json_payload["error"], json_payload.get("error_type"))
357
+
358
+ # Or parse token payload
353
359
  return ChatCompletionStreamOutput.parse_obj_as_instance(json_payload)
354
360
 
355
361
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: huggingface-hub
3
- Version: 0.25.0rc0
3
+ Version: 0.25.1
4
4
  Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
5
5
  Home-page: https://github.com/huggingface/huggingface_hub
6
6
  Author: Hugging Face, Inc.
@@ -1,4 +1,4 @@
1
- huggingface_hub/__init__.py,sha256=1dpvMU4PdU3S6Ws08T8VSpQtendIQlV8XFHg55-I_d8,34577
1
+ huggingface_hub/__init__.py,sha256=Kq9gwfu4AHiwoP27um_dC8uc3CQGF5ldzdw6R8yMbc4,34573
2
2
  huggingface_hub/_commit_api.py,sha256=Y9eTaW4bYzxtrZsSniVtfeAuFafqx8x1ofMI5es8hvM,31057
3
3
  huggingface_hub/_commit_scheduler.py,sha256=nlJS_vnLb8i92NLrRwJX8Mg9QZ7f3kfLbLlQuEd5YjU,13647
4
4
  huggingface_hub/_inference_endpoints.py,sha256=wzjD8P68VpUDHzIDbXzFXsM2Y-aNVSAap7BXsZFuthk,16750
@@ -8,7 +8,7 @@ huggingface_hub/_multi_commits.py,sha256=mFmCP_5hNsruEgDF6kOVyaFkpnbSdNxPWfGUlFb
8
8
  huggingface_hub/_snapshot_download.py,sha256=Dbm7aPH8xrKJGE6A7aSw6YG3HgMT-VacL2s18Ut9NYA,14321
9
9
  huggingface_hub/_space_api.py,sha256=QVOUNty2T4RxPoxf9FzUjXmjHiGXP0mqXJzqQ7GmoJo,5363
10
10
  huggingface_hub/_tensorboard_logger.py,sha256=F-2l3BsHVEar8PSFhPOwprMsvkwprPgpkOTWqeMMobM,8299
11
- huggingface_hub/_upload_large_folder.py,sha256=_HhfBp40qXbVBR_NCctdVt_PIqzLhAFaKwPU22Y0Ei0,21534
11
+ huggingface_hub/_upload_large_folder.py,sha256=hrm29zJXnWpxBgfJ-pmqaDwWl5WNYiYuQkKaGwXu-BA,23475
12
12
  huggingface_hub/_webhooks_payload.py,sha256=Xm3KaK7tCOGBlXkuZvbym6zjHXrT1XCrbUFWuXiBmNY,3617
13
13
  huggingface_hub/_webhooks_server.py,sha256=oCvpFrYjrhJjClAMw26SQfvN4DUItgK2IhFp1OVh2bU,15623
14
14
  huggingface_hub/community.py,sha256=4MtcoxEI9_0lmmilBEnvUEi8_O1Ivfa8p6eKxYU5-ts,12198
@@ -16,7 +16,7 @@ huggingface_hub/constants.py,sha256=BG3n2gl4JbxMw_JRvNTFyMcNnZIPzvT3KXSH-jm2J08,
16
16
  huggingface_hub/errors.py,sha256=kENdHLaBExWdu_dFJumYz7FFgLiROI4qgSvt03fJRec,9261
17
17
  huggingface_hub/fastai_utils.py,sha256=o0BnmigoNP3H7Sf8w8bwuRaN-9FKlL6uoPawr4HSyjc,16647
18
18
  huggingface_hub/file_download.py,sha256=LYbLa0OKoSeis7d3j6mB2V-IJqAkV18wYwqRSl-VTKs,85412
19
- huggingface_hub/hf_api.py,sha256=zeSuER_7gpe4qdxbKMTJbB0s9drQ-ut10WFmrDWVnTQ,432101
19
+ huggingface_hub/hf_api.py,sha256=wwxfPs9a6IHZB6DOnK0hHIMcV_NQJEAM_HbFDGcxCog,433714
20
20
  huggingface_hub/hf_file_system.py,sha256=-TfO8cnfsQTxwzd-K6vjrbGkziNrAyiSHDHu_ss1U-I,39148
21
21
  huggingface_hub/hub_mixin.py,sha256=ZeCxje9e42-pm78dVhUDoQZQchXH3i1svy5CzOL3l7o,37554
22
22
  huggingface_hub/inference_api.py,sha256=b4-NhPSn9b44nYKV8tDKXodmE4JVdEymMWL4CVGkzlE,8323
@@ -41,7 +41,7 @@ huggingface_hub/commands/user.py,sha256=QApZJOCQEHADhjunM3hlQ72uqHsearCiCE4SdpzG
41
41
  huggingface_hub/commands/version.py,sha256=vfCJn7GO1m-DtDmbdsty8_RTVtnZ7lX6MJsx0Bf4e-s,1266
42
42
  huggingface_hub/inference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
43
  huggingface_hub/inference/_client.py,sha256=yZ8YPWiZk0PEhNIfRsUKuoJij3QKYFqIO3jnJZa8Sho,126997
44
- huggingface_hub/inference/_common.py,sha256=8JNanqi7rQnFryT_11MFX9siRg-dEDlLtLwPHE6p_Rw,14906
44
+ huggingface_hub/inference/_common.py,sha256=B-CpkIn3sBh9J2tW9rcwy1hk1Cq45pHbg4E3HZcpF6I,15121
45
45
  huggingface_hub/inference/_templating.py,sha256=xWPzz_TyQpGOZyVP_ev-gSo92swSRVK8whPAG3bbQpM,3976
46
46
  huggingface_hub/inference/_generated/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  huggingface_hub/inference/_generated/_async_client.py,sha256=_pfb8C0NV-3-ixB5bblL9-XPgjqh7ECXry7A_InEw6c,133489
@@ -109,9 +109,9 @@ huggingface_hub/utils/insecure_hashlib.py,sha256=OjxlvtSQHpbLp9PWSrXBDJ0wHjxCBU-
109
109
  huggingface_hub/utils/logging.py,sha256=Cp03s0uEl3kDM9XHQW9a8GAoExODQ-e7kEtgMt-_To8,4728
110
110
  huggingface_hub/utils/sha.py,sha256=OFnNGCba0sNcT2gUwaVCJnldxlltrHHe0DS_PCpV3C4,2134
111
111
  huggingface_hub/utils/tqdm.py,sha256=jQiVYwRG78HK4_54u0vTtz6Kt9IMGiHy3ixbIn3h2TU,9368
112
- huggingface_hub-0.25.0rc0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
113
- huggingface_hub-0.25.0rc0.dist-info/METADATA,sha256=9drz2hRWlG4ta39dHHvxKI-zi8GoBvQpM0WVK0IUBpg,13057
114
- huggingface_hub-0.25.0rc0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
115
- huggingface_hub-0.25.0rc0.dist-info/entry_points.txt,sha256=Y3Z2L02rBG7va_iE6RPXolIgwOdwUFONyRN3kXMxZ0g,131
116
- huggingface_hub-0.25.0rc0.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
117
- huggingface_hub-0.25.0rc0.dist-info/RECORD,,
112
+ huggingface_hub-0.25.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
113
+ huggingface_hub-0.25.1.dist-info/METADATA,sha256=8bSs5SXnQb--QB4tNxinaqV5niWSTVRQZgJMqn-mdkE,13054
114
+ huggingface_hub-0.25.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
115
+ huggingface_hub-0.25.1.dist-info/entry_points.txt,sha256=Y3Z2L02rBG7va_iE6RPXolIgwOdwUFONyRN3kXMxZ0g,131
116
+ huggingface_hub-0.25.1.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
117
+ huggingface_hub-0.25.1.dist-info/RECORD,,