Skip to content

Commit f0523e1

Browse files
committed
feat: prefer upload_large_folder when many files
1 parent f4c7bab commit f0523e1

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

kernels/src/kernels/cli/upload.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,33 @@ def upload_kernels_dir(
7070
allow_patterns=["benchmark*.py"],
7171
)
7272

73-
api.upload_folder(
74-
repo_id=repo_id,
75-
folder_path=build_dir,
76-
revision=branch,
77-
path_in_repo="build",
78-
delete_patterns=list(delete_patterns),
79-
commit_message="Build uploaded using `kernels`.",
80-
allow_patterns=["torch*"],
73+
file_count = sum(
74+
1
75+
for p in build_dir.rglob("*")
76+
if p.is_file() and p.relative_to(build_dir).as_posix().startswith("torch")
8177
)
78+
79+
if file_count > 200:
80+
print(
81+
f"⚠️ Found {file_count} files to upload, which exceeds the 200 file limit for a single commit. Deleting old build files and re-uploading the whole build folder to avoid hitting file limits."
82+
)
83+
kernel_root_dir = build_dir.parent
84+
api.upload_large_folder(
85+
repo_id=repo_id,
86+
folder_path=kernel_root_dir,
87+
revision=branch,
88+
repo_type="model",
89+
allow_patterns=["build/torch*"],
90+
)
91+
else:
92+
api.upload_folder(
93+
repo_id=repo_id,
94+
folder_path=build_dir,
95+
revision=branch,
96+
path_in_repo="build",
97+
delete_patterns=list(delete_patterns),
98+
commit_message="Build uploaded using `kernels`.",
99+
allow_patterns=["torch*"],
100+
)
101+
82102
print(f"✅ Kernel upload successful. Find the kernel in: https://hf.co/{repo_id}")

0 commit comments

Comments
 (0)