Cion-lab commited on
Commit
2efe81e
·
verified ·
1 Parent(s): 595a4b1

Upload build/publish_mix.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. build/publish_mix.py +34 -14
build/publish_mix.py CHANGED
@@ -244,6 +244,7 @@ def main():
244
  print(f" (no resumable listing: {type(e).__name__}; uploading everything)", flush=True)
245
 
246
  failures = []
 
247
  for np, lp in to_upload:
248
  with open(lp, "rb") as fh:
249
  payload = fh.read()
@@ -251,20 +252,39 @@ def main():
251
  if remote_sha.get(np) == local_sha:
252
  print(f" = {np} already on the Hub with this sha256, skipped", flush=True)
253
  continue
254
- for attempt in (1, 2, 3):
255
- try:
256
- api.upload_file(path_or_fileobj=payload, path_in_repo=np, repo_id=a.repo,
257
- repo_type="dataset", commit_message=f"add {np} ({local_sha[:12]})")
258
- print(f" + {np} ({len(payload) / 1024**2:.1f} MB)", flush=True)
259
- break
260
- except Exception as e:
261
- # One dropped upload must not discard 129 completed ones. Retry, then record and move on,
262
- # so the final verification below can name every file that is still missing.
263
- print(f" ! {np} attempt {attempt}: {type(e).__name__}: {str(e)[:140]}", flush=True)
264
- if attempt == 3:
265
- failures.append(np)
266
- else:
267
- __import__("time").sleep(5 * attempt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  if failures:
269
  print(f"FATAL: {len(failures)} file(s) never landed: {failures[:8]} -- re-running publish_mix "
270
  "resumes from the ones that did", flush=True)
 
244
  print(f" (no resumable listing: {type(e).__name__}; uploading everything)", flush=True)
245
 
246
  failures = []
247
+ todo = []
248
  for np, lp in to_upload:
249
  with open(lp, "rb") as fh:
250
  payload = fh.read()
 
252
  if remote_sha.get(np) == local_sha:
253
  print(f" = {np} already on the Hub with this sha256, skipped", flush=True)
254
  continue
255
+ todo.append((np, lp, local_sha, payload))
256
+ print(f" {len(todo)} of {len(to_upload)} files still need uploading", flush=True)
257
+
258
+ # ONE commit for the whole batch, not one commit per file. Gate 2f proved why: 139 sequential
259
+ # `upload_file` commits succeeded and then the Hub began rejecting every request -- including 30-byte
260
+ # files -- with a bare HfHubHTTPError, which is a commit-rate limit, not a network fault. A single
261
+ # upload_folder call is one commit and handles LFS itself.
262
+ if todo:
263
+ try:
264
+ api.upload_folder(repo_id=a.repo, repo_type="dataset", folder_path=a.root, path_in_repo="",
265
+ allow_patterns=[t[0] for t in todo], max_workers=2,
266
+ commit_message=f"publish mix-v1: {len(todo)} file(s)",
267
+ commit_description="single batched commit; see audit.json for the "
268
+ "contamination verdict bound to these bytes")
269
+ print(f" + batched commit with {len(todo)} file(s)", flush=True)
270
+ except Exception as e:
271
+ print(f" batched commit failed ({type(e).__name__}: {str(e)[:160]}); "
272
+ "falling back to per-file uploads with retries", flush=True)
273
+ for np, lp, local_sha, payload in todo:
274
+ for attempt in (1, 2, 3):
275
+ try:
276
+ api.upload_file(path_or_fileobj=payload, path_in_repo=np, repo_id=a.repo,
277
+ repo_type="dataset",
278
+ commit_message=f"add {np} ({local_sha[:12]})")
279
+ print(f" + {np} ({len(payload) / 1024**2:.1f} MB)", flush=True)
280
+ break
281
+ except Exception as e2:
282
+ print(f" ! {np} attempt {attempt}: {type(e2).__name__}: {str(e2)[:140]}",
283
+ flush=True)
284
+ if attempt == 3:
285
+ failures.append(np)
286
+ else:
287
+ __import__("time").sleep(20 * attempt)
288
  if failures:
289
  print(f"FATAL: {len(failures)} file(s) never landed: {failures[:8]} -- re-running publish_mix "
290
  "resumes from the ones that did", flush=True)