Spaces:
Paused
Paused
Update app.py
Browse files
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 (
|
| 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 |
-
#
|
| 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:
|
| 322 |
|
| 323 |
-
#
|
|
|
|
| 324 |
pipeline.VGGT_model.cpu()
|
| 325 |
|
| 326 |
-
print(" - Calculating Device Map for VGGT...")
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
device_map = infer_auto_device_map(
|
| 329 |
pipeline.VGGT_model,
|
| 330 |
-
max_memory=
|
| 331 |
no_split_module_classes=["Block", "ResnetBlock"]
|
| 332 |
)
|
| 333 |
|
|
|
|
| 334 |
pipeline.VGGT_model = dispatch_model(pipeline.VGGT_model, device_map=device_map)
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|