Skip to content

Conversation

@yiyixuxu
Copy link
Collaborator

new draft based on #4131 (comment)

to-do:

  • add all the pipelines to the map
  • add doc + tests
from diffusers import AutoPipelineForImageToImage, AutoPipelineForTextToImage, AutoPipelineForInpainting

pipe_img2img = AutoPipelineForImageToImage.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe_txt2img = AutoPipelineForTextToImage.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe_inpaint = AutoPipelineForInpainting.from_pretrained("runwayml/stable-diffusion-v1-5")

print(type(pipe_img2img), type(pipe_txt2img), type(pipe_inpaint))
<class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline'> 
<class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline'> 
<class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_inpaint.StableDiffusionInpaintPipeline'>
pipe_txt2img = AutoPipelineForTextToImage.from_pipe(pipe_img2img)
pipe_inpaint = AutoPipelineForInpainting.from_pipe(pipe_txt2img)
pipe_img2img = AutoPipelineForImageToImage.from_pipe(pipe_inpaint)
print(type(pipe_img2img), type(pipe_txt2img), type(pipe_inpaint))
<class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline'> 
<class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline'> 
<class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_inpaint.StableDiffusionInpaintPipeline'>

yiyixuxu added 2 commits July 18, 2023 05:09
@yiyixuxu yiyixuxu mentioned this pull request Jul 18, 2023
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 18, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Now we just need to add a couple of tests and fix some nits


text_2_image_cls = _get_task_class(AUTO_TEXT2IMAGE_PIPELINES_MAPPING, config["_class_name"])

return text_2_image_cls.from_pretrained(pretrained_model_or_path, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we actually need to do a bit more because .components() doesn't have all the necessary inputs necessarily. E.g. SD has a require_safety_checker pipeline optional attribute that we need to pass here as well. What you could /should do here therefore is the following:

  1. Retrieve all optional kwargs that the pipeline can accept. You can have a look here at how this can be done:

    expected_modules, optional_kwargs = self._get_signature_keys(self)

  2. Now you check if these kwargs are in pipeline.config. If they are you should retrieve them and then pass them

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I don't quite understand this

we are not calling the __init__ method, we are calling the from_pretrained() - I think these steps are done inside from_pretrained() method no?

pipe = AutoPipelineForImage2Image.from_pipe(pipe)
pipe = AutoPipelineForText2Image.from_pipe(pipe)

assert dict(pipe.config) == original_config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yiyixuxu this test currently fails, but it shouldn't. The reason is that we don't correctly forward requires_safety_checker.

Note that there might even be harder examples in case we go from SD-XL Image-2-Image over Text-2-Image back to SD-XL Image-2-Image.

Could you think about how we can make this work? We should probably just make sure we correctly save all the optional kwargs in from_pipe with register_to_config

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhhhh I got it now -- we need to just forward all the arguments passed to the original pipeline's from_pretrained(), instead of expecting users to pass them again

Thanks for demonstrating it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrickvonplaten updated from_pipe here



AUTO_TEXT2IMAGE_PIPELINES_MAPPING = OrderedDict(
[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add controlnet here as well?

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one more test for https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-xl-pipe

where we go from img2img to text2img to img2img & make sure that the config stays correct?

@yiyixuxu
Copy link
Collaborator Author

@patrickvonplaten made it work with controlnet and added the tests

@patrickvonplaten
Copy link
Contributor

Very cool only some final comments and then it would be great if we could add a "AutoPipeline" to the docs here: https://github.com/huggingface/diffusers/tree/main/docs/source/en/api/pipelines :-)

Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice, I've actually been low-key following this! 😂

What do you think about also writing a tutorial for this new API abstraction so it gets more visibility and is potentially an even easier entry point for new users coming to the library (happy to help write or review this with you 🤗 )?

Comment on lines 37 to 40
("stable-diffusion", "runwayml/stable-diffusion-v1-5"),
("if", "DeepFloyd/IF-I-XL-v1.0"),
("kandinsky", "kandinsky-community/kandinsky-2-1"),
("kdnsinskyv22", "kandinsky-community/kandinsky-2-2-decoder"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include all the major ones:

  • SDXL
  • UniDiffuser

I mention UniDiffuser because it's pre-trained on a fairly large dataset.

Comment on lines +63 to +66
pipe = AutoPipelineForImage2Image.from_pipe(pipe, requires_safety_checker=True)
assert pipe.config.requires_safety_checker is True

pipe = AutoPipelineForText2Image.from_pipe(pipe, requires_safety_checker=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat 👌

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the API design!

yiyixuxu and others added 2 commits July 24, 2023 17:54
@patrickvonplaten
Copy link
Contributor

Merging now already so that it's easier to work on: #4207

@patrickvonplaten patrickvonplaten merged commit c11d11d into main Jul 25, 2023
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* initial

* style

* from ...pipelines -> from ..pipeline_util

* make style

* fix-copies

* fix value_guided_sampling oops

* style

* add test

* Show failing test

* update from_pipe

* fix

* add controlnet, additional test and register unused original config

* update for controlnet

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* store unused config as private attribute and pass if can

* add doc

* kandinsky inpaint pipeline does not work with decoder checkpoint

* update doc

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

* style

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* fix

* Apply suggestions from code review

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* initial

* style

* from ...pipelines -> from ..pipeline_util

* make style

* fix-copies

* fix value_guided_sampling oops

* style

* add test

* Show failing test

* update from_pipe

* fix

* add controlnet, additional test and register unused original config

* update for controlnet

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* store unused config as private attribute and pass if can

* add doc

* kandinsky inpaint pipeline does not work with decoder checkpoint

* update doc

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

* style

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* fix

* Apply suggestions from code review

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* initial

* style

* from ...pipelines -> from ..pipeline_util

* make style

* fix-copies

* fix value_guided_sampling oops

* style

* add test

* Show failing test

* update from_pipe

* fix

* add controlnet, additional test and register unused original config

* update for controlnet

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* store unused config as private attribute and pass if can

* add doc

* kandinsky inpaint pipeline does not work with decoder checkpoint

* update doc

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

* style

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* fix

* Apply suggestions from code review

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
@patrickvonplaten patrickvonplaten changed the title [draft v2] AutoPipeline AutoPipeline Aug 7, 2023
@kashif kashif deleted the auto-pipe-2 branch September 11, 2023 19:07
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* initial

* style

* from ...pipelines -> from ..pipeline_util

* make style

* fix-copies

* fix value_guided_sampling oops

* style

* add test

* Show failing test

* update from_pipe

* fix

* add controlnet, additional test and register unused original config

* update for controlnet

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* store unused config as private attribute and pass if can

* add doc

* kandinsky inpaint pipeline does not work with decoder checkpoint

* update doc

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

* style

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* fix

* Apply suggestions from code review

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* initial

* style

* from ...pipelines -> from ..pipeline_util

* make style

* fix-copies

* fix value_guided_sampling oops

* style

* add test

* Show failing test

* update from_pipe

* fix

* add controlnet, additional test and register unused original config

* update for controlnet

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* store unused config as private attribute and pass if can

* add doc

* kandinsky inpaint pipeline does not work with decoder checkpoint

* update doc

* Apply suggestions from code review

Co-authored-by: Sayak Paul <[email protected]>

* style

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <[email protected]>

* fix

* Apply suggestions from code review

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants