Daankular commited on
Commit
0030bd6
·
1 Parent(s): 8e4c4f3

Reduce startup GPU quota burn: skip CUDA pkg compile if already importable

Browse files

_install_cuda_packages now checks if nvdiffrast/diso/detectron2 are
importable before requesting a GPU. If packages survived the restart in
site-packages, skips the 120s GPU allocation entirely. Also reduces
@spaces.GPU duration from 300s to 120s (actual compile time is ~60-90s).

Each Space restart was burning 300s of ZeroGPU quota on recompilation
even when packages were already installed.

Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -144,9 +144,21 @@ from PIL import Image
144
  # Compile nvdiffrast / detectron2 / diso here, on first GPU allocation at startup.
145
  _CUDA_PKG_MARKER = Path("/tmp/.cuda_pkgs_installed")
146
 
147
- @spaces.GPU(duration=300)
 
 
 
 
 
 
 
 
 
 
148
  def _install_cuda_packages():
149
- if _CUDA_PKG_MARKER.exists():
 
 
150
  return
151
  print("[startup] Installing CUDA packages (nvdiffrast, detectron2, diso)...")
152
  import shutil as _shutil
 
144
  # Compile nvdiffrast / detectron2 / diso here, on first GPU allocation at startup.
145
  _CUDA_PKG_MARKER = Path("/tmp/.cuda_pkgs_installed")
146
 
147
+ def _cuda_pkgs_already_installed() -> bool:
148
+ """Return True if CUDA packages are importable (persisted in site-packages across restart)."""
149
+ try:
150
+ import nvdiffrast.torch # noqa: F401
151
+ import diso # noqa: F401
152
+ import detectron2 # noqa: F401
153
+ return True
154
+ except ImportError:
155
+ return False
156
+
157
+ @spaces.GPU(duration=120)
158
  def _install_cuda_packages():
159
+ if _CUDA_PKG_MARKER.exists() or _cuda_pkgs_already_installed():
160
+ print("[startup] CUDA packages already installed — skipping compilation.")
161
+ _CUDA_PKG_MARKER.touch()
162
  return
163
  print("[startup] Installing CUDA packages (nvdiffrast, detectron2, diso)...")
164
  import shutil as _shutil