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

ZeroGPU: compile CUDA packages at runtime startup (no nvcc in build container)

Browse files
Files changed (3) hide show
  1. app.py +26 -0
  2. packages.txt +0 -1
  3. requirements.txt +3 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import sys
2
  import os
 
3
  import tempfile
4
  import shutil
5
  import traceback
@@ -7,6 +8,31 @@ import json
7
  import random
8
  from pathlib import Path
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  import cv2
11
  import gradio as gr
12
  import spaces
 
1
  import sys
2
  import os
3
+ import subprocess
4
  import tempfile
5
  import shutil
6
  import traceback
 
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
37
  import gradio as gr
38
  import spaces
packages.txt CHANGED
@@ -8,4 +8,3 @@ cmake
8
  ninja-build
9
  build-essential
10
  pkg-config
11
- nvidia-cuda-toolkit
 
8
  ninja-build
9
  build-essential
10
  pkg-config
 
requirements.txt CHANGED
@@ -8,9 +8,9 @@ clip @ git+https://github.com/openai/CLIP.git@d05afc436d78f1c48dc0dbf8e5980a9d47
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 @ git+https://github.com/NVlabs/nvdiffrast.git@253ac4fcea7de5f396371124af597e6cc957bfae
12
- diso @ git+https://github.com/SarahWeiii/diso.git@9792ad928ccb09bdec938779651ee03e395758a6
13
- detectron2 @ git+https://github.com/facebookresearch/detectron2.git@8a9d885b3d4dcf1bef015f0593b872ed8d32b4ab
14
 
15
  # Core ML
16
  accelerate
 
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