You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,43 +16,7 @@ Batch inference processes multiple prompts at a time to increase throughput. It
16
16
17
17
The downside is increased latency because you must wait for the entire batch to complete, and more GPU memory is required for large batches.
18
18
19
-
<hfoptionsid="usage">
20
-
<hfoptionid="text-to-image">
21
-
22
-
For text-to-image, pass a list of prompts to the pipeline.
23
-
24
-
```py
25
-
import torch
26
-
from diffusers import DiffusionPipeline
27
-
28
-
pipeline = DiffusionPipeline.from_pretrained(
29
-
"stabilityai/stable-diffusion-xl-base-1.0",
30
-
torch_dtype=torch.float16
31
-
).to("cuda")
32
-
33
-
prompts = [
34
-
"cinematic photo of A beautiful sunset over mountains, 35mm photograph, film, professional, 4k, highly detailed",
35
-
"cinematic film still of a cat basking in the sun on a roof in Turkey, highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain",
36
-
"pixel-art a cozy coffee shop interior, low-res, blocky, pixel art style, 8-bit graphics"
37
-
]
38
-
39
-
images = pipeline(
40
-
prompt=prompts,
41
-
).images
42
-
43
-
fig, axes = plt.subplots(2, 2, figsize=(12, 12))
44
-
axes = axes.flatten()
45
-
46
-
for i, image inenumerate(images):
47
-
axes[i].imshow(image)
48
-
axes[i].set_title(f"Image {i+1}")
49
-
axes[i].axis('off')
50
-
51
-
plt.tight_layout()
52
-
plt.show()
53
-
```
54
-
55
-
To generate multiple variations of one prompt, use the `num_images_per_prompt` argument.
19
+
For text-to-image, pass a list of prompts to the pipeline and for image-to-image, pass a list of images and prompts to the pipeline. The example below demonstrates batched text-to-image inference.
56
20
57
21
```py
58
22
import torch
@@ -61,78 +25,19 @@ from diffusers import DiffusionPipeline
61
25
62
26
pipeline = DiffusionPipeline.from_pretrained(
63
27
"stabilityai/stable-diffusion-xl-base-1.0",
64
-
torch_dtype=torch.float16
65
-
).to("cuda")
66
-
67
-
images = pipeline(
68
-
prompt="pixel-art a cozy coffee shop interior, low-res, blocky, pixel art style, 8-bit graphics",
69
-
num_images_per_prompt=4
70
-
).images
71
-
72
-
fig, axes = plt.subplots(2, 2, figsize=(12, 12))
73
-
axes = axes.flatten()
74
-
75
-
for i, image inenumerate(images):
76
-
axes[i].imshow(image)
77
-
axes[i].set_title(f"Image {i+1}")
78
-
axes[i].axis('off')
79
-
80
-
plt.tight_layout()
81
-
plt.show()
82
-
```
83
-
84
-
Combine both approaches to generate different variations of different prompts.
85
-
86
-
```py
87
-
images = pipeline(
88
-
prompt=prompts,
89
-
num_images_per_prompt=2,
90
-
).images
91
-
92
-
fig, axes = plt.subplots(2, 2, figsize=(12, 12))
93
-
axes = axes.flatten()
94
-
95
-
for i, image inenumerate(images):
96
-
axes[i].imshow(image)
97
-
axes[i].set_title(f"Image {i+1}")
98
-
axes[i].axis('off')
99
-
100
-
plt.tight_layout()
101
-
plt.show()
102
-
```
103
-
104
-
</hfoption>
105
-
<hfoptionid="image-to-image">
106
-
107
-
For image-to-image, pass a list of input images and prompts to the pipeline.
"cinematic photo of a beautiful sunset over mountains, 35mm photograph, film, professional, 4k, highly detailed",
127
-
"cinematic film still of a cat basking in the sun on a roof in Turkey, highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain",
128
-
"pixel-art a cozy coffee shop interior, low-res, blocky, pixel art style, 8-bit graphics"
33
+
"Cinematic shot of a cozy coffee shop interior, warm pastel light streaming through a window where a cat rests. Shallow depth of field, glowing cups in soft focus, dreamy lofi-inspired mood, nostalgic tones, framed like a quiet film scene.",
34
+
"Polaroid-style photograph of a cozy coffee shop interior, bathed in warm pastel light. A cat sits on the windowsill near steaming mugs. Soft, slightly faded tones and dreamy blur evoke nostalgia, a lofi mood, and the intimate, imperfect charm of instant film.",
35
+
"Soft watercolor illustration of a cozy coffee shop interior, pastel washes of color filling the space. A cat rests peacefully on the windowsill as warm light glows through. Gentle brushstrokes create a dreamy, lofi-inspired atmosphere with whimsical textures and nostalgic calm.",
36
+
"Isometric pixel-art illustration of a cozy coffee shop interior in detailed 8-bit style. Warm pastel light fills the space as a cat rests on the windowsill. Blocky furniture and tiny mugs add charm, low-res retro graphics enhance the nostalgic, lofi-inspired game aesthetic."
"cinematic film still of a cat basking in the sun on a roof in Turkey, highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain",
193
-
"pixel-art a cozy coffee shop interior, low-res, blocky, pixel art style, 8-bit graphics"
Enable reproducible batch generation by passing a list of [Generator’s](https://pytorch.org/docs/stable/generated/torch.Generator.html) to the pipeline and tie each `Generator` to a seed to reuse it.
220
126
221
-
Use a list comprehension to iterate over the batch size specified in `range()` to create a unique `Generator` object for each image in the batch.
127
+
> [!TIP]
128
+
> Refer to the [Reproducibility](./reusing_seeds) docs to learn more about deterministic algorithms and the `Generator` object.
222
129
223
-
Don't multiply the `Generator` by the batch size because that only creates one `Generator` object that is used sequentially for each image in the batch.
130
+
Use a list comprehension to iterate over the batch size specified in `range()` to create a unique `Generator` object for each image in the batch. Don't multiply the `Generator` by the batch size because that only creates one `Generator` object that is used sequentially for each image in the batch.
@@ -234,14 +141,16 @@ from diffusers import DiffusionPipeline
234
141
235
142
pipeline = DiffusionPipeline.from_pretrained(
236
143
"stabilityai/stable-diffusion-xl-base-1.0",
237
-
torch_dtype=torch.float16
238
-
).to("cuda")
144
+
torch_dtype=torch.float16,
145
+
device_map="cuda"
146
+
)
239
147
240
148
generator = [torch.Generator(device="cuda").manual_seed(i) for i inrange(3)]
241
149
prompts = [
242
-
"cinematic photo of A beautiful sunset over mountains, 35mm photograph, film, professional, 4k, highly detailed",
243
-
"cinematic film still of a cat basking in the sun on a roof in Turkey, highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain",
244
-
"pixel-art a cozy coffee shop interior, low-res, blocky, pixel art style, 8-bit graphics"
150
+
"Cinematic shot of a cozy coffee shop interior, warm pastel light streaming through a window where a cat rests. Shallow depth of field, glowing cups in soft focus, dreamy lofi-inspired mood, nostalgic tones, framed like a quiet film scene.",
151
+
"Polaroid-style photograph of a cozy coffee shop interior, bathed in warm pastel light. A cat sits on the windowsill near steaming mugs. Soft, slightly faded tones and dreamy blur evoke nostalgia, a lofi mood, and the intimate, imperfect charm of instant film.",
152
+
"Soft watercolor illustration of a cozy coffee shop interior, pastel washes of color filling the space. A cat rests peacefully on the windowsill as warm light glows through. Gentle brushstrokes create a dreamy, lofi-inspired atmosphere with whimsical textures and nostalgic calm.",
153
+
"Isometric pixel-art illustration of a cozy coffee shop interior in detailed 8-bit style. Warm pastel light fills the space as a cat rests on the windowsill. Blocky furniture and tiny mugs add charm, low-res retro graphics enhance the nostalgic, lofi-inspired game aesthetic."
245
154
]
246
155
247
156
images = pipeline(
@@ -261,4 +170,4 @@ plt.tight_layout()
261
170
plt.show()
262
171
```
263
172
264
-
You can use this to iteratively select an image associated with a seed and then improve on it by crafting a more detailed prompt.
173
+
You can use this to select an image associated with a seed and iteratively improve on it by crafting a more detailed prompt.
Copy file name to clipboardExpand all lines: docs/source/en/using-diffusers/weighted_prompts.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,9 +22,9 @@ This guide covers general best practices for writing prompts and introduce a few
22
22
23
23
A good prompt foundation should include the following elements.
24
24
25
-
1. <spanclass="underline decoration-wavy decoration-blue-500 decoration-2 underline-offset-4">Subject</span> is what you want to generate an image or video of. It is the main focus and you should generally begin your prompt with the subject.
26
-
2. <spanclass="underline decoration-wavy decoration-purple-500 decoration-2 underline-offset-4">Style</span> describes the medium or aesthetic of the image or video. What do you want it to look like?
27
-
3. <spanclass="underline decoration-wavy decoration-green-500 decoration-2 underline-offset-4">Context</span> adds details to the image or video. For example, what is the subject doing and what is the setting and mood?
25
+
1. <spanclass="underline decoration-sky-500 decoration-2 underline-offset-4">Subject</span> is what you want to generate an image or video of. It is the main focus and you should generally begin your prompt with the subject.
26
+
2. <spanclass="underline decoration-pink-500 decoration-2 underline-offset-4">Style</span> describes the medium or aesthetic of the image or video. What do you want it to look like?
27
+
3. <spanclass="underline decoration-green-500 decoration-2 underline-offset-4">Context</span> adds details to the image or video. For example, what is the subject doing and what is the setting and mood?
28
28
29
29
Combine these elements into a structured narrative instead of a list of keywords. Modern models have powerful text encoders that have better language understanding. Start with a short prompt, and then iterate on it.
30
30
@@ -33,7 +33,7 @@ To generate an even better image, enhance the prompt with additional details suc
<figcaption class="mt-2 text-sm text-gray-500">A <span class="underline decoration-wavy decoration-blue-500 decoration-2 underline-offset-1">cute cat</span> <span class="underline decoration-wavy decoration-green-500 decoration-2 underline-offset-1">lounges on a leaf in a pool during a peaceful summer afternoon</span>, in <span class="underline decoration-wavy decoration-purple-500 decoration-2 underline-offset-1">lofi art style, illustration</span>.</figcaption>
36
+
<figcaption class="mt-2 text-sm text-gray-500">A <span class="underline decoration-sky-500 decoration-2 underline-offset-1">cute cat</span> <span class="underline decoration-pink-500 decoration-2 underline-offset-1">lounges on a leaf in a pool during a peaceful summer afternoon</span>, in <span class="underline decoration-green-500 decoration-2 underline-offset-1">lofi art style, illustration</span>.</figcaption>
0 commit comments