[Admin maintenance] Support new ZeroGPU hardware

#4
by multimodalart HF Staff - opened
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🔮
4
  colorFrom: purple
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 5.23.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: purple
5
  colorTo: yellow
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
@@ -21,9 +83,6 @@ from inference_ig2mv_sdxl import (
21
  )
22
  from mvadapter.utils import get_orthogonal_camera, make_image_grid, tensor_to_image
23
 
24
- # install others
25
- subprocess.run("pip install spandrel==0.4.1 --no-deps", shell=True, check=True)
26
-
27
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
28
  DTYPE = torch.float16
29
  MAX_SEED = np.iinfo(np.int32).max
 
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
 
83
  )
84
  from mvadapter.utils import get_orthogonal_camera, make_image_grid, tensor_to_image
85
 
 
 
 
86
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
87
  DTYPE = torch.float16
88
  MAX_SEED = np.iinfo(np.int32).max
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
@@ -23,5 +20,5 @@ kornia
23
  ninja
24
  cvcuda_cu12
25
  gltflib
26
- torch-cluster
27
- https://huggingface.co/spaces/VAST-AI/MV-Adapter-Img2Texture/resolve/main/wheels/nvdiffrast-0.3.3-cp310-cp310-linux_x86_64.whl?download=true
 
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
 
20
  ninja
21
  cvcuda_cu12
22
  gltflib
23
+ accelerate
24
+ safetensors
wheel DELETED
File without changes
wheels/nvdiffrast-0.3.3-cp310-cp310-linux_x86_64.whl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:026b3031cc647d279b5beb0a3ec2bfe992666d85f66431662d8f26be2b6894f9
3
- size 1047624