notenoughram commited on
Commit
2618acd
ยท
verified ยท
1 Parent(s): 7136696

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -18
app.py CHANGED
@@ -5,13 +5,13 @@ import gc
5
  import shutil
6
  from typing import *
7
 
8
- # [AUTO-INSTALL] accelerate
9
  try:
10
  import accelerate
11
  except ImportError:
12
  subprocess.check_call([sys.executable, "-m", "pip", "install", "accelerate"])
13
 
14
- # [์ค‘์š”] OOM ๋ฐฉ์ง€
15
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
16
  os.environ['SPCONV_ALGO'] = 'native'
17
 
@@ -128,6 +128,7 @@ def generate_and_extract_glb(
128
  image_files = [image[0] for image in multiimages]
129
 
130
  try:
 
131
  with torch.no_grad():
132
  outputs, _, _ = pipeline.run(
133
  image=image_files,
@@ -146,6 +147,7 @@ def generate_and_extract_glb(
146
  )
147
  except Exception as e:
148
  torch.cuda.empty_cache()
 
149
  raise RuntimeError(f"Generation Failed: {str(e)}")
150
 
151
  video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
@@ -217,7 +219,7 @@ demo = gr.Blocks(
217
  """
218
  )
219
  with demo:
220
- gr.Markdown("# ๐Ÿ’ป ReconViaGen (Device Mismatch Fixed)")
221
 
222
  with gr.Row():
223
  with gr.Column():
@@ -303,37 +305,47 @@ with demo:
303
  # Launch Script
304
  if __name__ == "__main__":
305
  print("๐Ÿš€ Initializing Pipeline...")
 
306
  pipeline = TrellisVGGTTo3DPipeline.from_pretrained("esther11/trellis-vggt-v0-2")
307
 
308
- # 1. ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ผ๋‹จ CUDA:0์œผ๋กœ ์ด๋™ (๊ธฐ๋ณธ ์ƒํƒœ ์ผ์น˜)
309
- pipeline.cuda()
310
-
311
- # [ํ•ต์‹ฌ ์ˆ˜์ •] ํŒŒ์ดํ”„๋ผ์ธ์˜ device ์ •๋ณด๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ˆ˜์ •ํ•˜์—ฌ ์ž…๋ ฅ ํ…์„œ๊ฐ€ GPU๋กœ ์ƒ์„ฑ๋˜๊ฒŒ ํ•จ
312
- pipeline._device = torch.device("cuda:0")
313
-
314
- # birefnet๋„ ํ™•์‹คํžˆ GPU0์— ์žˆ๋Š”์ง€ ํ™•์ธ (์ด๋ฏธ cuda()๋กœ ๊ฐ”๊ฒ ์ง€๋งŒ ์•ˆ์ „์žฅ์น˜)
315
- pipeline.birefnet_model = pipeline.birefnet_model.to("cuda:0")
316
 
317
  gpu_count = torch.cuda.device_count()
318
  print(f"โšก Detected {gpu_count} GPUs.")
319
 
320
  if gpu_count > 1:
321
- print("โšก Multi-GPU Mode: Splitting VGGT model.")
322
 
323
- # VGGT ๋ถ„์‚ฐ์„ ์œ„ํ•ด ์ž ์‹œ CPU๋กœ ์ด๋™ํ•˜์—ฌ ๋งต ๊ณ„์‚ฐ (์•ˆ์ „ํ•œ ๋ถ„ํ• ์„ ์œ„ํ•จ)
 
324
  pipeline.VGGT_model.cpu()
325
 
326
- print(" - Calculating Device Map for VGGT...")
327
- # ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ์„ ๋‘์–ด ๊ฐ•์ œ๋กœ ๋ถ„์‚ฐ ์œ ๋„ (Block ๋‹จ์œ„ ๋ณดํ˜ธ)
 
 
 
 
 
 
 
 
328
  device_map = infer_auto_device_map(
329
  pipeline.VGGT_model,
330
- max_memory={i: "10GiB" for i in range(gpu_count)},
331
  no_split_module_classes=["Block", "ResnetBlock"]
332
  )
333
 
 
334
  pipeline.VGGT_model = dispatch_model(pipeline.VGGT_model, device_map=device_map)
335
- print("โœ… VGGT Model dispatched.")
 
 
 
 
336
  else:
337
- print("โš ๏ธ Warning: Only 1 GPU detected.")
338
 
339
  demo.launch()
 
5
  import shutil
6
  from typing import *
7
 
8
+ # [AUTO-INSTALL] accelerate ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
9
  try:
10
  import accelerate
11
  except ImportError:
12
  subprocess.check_call([sys.executable, "-m", "pip", "install", "accelerate"])
13
 
14
+ # [์ค‘์š”] OOM ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ๋ฉ”๋ชจ๋ฆฌ ํŒŒํŽธํ™” ์„ค์ •
15
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
16
  os.environ['SPCONV_ALGO'] = 'native'
17
 
 
128
  image_files = [image[0] for image in multiimages]
129
 
130
  try:
131
+ # [์ค‘์š”] ์ถ”๋ก  ์‹œ ๊ทธ๋ž˜๋””์–ธํŠธ ๊ณ„์‚ฐ ๋” (๋ฉ”๋ชจ๋ฆฌ ์ ˆ์•ฝ)
132
  with torch.no_grad():
133
  outputs, _, _ = pipeline.run(
134
  image=image_files,
 
147
  )
148
  except Exception as e:
149
  torch.cuda.empty_cache()
150
+ # ๊ตฌ์ฒด์ ์ธ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜
151
  raise RuntimeError(f"Generation Failed: {str(e)}")
152
 
153
  video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
 
219
  """
220
  )
221
  with demo:
222
+ gr.Markdown("# ๐Ÿ’ป ReconViaGen (GPU 0 Freed)")
223
 
224
  with gr.Row():
225
  with gr.Column():
 
305
  # Launch Script
306
  if __name__ == "__main__":
307
  print("๐Ÿš€ Initializing Pipeline...")
308
+ # 1. Pipeline ๋กœ๋“œ
309
  pipeline = TrellisVGGTTo3DPipeline.from_pretrained("esther11/trellis-vggt-v0-2")
310
 
311
+ # 2. ๋ชจ๋“  ๋ชจ๋ธ์„ ์ผ๋‹จ CUDA:0์— ์˜ฌ๋ ค์„œ ๊ธฐ๋ณธ ์„ค์ •(device mismatch ๋ฐฉ์ง€)์„ ์™„๋ฃŒํ•จ
312
+ pipeline.cuda()
313
+ pipeline._device = torch.device("cuda:0") # ๋‚ด๋ถ€ device ์†์„ฑ ๊ณ ์ •
 
 
 
 
 
314
 
315
  gpu_count = torch.cuda.device_count()
316
  print(f"โšก Detected {gpu_count} GPUs.")
317
 
318
  if gpu_count > 1:
319
+ print("โšก Multi-GPU Mode: Offloading VGGT from GPU 0.")
320
 
321
+ # [ํ•ต์‹ฌ ๋กœ์ง] GPU 0์„ ๋น„์šฐ๊ธฐ ์œ„ํ•œ ์ „๋žต
322
+ # VGGT ๋ชจ๋ธ์„ ์ž ์‹œ CPU๋กœ ๋‚ด๋ฆฝ๋‹ˆ๋‹ค.
323
  pipeline.VGGT_model.cpu()
324
 
325
+ print(" - Calculating Device Map (Banning GPU 0 for VGGT)...")
326
+
327
+ # max_memory ์„ค์ •:
328
+ # GPU 0: "10MiB" (์‚ฌ์‹ค์ƒ VGGT ๋ชจ๋ธ ์ ์žฌ ๊ธˆ์ง€)
329
+ # GPU 1~N: "20GiB" (์—ฌ์œ ๋กญ๊ฒŒ ํ• ๋‹น)
330
+ max_mem = {0: "10MiB"}
331
+ for i in range(1, gpu_count):
332
+ max_mem[i] = "20GiB"
333
+
334
+ # ์ด ์„ค์ •์œผ๋กœ ๋งต์„ ์งœ๋ฉด accelerate๋Š” GPU 0์„ ๊ฑด๋„ˆ๋›ฐ๊ณ  GPU 1๋ถ€ํ„ฐ ๋ชจ๋ธ์„ ์ฑ„์›๋‹ˆ๋‹ค.
335
  device_map = infer_auto_device_map(
336
  pipeline.VGGT_model,
337
+ max_memory=max_mem,
338
  no_split_module_classes=["Block", "ResnetBlock"]
339
  )
340
 
341
+ # ๋งต ์ ์šฉํ•˜์—ฌ ๋ถ„์‚ฐ ๋กœ๋“œ
342
  pipeline.VGGT_model = dispatch_model(pipeline.VGGT_model, device_map=device_map)
343
+
344
+ print("โœ… VGGT Model successfully pushed to GPU 1+.")
345
+ print(" - GPU 0: Birefnet (Preprocessing) + Controller")
346
+ print(" - GPU 1+: VGGT (Inference)")
347
+
348
  else:
349
+ print("โš ๏ธ Warning: Only 1 GPU detected. Expect OOM if VRAM < 24GB.")
350
 
351
  demo.launch()