Spaces:
Configuration error
Configuration error
[Admin maintenance] Support new ZeroGPU hardware
#13
by multimodalart HF Staff - opened
- app.py +87 -5
- requirements.txt +8 -16
app.py
CHANGED
|
@@ -1,15 +1,97 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import spaces
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
-
import os
|
| 6 |
import shutil
|
| 7 |
-
os.environ['SPCONV_ALGO'] = 'native'
|
| 8 |
from typing import *
|
| 9 |
-
import torch
|
| 10 |
import numpy as np
|
| 11 |
import imageio
|
| 12 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
| 14 |
from trellis.utils import render_utils
|
| 15 |
import trimesh
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
# Force attention backends compatible with the new ZeroGPU (Blackwell) stack.
|
| 3 |
+
# Must be set BEFORE any trellis import.
|
| 4 |
+
os.environ.setdefault('ATTN_BACKEND', 'xformers')
|
| 5 |
+
os.environ.setdefault('SPARSE_ATTN_BACKEND', 'xformers')
|
| 6 |
+
os.environ.setdefault('SPCONV_ALGO', 'native')
|
| 7 |
+
|
| 8 |
+
import sys
|
| 9 |
+
import subprocess
|
| 10 |
+
import tempfile
|
| 11 |
+
import ctypes
|
| 12 |
+
|
| 13 |
import spaces
|
| 14 |
+
import torch
|
| 15 |
+
import gradio as gr
|
| 16 |
|
|
|
|
| 17 |
import shutil
|
|
|
|
| 18 |
from typing import *
|
|
|
|
| 19 |
import numpy as np
|
| 20 |
import imageio
|
| 21 |
from PIL import Image
|
| 22 |
+
|
| 23 |
+
# Build nvdiffrast and diff_gaussian_rasterization from source on first GPU call.
|
| 24 |
+
CUDA_HOME = "/cuda-image/usr/local/cuda-13.0"
|
| 25 |
+
CUDA_LIBDIR = os.path.join(CUDA_HOME, "lib64")
|
| 26 |
+
_NVDIFFRAST_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "extensions", "nvdiffrast")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@spaces.GPU(duration=600)
|
| 30 |
+
def _first_gpu_setup():
|
| 31 |
+
need = {}
|
| 32 |
+
for name, modname in [
|
| 33 |
+
("nvdiffrast", "nvdiffrast"),
|
| 34 |
+
("diff_gaussian_rasterization", "diff_gaussian_rasterization"),
|
| 35 |
+
]:
|
| 36 |
+
try:
|
| 37 |
+
__import__(modname)
|
| 38 |
+
except ImportError:
|
| 39 |
+
need[name] = True
|
| 40 |
+
if not need:
|
| 41 |
+
return
|
| 42 |
+
|
| 43 |
+
patch_dir = tempfile.mkdtemp(prefix="torch_cuda_patch_")
|
| 44 |
+
with open(os.path.join(patch_dir, "sitecustomize.py"), "w") as f:
|
| 45 |
+
f.write(
|
| 46 |
+
"try:\n"
|
| 47 |
+
" import torch.utils.cpp_extension as _c\n"
|
| 48 |
+
" _c._check_cuda_version = lambda *a, **k: None\n"
|
| 49 |
+
"except Exception:\n"
|
| 50 |
+
" pass\n"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
env = os.environ.copy()
|
| 54 |
+
env["CUDA_HOME"] = CUDA_HOME
|
| 55 |
+
env["CUDA_PATH"] = CUDA_HOME
|
| 56 |
+
env["PATH"] = os.path.join(CUDA_HOME, "bin") + os.pathsep + env.get("PATH", "")
|
| 57 |
+
env["PYTHONPATH"] = patch_dir + os.pathsep + env.get("PYTHONPATH", "")
|
| 58 |
+
env["TORCH_CUDA_ARCH_LIST"] = "12.0" # Blackwell sm_120
|
| 59 |
+
|
| 60 |
+
subprocess.check_call(
|
| 61 |
+
[sys.executable, "-m", "pip", "install", "--no-deps",
|
| 62 |
+
"setuptools", "wheel", "ninja", "packaging"],
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
if "nvdiffrast" in need:
|
| 66 |
+
subprocess.check_call(
|
| 67 |
+
[sys.executable, "-m", "pip", "install",
|
| 68 |
+
"--no-build-isolation", "--no-deps",
|
| 69 |
+
_NVDIFFRAST_DIR],
|
| 70 |
+
env=env,
|
| 71 |
+
)
|
| 72 |
+
if "diff_gaussian_rasterization" in need:
|
| 73 |
+
# Hi3DGen actually uses the mip-splatting submodule fork; not the
|
| 74 |
+
# original graphdeco-inria release on PyPI.
|
| 75 |
+
mip = tempfile.mkdtemp(prefix="mip_")
|
| 76 |
+
subprocess.check_call(
|
| 77 |
+
["git", "clone", "--recursive", "--depth=1",
|
| 78 |
+
"https://github.com/autonomousvision/mip-splatting.git", mip],
|
| 79 |
+
)
|
| 80 |
+
subprocess.check_call(
|
| 81 |
+
[sys.executable, "-m", "pip", "install",
|
| 82 |
+
"--no-build-isolation", "--no-deps",
|
| 83 |
+
os.path.join(mip, "submodules", "diff-gaussian-rasterization")],
|
| 84 |
+
env=env,
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
_first_gpu_setup()
|
| 89 |
+
try:
|
| 90 |
+
ctypes.CDLL(os.path.join(CUDA_LIBDIR, "libcudart.so.13"), mode=ctypes.RTLD_GLOBAL)
|
| 91 |
+
os.environ["LD_LIBRARY_PATH"] = CUDA_LIBDIR + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "")
|
| 92 |
+
except OSError:
|
| 93 |
+
pass
|
| 94 |
+
|
| 95 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
| 96 |
from trellis.utils import render_utils
|
| 97 |
import trimesh
|
requirements.txt
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
-
-
|
| 2 |
-
huggingface-hub==0.36.0
|
| 3 |
diffusers==0.35.0
|
| 4 |
accelerate==1.2.1
|
| 5 |
kornia==0.8.0
|
| 6 |
-
timm
|
| 7 |
-
torch==2.
|
| 8 |
-
torchvision==0.
|
| 9 |
pillow==10.4.0
|
| 10 |
imageio==2.36.1
|
| 11 |
imageio-ffmpeg==0.5.1
|
|
@@ -21,15 +20,8 @@ pyvista==0.44.2
|
|
| 21 |
pymeshfix==0.17.0
|
| 22 |
igraph==0.11.8
|
| 23 |
git+https://github.com/EasternJournalist/utils3d.git@9a4eb15e4021b67b12c460c7057d642626897ec8
|
| 24 |
-
xformers
|
| 25 |
-
spconv-
|
| 26 |
transformers==4.46.3
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
nvidia-cudnn-cu12==9.1.0.70
|
| 30 |
-
nvidia-nccl-cu12==2.20.5
|
| 31 |
-
tokenizers==0.20.3
|
| 32 |
-
spaces==0.42.1
|
| 33 |
-
https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.0.post2/flash_attn-2.7.0.post2+cu12torch2.4cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
|
| 34 |
-
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl?download=true
|
| 35 |
-
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/nvdiffrast-0.3.3-cp310-cp310-linux_x86_64.whl?download=true
|
|
|
|
| 1 |
+
huggingface-hub
|
|
|
|
| 2 |
diffusers==0.35.0
|
| 3 |
accelerate==1.2.1
|
| 4 |
kornia==0.8.0
|
| 5 |
+
timm
|
| 6 |
+
torch==2.11.0
|
| 7 |
+
torchvision==0.26.0
|
| 8 |
pillow==10.4.0
|
| 9 |
imageio==2.36.1
|
| 10 |
imageio-ffmpeg==0.5.1
|
|
|
|
| 20 |
pymeshfix==0.17.0
|
| 21 |
igraph==0.11.8
|
| 22 |
git+https://github.com/EasternJournalist/utils3d.git@9a4eb15e4021b67b12c460c7057d642626897ec8
|
| 23 |
+
xformers
|
| 24 |
+
spconv-cu126==2.3.8
|
| 25 |
transformers==4.46.3
|
| 26 |
+
einops
|
| 27 |
+
spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|