xinjjj commited on
Commit
13b4afd
·
1 Parent(s): 06dfe43

fix(texture): unload IP adapter after generation

Browse files
Files changed (1) hide show
  1. common.py +26 -18
common.py CHANGED
@@ -693,24 +693,32 @@ def generate_texture_mvimages(
693
  if PIPELINE_HAS_IP_ADAPTER:
694
  PIPELINE.set_ip_adapter_scale([ip_adapt_scale if use_ip_adapter else 0.0])
695
 
696
- img_save_paths = infer_pipe(
697
- index_file=f"{output_root}/condition/index.json",
698
- controlnet_cond_scale=controlnet_cond_scale,
699
- guidance_scale=guidance_scale,
700
- strength=strength,
701
- num_inference_steps=num_inference_steps,
702
- ip_adapt_scale=ip_adapt_scale if use_ip_adapter else 0.0,
703
- ip_img_path=ip_img_path if use_ip_adapter else None,
704
- uid=uid,
705
- prompt=prompt,
706
- save_dir=f"{output_root}/multi_view",
707
- sub_idxs=sub_idxs,
708
- pipeline=PIPELINE,
709
- seed=seed,
710
- )
711
-
712
- gc.collect()
713
- torch.cuda.empty_cache()
 
 
 
 
 
 
 
 
714
 
715
  return img_save_paths + img_save_paths
716
 
 
693
  if PIPELINE_HAS_IP_ADAPTER:
694
  PIPELINE.set_ip_adapter_scale([ip_adapt_scale if use_ip_adapter else 0.0])
695
 
696
+ try:
697
+ img_save_paths = infer_pipe(
698
+ index_file=f"{output_root}/condition/index.json",
699
+ controlnet_cond_scale=controlnet_cond_scale,
700
+ guidance_scale=guidance_scale,
701
+ strength=strength,
702
+ num_inference_steps=num_inference_steps,
703
+ ip_adapt_scale=ip_adapt_scale if use_ip_adapter else 0.0,
704
+ ip_img_path=ip_img_path if use_ip_adapter else None,
705
+ uid=uid,
706
+ prompt=prompt,
707
+ save_dir=f"{output_root}/multi_view",
708
+ sub_idxs=sub_idxs,
709
+ pipeline=PIPELINE,
710
+ seed=seed,
711
+ )
712
+ finally:
713
+ if use_ip_adapter and PIPELINE_HAS_IP_ADAPTER:
714
+ logger.info("Unload IP adapter from default texture pipeline")
715
+ if hasattr(PIPELINE, "unload_ip_adapter"):
716
+ PIPELINE.unload_ip_adapter()
717
+ else:
718
+ PIPELINE = None
719
+ PIPELINE_HAS_IP_ADAPTER = False
720
+ gc.collect()
721
+ torch.cuda.empty_cache()
722
 
723
  return img_save_paths + img_save_paths
724