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
@@ -12,178 +12,110 @@ specific language governing permissions and limitations under the License.
12
12
13
13
# SequentialPipelineBlocks
14
14
15
-
<Tipwarning={true}>
15
+
[`SequentialPipelineBlocks`] are a multi-block type that composes other [`PipelineBlocks`] together in a sequence. Data flows linearly from one block to the next using `intermediate_inputs` and `intermediate_outputs`. Each block in [`SequentialPipelineBlocks`] usually represents a step in the pipeline, and by combining them, you gradually build a pipeline.
16
16
17
-
🧪 **Experimental Feature**: Modular Diffusers is an experimental feature we are actively developing. The API may be subject to breaking changes.
17
+
This guide shows you how to connect two blocks into a [`SequentialPipelineBlocks`].
18
18
19
-
</Tip>
19
+
Create two [`PipelineBlocks`]. The first block, `InputBlock`, outputs a `batch_size` value and the second block, `ImageEncoderBlock` uses `batch_size` as `intermediate_inputs`.
20
20
21
-
`SequentialPipelineBlocks` is a subclass of `ModularPipelineBlocks`. Unlike `PipelineBlock`, it is a multi-block that composes other blocks together in sequence, creating modular workflows where data flows from one block to the next. It's one of the most common ways to build complex pipelines by combining simpler building blocks.
22
-
23
-
<Tip>
24
-
25
-
Other types of multi-blocks include [AutoPipelineBlocks](auto_pipeline_blocks.md) (for conditional block selection) and [LoopSequentialPipelineBlocks](loop_sequential_pipeline_blocks.md) (for iterative workflows). For information on creating individual blocks, see the [PipelineBlock guide](pipeline_block.md).
26
-
27
-
Additionally, like all `ModularPipelineBlocks`, `SequentialPipelineBlocks` are definitions/specifications, not runnable pipelines. You need to convert them into a `ModularPipeline` to actually execute them. For information on creating and running pipelines, see the [Modular Pipeline guide](modular_pipeline.md).
28
-
29
-
</Tip>
30
-
31
-
In this tutorial, we will focus on how to create `SequentialPipelineBlocks` and how blocks connect and work together.
32
-
33
-
The key insight is that blocks connect through their intermediate inputs and outputs - the "studs and anti-studs" we discussed in the [PipelineBlock guide](pipeline_block.md). When one block produces an intermediate output, it becomes available as an intermediate input for subsequent blocks.
34
-
35
-
Let's explore this through an example. We will use the same helper function from the PipelineBlock guide to create blocks.
21
+
<hfoptionsid="sequential">
22
+
<hfoptionid="InputBlock">
36
23
37
24
```py
38
25
from diffusers.modular_pipelines import PipelineBlock, InputParam, OutputParam
InputParam(name="image", type_hint="PIL.Image", description="raw input image to process")
108
-
],
109
-
intermediate_inputs=[
110
-
InputParam(name="batch_size", type_hint=int)
111
-
],
112
-
intermediate_outputs=[
113
-
OutputParam(name="image_latents", description="latents representing the image")
114
-
],
115
-
block_fn=image_encoder_block_fn,
116
-
description="Encode raw image into its latent presentation"
117
-
)
118
-
image_encoder_block = image_encoder_block_cls()
119
-
```
102
+
Connect the two blocks by defining an [`InsertableDict`] to map the block names to the block instances. Blocks are executed in the order they're registered in `blocks_dict`.
120
103
121
-
Now let's connect these blocks to create a `SequentialPipelineBlocks`:
104
+
Use [`~SequentialPipelineBlocks.from_blocks_dict`]to create a [`SequentialPipelineBlocks`].
122
105
123
106
```py
124
107
from diffusers.modular_pipelines import SequentialPipelineBlocks, InsertableDict
125
108
126
-
# Define a dict mapping block names to block instances
Now you have a `SequentialPipelineBlocks` with 2 blocks:
116
+
Inspect the sub-blocks in [`SequentialPipelineBlocks`] by calling `blocks`, and for more details about the inputs and outputs, access the `docs` attribute.
136
117
137
118
```py
138
-
>>> blocks
139
-
SequentialPipelineBlocks(
140
-
Class: ModularPipelineBlocks
141
-
142
-
Description:
143
-
144
-
145
-
Sub-Blocks:
146
-
[0] input (TestBlock)
147
-
Description: A block that determines batch_size based on the number of prompts and num_images_per_prompt argument.
148
-
149
-
[1] image_encoder (TestBlock)
150
-
Description: Encode raw image into its latent presentation
151
-
152
-
)
153
-
```
154
-
155
-
When you inspect `blocks.doc`, you can see that `batch_size` is not listed as an input. The pipeline automatically detects that the `input_block` can produce `batch_size` for the `image_encoder_block`, so it doesn't ask the user to provide it.
1. Blocks are executed in the order they're registered in the `blocks_dict`
185
-
2. Outputs from one block become available as intermediate inputs to all subsequent blocks
186
-
3. The pipeline automatically figures out which values need to be provided by the user and which will be generated by previous blocks
187
-
4. Each block maintains its own behavior and operates through its defined interface, while collectively these interfaces determine what the entire pipeline accepts and produces
188
-
189
-
What happens within each block follows the same pattern we described earlier: each block gets its own `block_state` with the relevant inputs and intermediate inputs, performs its computation, and updates the pipeline state with its intermediate outputs.
0 commit comments