Spaces:
Running on Zero
Running on Zero
[Admin maintenance] Fix for new ZeroGPU hardware (Blackwell sm_120)
#52
by multimodalart HF Staff - opened
- README.md +1 -1
- app.py +101 -3
- requirements.txt +0 -5
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🏢
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.34.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -1,16 +1,114 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from gradio_litmodel3d import LitModel3D
|
| 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 easydict import EasyDict as edict
|
| 13 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
| 15 |
from trellis.representations import Gaussian, MeshExtractResult
|
| 16 |
from trellis.utils import render_utils, postprocessing_utils
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ['SPCONV_ALGO'] = 'native'
|
| 3 |
+
os.environ['ATTN_BACKEND'] = 'xformers'
|
| 4 |
+
os.environ['SPARSE_ATTN'] = 'xformers'
|
| 5 |
+
|
| 6 |
+
import subprocess, sys, tempfile, ctypes
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
import gradio_litmodel3d # noqa: F401
|
| 10 |
+
except ImportError:
|
| 11 |
+
subprocess.check_call(
|
| 12 |
+
[sys.executable, "-m", "pip", "install", "--no-deps",
|
| 13 |
+
"gradio_litmodel3d==0.0.1"],
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
import spaces
|
| 17 |
+
|
| 18 |
+
CUDA_HOME = "/cuda-image/usr/local/cuda-13.0"
|
| 19 |
+
CUDA_LIBDIR = os.path.join(CUDA_HOME, "lib64")
|
| 20 |
+
REPO_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@spaces.GPU(duration=600)
|
| 24 |
+
def first_gpu_setup():
|
| 25 |
+
need_nvdiffrast = need_dgr = False
|
| 26 |
+
try:
|
| 27 |
+
import nvdiffrast # noqa: F401
|
| 28 |
+
except ImportError:
|
| 29 |
+
need_nvdiffrast = True
|
| 30 |
+
try:
|
| 31 |
+
import diff_gaussian_rasterization # noqa: F401
|
| 32 |
+
except ImportError:
|
| 33 |
+
need_dgr = True
|
| 34 |
+
if not (need_nvdiffrast or need_dgr):
|
| 35 |
+
print("CUDA extensions already installed; skipping build.")
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
if not os.path.exists(os.path.join(CUDA_HOME, "bin", "nvcc")):
|
| 39 |
+
raise RuntimeError(
|
| 40 |
+
f"nvcc not found at {CUDA_HOME}/bin/nvcc on the ZeroGPU worker. "
|
| 41 |
+
"The new-hardware CUDA path may have moved; please update CUDA_HOME."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
patch_dir = tempfile.mkdtemp(prefix="torch_cuda_patch_")
|
| 45 |
+
with open(os.path.join(patch_dir, "sitecustomize.py"), "w") as f:
|
| 46 |
+
f.write(
|
| 47 |
+
"try:\n"
|
| 48 |
+
" import torch.utils.cpp_extension as _c\n"
|
| 49 |
+
" _c._check_cuda_version = lambda *a, **k: None\n"
|
| 50 |
+
"except Exception:\n"
|
| 51 |
+
" pass\n"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
env = os.environ.copy()
|
| 55 |
+
env["CUDA_HOME"] = CUDA_HOME
|
| 56 |
+
env["CUDA_PATH"] = CUDA_HOME
|
| 57 |
+
env["PATH"] = os.path.join(CUDA_HOME, "bin") + os.pathsep + env.get("PATH", "")
|
| 58 |
+
env["PYTHONPATH"] = patch_dir + os.pathsep + env.get("PYTHONPATH", "")
|
| 59 |
+
env["TORCH_CUDA_ARCH_LIST"] = "12.0"
|
| 60 |
+
|
| 61 |
+
subprocess.check_call(
|
| 62 |
+
[sys.executable, "-m", "pip", "install", "--no-deps",
|
| 63 |
+
"setuptools", "wheel", "ninja"],
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if need_nvdiffrast:
|
| 67 |
+
subprocess.check_call(
|
| 68 |
+
[sys.executable, "-m", "pip", "install", "--no-build-isolation",
|
| 69 |
+
os.path.join(REPO_DIR, "extensions", "nvdiffrast")],
|
| 70 |
+
env=env,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if need_dgr:
|
| 74 |
+
mip_dir = tempfile.mkdtemp(prefix="mip_splatting_")
|
| 75 |
+
subprocess.check_call(
|
| 76 |
+
["git", "clone", "--recursive", "--depth=1",
|
| 77 |
+
"https://github.com/autonomousvision/mip-splatting.git", mip_dir],
|
| 78 |
+
)
|
| 79 |
+
subprocess.check_call(
|
| 80 |
+
[sys.executable, "-m", "pip", "install", "--no-build-isolation",
|
| 81 |
+
os.path.join(mip_dir, "submodules", "diff-gaussian-rasterization")],
|
| 82 |
+
env=env,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
first_gpu_setup()
|
| 87 |
+
|
| 88 |
+
ctypes.CDLL(os.path.join(CUDA_LIBDIR, "libcudart.so.13"), mode=ctypes.RTLD_GLOBAL)
|
| 89 |
+
os.environ["LD_LIBRARY_PATH"] = CUDA_LIBDIR + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "")
|
| 90 |
+
|
| 91 |
+
import gradio as gr
|
| 92 |
from gradio_litmodel3d import LitModel3D
|
| 93 |
|
|
|
|
| 94 |
import shutil
|
|
|
|
| 95 |
from typing import *
|
| 96 |
import torch
|
| 97 |
import numpy as np
|
| 98 |
import imageio
|
| 99 |
from easydict import EasyDict as edict
|
| 100 |
from PIL import Image
|
| 101 |
+
|
| 102 |
+
# xformers on Blackwell (sm_120) picks Flash-Attn-3 (Hopper-only) and crashes
|
| 103 |
+
# with "invalid argument". Force it to use Cutlass kernels instead.
|
| 104 |
+
import xformers.ops as _xops
|
| 105 |
+
_orig_mea = _xops.memory_efficient_attention
|
| 106 |
+
_cutlass_op = (_xops.fmha.cutlass.FwOp, _xops.fmha.cutlass.BwOp)
|
| 107 |
+
def _mea_cutlass(*args, **kwargs):
|
| 108 |
+
kwargs.setdefault("op", _cutlass_op)
|
| 109 |
+
return _orig_mea(*args, **kwargs)
|
| 110 |
+
_xops.memory_efficient_attention = _mea_cutlass
|
| 111 |
+
|
| 112 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
| 113 |
from trellis.representations import Gaussian, MeshExtractResult
|
| 114 |
from trellis.utils import render_utils, postprocessing_utils
|
requirements.txt
CHANGED
|
@@ -18,8 +18,3 @@ git+https://github.com/EasternJournalist/utils3d.git@9a4eb15e4021b67b12c460c7057
|
|
| 18 |
xformers
|
| 19 |
spconv-cu120==2.3.6
|
| 20 |
transformers==4.46.3
|
| 21 |
-
gradio_litmodel3d==0.0.1
|
| 22 |
-
pydantic==2.10.6
|
| 23 |
-
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
|
| 24 |
-
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl?download=true
|
| 25 |
-
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/nvdiffrast-0.3.3-cp310-cp310-linux_x86_64.whl?download=true
|
|
|
|
| 18 |
xformers
|
| 19 |
spconv-cu120==2.3.6
|
| 20 |
transformers==4.46.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|