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
Copy file name to clipboardExpand all lines: docs/source/en/modular_diffusers/overview.md
+61-54Lines changed: 61 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ specific language governing permissions and limitations under the License.
12
12
13
13
# Overview
14
14
15
-
The Modular Diffusers Framework consist of three main components
15
+
The Modular Diffusers Framework consists of three main components:
16
16
17
17
## ModularPipelineBlocks
18
18
@@ -23,35 +23,37 @@ Pipeline blocks are the fundamental building blocks of the Modular Diffusers sys
23
23
-[`AutoPipelineBlocks`](TODO)
24
24
25
25
26
-
Each block defines:
27
-
28
-
**Specifications:**
29
-
- Inputs: User-provided parameters that the block expects
30
-
- Intermediate inputs: Variables from other blocks that this block needs
31
-
- Intermediate outputs: Variables this block produces for other blocks to use
32
-
- Components: Models and processors the block requires (e.g., UNet, VAE, scheduler)
33
-
34
-
**Computation:**
35
-
-`__call__` method: Defines the actual computational steps within the block
36
-
37
-
Pipeline blocks are essentially **"definitions"** - they define the specifications and computational steps for a pipeline, but are not runnable until converted into a `ModularPipeline` object.
38
-
39
-
All blocks interact with a global `PipelineState` object that maintains the pipeline's state throughout execution.
40
-
41
-
### Load/save a custom `ModularPipelineBlocks`
42
-
43
-
You can load a custom pipeline block from a hub repository directly
44
-
26
+
To use a `ModularPipelineBlocks` officially supported in 🧨 Diffusers
Each [`ModularPipelineBlocks`] defines its requirement for components, configs, inputs, intermediate inputs, and outputs. You'll see that this text encoder block uses text_encoders, tokenizers as well as a guider component. It takes user inputs such as `prompt` and `negative_prompt`, and return a list of conditional text embeddings.
51
33
52
-
```py
53
-
diffdiff_block.save(repo_id)
54
34
```
35
+
>>> text_encoder_block
36
+
StableDiffusionXLTextEncoderStep(
37
+
Class: PipelineBlock
38
+
Description: Text Encoder step that generate text_embeddings to guide the image generation
Pipeline blocks are essentially **"definitions"** - they define the specifications and computational steps for a pipeline. However, they do not contain any model states, and are not runnable until converted into a `ModularPipeline` object.
55
+
56
+
Read more about how to write your own `ModularPipelineBlocks`[here](TODO)
55
57
56
58
## PipelineState & BlockState
57
59
@@ -67,15 +69,9 @@ You typically don't need to manually create or manage these state objects. The `
67
69
68
70
`ModularPipeline` is the main interface to create and execute pipelines in the Modular Diffusers system.
69
71
70
-
### Create a `ModularPipeline`
72
+
### Modular Repo
71
73
72
-
Each `ModularPipelineBlocks` has an `init_pipeline` method that can initialize a `ModularPipeline` object based on its component and configuration specifications.
`ModularPipeline` only works with modular repositories, so make sure `pretrained_model_name_or_path` points to a modular repo (you can see an example [here](https://huggingface.co/YiYiXu/modular-diffdiff)).
74
+
`ModularPipeline` only works with modular repositories. You can find an example modular repo [here](https://huggingface.co/YiYiXu/modular-diffdiff).
79
75
80
76
The main differences from standard diffusers repositories are:
81
77
@@ -93,7 +89,7 @@ In standard `model_index.json`, each component entry is a `(library, class)` tup
93
89
In `modular_model_index.json`, each component entry contains 3 elements: `(library, class, loading_specs {})`
94
90
95
91
-`library` and `class`: Information about the actual component loaded in the pipeline at the time of saving (can be `None` if not loaded)
96
-
-**`loading_specs`**: A dictionary containing all information required to load this component, including `repo`, `revision`, `subfolder`, `variant`, and `type_hint`
92
+
-`loading_specs`: A dictionary containing all information required to load this component, including `repo`, `revision`, `subfolder`, `variant`, and `type_hint`
97
93
98
94
```py
99
95
"text_encoder": [
@@ -114,7 +110,16 @@ In `modular_model_index.json`, each component entry contains 3 elements: `(libra
114
110
115
111
2. Cross-Repository Component Loading
116
112
117
-
Unlike standard repositories where components must be in subfolders within the same repo, modular repositories can fetch components from different repositories based on the `loading_specs` dictionary. In our example above, the `text_encoder` component will be fetched from the "text_encoder" folder in `stabilityai/stable-diffusion-xl-base-1.0` while other components come from different repositories.
113
+
Unlike standard repositories where components must be in subfolders within the same repo, modular repositories can fetch components from different repositories based on the `loading_specs` dictionary. e.g. the `text_encoder` component will be fetched from the "text_encoder" folder in `stabilityai/stable-diffusion-xl-base-1.0` while other components come from different repositories.
114
+
115
+
116
+
### Create a `ModularPipeline` from `ModularPipelineBlocks`
117
+
118
+
Each `ModularPipelineBlocks` has an `init_pipeline` method that can initialize a `ModularPipeline` object based on its component and configuration specifications.
1. You can also pass a `PipelineState` object directly to the pipeline instead of individual arguments
168
-
2. If you do not specify the `output` argument, it returns the `PipelineState` object
169
-
3. You can pass a list as `output`, e.g. `pipeline(... output=["images", "latents"])` will return a dictionary containing both the generated image and the final denoised latents
170
+
Loading custom code is also supported:
170
171
171
-
Under the hood, `ModularPipeline`'s `__call__` method is a wrapper around the pipeline blocks' `__call__` method: it creates a `PipelineState` object and populates it with user inputs, then returns the output to the user based on the `output` argument. It also ensures that all pipeline-level config and components are exposed to all pipeline blocks by preparing and passing a `components` input.
Similar to `init_pipeline` method, the modular pipeline will not load any components automatically, so you will have to call `load_components` to explicitly load the components you need.
174
177
175
-
You can directly load a `ModularPipeline` from a HuggingFace Hub repository, as long as it's a modular repo
The ModularPipeine created with `from_pretrained` method also would not load any components and you would have to call `load_components` to explicitly load components you need.
187
+
There are a few key differences though:
188
+
1. You can also pass a `PipelineState` object directly to the pipeline instead of individual arguments
189
+
2. If you do not specify the `output` argument, it returns the `PipelineState` object
190
+
3. You can pass a list as `output`, e.g. `pipeline(... output=["images", "latents"])` will return a dictionary containing both the generated image and the final denoised latents
191
+
192
+
Under the hood, `ModularPipeline`'s `__call__` method is a wrapper around the pipeline blocks' `__call__` method: it creates a `PipelineState` object and populates it with user inputs, then returns the output to the user based on the `output` argument. It also ensures that all pipeline-level config and components are exposed to all pipeline blocks by preparing and passing a `components` input.
188
193
189
194
190
195
### Save a `ModularPipeline`
191
196
192
-
to save a `ModularPipeline` and publish it to hub
197
+
To save a `ModularPipeline` and publish it to hub:
We do not automatically save custom code and share it on hub for you, please read more about how to share your custom pipeline on hub [here](TODO: ModularPipeline/CustomCode)
205
+
We do not automatically save custom code and share it on hub for you. Please read more about how to share your custom pipeline on hub [here](TODO: ModularPipeline/CustomCode)
0 commit comments