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
# Trigger inputs that determine which block to run
128
128
# - "mask" triggers inpaint workflow
129
129
# - "image" triggers img2img workflow (but only if mask is not provided)
130
130
# - if none of above, runs the text2img workflow (default)
131
131
block_trigger_inputs = ["mask", "image", None]
132
-
# Description is extremely important for AutoPipelineBlocks
133
132
133
+
@property
134
134
defdescription(self):
135
135
return (
136
136
"Pipeline generates images given different types of conditions!\n"
@@ -141,7 +141,7 @@ class AutoImageBlocks(AutoPipelineBlocks):
141
141
)
142
142
```
143
143
144
-
It is **very** important to include a `description` to avoid any confusion over how to run a block and what inputs are required. While [`~modular_pipelines.AutoPipelineBlocks`] are convenient, it's conditional logic may be difficult to figure out if it isn't properly explained.
144
+
It is **very** important to include a `description` to avoid any confusion over how to run a block and what inputs are required. While [`~modular_pipelines.AutoPipelineBlocks`] are convenient, its conditional logic may be difficult to figure out if it isn't properly explained.
For more complex compositions, such as nested [`~modular_pipelines.AutoPipelineBlocks`] blocks when they're used as sub-blocks in larger pipelines, use the [`~modular_pipelines.SequentialPipelineBlocks.get_execution_blocks`] method to extract the a block that is actually run based on your input.
153
153
154
154
```py
155
-
auto_blocks.get_execution_blocks("mask")
155
+
auto_blocks.get_execution_blocks(mask=True)
156
+
```
157
+
158
+
## ConditionalPipelineBlocks
159
+
160
+
[`~modular_pipelines.AutoPipelineBlocks`] is a special case of [`~modular_pipelines.ConditionalPipelineBlocks`]. While [`~modular_pipelines.AutoPipelineBlocks`] selects blocks based on whether a trigger input is provided or not, [`~modular_pipelines.ConditionalPipelineBlocks`] is able to select a block based on custom selection logic provided in the `select_block` method.
161
+
162
+
Here is the same example written using [`~modular_pipelines.ConditionalPipelineBlocks`] directly:
163
+
164
+
```py
165
+
from diffusers.modular_pipelines import ConditionalPipelineBlocks
returnNone# falls back to default_block_name ("text2img")
189
+
```
190
+
191
+
The inputs listed in `block_trigger_inputs` are passed as keyword arguments to `select_block()`. When `select_block` returns `None`, it falls back to `default_block_name`. If `default_block_name` is also `None`, the entire conditional block is skipped — this is useful for optional processing steps that should only run when specific inputs are provided.
192
+
193
+
## Workflows
194
+
195
+
Pipelines that contain conditional blocks ([`~modular_pipelines.AutoPipelineBlocks`] or [`~modular_pipelines.ConditionalPipelineBlocks]`) can support multiple workflows — for example, our SDXL modular pipeline supports a dozen workflows all in one pipeline. But this also means it can be confusing for users to know what workflows are supported and how to run them. For pipeline builders, it's useful to be able to extract only the blocks relevant to a specific workflow.
196
+
197
+
We recommend defining a `_workflow_map` to give each workflow a name and explicitly list the inputs it requires.
198
+
199
+
```py
200
+
from diffusers.modular_pipelines import SequentialPipelineBlocks
0 commit comments