fix(zerogpu): lazy-import nvdiffrast in postprocessing_utils
Browse files`import nvdiffrast.torch as dr` at module top level triggered CUDA init
in the main process via the import chain:
app.py
→ trellis.pipelines.NeARImageToRelightable3DPipeline
→ trellis.utils.render_utils_rl
→ trellis.utils.postprocessing_utils
→ import nvdiffrast.torch as dr ← CUDA init here
This caused ZeroGPU's stateless-GPU enforcement to fire even before any
@spaces.GPU callback ran, blocking every GPU callback silently.
Fix: remove top-level import; add `import nvdiffrast.torch as dr` lazily
inside the `mode == 'opt'` branch where it is actually used.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
trellis/utils/postprocessing_utils.py
CHANGED
|
@@ -2,7 +2,6 @@ from typing import *
|
|
| 2 |
import numpy as np
|
| 3 |
import torch
|
| 4 |
import utils3d
|
| 5 |
-
import nvdiffrast.torch as dr
|
| 6 |
from tqdm import tqdm
|
| 7 |
import trimesh
|
| 8 |
import trimesh.visual
|
|
@@ -346,6 +345,7 @@ def bake_texture(
|
|
| 346 |
texture = cv2.inpaint(texture, mask, 3, cv2.INPAINT_TELEA)
|
| 347 |
|
| 348 |
elif mode == 'opt':
|
|
|
|
| 349 |
rastctx = utils3d.torch.RastContext(backend='cuda')
|
| 350 |
observations = [observations.flip(0) for observations in observations]
|
| 351 |
masks = [m.flip(0) for m in masks]
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import torch
|
| 4 |
import utils3d
|
|
|
|
| 5 |
from tqdm import tqdm
|
| 6 |
import trimesh
|
| 7 |
import trimesh.visual
|
|
|
|
| 345 |
texture = cv2.inpaint(texture, mask, 3, cv2.INPAINT_TELEA)
|
| 346 |
|
| 347 |
elif mode == 'opt':
|
| 348 |
+
import nvdiffrast.torch as dr # lazy: needs active CUDA context
|
| 349 |
rastctx = utils3d.torch.RastContext(backend='cuda')
|
| 350 |
observations = [observations.flip(0) for observations in observations]
|
| 351 |
masks = [m.flip(0) for m in masks]
|