[Admin maintenance] Support new ZeroGPU hardware

#1
by multimodalart HF Staff - opened
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +63 -4
  3. requirements.txt +7 -10
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 👁
4
  colorFrom: blue
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 5.23.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: blue
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -1,13 +1,75 @@
 
1
  import os
2
  import random
3
  import shutil
4
  import subprocess
 
 
5
  from typing import List
6
 
7
  import gradio as gr
8
  import numpy as np
9
  import spaces
10
  import torch
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  from huggingface_hub import hf_hub_download, snapshot_download
12
  from PIL import Image
13
  from torchvision import transforms
@@ -16,10 +78,6 @@ from transformers import AutoModelForImageSegmentation
16
  from inference_tg2mv_sdxl import prepare_pipeline, run_pipeline
17
  from mvadapter.utils import get_orthogonal_camera, make_image_grid, tensor_to_image
18
 
19
- # install others
20
- subprocess.run("pip install spandrel==0.4.1 --no-deps", shell=True, check=True)
21
-
22
-
23
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
24
  DTYPE = torch.float16
25
  MAX_SEED = np.iinfo(np.int32).max
@@ -145,6 +203,7 @@ def run_texturing(
145
  req: gr.Request,
146
  ):
147
  save_dir = os.path.join(TMP_DIR, str(req.session_hash))
 
148
  mv_image_path = os.path.join(save_dir, f"mv_adapter_{get_random_hex()}.png")
149
  mv_images = [item[0] for item in mv_images]
150
  make_image_grid(mv_images, rows=1).save(mv_image_path)
 
1
+ import ctypes
2
  import os
3
  import random
4
  import shutil
5
  import subprocess
6
+ import sys
7
+ import tempfile
8
  from typing import List
9
 
10
  import gradio as gr
11
  import numpy as np
12
  import spaces
13
  import torch
14
+
15
+ # install others
16
+ subprocess.run("pip install spandrel==0.4.1 --no-deps", shell=True, check=True)
17
+
18
+ CUDA_HOME = "/cuda-image/usr/local/cuda-13.0"
19
+ CUDA_LIBDIR = os.path.join(CUDA_HOME, "lib64")
20
+
21
+
22
+ @spaces.GPU(duration=600)
23
+ def _first_gpu_setup():
24
+ """Build nvdiffrast from source against the active torch (2.10) ABI.
25
+
26
+ The previously-bundled cu12/torch2.4 wheel doesn't load on the new
27
+ Blackwell ZeroGPU stack (sm_120 / CUDA 13). We rebuild it inside a
28
+ @spaces.GPU context so CUDA is available, and use a sitecustomize
29
+ shim to silence torch's CUDA version mismatch check (the toolkit
30
+ is 13.0 but torch was built against 12.8 — they're ABI-compatible
31
+ for our purposes here).
32
+ """
33
+ try:
34
+ import nvdiffrast # noqa: F401
35
+ return
36
+ except ImportError:
37
+ pass
38
+
39
+ patch_dir = tempfile.mkdtemp(prefix="torch_cuda_patch_")
40
+ with open(os.path.join(patch_dir, "sitecustomize.py"), "w") as f:
41
+ f.write(
42
+ "try:\n"
43
+ " import torch.utils.cpp_extension as _c\n"
44
+ " _c._check_cuda_version = lambda *a, **k: None\n"
45
+ "except Exception:\n"
46
+ " pass\n"
47
+ )
48
+
49
+ env = os.environ.copy()
50
+ env["CUDA_HOME"] = CUDA_HOME
51
+ env["CUDA_PATH"] = CUDA_HOME
52
+ env["PATH"] = os.path.join(CUDA_HOME, "bin") + os.pathsep + env.get("PATH", "")
53
+ env["PYTHONPATH"] = patch_dir + os.pathsep + env.get("PYTHONPATH", "")
54
+ env["TORCH_CUDA_ARCH_LIST"] = "12.0" # Blackwell sm_120
55
+
56
+ subprocess.check_call(
57
+ [sys.executable, "-m", "pip", "install",
58
+ "--no-build-isolation", "--no-deps",
59
+ "git+https://github.com/NVlabs/nvdiffrast/"],
60
+ env=env,
61
+ )
62
+
63
+
64
+ _first_gpu_setup()
65
+ # Make sure the CUDA 13 runtime is preloaded and discoverable before any
66
+ # extension import that links libcudart at runtime.
67
+ try:
68
+ ctypes.CDLL(os.path.join(CUDA_LIBDIR, "libcudart.so.13"), mode=ctypes.RTLD_GLOBAL)
69
+ except OSError:
70
+ pass
71
+ os.environ["LD_LIBRARY_PATH"] = CUDA_LIBDIR + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "")
72
+
73
  from huggingface_hub import hf_hub_download, snapshot_download
74
  from PIL import Image
75
  from torchvision import transforms
 
78
  from inference_tg2mv_sdxl import prepare_pipeline, run_pipeline
79
  from mvadapter.utils import get_orthogonal_camera, make_image_grid, tensor_to_image
80
 
 
 
 
 
81
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
82
  DTYPE = torch.float16
83
  MAX_SEED = np.iinfo(np.int32).max
 
203
  req: gr.Request,
204
  ):
205
  save_dir = os.path.join(TMP_DIR, str(req.session_hash))
206
+ os.makedirs(save_dir, exist_ok=True)
207
  mv_image_path = os.path.join(save_dir, f"mv_adapter_{get_random_hex()}.png")
208
  mv_images = [item[0] for item in mv_images]
209
  make_image_grid(mv_images, rows=1).save(mv_image_path)
requirements.txt CHANGED
@@ -1,17 +1,14 @@
1
- --extra-index-url https://download.pytorch.org/whl/cu124
2
- --find-links https://data.pyg.org/whl/torch-2.5.1+cu124.html
3
-
4
- torch==2.5.1
5
- torchvision==0.20.1
6
- diffusers
7
- transformers==4.49.0
8
  einops
9
  huggingface_hub
10
  opencv-python
11
  trimesh==4.5.3
12
  omegaconf
13
  scikit-image
14
- numpy
15
  peft
16
  scipy==1.11.4
17
  jaxtyping
@@ -21,7 +18,7 @@ open3d
21
  timm
22
  kornia
23
  ninja
24
- https://huggingface.co/spaces/VAST-AI/MV-Adapter-Img2Texture/resolve/main/wheels/nvdiffrast-0.3.3-cp310-cp310-linux_x86_64.whl?download=true
25
  cvcuda_cu12
26
  gltflib
27
- torch-cluster
 
 
1
+ torch==2.10.0
2
+ torchvision==0.25.0
3
+ diffusers==0.31.0
4
+ transformers==4.46.3
 
 
 
5
  einops
6
  huggingface_hub
7
  opencv-python
8
  trimesh==4.5.3
9
  omegaconf
10
  scikit-image
11
+ numpy==1.26.2
12
  peft
13
  scipy==1.11.4
14
  jaxtyping
 
18
  timm
19
  kornia
20
  ninja
 
21
  cvcuda_cu12
22
  gltflib
23
+ accelerate
24
+ safetensors