-
Notifications
You must be signed in to change notification settings - Fork 6.5k
AutoPipeline #4138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutoPipeline #4138
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
patrickvonplaten
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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:
-
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) -
Now you check if these kwargs are in
pipeline.config. If they are you should retrieve them and then pass them
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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( | ||
| [ |
There was a problem hiding this comment.
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?
patrickvonplaten
left a comment
There was a problem hiding this 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?
|
@patrickvonplaten made it work with controlnet and added the tests |
|
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 :-) |
stevhliu
left a comment
There was a problem hiding this 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 🤗 )?
| ("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"), |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat 👌
sayakpaul
left a comment
There was a problem hiding this 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!
Co-authored-by: Sayak Paul <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
|
Merging now already so that it's easier to work on: #4207 |
* 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]>
* 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]>
* 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]>
* 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]>
* 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]>
new draft based on #4131 (comment)
to-do: