multimodalart HF Staff commited on
Commit
d10570e
·
verified ·
1 Parent(s): ef13f4e

[Admin maintenance] Support new ZeroGPU hardware

Browse files
Files changed (1) hide show
  1. app.py +47 -5
app.py CHANGED
@@ -13,15 +13,57 @@ from einops import rearrange, repeat
13
  from tqdm import tqdm
14
  from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler
15
 
16
- import subprocess, sys
 
 
 
17
 
18
  @spaces.GPU(duration=210)
19
  def first_gpu_setup():
20
- subprocess.check_call([
21
- sys.executable, "-m", "pip", "install", "--no-build-isolation",
22
- "git+https://github.com/NVlabs/nvdiffrast/",
23
- ])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  first_gpu_setup()
 
 
 
 
25
  from src.utils.train_util import instantiate_from_config
26
  from src.utils.camera_util import (
27
  FOV_to_intrinsics,
 
13
  from tqdm import tqdm
14
  from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler
15
 
16
+ import subprocess, sys, glob, tempfile, ctypes
17
+
18
+ CUDA_HOME = "/cuda-image/usr/local/cuda-13.0"
19
+ CUDA_LIBDIR = os.path.join(CUDA_HOME, "lib64")
20
 
21
  @spaces.GPU(duration=210)
22
  def first_gpu_setup():
23
+ try:
24
+ import nvdiffrast # noqa: F401
25
+ print("nvdiffrast already installed; skipping build.")
26
+ return
27
+ except ImportError:
28
+ pass
29
+
30
+ if not os.path.exists(os.path.join(CUDA_HOME, "bin", "nvcc")):
31
+ raise RuntimeError(
32
+ f"nvcc not found at {CUDA_HOME}/bin/nvcc on the ZeroGPU worker. "
33
+ "The new-hardware CUDA path may have moved; please update CUDA_HOME."
34
+ )
35
+
36
+ patch_dir = tempfile.mkdtemp(prefix="torch_cuda_patch_")
37
+ with open(os.path.join(patch_dir, "sitecustomize.py"), "w") as f:
38
+ f.write(
39
+ "try:\n"
40
+ " import torch.utils.cpp_extension as _c\n"
41
+ " _c._check_cuda_version = lambda *a, **k: None\n"
42
+ "except Exception:\n"
43
+ " pass\n"
44
+ )
45
+
46
+ env = os.environ.copy()
47
+ env["CUDA_HOME"] = CUDA_HOME
48
+ env["CUDA_PATH"] = CUDA_HOME
49
+ env["PATH"] = os.path.join(CUDA_HOME, "bin") + os.pathsep + env.get("PATH", "")
50
+ env["PYTHONPATH"] = patch_dir + os.pathsep + env.get("PYTHONPATH", "")
51
+ env["TORCH_CUDA_ARCH_LIST"] = "12.0"
52
+
53
+ subprocess.check_call(
54
+ [sys.executable, "-m", "pip", "install", "--no-deps",
55
+ "setuptools", "wheel", "ninja"],
56
+ )
57
+ subprocess.check_call(
58
+ [sys.executable, "-m", "pip", "install", "--no-build-isolation",
59
+ "git+https://github.com/NVlabs/nvdiffrast/"],
60
+ env=env,
61
+ )
62
  first_gpu_setup()
63
+
64
+ ctypes.CDLL(os.path.join(CUDA_LIBDIR, "libcudart.so.13"), mode=ctypes.RTLD_GLOBAL)
65
+ os.environ["LD_LIBRARY_PATH"] = CUDA_LIBDIR + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "")
66
+
67
  from src.utils.train_util import instantiate_from_config
68
  from src.utils.camera_util import (
69
  FOV_to_intrinsics,