AdithyaSK HF Staff commited on
Commit
ec7f10b
·
verified ·
1 Parent(s): d992b32

Serve Crello corpus aafdb0e86816 from the mounted bucket

Browse files
Files changed (3) hide show
  1. core/corpus.py +1 -1
  2. scripts/deploy_space.py +13 -7
  3. server/router.py +2 -2
core/corpus.py CHANGED
@@ -138,7 +138,7 @@ class BucketSource:
138
 
139
  def fetch(self, path: str, dest: Path) -> Path:
140
  dest.parent.mkdir(parents=True, exist_ok=True)
141
- tmp = dest.with_suffix(dest.suffix + ".part")
142
  with self.open(path) as src, open(tmp, "wb") as out:
143
  shutil.copyfileobj(src, out, 1 << 22)
144
  tmp.replace(dest)
 
138
 
139
  def fetch(self, path: str, dest: Path) -> Path:
140
  dest.parent.mkdir(parents=True, exist_ok=True)
141
+ tmp = dest.with_suffix(dest.suffix + f".{os.getpid()}.part") # workers may fetch the same file at once
142
  with self.open(path) as src, open(tmp, "wb") as out:
143
  shutil.copyfileobj(src, out, 1 << 22)
144
  tmp.replace(dest)
scripts/deploy_space.py CHANGED
@@ -1,11 +1,11 @@
1
  """Publish the environment as a Hugging Face Space that serves the full corpus.
2
 
3
- The Space image holds code and the corpus manifest only. The Crello bucket is
4
- attached read-only at /corpus; the catalog is copied from it at startup and
5
- each design's pixels are read from the mount the first time an episode uses it.
6
 
7
  python scripts/deploy_space.py --space FineEnvs/design-canvas \\
8
- --manifest corpus-manifest.json
9
 
10
  Refuses to deploy unless the manifest's catalog is published in the bucket
11
  with the exact size recorded in the manifest.
@@ -36,6 +36,9 @@ def main(argv=None) -> int:
36
  ap.add_argument("--max-envs", type=int, default=32, help="concurrent environment sessions per worker")
37
  ap.add_argument("--workers", type=int, default=4, help="server processes behind the Space's one URL")
38
  ap.add_argument("--reward", default="3", help="DESIGN_CANVAS_REWARD (3 = reward v3, as the evals use)")
 
 
 
39
  args = ap.parse_args(argv)
40
 
41
  manifest = json.loads(Path(args.manifest).read_text())
@@ -63,18 +66,21 @@ def main(argv=None) -> int:
63
  "from the mounted bucket")
64
  runtime = api.space_info(args.space).runtime
65
  volumes = [v for v in (runtime.volumes or []) if v.mount_path != "/corpus"] if runtime else []
66
- volumes.append(Volume(type="bucket", source=bucket, mount_path="/corpus", read_only=True))
 
67
  api.set_space_volumes(args.space, volumes=volumes)
68
  current = api.get_space_variables(args.space)
 
 
69
  for key, value in {"MAX_CONCURRENT_ENVS": str(args.max_envs),
70
  "DESIGN_CANVAS_WORKERS": str(args.workers),
71
  "DESIGN_CANVAS_REWARD": args.reward,
72
- "DESIGN_CANVAS_SOURCE_ROOT": "/corpus",
73
  "DESIGN_CANVAS_PUBLIC_URL": f"https://{args.space.replace('/', '-').lower()}.hf.space"}.items():
74
  if key not in current or current[key].value != value:
75
  api.add_space_variable(args.space, key, value)
76
  print(json.dumps({"space": args.space, "commit": commit.oid, "snapshot_id": manifest["snapshot_id"],
77
- "bucket": bucket, "mount": "/corpus (read-only)",
78
  "url": f"https://huggingface.co/spaces/{args.space}"}, indent=2))
79
  return 0
80
 
 
1
  """Publish the environment as a Hugging Face Space that serves the full corpus.
2
 
3
+ The Space image holds code and the corpus manifest only. The catalog is copied from the bucket at startup, and
4
+ each design's pixels are read from it the first time an episode uses it: over HTTP by default, or with
5
+ --transport mount from the bucket attached read-only at /corpus.
6
 
7
  python scripts/deploy_space.py --space FineEnvs/design-canvas \\
8
+ --manifest corpus-manifest.json --private
9
 
10
  Refuses to deploy unless the manifest's catalog is published in the bucket
11
  with the exact size recorded in the manifest.
 
36
  ap.add_argument("--max-envs", type=int, default=32, help="concurrent environment sessions per worker")
37
  ap.add_argument("--workers", type=int, default=4, help="server processes behind the Space's one URL")
38
  ap.add_argument("--reward", default="3", help="DESIGN_CANVAS_REWARD (3 = reward v3, as the evals use)")
39
+ ap.add_argument("--transport", choices=["http", "mount"], default="http",
40
+ help="read designs over HTTP (default) or from the bucket mounted at /corpus; the mount returned "
41
+ "I/O errors under the workers' random reads (2026-10-05)")
42
  args = ap.parse_args(argv)
43
 
44
  manifest = json.loads(Path(args.manifest).read_text())
 
66
  "from the mounted bucket")
67
  runtime = api.space_info(args.space).runtime
68
  volumes = [v for v in (runtime.volumes or []) if v.mount_path != "/corpus"] if runtime else []
69
+ if args.transport == "mount":
70
+ volumes.append(Volume(type="bucket", source=bucket, mount_path="/corpus", read_only=True))
71
  api.set_space_volumes(args.space, volumes=volumes)
72
  current = api.get_space_variables(args.space)
73
+ if args.transport == "http" and "DESIGN_CANVAS_SOURCE_ROOT" in current:
74
+ api.delete_space_variable(args.space, "DESIGN_CANVAS_SOURCE_ROOT")
75
  for key, value in {"MAX_CONCURRENT_ENVS": str(args.max_envs),
76
  "DESIGN_CANVAS_WORKERS": str(args.workers),
77
  "DESIGN_CANVAS_REWARD": args.reward,
78
+ **({"DESIGN_CANVAS_SOURCE_ROOT": "/corpus"} if args.transport == "mount" else {}),
79
  "DESIGN_CANVAS_PUBLIC_URL": f"https://{args.space.replace('/', '-').lower()}.hf.space"}.items():
80
  if key not in current or current[key].value != value:
81
  api.add_space_variable(args.space, key, value)
82
  print(json.dumps({"space": args.space, "commit": commit.oid, "snapshot_id": manifest["snapshot_id"],
83
+ "bucket": bucket, "transport": args.transport,
84
  "url": f"https://huggingface.co/spaces/{args.space}"}, indent=2))
85
  return 0
86
 
server/router.py CHANGED
@@ -166,7 +166,7 @@ class Router:
166
  except WebSocketDisconnect:
167
  pass
168
  finally:
169
- await up.close()
170
 
171
  async def up_to_down():
172
  try:
@@ -182,7 +182,7 @@ class Router:
182
  finally:
183
  try:
184
  await ws.close(code=up.close_code or 1000)
185
- except RuntimeError:
186
  pass
187
 
188
  await asyncio.gather(down_to_up(), up_to_down())
 
166
  except WebSocketDisconnect:
167
  pass
168
  finally:
169
+ await up.close() # also ends up_to_down when the client goes
170
 
171
  async def up_to_down():
172
  try:
 
182
  finally:
183
  try:
184
  await ws.close(code=up.close_code or 1000)
185
+ except (RuntimeError, WebSocketDisconnect): # the client left first
186
  pass
187
 
188
  await asyncio.gather(down_to_up(), up_to_down())