Build nvdiffrast from source at startup (fixes broken NVDR_CHECK_CPU in prebuilt Blackwell wheel); revert debug patch
Browse files
app.py
CHANGED
|
@@ -19,6 +19,14 @@ subprocess.run("pip install spandrel==0.4.1 --no-deps", shell=True, check=True)
|
|
| 19 |
# hides torch from diso's setup.py). FORCE_CUDA/TORCH_CUDA_ARCH_LIST are set
|
| 20 |
# as Space variables since no GPU is visible in this (non-@spaces.GPU) process.
|
| 21 |
subprocess.run("pip install diso==0.1.4 --no-build-isolation", shell=True, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 24 |
DTYPE = torch.float16
|
|
@@ -86,19 +94,6 @@ NUM_VIEWS = 6
|
|
| 86 |
from inference_ig2mv_sdxl import prepare_pipeline, preprocess_image, remove_bg
|
| 87 |
from mvadapter.utils import get_orthogonal_camera, tensor_to_image, make_image_grid
|
| 88 |
from mvadapter.utils.render import NVDiffRastContextWrapper, load_mesh, render
|
| 89 |
-
# nvdiffrast's rasterize() defaults `ranges` to an empty CPU tensor when None,
|
| 90 |
-
# but the Blackwell-built nvdiffrast 0.4.0 wheel's rasterize_fwd_cuda rejects
|
| 91 |
-
# whatever it actually receives on this path. Force an explicit CPU tensor at
|
| 92 |
-
# the wrapper boundary so the C++ device check always sees what it expects.
|
| 93 |
-
_orig_ctx_rasterize = NVDiffRastContextWrapper.rasterize
|
| 94 |
-
def _cpu_ranges_rasterize(self, pos, tri, resolution, ranges=None, grad_db=True):
|
| 95 |
-
if ranges is None:
|
| 96 |
-
ranges = torch.empty((0, 2), dtype=torch.int32, device=pos.device)
|
| 97 |
-
print(f"[rasterize debug] pos={pos.device},{pos.dtype},{tuple(pos.shape)} "
|
| 98 |
-
f"tri={tri.device},{tri.dtype},{tuple(tri.shape)} "
|
| 99 |
-
f"ranges={ranges.device},{ranges.dtype},{tuple(ranges.shape)}")
|
| 100 |
-
return _orig_ctx_rasterize(self, pos, tri, resolution, ranges=ranges, grad_db=grad_db)
|
| 101 |
-
NVDiffRastContextWrapper.rasterize = _cpu_ranges_rasterize
|
| 102 |
mv_adapter_pipe = prepare_pipeline(
|
| 103 |
base_model="stabilityai/stable-diffusion-xl-base-1.0",
|
| 104 |
vae_model="madebyollin/sdxl-vae-fp16-fix",
|
|
|
|
| 19 |
# hides torch from diso's setup.py). FORCE_CUDA/TORCH_CUDA_ARCH_LIST are set
|
| 20 |
# as Space variables since no GPU is visible in this (non-@spaces.GPU) process.
|
| 21 |
subprocess.run("pip install diso==0.1.4 --no-build-isolation", shell=True, check=True)
|
| 22 |
+
# The prebuilt Blackwell nvdiffrast 0.4.0 wheel has a broken NVDR_CHECK_CPU
|
| 23 |
+
# device check (rejects tensors regardless of actual device - ABI skew vs.
|
| 24 |
+
# the torch it's dynamically linked against). Build from source instead so
|
| 25 |
+
# it's compiled against the exact torch/ABI installed in this env.
|
| 26 |
+
subprocess.run(
|
| 27 |
+
"pip install git+https://github.com/NVlabs/nvdiffrast.git --no-build-isolation",
|
| 28 |
+
shell=True, check=True,
|
| 29 |
+
)
|
| 30 |
|
| 31 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 32 |
DTYPE = torch.float16
|
|
|
|
| 94 |
from inference_ig2mv_sdxl import prepare_pipeline, preprocess_image, remove_bg
|
| 95 |
from mvadapter.utils import get_orthogonal_camera, tensor_to_image, make_image_grid
|
| 96 |
from mvadapter.utils.render import NVDiffRastContextWrapper, load_mesh, render
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
mv_adapter_pipe = prepare_pipeline(
|
| 98 |
base_model="stabilityai/stable-diffusion-xl-base-1.0",
|
| 99 |
vae_model="madebyollin/sdxl-vae-fp16-fix",
|