question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge Stable Diffusion pipelines into one

See original GitHub issue

Is your feature request related to a problem? Please describe. It would be nice to be able to use text2img & img2img & inpaint with the same instanced pipeline

Describe the solution you’d like pipe.generate(...) pipe.image_to_image(...) pipe.inpaint(...)

Describe alternatives you’ve considered It’s possible to call StableDiffusionInpaintPipeline.__call__(pipe, ...), but it might break at some point if classes are not compatible

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
leszekhanuszcommented, Sep 11, 2022

@Inkorak With a few changes I was able to make it work.

1reaction
Inkorakcommented, Sep 1, 2022

@python273 You can also write something like this. But I haven’t tried it myself yet.

class  StableDiffusionUnifiedPipeline(DiffusionPipeline):
    def __init__(
        self,
        vae: AutoencoderKL,
        text_encoder: CLIPTextModel,
        tokenizer: CLIPTokenizer,
        unet: UNet2DConditionModel,
        scheduler: Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler],
        safety_checker: StableDiffusionSafetyChecker,
        feature_extractor: CLIPFeatureExtractor,
    ):
        super().__init__()
        text2img = StableDiffusionPipeline(vae=vae,
                                          text_encoder=text_encoder,
                                          tokenizer=tokenizer,
                                          unet=unet,
                                          scheduler=scheduler,
                                          safety_checker=safety_checker,
                                          feature_extractor=feature_extractor)
        img2img = StableDiffusionImg2ImgPipeline(vae=vae,
                                          text_encoder=text_encoder,
                                          tokenizer=tokenizer,
                                          unet=unet,
                                          scheduler=scheduler,
                                          safety_checker=safety_checker,
                                          feature_extractor=feature_extractor)
        inpaint =  StableDiffusionInpaintPipeline(vae=vae,
                                          text_encoder=text_encoder,
                                          tokenizer=tokenizer,
                                          unet=unet,
                                          scheduler=scheduler,
                                          safety_checker=safety_checker,
                                          feature_extractor=feature_extractor)
        
        self.register_modules(
            text2img=text2img,
            img2img=img2img,
            inpaint=inpaint,
        )

    def __call__(
        self,
        prompt: Union[str, List[str]],
        init_image: Union[torch.FloatTensor, PIL.Image.Image],
        mask_image: Union[torch.FloatTensor, PIL.Image.Image],
        strength: float = 0.8,
        height: Optional[int] = 512,
        width: Optional[int] = 512,
        num_inference_steps: Optional[int] = 50,
        guidance_scale: Optional[float] = 7.5,
        eta: Optional[float] = 0.0,
        generator: Optional[torch.Generator] = None,
        latents: Optional[torch.FloatTensor] = None,
        output_type: Optional[str] = "pil",
        **kwargs,
    ):
      if init_image is None and mask_image is None:
        result = self.text2img(prompt =prompt,
                    height = height,
                    width = width,
                    num_inference_steps = num_inference_steps,
                    guidance_scale = guidance_scale,
                    eta = eta,
                    generator = generator,
                    latents = latents,
                    output_type = output_type,
                    **kwargs,)
      elif init_image is not None and mask_image is None:
        result = self.img2img(prompt =prompt,
                    init_image = init_image,
                    strength = strength,
                    num_inference_steps = num_inference_steps,
                    guidance_scale = guidance_scale,
                    eta = eta,
                    generator = generator,
                    output_type = output_type,
                    **kwargs,)
      else:
        result = self.inpaint(prompt =prompt,
                    init_image = init_image,
                    mask_image = mask_image,
                    strength = strength,
                    num_inference_steps = num_inference_steps,
                    guidance_scale = guidance_scale,
                    eta = eta,
                    generator = generator,
                    output_type = output_type,
                    **kwargs,)
      return result

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merging Stable diffusion pipelines just makes sense #551
Here we have a single model (Stable diffusion) which has 3 different pipelines (ignoring onnx for now) in different files doing more or...
Read more >
Custom Pipelines - Hugging Face
Stable Diffusion Mega, One Stable Diffusion Pipeline with all ... Feel free to send a PR with your own pipelines, we will merge...
Read more >
Stable Diffusion Tutorial Part 2: Using Textual Inversion ...
Once we have walked through the code, we will demonstrate how to combine our new embedding with our Dreambooth concept in the Stable...
Read more >
Stable diffusion using Hugging Face — DiffEdit paper ...
An implementation of DIFFEDIT: DIFFUSION-BASED SEMANTIC IMAGE EDITING WITH MASK GUIDANCE using hugging face diffusers library.
Read more >
Three Challenges Ahead for Stable Diffusion - Unite.AI
1 : Optimizing Tile-Based Pipelines. Presented with limited hardware resources and hard limits on the resolution of training images, it seems ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found