Daankular commited on
Commit
18deb9a
Β·
1 Parent(s): 738fd2b

Move hmr2/skel/chumpy to runtime --no-build-isolation; document all ZeroGPU constraints

Browse files
Files changed (2) hide show
  1. app.py +42 -13
  2. requirements.txt +7 -7
app.py CHANGED
@@ -8,29 +8,58 @@ import json
8
  import random
9
  from pathlib import Path
10
 
11
- # ── ZeroGPU: compile CUDA extensions on first startup ─────────────────────────
12
- # nvdiffrast, diso, and detectron2 require nvcc to compile their CUDA kernels.
13
- # HuggingFace ZeroGPU build containers have no GPU/nvcc; only the runtime
14
- # containers do. We install these once on startup and cache via a marker file.
15
- _CUDA_PKG_MARKER = Path("/tmp/.cuda_pkgs_installed")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  _CUDA_PACKAGES = [
17
  "nvdiffrast @ git+https://github.com/NVlabs/nvdiffrast.git@253ac4fcea7de5f396371124af597e6cc957bfae",
18
  "diso @ git+https://github.com/SarahWeiii/diso.git@9792ad928ccb09bdec938779651ee03e395758a6",
19
  "detectron2 @ git+https://github.com/facebookresearch/detectron2.git@8a9d885b3d4dcf1bef015f0593b872ed8d32b4ab",
20
  ]
21
 
22
- def _install_cuda_packages():
23
- if _CUDA_PKG_MARKER.exists():
24
  return
25
- print("[startup] Installing CUDA-compiled packages (first run, may take a few minutes)...")
 
 
 
 
 
26
  subprocess.run(
27
- [sys.executable, "-m", "pip", "install", "--quiet"] + _CUDA_PACKAGES,
28
- check=True
 
29
  )
30
- _CUDA_PKG_MARKER.touch()
31
- print("[startup] CUDA packages installed.")
32
 
33
- _install_cuda_packages()
34
  # ──────────────────────────────────────────────────────────────────────────────
35
 
36
  import cv2
 
8
  import random
9
  from pathlib import Path
10
 
11
+ # ── ZeroGPU: install packages that can't be built at Docker build time ─────────
12
+ #
13
+ # Two categories of packages must be installed at runtime, not at build time:
14
+ #
15
+ # 1. CUDA-compiled extensions (nvdiffrast, diso, detectron2):
16
+ # These require nvcc (NVIDIA CUDA compiler). The ZeroGPU Docker build stage
17
+ # has no GPU/nvcc; only the runtime containers do.
18
+ #
19
+ # 2. Packages with broken build isolation (hmr2, skel β†’ chumpy):
20
+ # hmr2 and skel declare `chumpy @ git+https://...` as a direct-reference dep.
21
+ # chumpy's setup.py does `from pip._internal.req import parse_requirements`,
22
+ # which fails when pip>=21 creates an isolated build environment (pip is not
23
+ # importable there). Fix: --no-build-isolation skips isolated environments,
24
+ # making pip importable. This flag can only be passed via subprocess, not
25
+ # requirements.txt.
26
+ #
27
+ # Packages are installed once on first startup and cached via a marker file.
28
+ # ──────────────────────────────────────────────────────────────────────────────
29
+ _RUNTIME_PKG_MARKER = Path("/tmp/.runtime_pkgs_installed")
30
+
31
+ # Packages requiring --no-build-isolation (chumpy transitive dep chain)
32
+ _NO_ISOLATION_PACKAGES = [
33
+ "chumpy @ git+https://github.com/mattloper/chumpy.git@580566eafc9ac68b2614b64d6f7aaa84eebb70da",
34
+ "hmr2 @ git+https://github.com/shubham-goel/4D-Humans.git@efe18deff163b29dff87ddbd575fa29b716a356c",
35
+ "skel @ git+https://github.com/MarilynKeller/SKEL.git@c32cf16581295bff19399379efe5b776d707cd95",
36
+ ]
37
+
38
+ # Packages requiring nvcc (compiled at runtime when GPU container is available)
39
  _CUDA_PACKAGES = [
40
  "nvdiffrast @ git+https://github.com/NVlabs/nvdiffrast.git@253ac4fcea7de5f396371124af597e6cc957bfae",
41
  "diso @ git+https://github.com/SarahWeiii/diso.git@9792ad928ccb09bdec938779651ee03e395758a6",
42
  "detectron2 @ git+https://github.com/facebookresearch/detectron2.git@8a9d885b3d4dcf1bef015f0593b872ed8d32b4ab",
43
  ]
44
 
45
+ def _install_runtime_packages():
46
+ if _RUNTIME_PKG_MARKER.exists():
47
  return
48
+ print("[startup] Installing runtime packages (first run, ~5-10 min)...")
49
+ subprocess.run(
50
+ [sys.executable, "-m", "pip", "install", "--quiet", "--no-build-isolation"]
51
+ + _NO_ISOLATION_PACKAGES,
52
+ check=True,
53
+ )
54
  subprocess.run(
55
+ [sys.executable, "-m", "pip", "install", "--quiet"]
56
+ + _CUDA_PACKAGES,
57
+ check=True,
58
  )
59
+ _RUNTIME_PKG_MARKER.touch()
60
+ print("[startup] Runtime packages installed.")
61
 
62
+ _install_runtime_packages()
63
  # ──────────────────────────────────────────────────────────────────────────────
64
 
65
  import cv2
requirements.txt CHANGED
@@ -1,16 +1,16 @@
1
  # HuggingFace ZeroGPU Space β€” Gradio SDK
2
- # chumpy vendored locally with patched setup.py (original does `import pip` which breaks isolated builds)
3
  spaces
4
 
5
  # Git-pinned installs
6
- hmr2 @ git+https://github.com/shubham-goel/4D-Humans.git@efe18deff163b29dff87ddbd575fa29b716a356c
 
 
 
 
 
 
7
  clip @ git+https://github.com/openai/CLIP.git@d05afc436d78f1c48dc0dbf8e5980a9d471f35f6
8
  mvadapter @ git+https://github.com/huanngzh/MV-Adapter.git@4277e0018232bac82bb2c103caf0893cedb711be
9
- chumpy @ https://huggingface.co/datasets/Daankular/wheels/resolve/main/chumpy-0.71-py3-none-any.whl
10
- skel @ git+https://github.com/MarilynKeller/SKEL.git@c32cf16581295bff19399379efe5b776d707cd95
11
- # nvdiffrast, diso, detectron2 require nvcc (CUDA compiler) which is only available
12
- # in the ZeroGPU runtime container, not the Docker build container.
13
- # These are compiled and installed on first startup β€” see app.py _install_cuda_packages().
14
 
15
  # Core ML
16
  accelerate
 
1
  # HuggingFace ZeroGPU Space β€” Gradio SDK
 
2
  spaces
3
 
4
  # Git-pinned installs
5
+ # NOTE: hmr2, chumpy, skel, nvdiffrast, diso, detectron2 are installed at runtime
6
+ # in app.py because:
7
+ # - hmr2/skel declare `chumpy @ git+https://...` as a direct-ref dep; chumpy's
8
+ # setup.py does `from pip._internal.req import parse_requirements` which fails
9
+ # in pip>=21 isolated builds. Fix: --no-build-isolation at runtime.
10
+ # - nvdiffrast/diso/detectron2 require nvcc (NVIDIA CUDA compiler) which is only
11
+ # available in the ZeroGPU runtime container, not the Docker build stage.
12
  clip @ git+https://github.com/openai/CLIP.git@d05afc436d78f1c48dc0dbf8e5980a9d471f35f6
13
  mvadapter @ git+https://github.com/huanngzh/MV-Adapter.git@4277e0018232bac82bb2c103caf0893cedb711be
 
 
 
 
 
14
 
15
  # Core ML
16
  accelerate