Skip to content

Commit c11d11d

Browse files
yiyixuxuyiyixuxupatrickvonplatensayakpaul
authored
[draft v2] AutoPipeline (huggingface#4138)
* 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]>
1 parent d74561d commit c11d11d

23 files changed

+1170
-25
lines changed

docs/source/en/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182
title: Audio Diffusion
183183
- local: api/pipelines/audioldm
184184
title: AudioLDM
185+
- local: api/pipelines/auto_pipeline
186+
title: AutoPipeline
185187
- local: api/pipelines/consistency_models
186188
title: Consistency Models
187189
- local: api/pipelines/controlnet
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# AutoPipeline
14+
15+
In many cases, one checkpoint can be used for multiple tasks. For example, you may be able to use the same checkpoint for Text-to-Image, Image-to-Image, and Inpainting. However, you'll need to know the pipeline class names linked to your checkpoint.
16+
17+
AutoPipeline is designed to make it easy for you to use multiple pipelines in your workflow. We currently provide 3 AutoPipeline classes to perform three different tasks, i.e. [`AutoPipelineForText2Image`], [`AutoPipelineForImage2Image`], and [`AutoPipelineForInpainting`]. You'll need to choose the AutoPipeline class based on the task you want to perform and use it to automatically retrieve the relevant pipeline given the name/path to the pre-trained weights.
18+
19+
For example, to perform Image-to-Image with the SD1.5 checkpoint, you can do
20+
21+
```python
22+
from diffusers import PipelineForImageToImage
23+
24+
pipe_i2i = PipelineForImageoImage.from_pretrained("runwayml/stable-diffusion-v1-5")
25+
```
26+
27+
It will also help you switch between tasks seamlessly using the same checkpoint without reallocating additional memory. For example, to re-use the Image-to-Image pipeline we just created for inpainting, you can do
28+
29+
```python
30+
from diffusers import PipelineForInpainting
31+
32+
pipe_inpaint = AutoPipelineForInpainting.from_pipe(pipe_i2i)
33+
```
34+
All the components will be transferred to the inpainting pipeline with zero cost.
35+
36+
37+
Currently AutoPipeline support the Text-to-Image, Image-to-Image, and Inpainting tasks for below diffusion models:
38+
- [stable Diffusion](./stable_diffusion)
39+
- [Stable Diffusion Controlnet](./api/pipelines/controlnet)
40+
- [Stable Diffusion XL](./stable_diffusion/stable_diffusion_xl)
41+
- [IF](./if)
42+
- [Kandinsky](./kandinsky)(./kandinsky)(./kandinsky)(./kandinsky)(./kandinsky)
43+
- [Kandinsky 2.2]()(./kandinsky)
44+
45+
46+
## AutoPipelineForText2Image
47+
48+
[[autodoc]] AutoPipelineForText2Image
49+
- all
50+
- from_pretrained
51+
- from_pipe
52+
53+
54+
## AutoPipelineForImage2Image
55+
56+
[[autodoc]] AutoPipelineForImage2Image
57+
- all
58+
- from_pretrained
59+
- from_pipe
60+
61+
## AutoPipelineForInpainting
62+
63+
[[autodoc]] AutoPipelineForInpainting
64+
- all
65+
- from_pretrained
66+
- from_pipe
67+
68+

src/diffusers/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
)
6363
from .pipelines import (
6464
AudioPipelineOutput,
65+
AutoPipelineForImage2Image,
66+
AutoPipelineForInpainting,
67+
AutoPipelineForText2Image,
6568
ConsistencyModelPipeline,
6669
DanceDiffusionPipeline,
6770
DDIMPipeline,

src/diffusers/pipelines/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
except OptionalDependencyNotAvailable:
1818
from ..utils.dummy_pt_objects import * # noqa F403
1919
else:
20+
from .auto_pipeline import AutoPipelineForImage2Image, AutoPipelineForInpainting, AutoPipelineForText2Image
2021
from .consistency_models import ConsistencyModelPipeline
2122
from .dance_diffusion import DanceDiffusionPipeline
2223
from .ddim import DDIMPipeline

0 commit comments

Comments
 (0)