Skip to content

Commit f1a7ed4

Browse files
authored
Suggest using upload_large_folder when appropriate (#2547)
1 parent 796eb5a commit f1a7ed4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
validate_hf_hub_args,
137137
)
138138
from .utils import tqdm as hf_tqdm
139+
from .utils._deprecation import _deprecate_method
139140
from .utils._typing import CallableT
140141
from .utils.endpoint_helpers import _is_emission_within_threshold
141142

@@ -4018,6 +4019,9 @@ def _payload_as_ndjson() -> Iterable[bytes]:
40184019

40194020
@experimental
40204021
@validate_hf_hub_args
4022+
@_deprecate_method(
4023+
version="0.27", message="This is an experimental feature. Please use `upload_large_folder` instead."
4024+
)
40214025
def create_commits_on_pr(
40224026
self,
40234027
*,
@@ -4856,8 +4860,10 @@ def upload_folder(
48564860
new files. This is useful if you don't know which files have already been uploaded.
48574861
Note: to avoid discrepancies the `.gitattributes` file is not deleted even if it matches the pattern.
48584862
multi_commits (`bool`):
4863+
Deprecated. For large uploads, use `upload_large_folder` instead.
48594864
If True, changes are pushed to a PR using a multi-commit process. Defaults to `False`.
48604865
multi_commits_verbose (`bool`):
4866+
Deprecated. For large uploads, use `upload_large_folder` instead.
48614867
If True and `multi_commits` is used, more information will be displayed to the user.
48624868
run_as_future (`bool`, *optional*):
48634869
Whether or not to run this method in the background. Background jobs are run sequentially without
@@ -9472,14 +9478,24 @@ def _prepare_upload_folder_additions(
94729478
repo_type=repo_type,
94739479
token=token,
94749480
)
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+
)
94759488

9476-
return [
9489+
logger.info(f"Start hashing {len(filtered_repo_objects)} files.")
9490+
operations = [
94779491
CommitOperationAdd(
94789492
path_or_fileobj=relpath_to_abspath[relpath], # absolute path on disk
94799493
path_in_repo=prefix + relpath, # "absolute" path in repo
94809494
)
94819495
for relpath in filtered_repo_objects
94829496
]
9497+
logger.info(f"Finished hashing {len(filtered_repo_objects)} files.")
9498+
return operations
94839499

94849500
def _validate_yaml(self, content: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None):
94859501
"""

0 commit comments

Comments
 (0)