mirror of
https://github.com/huggingface/diffusers.git
synced 2025-12-12 15:34:17 +08:00
Compare commits
2 Commits
pipeline-s
...
modular-do
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d9c5a8d3a | ||
|
|
d6f66f4946 |
@@ -12,7 +12,7 @@ specific language governing permissions and limitations under the License.
|
|||||||
|
|
||||||
# LoopSequentialPipelineBlocks
|
# LoopSequentialPipelineBlocks
|
||||||
|
|
||||||
[`~modular_pipelines.LoopSequentialPipelineBlocks`] are a multi-block type that composes other [`~modular_pipelines.ModularPipelineBlocks`] together in a loop. Data flows circularly, using `intermediate_inputs` and `intermediate_outputs`, and each block is run iteratively. This is typically used to create a denoising loop which is iterative by default.
|
[`~modular_pipelines.LoopSequentialPipelineBlocks`] are a multi-block type that composes other [`~modular_pipelines.ModularPipelineBlocks`] together in a loop. Data flows circularly, using `inputs` and `intermediate_outputs`, and each block is run iteratively. This is typically used to create a denoising loop which is iterative by default.
|
||||||
|
|
||||||
This guide shows you how to create [`~modular_pipelines.LoopSequentialPipelineBlocks`].
|
This guide shows you how to create [`~modular_pipelines.LoopSequentialPipelineBlocks`].
|
||||||
|
|
||||||
@@ -21,7 +21,6 @@ This guide shows you how to create [`~modular_pipelines.LoopSequentialPipelineBl
|
|||||||
[`~modular_pipelines.LoopSequentialPipelineBlocks`], is also known as the *loop wrapper* because it defines the loop structure, iteration variables, and configuration. Within the loop wrapper, you need the following variables.
|
[`~modular_pipelines.LoopSequentialPipelineBlocks`], is also known as the *loop wrapper* because it defines the loop structure, iteration variables, and configuration. Within the loop wrapper, you need the following variables.
|
||||||
|
|
||||||
- `loop_inputs` are user provided values and equivalent to [`~modular_pipelines.ModularPipelineBlocks.inputs`].
|
- `loop_inputs` are user provided values and equivalent to [`~modular_pipelines.ModularPipelineBlocks.inputs`].
|
||||||
- `loop_intermediate_inputs` are intermediate variables from the [`~modular_pipelines.PipelineState`] and equivalent to [`~modular_pipelines.ModularPipelineBlocks.intermediate_inputs`].
|
|
||||||
- `loop_intermediate_outputs` are new intermediate variables created by the block and added to the [`~modular_pipelines.PipelineState`]. It is equivalent to [`~modular_pipelines.ModularPipelineBlocks.intermediate_outputs`].
|
- `loop_intermediate_outputs` are new intermediate variables created by the block and added to the [`~modular_pipelines.PipelineState`]. It is equivalent to [`~modular_pipelines.ModularPipelineBlocks.intermediate_outputs`].
|
||||||
- `__call__` method defines the loop structure and iteration logic.
|
- `__call__` method defines the loop structure and iteration logic.
|
||||||
|
|
||||||
|
|||||||
@@ -37,17 +37,7 @@ A [`~modular_pipelines.ModularPipelineBlocks`] requires `inputs`, and `intermedi
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
- `intermediate_inputs` are values typically created from a previous block but it can also be directly provided if no preceding block generates them. Unlike `inputs`, `intermediate_inputs` can be modified.
|
- `intermediate_outputs` are new values created by a block and added to the [`~modular_pipelines.PipelineState`]. The `intermediate_outputs` are available as `inputs` for subsequent blocks or available as the final output from running the pipeline.
|
||||||
|
|
||||||
Use `InputParam` to define `intermediate_inputs`.
|
|
||||||
|
|
||||||
```py
|
|
||||||
user_intermediate_inputs = [
|
|
||||||
InputParam(name="processed_image", type_hint="torch.Tensor", description="image that has been preprocessed and normalized"),
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
- `intermediate_outputs` are new values created by a block and added to the [`~modular_pipelines.PipelineState`]. The `intermediate_outputs` are available as `intermediate_inputs` for subsequent blocks or available as the final output from running the pipeline.
|
|
||||||
|
|
||||||
Use `OutputParam` to define `intermediate_outputs`.
|
Use `OutputParam` to define `intermediate_outputs`.
|
||||||
|
|
||||||
@@ -65,8 +55,8 @@ The intermediate inputs and outputs share data to connect blocks. They are acces
|
|||||||
|
|
||||||
The computation a block performs is defined in the `__call__` method and it follows a specific structure.
|
The computation a block performs is defined in the `__call__` method and it follows a specific structure.
|
||||||
|
|
||||||
1. Retrieve the [`~modular_pipelines.BlockState`] to get a local view of the `inputs` and `intermediate_inputs`.
|
1. Retrieve the [`~modular_pipelines.BlockState`] to get a local view of the `inputs`
|
||||||
2. Implement the computation logic on the `inputs` and `intermediate_inputs`.
|
2. Implement the computation logic on the `inputs`.
|
||||||
3. Update [`~modular_pipelines.PipelineState`] to push changes from the local [`~modular_pipelines.BlockState`] back to the global [`~modular_pipelines.PipelineState`].
|
3. Update [`~modular_pipelines.PipelineState`] to push changes from the local [`~modular_pipelines.BlockState`] back to the global [`~modular_pipelines.PipelineState`].
|
||||||
4. Return the components and state which becomes available to the next block.
|
4. Return the components and state which becomes available to the next block.
|
||||||
|
|
||||||
@@ -76,7 +66,7 @@ def __call__(self, components, state):
|
|||||||
block_state = self.get_block_state(state)
|
block_state = self.get_block_state(state)
|
||||||
|
|
||||||
# Your computation logic here
|
# Your computation logic here
|
||||||
# block_state contains all your inputs and intermediate_inputs
|
# block_state contains all your inputs
|
||||||
# Access them like: block_state.image, block_state.processed_image
|
# Access them like: block_state.image, block_state.processed_image
|
||||||
|
|
||||||
# Update the pipeline state with your updated block_states
|
# Update the pipeline state with your updated block_states
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ from diffusers.modular_pipelines import ComponentsManager
|
|||||||
components = ComponentManager()
|
components = ComponentManager()
|
||||||
|
|
||||||
dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", components_manager=components, collection="diffdiff")
|
dd_pipeline = dd_blocks.init_pipeline("YiYiXu/modular-demo-auto", components_manager=components, collection="diffdiff")
|
||||||
dd_pipeline.load_default_componenets(torch_dtype=torch.float16)
|
dd_pipeline.load_componenets(torch_dtype=torch.float16)
|
||||||
dd_pipeline.to("cuda")
|
dd_pipeline.to("cuda")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ specific language governing permissions and limitations under the License.
|
|||||||
|
|
||||||
# SequentialPipelineBlocks
|
# SequentialPipelineBlocks
|
||||||
|
|
||||||
[`~modular_pipelines.SequentialPipelineBlocks`] are a multi-block type that composes other [`~modular_pipelines.ModularPipelineBlocks`] together in a sequence. Data flows linearly from one block to the next using `intermediate_inputs` and `intermediate_outputs`. Each block in [`~modular_pipelines.SequentialPipelineBlocks`] usually represents a step in the pipeline, and by combining them, you gradually build a pipeline.
|
[`~modular_pipelines.SequentialPipelineBlocks`] are a multi-block type that composes other [`~modular_pipelines.ModularPipelineBlocks`] together in a sequence. Data flows linearly from one block to the next using `inputs` and `intermediate_outputs`. Each block in [`~modular_pipelines.SequentialPipelineBlocks`] usually represents a step in the pipeline, and by combining them, you gradually build a pipeline.
|
||||||
|
|
||||||
This guide shows you how to connect two blocks into a [`~modular_pipelines.SequentialPipelineBlocks`].
|
This guide shows you how to connect two blocks into a [`~modular_pipelines.SequentialPipelineBlocks`].
|
||||||
|
|
||||||
Create two [`~modular_pipelines.ModularPipelineBlocks`]. The first block, `InputBlock`, outputs a `batch_size` value and the second block, `ImageEncoderBlock` uses `batch_size` as `intermediate_inputs`.
|
Create two [`~modular_pipelines.ModularPipelineBlocks`]. The first block, `InputBlock`, outputs a `batch_size` value and the second block, `ImageEncoderBlock` uses `batch_size` as `inputs`.
|
||||||
|
|
||||||
<hfoptions id="sequential">
|
<hfoptions id="sequential">
|
||||||
<hfoption id="InputBlock">
|
<hfoption id="InputBlock">
|
||||||
|
|||||||
Reference in New Issue
Block a user