Skip to content

Commit 5c75a5f

Browse files
[Docs] Fix typos, improve, update at Tutorials page (huggingface#5586)
* Fix typos, improve, update * Update autopipeline.md * Update docs/source/en/tutorials/using_peft_for_inference.md Co-authored-by: Steven Liu <[email protected]> * Update docs/source/en/tutorials/using_peft_for_inference.md Co-authored-by: Steven Liu <[email protected]> * Update docs/source/en/tutorials/using_peft_for_inference.md Co-authored-by: Steven Liu <[email protected]> --------- Co-authored-by: Steven Liu <[email protected]>
1 parent 442017c commit 5c75a5f

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

docs/source/en/tutorials/autopipeline.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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+
113
# AutoPipeline
214

315
🤗 Diffusers is able to complete many different tasks, and you can often reuse the same pretrained weights for multiple tasks such as text-to-image, image-to-image, and inpainting. If you're new to the library and diffusion models though, it may be difficult to know which pipeline to use for a task. For example, if you're using the [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5) checkpoint for text-to-image, you might not know that you could also use it for image-to-image and inpainting by loading the checkpoint with the [`StableDiffusionImg2ImgPipeline`] and [`StableDiffusionInpaintPipeline`] classes respectively.
@@ -6,7 +18,7 @@ The `AutoPipeline` class is designed to simplify the variety of pipelines in
618

719
<Tip>
820

9-
Take a look at the [AutoPipeline](./pipelines/auto_pipeline) reference to see which tasks are supported. Currently, it supports text-to-image, image-to-image, and inpainting.
21+
Take a look at the [AutoPipeline](../api/pipelines/auto_pipeline) reference to see which tasks are supported. Currently, it supports text-to-image, image-to-image, and inpainting.
1022

1123
</Tip>
1224

@@ -26,6 +38,7 @@ pipeline = AutoPipelineForText2Image.from_pretrained(
2638
prompt = "peasant and dragon combat, wood cutting style, viking era, bevel with rune"
2739

2840
image = pipeline(prompt, num_inference_steps=25).images[0]
41+
image
2942
```
3043

3144
<div class="flex justify-center">
@@ -35,12 +48,16 @@ image = pipeline(prompt, num_inference_steps=25).images[0]
3548
Under the hood, [`AutoPipelineForText2Image`]:
3649

3750
1. automatically detects a `"stable-diffusion"` class from the [`model_index.json`](https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/model_index.json) file
38-
2. loads the corresponding text-to-image [`StableDiffusionPipline`] based on the `"stable-diffusion"` class name
51+
2. loads the corresponding text-to-image [`StableDiffusionPipeline`] based on the `"stable-diffusion"` class name
3952

4053
Likewise, for image-to-image, [`AutoPipelineForImage2Image`] detects a `"stable-diffusion"` checkpoint from the `model_index.json` file and it'll load the corresponding [`StableDiffusionImg2ImgPipeline`] behind the scenes. You can also pass any additional arguments specific to the pipeline class such as `strength`, which determines the amount of noise or variation added to an input image:
4154

4255
```py
4356
from diffusers import AutoPipelineForImage2Image
57+
import torch
58+
import requests
59+
from PIL import Image
60+
from io import BytesIO
4461

4562
pipeline = AutoPipelineForImage2Image.from_pretrained(
4663
"runwayml/stable-diffusion-v1-5",
@@ -56,6 +73,7 @@ image = Image.open(BytesIO(response.content)).convert("RGB")
5673
image.thumbnail((768, 768))
5774

5875
image = pipeline(prompt, image, num_inference_steps=200, strength=0.75, guidance_scale=10.5).images[0]
76+
image
5977
```
6078

6179
<div class="flex justify-center">
@@ -67,6 +85,7 @@ And if you want to do inpainting, then [`AutoPipelineForInpainting`] loads the u
6785
```py
6886
from diffusers import AutoPipelineForInpainting
6987
from diffusers.utils import load_image
88+
import torch
7089

7190
pipeline = AutoPipelineForInpainting.from_pretrained(
7291
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True
@@ -80,6 +99,7 @@ mask_image = load_image(mask_url).convert("RGB")
8099

81100
prompt = "A majestic tiger sitting on a bench"
82101
image = pipeline(prompt, image=init_image, mask_image=mask_image, num_inference_steps=50, strength=0.80).images[0]
102+
image
83103
```
84104

85105
<div class="flex justify-center">
@@ -106,6 +126,7 @@ The [`~AutoPipelineForImage2Image.from_pipe`] method detects the original pipeli
106126

107127
```py
108128
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image
129+
import torch
109130

110131
pipeline_text2img = AutoPipelineForText2Image.from_pretrained(
111132
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, use_safetensors=True
@@ -126,6 +147,7 @@ If you passed an optional argument - like disabling the safety checker - to the
126147

127148
```py
128149
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image
150+
import torch
129151

130152
pipeline_text2img = AutoPipelineForText2Image.from_pretrained(
131153
"runwayml/stable-diffusion-v1-5",
@@ -135,12 +157,14 @@ pipeline_text2img = AutoPipelineForText2Image.from_pretrained(
135157
).to("cuda")
136158

137159
pipeline_img2img = AutoPipelineForImage2Image.from_pipe(pipeline_text2img)
138-
print(pipe.config.requires_safety_checker)
160+
print(pipeline_img2img.config.requires_safety_checker)
139161
"False"
140162
```
141163

142164
You can overwrite any of the arguments and even configuration from the original pipeline if you want to change the behavior of the new pipeline. For example, to turn the safety checker back on and add the `strength` argument:
143165

144166
```py
145167
pipeline_img2img = AutoPipelineForImage2Image.from_pipe(pipeline_text2img, requires_safety_checker=True, strength=0.3)
168+
print(pipeline_img2img.config.requires_safety_checker)
169+
"True"
146170
```

docs/source/en/tutorials/basic_training.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Before you begin, make sure you have 🤗 Datasets installed to load and preproc
3131
#!pip install diffusers[training]
3232
```
3333

34-
We encourage you to share your model with the community, and in order to do that, you'll need to login to your Hugging Face account (create one [here](https://hf.co/join) if you don't already have one!). You can login from a notebook and enter your token when prompted:
34+
We encourage you to share your model with the community, and in order to do that, you'll need to login to your Hugging Face account (create one [here](https://hf.co/join) if you don't already have one!). You can login from a notebook and enter your token when prompted. Make sure your token has the write role.
3535

3636
```py
3737
>>> from huggingface_hub import notebook_login
@@ -59,7 +59,6 @@ For convenience, create a `TrainingConfig` class containing the training hyperpa
5959
```py
6060
>>> from dataclasses import dataclass
6161

62-
6362
>>> @dataclass
6463
... class TrainingConfig:
6564
... image_size = 128 # the generated image resolution
@@ -75,6 +74,7 @@ For convenience, create a `TrainingConfig` class containing the training hyperpa
7574
... output_dir = "ddpm-butterflies-128" # the model name locally and on the HF Hub
7675

7776
... push_to_hub = True # whether to upload the saved model to the HF Hub
77+
... hub_model_id = "<your-username>/<my-awesome-model>" # the name of the repository to create on the HF Hub
7878
... hub_private_repo = False
7979
... overwrite_output_dir = True # overwrite the old model when re-running the notebook
8080
... seed = 0
@@ -253,10 +253,8 @@ Then, you'll need a way to evaluate the model. For evaluation, you can use the [
253253
```py
254254
>>> from diffusers import DDPMPipeline
255255
>>> from diffusers.utils import make_image_grid
256-
>>> import math
257256
>>> import os
258257

259-
260258
>>> def evaluate(config, epoch, pipeline):
261259
... # Sample some images from random noise (this is the backward diffusion process).
262260
... # The default pipeline output type is `List[PIL.Image]`

docs/source/en/tutorials/tutorial_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ After completing the tutorials, you'll have gained the necessary skills to start
2020

2121
Feel free to join our community on [Discord](https://discord.com/invite/JfAtkvEtRb) or the [forums](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63) to connect and collaborate with other users and developers!
2222

23-
Let's start diffusing! 🧨
23+
Let's start diffusing! 🧨

docs/source/en/tutorials/using_peft_for_inference.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
1010
specific language governing permissions and limitations under the License.
1111
-->
1212

13-
[[open-in-colab]]
13+
[[open-in-colab]]
1414

1515
# Inference with PEFT
1616

17-
There are many adapters trained in different styles to achieve different effects. You can even combine multiple adapters to create new and unique images. With the 🤗 [PEFT](https://huggingface.co/docs/peft/index) integration in 🤗 Diffusers, it is really easy to load and manage adapters for inference. In this guide, you'll learn how to use different adapters with [Stable Diffusion XL (SDXL)](./pipelines/stable_diffusion/stable_diffusion_xl) for inference.
17+
There are many adapters trained in different styles to achieve different effects. You can even combine multiple adapters to create new and unique images. With the 🤗 [PEFT](https://huggingface.co/docs/peft/index) integration in 🤗 Diffusers, it is really easy to load and manage adapters for inference. In this guide, you'll learn how to use different adapters with [Stable Diffusion XL (SDXL)](../api/pipelines/stable_diffusion/stable_diffusion_xl) for inference.
1818

1919
Throughout this guide, you'll use LoRA as the main adapter technique, so we'll use the terms LoRA and adapter interchangeably. You should have some familiarity with LoRA, and if you don't, we welcome you to check out the [LoRA guide](https://huggingface.co/docs/peft/conceptual_guides/lora).
2020

@@ -63,7 +63,7 @@ image
6363

6464
With the `adapter_name` parameter, it is really easy to use another adapter for inference! Load the [nerijs/pixel-art-xl](https://huggingface.co/nerijs/pixel-art-xl) adapter that has been fine-tuned to generate pixel art images, and let's call it `"pixel"`.
6565

66-
The pipeline automatically sets the first loaded adapter (`"toy"`) as the active adapter. But you can activate the `"pixel"` adapter with the [`~diffusers.loaders.set_adapters`] method as shown below:
66+
The pipeline automatically sets the first loaded adapter (`"toy"`) as the active adapter. But you can activate the `"pixel"` adapter with the [`~diffusers.loaders.UNet2DConditionLoadersMixin.set_adapters`] method as shown below:
6767

6868
```python
6969
pipe.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
@@ -86,7 +86,7 @@ image
8686

8787
You can also perform multi-adapter inference where you combine different adapter checkpoints for inference.
8888

89-
Once again, use the [`~diffusers.loaders.set_adapters`] method to activate two LoRA checkpoints and specify the weight for how the checkpoints should be combined.
89+
Once again, use the [`~diffusers.loaders.UNet2DConditionLoadersMixin.set_adapters`] method to activate two LoRA checkpoints and specify the weight for how the checkpoints should be combined.
9090

9191
```python
9292
pipe.set_adapters(["pixel", "toy"], adapter_weights=[0.5, 1.0])
@@ -116,7 +116,7 @@ image
116116

117117
Impressive! As you can see, the model was able to generate an image that mixes the characteristics of both adapters.
118118

119-
If you want to go back to using only one adapter, use the [`~diffusers.loaders.set_adapters`] method to activate the `"toy"` adapter:
119+
If you want to go back to using only one adapter, use the [`~diffusers.loaders.UNet2DConditionLoadersMixin.set_adapters`] method to activate the `"toy"` adapter:
120120

121121
```python
122122
# First, set the adapter.
@@ -134,7 +134,7 @@ image
134134
![toy-face-again](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peft_integration/diffusers_peft_lora_inference_18_1.png)
135135

136136

137-
If you want to switch to only the base model, disable all LoRAs with the [`~diffusers.loaders.disable_lora`] method.
137+
If you want to switch to only the base model, disable all LoRAs with the [`~diffusers.loaders.UNet2DConditionLoadersMixin.disable_lora`] method.
138138

139139

140140
```python
@@ -150,16 +150,18 @@ image
150150

151151
## Monitoring active adapters
152152

153-
You have attached multiple adapters in this tutorial, and if you're feeling a bit lost on what adapters have been attached to the pipeline's components, you can easily check the list of active adapters using the [`~diffusers.loaders.get_active_adapters`] method:
153+
You have attached multiple adapters in this tutorial, and if you're feeling a bit lost on what adapters have been attached to the pipeline's components, you can easily check the list of active adapters using the [`~diffusers.loaders.LoraLoaderMixin.get_active_adapters`] method:
154154

155-
```python
155+
```py
156156
active_adapters = pipe.get_active_adapters()
157-
>>> ["toy", "pixel"]
157+
active_adapters
158+
["toy", "pixel"]
158159
```
159160

160-
You can also get the active adapters of each pipeline component with [`~diffusers.loaders.get_list_adapters`]:
161+
You can also get the active adapters of each pipeline component with [`~diffusers.loaders.LoraLoaderMixin.get_list_adapters`]:
161162

162-
```python
163+
```py
163164
list_adapters_component_wise = pipe.get_list_adapters()
164-
>>> {"text_encoder": ["toy", "pixel"], "unet": ["toy", "pixel"], "text_encoder_2": ["toy", "pixel"]}
165+
list_adapters_component_wise
166+
{"text_encoder": ["toy", "pixel"], "unet": ["toy", "pixel"], "text_encoder_2": ["toy", "pixel"]}
165167
```

docs/source/en/using-diffusers/write_own_pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,5 @@ This is really what 🧨 Diffusers is designed for: to make it intuitive and eas
290290

291291
For your next steps, feel free to:
292292

293-
* Learn how to [build and contribute a pipeline](contribute_pipeline) to 🧨 Diffusers. We can't wait and see what you'll come up with!
293+
* Learn how to [build and contribute a pipeline](../using-diffusers/contribute_pipeline) to 🧨 Diffusers. We can't wait and see what you'll come up with!
294294
* Explore [existing pipelines](../api/pipelines/overview) in the library, and see if you can deconstruct and build a pipeline from scratch using the models and schedulers separately.

0 commit comments

Comments
 (0)