Skip to content

Commit 10b84fe

Browse files
committed
state, pipelineblock, apis
1 parent 5ffc8de commit 10b84fe

File tree

6 files changed

+140
-246
lines changed

6 files changed

+140
-246
lines changed

docs/source/en/_toctree.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,20 @@
116116
title: Quickstart
117117
- local: modular_diffusers/end_to_end_guide
118118
title: End-to-end example
119-
- local: modular_diffusers/modular_pipeline
120-
title: Modular Pipeline
121-
- local: modular_diffusers/components_manager
122-
title: Components Manager
123119
- local: modular_diffusers/modular_diffusers_states
124-
title: Modular Diffusers States
120+
title: Block states
125121
- local: modular_diffusers/pipeline_block
126-
title: Pipeline Block
122+
title: PipelineBlock
127123
- local: modular_diffusers/sequential_pipeline_blocks
128-
title: Sequential Pipeline Blocks
124+
title: SequentialPipelineBlocks
129125
- local: modular_diffusers/loop_sequential_pipeline_blocks
130-
title: Loop Sequential Pipeline Blocks
126+
title: LoopSequentialPipelineBlocks
131127
- local: modular_diffusers/auto_pipeline_blocks
132-
title: Auto Pipeline Blocks
128+
title: AutoPipelineBlocks
129+
- local: modular_diffusers/modular_pipeline
130+
title: ModularPipeline
131+
- local: modular_diffusers/components_manager
132+
title: Components Manager
133133
title: Modular Diffusers
134134
- sections:
135135
- local: using-diffusers/consisid
@@ -299,6 +299,13 @@
299299
isExpanded: false
300300
sections:
301301
- title: Main Classes
302+
sections:
303+
- local: api/modular_diffusers/pipeline_blocks
304+
title: Pipeline blocks
305+
- local: api/modular_diffusers/pipeline_states
306+
title: Pipeline states
307+
title: Modular Diffusers
308+
- isExpanded: false
302309
sections:
303310
- local: api/configuration
304311
title: Configuration
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Pipeline blocks
2+
3+
## ModularPipelineBlocks
4+
5+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks
6+
7+
## PipelineBlock
8+
9+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.PipelineBlock
10+
11+
## SequentialPipelineBlocks
12+
13+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.SequentialPipelineBlocks
14+
15+
## LoopSequentialPipelineBlocks
16+
17+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.LoopSequentialPipelineBlocks
18+
19+
## AutoPipelineBlocks
20+
21+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.AutoPipelineBlocks
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Components and configs
2+
3+
## ComponentSpec
4+
5+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.ComponentSpec
6+
7+
## ConfigSpec
8+
9+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.ConfigSpec
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Pipeline states
2+
3+
## PipelineState
4+
5+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.PipelineState
6+
7+
## BlockState
8+
9+
[[autodoc]] diffusers.modular_pipelines.modular_pipeline.BlockState

docs/source/en/modular_diffusers/modular_diffusers_states.md

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ 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-
# PipelineState and BlockState
13+
# Block states
1414

15-
<Tip warning={true}>
15+
Blocks rely on the [`PipelineState`] and [`BlockState`] data structures for communicating and sharing data.
1616

17-
🧪 **Experimental Feature**: Modular Diffusers is an experimental feature we are actively developing. The API may be subject to breaking changes.
17+
| State | Description |
18+
|-------|-------------|
19+
| `PipelineState` | Maintains the overall data required for a pipeline's execution and allows blocks to read and update its data. |
20+
| `BlockState` | Allows each block to perform its computation with the necessary data from `inputs` and `intermediate_inputs` |
1821

19-
</Tip>
22+
This guide explains how states work and how they connect blocks.
2023

21-
In Modular Diffusers, `PipelineState` and `BlockState` are the core data structures that enable blocks to communicate and share data. The concept is fundamental to understand how blocks interact with each other and the pipeline system.
24+
## PipelineState
2225

23-
In the modular diffusers system, `PipelineState` acts as the global state container that all pipeline blocks operate on. It maintains the complete runtime state of the pipeline and provides a structured way for blocks to read from and write to shared data.
26+
The [`PipelineState`] is a global state container for all pipeline blocks. It maintains the complete runtime state of the pipeline and provides a structured way for blocks to read from and write to shared data.
2427

25-
A `PipelineState` consists of two distinct states:
28+
There are two dict's in [`PipelineState`] for structuring data.
2629

27-
- **The immutable state** (i.e. the `inputs` dict) contains a copy of values provided by users. Once a value is added to the immutable state, it cannot be changed. Blocks can read from the immutable state but cannot write to it.
28-
29-
- **The mutable state** (i.e. the `intermediates` dict) contains variables that are passed between blocks and can be modified by them.
30-
31-
Here's an example of what a `PipelineState` looks like:
30+
- The `inputs` dict is an **immutable** state containing a copy of user provided values. A value added to `inputs` cannot be changed. Blocks can read from `inputs` but cannot write to it.
31+
- The `intermediates` dict is a **mutable** state containing variables that are passed between blocks and can be modified by them.
3232

3333
```py
3434
PipelineState(
@@ -44,16 +44,41 @@ PipelineState(
4444
)
4545
```
4646

47-
Each pipeline blocks define what parts of that state they can read from and write to through their `inputs`, `intermediate_inputs`, and `intermediate_outputs` properties. At run time, they gets a local view (`BlockState`) of the relevant variables it needs from `PipelineState`, performs its operations, and then updates `PipelineState` with any changes.
47+
## BlockState
48+
49+
The [`BlockState`] is a local view of the relevant variables, `inputs` and `intermediate_inputs`, that an individual pipeline block needs from [`PipelineState`] for performing it's computations.
4850

49-
For example, if a block defines an input `image`, inside the block's `__call__` method, the `BlockState` would contain:
51+
You can access these variables directly as attributes like `block_state.image`.
5052

5153
```py
5254
BlockState(
5355
image: <PIL.Image.Image image mode=RGB size=512x512 at 0x7F3ECC494640>
5456
)
5557
```
5658

57-
You can access the variables directly as attributes: `block_state.image`.
59+
When a block's `__call__` method is executed, it retrieves the [`BlockState`] with `self.get_block_state(state)`, performs it's operations, and updates [`PipelineState`] with `self.set_block_state(state, block_state)`.
60+
61+
```py
62+
def __call__(self, components, state):
63+
# retrieve BlockState
64+
block_state = self.get_block_state(state)
65+
66+
# computation logic on inputs and intermediate_inputs
67+
68+
# update PipelineState
69+
self.set_block_state(state, block_state)
70+
return components, state
71+
```
72+
73+
## State interaction
74+
75+
[`PipelineState`] and [`BlockState`] interaction is defined by a block's `inputs`, `intermediate_inputs`, and `intermediate_outputs`.
76+
77+
- `inputs`, a block can modify an input - like `block_state.image` - but the change is local to the [`BlockState`] and won't affect the original image in [`PipelineState`].
78+
- `intermediate_inputs`, is often values created from a previous block. When a block modifies `intermediate_inputs` - like `batch_size` - this change is reflected in both the [`BlockState`] and [`PipelineState`]. Any subsequent blocks are also affected.
79+
80+
If a previous block doesn't provide an `intermediate_inputs`, then the pipeline makes it available as a user input. However, the value is still a mutable intermediate state.
81+
82+
- `intermediate_outputs`, is a new variable that a block creates from `intermediate_inputs`. It is added to the [`PipelineState`]'s `intermediates` dict and available as an `intermediate_inputs` for subsequent blocks or accessed by users as a final output from the pipeline.
5883

59-
We will explore more on how blocks interact with pipeline state through their `inputs`, `intermediate_inputs`, and `intermediate_outputs` properties, see the [PipelineBlock guide](./pipeline_block.md).
84+
If a variable is modified in `block_state` but not declared as an `intermediate_outputs`, it won't be added to [`PipelineState`].

0 commit comments

Comments
 (0)