harp-dev commited on
Commit
25da1db
·
verified ·
1 Parent(s): 85f0b0f

Download files beside their final path, then move them into place

Browse files

A download cut short left a partial file at the path whose existence skips the download, so every later start used it. See Model Weights in HARP's deployment guide.

Files changed (1) hide show
  1. backend_worker.py +4 -1
backend_worker.py CHANGED
@@ -69,7 +69,10 @@ def _ensure_model(model_name):
69
  out = os.path.join(dest, fname)
70
  if not os.path.exists(out):
71
  url = f"https://storage.googleapis.com/{_GCS_BUCKET}/{urllib.parse.quote(obj, safe='')}"
72
- urllib.request.urlretrieve(url, out)
 
 
 
73
  if not os.path.exists(gin_file):
74
  raise RuntimeError(f"Downloaded {model_name!r} but operative_config-0.gin is missing.")
75
  return dest
 
69
  out = os.path.join(dest, fname)
70
  if not os.path.exists(out):
71
  url = f"https://storage.googleapis.com/{_GCS_BUCKET}/{urllib.parse.quote(obj, safe='')}"
72
+ # Fetched beside its final path and moved there once complete, so that a download
73
+ # cut short cannot leave a file the check above would take for the checkpoint
74
+ urllib.request.urlretrieve(url, out + ".part")
75
+ os.replace(out + ".part", out)
76
  if not os.path.exists(gin_file):
77
  raise RuntimeError(f"Downloaded {model_name!r} but operative_config-0.gin is missing.")
78
  return dest