multimodalart HF Staff commited on
Commit
ef7ba95
·
verified ·
1 Parent(s): 7dfaaee

In-process COLMAP (thread-capped); CUDA-driver diagnostics

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -22,7 +22,6 @@ sys.path.insert(0, str(APP_DIR))
22
  # pycolmap's bundled OpenBLAS segfaults ("Bad memory unallocation") when many matcher
23
  # threads each spin up a multi-threaded BLAS; keep BLAS single-threaded.
24
  os.environ["OPENBLAS_NUM_THREADS"] = "1"
25
- os.environ.setdefault("OMP_NUM_THREADS", "4")
26
 
27
  import spaces # noqa: E402 (must precede any CUDA-touching import)
28
  import torch # noqa: E402
@@ -30,6 +29,26 @@ import torch # noqa: E402
30
  torch.set_float32_matmul_precision("high")
31
 
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # ---------------------------------------------------------------------------
34
  # 2. Model
35
  # ---------------------------------------------------------------------------
@@ -41,7 +60,9 @@ from PIL import Image # noqa: E402
41
 
42
  import codecsplat_pipeline as cp # noqa: E402
43
 
44
- from colmap_sfm import IMAGE_EXT, run_sfm_subprocess # noqa: E402
 
 
45
 
46
  MODEL_REPO = "pengpeng-yu/CodecSplat"
47
  CHECKPOINT_FILE = "codecsplat-base-dl3dv-256x448-view8-075062d0.pth"
@@ -55,6 +76,7 @@ print("[setup] building CodecSplat...", flush=True)
55
  ENCODER = cp.build_encoder(ckpt_path).to("cuda")
56
  DECODER = cp.build_decoder().to("cuda")
57
  print("[setup] model ready", flush=True)
 
58
 
59
 
60
  def _u8(t: torch.Tensor) -> np.ndarray:
@@ -164,12 +186,13 @@ def reconstruct(images, lmb: float = 1024.0, matcher: str = "exhaustive",
164
  workdir = Path(tempfile.mkdtemp(prefix="codecsplat_"))
165
  progress(0.05, desc=f"COLMAP on {len(paths)} images")
166
  try:
167
- sfm = run_sfm_subprocess(paths, workdir, max_image_size=1024, matcher=matcher,
168
  log=lambda m: print(m, flush=True))
169
  except (ValueError, RuntimeError) as exc:
170
  raise gr.Error(str(exc)) from exc
171
  t_sfm = time.time() - t_start
172
  img_paths, c2w, K = _scene_arrays(sfm["frames"])
 
173
 
174
  progress(0.55, desc="CodecSplat: encode -> bitstream -> decode -> render")
175
  r = codecsplat_gpu(img_paths, c2w, K, float(lmb))
@@ -273,5 +296,7 @@ with gr.Blocks(title="CodecSplat") as demo:
273
  label="Frames from the DL3DV demo scene (via the DepthSplat authors)",
274
  )
275
 
 
 
276
  if __name__ == "__main__":
277
  demo.queue(max_size=12).launch(theme=gr.themes.Citrus(), css=CSS, mcp_server=True, show_error=True)
 
22
  # pycolmap's bundled OpenBLAS segfaults ("Bad memory unallocation") when many matcher
23
  # threads each spin up a multi-threaded BLAS; keep BLAS single-threaded.
24
  os.environ["OPENBLAS_NUM_THREADS"] = "1"
 
25
 
26
  import spaces # noqa: E402 (must precede any CUDA-touching import)
27
  import torch # noqa: E402
 
29
  torch.set_float32_matmul_precision("high")
30
 
31
 
32
+ def _nvidia_fds(stage: str) -> None:
33
+ """Diagnostics: open /dev/nvidia* handles in the (GPU-less) main process mean the
34
+ CUDA driver was initialised there, which breaks ZeroGPU's forked workers."""
35
+ try:
36
+ fds = []
37
+ for fd in os.listdir("/proc/self/fd"):
38
+ try:
39
+ t = os.readlink(f"/proc/self/fd/{fd}")
40
+ except OSError:
41
+ continue
42
+ if "nvidia" in t:
43
+ fds.append(t)
44
+ print(f"[diag] {stage}: nvidia fds={sorted(set(fds))}", flush=True)
45
+ except Exception as exc:
46
+ print(f"[diag] {stage}: {exc}", flush=True)
47
+
48
+
49
+ _nvidia_fds("after torch import")
50
+
51
+
52
  # ---------------------------------------------------------------------------
53
  # 2. Model
54
  # ---------------------------------------------------------------------------
 
60
 
61
  import codecsplat_pipeline as cp # noqa: E402
62
 
63
+ _nvidia_fds("after pipeline import")
64
+
65
+ from colmap_sfm import IMAGE_EXT, run_sfm # noqa: E402
66
 
67
  MODEL_REPO = "pengpeng-yu/CodecSplat"
68
  CHECKPOINT_FILE = "codecsplat-base-dl3dv-256x448-view8-075062d0.pth"
 
76
  ENCODER = cp.build_encoder(ckpt_path).to("cuda")
77
  DECODER = cp.build_decoder().to("cuda")
78
  print("[setup] model ready", flush=True)
79
+ _nvidia_fds("after model build")
80
 
81
 
82
  def _u8(t: torch.Tensor) -> np.ndarray:
 
186
  workdir = Path(tempfile.mkdtemp(prefix="codecsplat_"))
187
  progress(0.05, desc=f"COLMAP on {len(paths)} images")
188
  try:
189
+ sfm = run_sfm(paths, workdir, max_image_size=1024, matcher=matcher,
190
  log=lambda m: print(m, flush=True))
191
  except (ValueError, RuntimeError) as exc:
192
  raise gr.Error(str(exc)) from exc
193
  t_sfm = time.time() - t_start
194
  img_paths, c2w, K = _scene_arrays(sfm["frames"])
195
+ _nvidia_fds("before GPU call")
196
 
197
  progress(0.55, desc="CodecSplat: encode -> bitstream -> decode -> render")
198
  r = codecsplat_gpu(img_paths, c2w, K, float(lmb))
 
296
  label="Frames from the DL3DV demo scene (via the DepthSplat authors)",
297
  )
298
 
299
+ _nvidia_fds("after UI build")
300
+
301
  if __name__ == "__main__":
302
  demo.queue(max_size=12).launch(theme=gr.themes.Citrus(), css=CSS, mcp_server=True, show_error=True)