weijielyu commited on
Commit
839dee5
·
1 Parent(s): 40e81a0

Update demo

Browse files
Files changed (1) hide show
  1. app.py +32 -21
app.py CHANGED
@@ -29,19 +29,36 @@ import spaces
29
  import subprocess
30
  import sys
31
  import os
 
 
 
32
  try:
33
- import diff_gaussian_rasterization
34
  except ImportError:
35
- print("Installing diff-gaussian-rasterization...")
36
- # Set CUDA architecture for A100 (compute capability 8.0)
37
- # This prevents the IndexError in _get_cuda_arch_flags
38
  env = os.environ.copy()
39
- env["TORCH_CUDA_ARCH_LIST"] = "8.0"
40
- subprocess.check_call([
41
- sys.executable, "-m", "pip", "install",
42
- "git+https://github.com/graphdeco-inria/diff-gaussian-rasterization"
43
- ], env=env)
44
- import diff_gaussian_rasterization
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  from gslrm.model.gaussians_renderer import render_turntable, imageseq2video
47
  from mvdiffusion.pipelines.pipeline_mvdiffusion_unclip import StableUnCLIPImg2ImgPipeline
@@ -93,7 +110,7 @@ class FaceLiftPipeline:
93
 
94
  # Parameters
95
  self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
96
- self.image_size = 384 # Reduced from 512 for ZeroGPU memory constraints
97
  self.camera_indices = [2, 1, 0, 5, 4, 3]
98
 
99
  # Load models (keep on CPU for ZeroGPU compatibility)
@@ -244,13 +261,7 @@ class FaceLiftPipeline:
244
  print("Moving GS-LRM model to GPU...")
245
  self.gs_lrm_model.to(self.device)
246
  torch.cuda.empty_cache()
247
-
248
- # Log GPU memory status
249
- if torch.cuda.is_available():
250
- allocated = torch.cuda.memory_allocated() / 1024**3
251
- reserved = torch.cuda.memory_reserved() / 1024**3
252
- print(f"GPU memory before GS-LRM: {allocated:.2f}GB allocated, {reserved:.2f}GB reserved")
253
-
254
  # Final memory cleanup before reconstruction
255
  torch.cuda.empty_cache()
256
 
@@ -283,9 +294,9 @@ class FaceLiftPipeline:
283
  output_path = output_dir / "output.png"
284
  Image.fromarray(comp_image).save(output_path)
285
 
286
- # Generate turntable video (reduced resolution and frames for ZeroGPU memory limits)
287
- turntable_resolution = 256 # Lower resolution for turntable to save memory
288
- num_turntable_views = 120 # Reduced from 180
289
  turntable_frames = render_turntable(gaussians, rendering_resolution=turntable_resolution,
290
  num_views=num_turntable_views)
291
  turntable_frames = rearrange(turntable_frames, "h (v w) c -> v h w c", v=num_turntable_views)
 
29
  import subprocess
30
  import sys
31
  import os
32
+ import subprocess, sys, os
33
+
34
+ # Ensure diff-gaussian-rasterization is compiled for the current GPU arch
35
  try:
36
+ import diff_gaussian_rasterization # noqa: F401
37
  except ImportError:
38
+ print("Installing diff-gaussian-rasterization (compiling for detected CUDA arch)...")
 
 
39
  env = os.environ.copy()
40
+ try:
41
+ import torch
42
+ if torch.cuda.is_available():
43
+ maj, minr = torch.cuda.get_device_capability()
44
+ arch = f"{maj}.{minr}" # e.g., "9.0" on H100/H200, "8.0" on A100
45
+ env["TORCH_CUDA_ARCH_LIST"] = f"{arch}+PTX"
46
+ else:
47
+ # Build stage may not see a GPU on HF Spaces: compile a cross-arch set
48
+ env["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6;8.9;9.0+PTX"
49
+ except Exception:
50
+ env["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6;8.9;9.0+PTX"
51
+
52
+ # (Optional) side-step allocator+NVML quirks in restrictive containers
53
+ env.setdefault("PYTORCH_NO_CUDA_MEMORY_CACHING", "1")
54
+
55
+ subprocess.check_call(
56
+ [sys.executable, "-m", "pip", "install",
57
+ "git+https://github.com/graphdeco-inria/diff-gaussian-rasterization"],
58
+ env=env,
59
+ )
60
+ import diff_gaussian_rasterization # noqa: F401
61
+
62
 
63
  from gslrm.model.gaussians_renderer import render_turntable, imageseq2video
64
  from mvdiffusion.pipelines.pipeline_mvdiffusion_unclip import StableUnCLIPImg2ImgPipeline
 
110
 
111
  # Parameters
112
  self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
113
+ self.image_size = 512
114
  self.camera_indices = [2, 1, 0, 5, 4, 3]
115
 
116
  # Load models (keep on CPU for ZeroGPU compatibility)
 
261
  print("Moving GS-LRM model to GPU...")
262
  self.gs_lrm_model.to(self.device)
263
  torch.cuda.empty_cache()
264
+
 
 
 
 
 
 
265
  # Final memory cleanup before reconstruction
266
  torch.cuda.empty_cache()
267
 
 
294
  output_path = output_dir / "output.png"
295
  Image.fromarray(comp_image).save(output_path)
296
 
297
+ # Generate turntable video
298
+ turntable_resolution = 512
299
+ num_turntable_views = 180
300
  turntable_frames = render_turntable(gaussians, rendering_resolution=turntable_resolution,
301
  num_views=num_turntable_views)
302
  turntable_frames = rearrange(turntable_frames, "h (v w) c -> v h w c", v=num_turntable_views)