DawnC commited on
Commit
cd34421
·
verified ·
1 Parent(s): 4c3852d

Update inpainting_module.py

Browse files
Files changed (1) hide show
  1. inpainting_module.py +27 -14
inpainting_module.py CHANGED
@@ -612,19 +612,32 @@ class InpaintingModule:
612
  strength: float,
613
  generator: torch.Generator
614
  ) -> Image.Image:
615
- """Generate using pure SDXL Inpainting pipeline."""
616
- with torch.inference_mode():
617
- result = self._pipeline(
618
- prompt=prompt,
619
- negative_prompt=negative_prompt,
620
- image=image,
621
- mask_image=mask,
622
- num_inference_steps=num_steps,
623
- guidance_scale=guidance_scale,
624
- strength=strength,
625
- generator=generator
626
- )
627
- return result.images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
628
 
629
  def _generate_controlnet_inpaint(
630
  self,
@@ -663,4 +676,4 @@ class InpaintingModule:
663
  "mode": self._current_mode,
664
  "conditioning_type": self._current_conditioning_type,
665
  "model_key": self._current_model_key,
666
- }
 
612
  strength: float,
613
  generator: torch.Generator
614
  ) -> Image.Image:
615
+ """Generate using pure SDXL Inpainting pipeline with DPM++ scheduler for speed."""
616
+ # Use DPM++ 2M Karras scheduler for faster generation
617
+ original_scheduler = self._pipeline.scheduler
618
+ self._pipeline.scheduler = DPMSolverMultistepScheduler.from_config(
619
+ self._pipeline.scheduler.config,
620
+ use_karras_sigmas=True,
621
+ algorithm_type="dpmsolver++"
622
+ )
623
+ logger.info("Switched to DPM++ 2M Karras scheduler for Pure Inpainting")
624
+
625
+ try:
626
+ with torch.inference_mode():
627
+ result = self._pipeline(
628
+ prompt=prompt,
629
+ negative_prompt=negative_prompt,
630
+ image=image,
631
+ mask_image=mask,
632
+ num_inference_steps=num_steps,
633
+ guidance_scale=guidance_scale,
634
+ strength=strength,
635
+ generator=generator
636
+ )
637
+ return result.images[0]
638
+ finally:
639
+ # Restore original scheduler
640
+ self._pipeline.scheduler = original_scheduler
641
 
642
  def _generate_controlnet_inpaint(
643
  self,
 
676
  "mode": self._current_mode,
677
  "conditioning_type": self._current_conditioning_type,
678
  "model_key": self._current_model_key,
679
+ }