From 5d0405dc68bd01d1903010470aec4cd58c8a65a5 Mon Sep 17 00:00:00 2001 From: Akasei Date: Mon, 16 Mar 2026 21:05:14 +0800 Subject: [PATCH] feat(gradio): apply VRAM optimization and fix texture config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - generation_all(): offload i23d_worker to CPU before texture gen, restore after — mirrors batch_generate.py sequential strategy. Prevents OOM when both models peak simultaneously on RTX 3080. - Change texture config: max_num_view 8→9, resolution 768→512. 768 resolution OOMs (14.6GB activation); 512 is practical max for RTX 3080 20GB. max_views 9 gives better texture coverage. - Only active when --low_vram_mode flag is passed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- gradio_app.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gradio_app.py b/gradio_app.py index 46b219d..b300a61 100644 --- a/gradio_app.py +++ b/gradio_app.py @@ -378,7 +378,19 @@ def generation_all( tmp_time = time.time() text_path = os.path.join(save_folder, f'textured_mesh.obj') + + # In low_vram_mode: offload shape model to CPU before texture gen to free VRAM, + # mirroring the sequential-load strategy in batch_generate.py. + if args.low_vram_mode: + i23d_worker.to('cpu') + torch.cuda.empty_cache() + path_textured = tex_pipeline(mesh_path=path, image_path=image, output_mesh_path=text_path, save_glb=False) + + # Restore shape model to GPU so subsequent requests don't need to reload from disk. + if args.low_vram_mode: + i23d_worker.to('cuda') + torch.cuda.empty_cache() logger.info("---Texture Generation takes %s seconds ---" % (time.time() - tmp_time)) stats['time']['texture generation'] = time.time() - tmp_time @@ -796,7 +808,7 @@ if __name__ == '__main__': # texgen_worker.enable_model_cpu_offload() from hy3dpaint.textureGenPipeline import Hunyuan3DPaintPipeline, Hunyuan3DPaintConfig - conf = Hunyuan3DPaintConfig(max_num_view=8, resolution=768) + conf = Hunyuan3DPaintConfig(max_num_view=9, resolution=512) conf.realesrgan_ckpt_path = "hy3dpaint/ckpt/RealESRGAN_x4plus.pth" conf.multiview_cfg_path = "hy3dpaint/cfgs/hunyuan-paint-pbr.yaml" conf.custom_pipeline = "hy3dpaint/hunyuanpaintpbr"