Skip to content

Commit c919ec0

Browse files
yiyixuxugithub-actions[bot]sayakpaulyiyi@huggingface.coyiyi@huggingface.co
authored
[Modular] add explicit workflow support (#13028)
* up * up up * update outputs * style * add modular_auto_docstring! * more auto docstring * style * up up up * more more * up * address feedbacks * add TODO in the description for empty docstring * refactor based on dhruv's feedback: remove the class method * add template method * up * up up up * apply auto docstring * make style * rmove space in make docstring * Apply suggestions from code review * revert change in z * fix * Apply style fixes * include auto-docstring check in the modular ci. (#13004) * initial support: workflow * up up * treeat loop sequential pipeline blocks as leaf * update qwen image docstring note * add workflow support for sdxl * add a test suit * add test for qwen-image * refactor flux a bit, seperate modular_blocks into modular_blocks_flux and modular_blocks_flux_kontext + support workflow * refactor flux2: seperate blocks for klein_base + workflow * qwen: remove import support for stuff other than the default blocks * add workflow support for wan * sdxl: remove some imports: * refactor z * update flux2 auto core denoise * add workflow test for z and flux2 * Apply suggestions from code review * Apply suggestions from code review * add test for flux * add workflow test for flux * add test for flux-klein * sdxl: modular_blocks.py -> modular_blocks_stable_diffusion_xl.py * style * up * add auto docstring * workflow_names -> available_workflows * fix workflow test for klein base * Apply suggestions from code review Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * fix workflow tests * qwen: edit -> image_conditioned to be consistent with flux kontext/2 such * remove Optional * update type hints * update guider update_components * fix more * update docstring auto again --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: yiyi@huggingface.co <yiyi@ip-26-0-160-103.ec2.internal> Co-authored-by: yiyi@huggingface.co <yiyi@ip-26-0-161-123.ec2.internal> Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
1 parent 3c7506b commit c919ec0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4267
-1478
lines changed

docs/source/en/modular_diffusers/guiders.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,15 @@ t2i_pipeline.guider
8989

9090
## Changing guider parameters
9191

92-
The guider parameters can be adjusted with either the [`~ComponentSpec.create`] method or with [`~ModularPipeline.update_components`]. The example below changes the `guidance_scale` value.
92+
The guider parameters can be adjusted with the [`~ComponentSpec.create`] method and [`~ModularPipeline.update_components`]. The example below changes the `guidance_scale` value.
9393

94-
<hfoptions id="switch">
95-
<hfoption id="create">
9694

9795
```py
9896
guider_spec = t2i_pipeline.get_component_spec("guider")
9997
guider = guider_spec.create(guidance_scale=10)
10098
t2i_pipeline.update_components(guider=guider)
10199
```
102100

103-
</hfoption>
104-
<hfoption id="update_components">
105-
106-
```py
107-
guider_spec = t2i_pipeline.get_component_spec("guider")
108-
guider_spec.config["guidance_scale"] = 10
109-
t2i_pipeline.update_components(guider=guider_spec)
110-
```
111-
112-
</hfoption>
113-
</hfoptions>
114-
115101
## Uploading custom guiders
116102

117103
Call the [`~utils.PushToHubMixin.push_to_hub`] method on a custom guider to share it to the Hub.

docs/source/zh/modular_diffusers/guiders.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,14 @@ t2i_pipeline.guider
8686

8787
## 更改引导器参数
8888

89-
引导器参数可以通过 [`~ComponentSpec.create`] 方法或 [`~ModularPipeline.update_components`] 方法进行调整。下面的示例更改了 `guidance_scale` 值。
90-
91-
<hfoptions id="switch">
92-
<hfoption id="create">
89+
引导器参数可以通过 [`~ComponentSpec.create`] 方法以及 [`~ModularPipeline.update_components`] 方法进行调整。下面的示例更改了 `guidance_scale` 值。
9390

9491
```py
9592
guider_spec = t2i_pipeline.get_component_spec("guider")
9693
guider = guider_spec.create(guidance_scale=10)
9794
t2i_pipeline.update_components(guider=guider)
9895
```
9996

100-
</hfoption>
101-
<hfoption id="update_components">
102-
103-
```py
104-
guider_spec = t2i_pipeline.get_component_spec("guider")
105-
guider_spec.config["guidance_scale"] = 10
106-
t2i_pipeline.update_components(guider=guider_spec)
107-
```
108-
109-
</hfoption>
110-
</hfoptions>
111-
11297
## 上传自定义引导器
11398

11499
在自定义引导器上调用 [`~utils.PushToHubMixin.push_to_hub`] 方法,将其分享到 Hub。

src/diffusers/modular_pipelines/flux/__init__.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,8 @@
2121

2222
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
2323
else:
24-
_import_structure["encoders"] = ["FluxTextEncoderStep"]
25-
_import_structure["modular_blocks"] = [
26-
"ALL_BLOCKS",
27-
"AUTO_BLOCKS",
28-
"AUTO_BLOCKS_KONTEXT",
29-
"FLUX_KONTEXT_BLOCKS",
30-
"TEXT2IMAGE_BLOCKS",
31-
"FluxAutoBeforeDenoiseStep",
32-
"FluxAutoBlocks",
33-
"FluxAutoDecodeStep",
34-
"FluxAutoDenoiseStep",
35-
"FluxKontextAutoBlocks",
36-
"FluxKontextAutoDenoiseStep",
37-
"FluxKontextBeforeDenoiseStep",
38-
]
24+
_import_structure["modular_blocks_flux"] = ["FluxAutoBlocks"]
25+
_import_structure["modular_blocks_flux_kontext"] = ["FluxKontextAutoBlocks"]
3926
_import_structure["modular_pipeline"] = ["FluxKontextModularPipeline", "FluxModularPipeline"]
4027

4128
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
@@ -45,21 +32,8 @@
4532
except OptionalDependencyNotAvailable:
4633
from ...utils.dummy_torch_and_transformers_objects import * # noqa F403
4734
else:
48-
from .encoders import FluxTextEncoderStep
49-
from .modular_blocks import (
50-
ALL_BLOCKS,
51-
AUTO_BLOCKS,
52-
AUTO_BLOCKS_KONTEXT,
53-
FLUX_KONTEXT_BLOCKS,
54-
TEXT2IMAGE_BLOCKS,
55-
FluxAutoBeforeDenoiseStep,
56-
FluxAutoBlocks,
57-
FluxAutoDecodeStep,
58-
FluxAutoDenoiseStep,
59-
FluxKontextAutoBlocks,
60-
FluxKontextAutoDenoiseStep,
61-
FluxKontextBeforeDenoiseStep,
62-
)
35+
from .modular_blocks_flux import FluxAutoBlocks
36+
from .modular_blocks_flux_kontext import FluxKontextAutoBlocks
6337
from .modular_pipeline import FluxKontextModularPipeline, FluxModularPipeline
6438
else:
6539
import sys

src/diffusers/modular_pipelines/flux/encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __call__(self, components: FluxModularPipeline, state: PipelineState):
205205
return components, state
206206

207207

208-
class FluxVaeEncoderDynamicStep(ModularPipelineBlocks):
208+
class FluxVaeEncoderStep(ModularPipelineBlocks):
209209
model_name = "flux"
210210

211211
def __init__(

src/diffusers/modular_pipelines/flux/inputs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __call__(self, components: FluxModularPipeline, state: PipelineState) -> Pip
121121

122122

123123
# Adapted from `QwenImageAdditionalInputsStep`
124-
class FluxInputsDynamicStep(ModularPipelineBlocks):
124+
class FluxAdditionalInputsStep(ModularPipelineBlocks):
125125
model_name = "flux"
126126

127127
def __init__(
@@ -243,7 +243,7 @@ def __call__(self, components: FluxModularPipeline, state: PipelineState) -> Pip
243243
return components, state
244244

245245

246-
class FluxKontextInputsDynamicStep(FluxInputsDynamicStep):
246+
class FluxKontextAdditionalInputsStep(FluxAdditionalInputsStep):
247247
model_name = "flux-kontext"
248248

249249
def __call__(self, components: FluxModularPipeline, state: PipelineState) -> PipelineState:
@@ -256,7 +256,7 @@ def __call__(self, components: FluxModularPipeline, state: PipelineState) -> Pip
256256
continue
257257

258258
# 1. Calculate height/width from latents
259-
# Unlike the `FluxInputsDynamicStep`, we don't overwrite the `block.height` and `block.width`
259+
# Unlike the `FluxAdditionalInputsStep`, we don't overwrite the `block.height` and `block.width`
260260
height, width = calculate_dimension_from_latents(image_latent_tensor, components.vae_scale_factor)
261261
if not hasattr(block_state, "image_height"):
262262
block_state.image_height = height
@@ -303,6 +303,7 @@ def __call__(self, components: FluxModularPipeline, state: PipelineState) -> Pip
303303
class FluxKontextSetResolutionStep(ModularPipelineBlocks):
304304
model_name = "flux-kontext"
305305

306+
@property
306307
def description(self):
307308
return (
308309
"Determines the height and width to be used during the subsequent computations.\n"

0 commit comments

Comments
 (0)