Spaces:
Running on Zero
Running on Zero
fix(texture): avoid dual pipelines for IP generation
Browse files
common.py
CHANGED
|
@@ -667,12 +667,17 @@ def generate_texture_mvimages(
|
|
| 667 |
sub_idxs: tuple[tuple[int]] = ((0, 1, 2), (3, 4, 5)),
|
| 668 |
req: gr.Request = None,
|
| 669 |
) -> list[str]:
|
| 670 |
-
global PIPELINE_IP
|
| 671 |
|
| 672 |
output_root = os.path.join(TMP_DIR, str(req.session_hash))
|
| 673 |
use_ip_adapter = True if ip_img_path and ip_adapt_scale > 0 else False
|
| 674 |
-
|
| 675 |
if use_ip_adapter:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
if PIPELINE_IP is None:
|
| 677 |
PIPELINE_IP = build_texture_gen_pipe(
|
| 678 |
base_ckpt_dir="./weights",
|
|
@@ -681,25 +686,37 @@ def generate_texture_mvimages(
|
|
| 681 |
)
|
| 682 |
PIPELINE_IP.set_ip_adapter_scale([ip_adapt_scale])
|
| 683 |
pipeline = PIPELINE_IP
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
|
| 704 |
return img_save_paths + img_save_paths
|
| 705 |
|
|
|
|
| 667 |
sub_idxs: tuple[tuple[int]] = ((0, 1, 2), (3, 4, 5)),
|
| 668 |
req: gr.Request = None,
|
| 669 |
) -> list[str]:
|
| 670 |
+
global PIPELINE, PIPELINE_IP
|
| 671 |
|
| 672 |
output_root = os.path.join(TMP_DIR, str(req.session_hash))
|
| 673 |
use_ip_adapter = True if ip_img_path and ip_adapt_scale > 0 else False
|
| 674 |
+
|
| 675 |
if use_ip_adapter:
|
| 676 |
+
if PIPELINE is not None:
|
| 677 |
+
logger.info("Release default texture pipeline before IP generation")
|
| 678 |
+
PIPELINE = None
|
| 679 |
+
gc.collect()
|
| 680 |
+
torch.cuda.empty_cache()
|
| 681 |
if PIPELINE_IP is None:
|
| 682 |
PIPELINE_IP = build_texture_gen_pipe(
|
| 683 |
base_ckpt_dir="./weights",
|
|
|
|
| 686 |
)
|
| 687 |
PIPELINE_IP.set_ip_adapter_scale([ip_adapt_scale])
|
| 688 |
pipeline = PIPELINE_IP
|
| 689 |
+
else:
|
| 690 |
+
if PIPELINE is None:
|
| 691 |
+
PIPELINE = build_texture_gen_pipe(
|
| 692 |
+
base_ckpt_dir="./weights",
|
| 693 |
+
ip_adapt_scale=0,
|
| 694 |
+
device="cuda",
|
| 695 |
+
)
|
| 696 |
+
pipeline = PIPELINE
|
| 697 |
+
|
| 698 |
+
try:
|
| 699 |
+
img_save_paths = infer_pipe(
|
| 700 |
+
index_file=f"{output_root}/condition/index.json",
|
| 701 |
+
controlnet_cond_scale=controlnet_cond_scale,
|
| 702 |
+
guidance_scale=guidance_scale,
|
| 703 |
+
strength=strength,
|
| 704 |
+
num_inference_steps=num_inference_steps,
|
| 705 |
+
ip_adapt_scale=ip_adapt_scale,
|
| 706 |
+
ip_img_path=ip_img_path,
|
| 707 |
+
uid=uid,
|
| 708 |
+
prompt=prompt,
|
| 709 |
+
save_dir=f"{output_root}/multi_view",
|
| 710 |
+
sub_idxs=sub_idxs,
|
| 711 |
+
pipeline=pipeline,
|
| 712 |
+
seed=seed,
|
| 713 |
+
)
|
| 714 |
+
finally:
|
| 715 |
+
if use_ip_adapter:
|
| 716 |
+
pipeline = None
|
| 717 |
+
PIPELINE_IP = None
|
| 718 |
+
gc.collect()
|
| 719 |
+
torch.cuda.empty_cache()
|
| 720 |
|
| 721 |
return img_save_paths + img_save_paths
|
| 722 |
|