Skip to content

Commit 6664d80

Browse files
committed
up
1 parent 600bc51 commit 6664d80

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

src/diffusers/modular_pipelines/flux/before_denoise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def __call__(self, components: FluxModularPipeline, state: PipelineState) -> Pip
583583
return components, state
584584

585585

586-
class FluxLImg2ImgPrepareLatentsStep(PipelineBlock):
586+
class FluxImg2ImgPrepareLatentsStep(PipelineBlock):
587587
model_name = "flux"
588588

589589
@property

src/diffusers/modular_pipelines/flux/modular_blocks.py

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,38 @@
1515
from ...utils import logging
1616
from ..modular_pipeline import AutoPipelineBlocks, SequentialPipelineBlocks
1717
from ..modular_pipeline_utils import InsertableDict
18-
from .before_denoise import FluxInputStep, FluxPrepareLatentsStep, FluxSetTimestepsStep
18+
from .before_denoise import (
19+
FluxImg2ImgPrepareLatentsStep,
20+
FluxImg2ImgSetTimestepsStep,
21+
FluxInputStep,
22+
FluxPrepareLatentsStep,
23+
FluxSetTimestepsStep,
24+
)
1925
from .decoders import FluxDecodeStep
2026
from .denoise import FluxDenoiseStep
21-
from .encoders import FluxTextEncoderStep
27+
from .encoders import FluxTextEncoderStep, FluxVaeEncoderStep
2228

2329

2430
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
2531

2632

27-
# before_denoise: text2vid
33+
# vae encoder (run before before_denoise)
34+
class FluxAutoVaeEncoderStep(AutoPipelineBlocks):
35+
block_classes = [FluxVaeEncoderStep]
36+
block_names = ["img2img"]
37+
block_trigger_inputs = ["image"]
38+
39+
@property
40+
def description(self):
41+
return (
42+
"Vae encoder step that encode the image inputs into their latent representations.\n"
43+
+ "This is an auto pipeline block that works for img2img tasks.\n"
44+
+ " - `FluxVaeEncoderStep` (img2img) is used when only `image` is provided."
45+
+ " - if `image` is provided, step will be skipped."
46+
)
47+
48+
49+
# before_denoise: text2img, img2img
2850
class FluxBeforeDenoiseStep(SequentialPipelineBlocks):
2951
block_classes = [
3052
FluxInputStep,
@@ -44,18 +66,35 @@ def description(self):
4466
)
4567

4668

47-
# before_denoise: all task (text2vid,)
69+
# before_denoise: img2img
70+
class FluxImg2ImgBeforeDenoiseStep(SequentialPipelineBlocks):
71+
block_classes = [FluxInputStep, FluxImg2ImgSetTimestepsStep, FluxImg2ImgPrepareLatentsStep]
72+
block_names = ["input", "set_timesteps", "prepare_latents"]
73+
74+
@property
75+
def description(self):
76+
return (
77+
"Before denoise step that prepare the inputs for the denoise step for img2img task.\n"
78+
+ "This is a sequential pipeline blocks:\n"
79+
+ " - `FluxInputStep` is used to adjust the batch size of the model inputs\n"
80+
+ " - `FluxImg2ImgSetTimestepsStep` is used to set the timesteps\n"
81+
+ " - `FluxImg2ImgPrepareLatentsStep` is used to prepare the latents\n"
82+
)
83+
84+
85+
# before_denoise: all task (text2img, img2img)
4886
class FluxAutoBeforeDenoiseStep(AutoPipelineBlocks):
49-
block_classes = [FluxBeforeDenoiseStep]
50-
block_names = ["text2image"]
51-
block_trigger_inputs = [None]
87+
block_classes = [FluxBeforeDenoiseStep, FluxImg2ImgBeforeDenoiseStep]
88+
block_names = ["text2image", "img2img"]
89+
block_trigger_inputs = [None, "image_latents"]
5290

5391
@property
5492
def description(self):
5593
return (
5694
"Before denoise step that prepare the inputs for the denoise step.\n"
5795
+ "This is an auto pipeline block that works for text2image.\n"
5896
+ " - `FluxBeforeDenoiseStep` (text2image) is used.\n"
97+
+ " - `FluxImg2ImgBeforeDenoiseStep` (img2img) is used when only `image_latents` is provided.\n"
5998
)
6099

61100

@@ -69,8 +108,8 @@ class FluxAutoDenoiseStep(AutoPipelineBlocks):
69108
def description(self) -> str:
70109
return (
71110
"Denoise step that iteratively denoise the latents. "
72-
"This is a auto pipeline block that works for text2image tasks."
73-
" - `FluxDenoiseStep` (denoise) for text2image tasks."
111+
"This is a auto pipeline block that works for text2image and img2img tasks."
112+
" - `FluxDenoiseStep` (denoise) for text2image and img2img tasks."
74113
)
75114

76115

@@ -82,19 +121,26 @@ class FluxAutoDecodeStep(AutoPipelineBlocks):
82121

83122
@property
84123
def description(self):
85-
return "Decode step that decode the denoised latents into videos outputs.\n - `FluxDecodeStep`"
124+
return "Decode step that decode the denoised latents into image outputs.\n - `FluxDecodeStep`"
86125

87126

88127
# text2image
89128
class FluxAutoBlocks(SequentialPipelineBlocks):
90-
block_classes = [FluxTextEncoderStep, FluxAutoBeforeDenoiseStep, FluxAutoDenoiseStep, FluxAutoDecodeStep]
91-
block_names = ["text_encoder", "before_denoise", "denoise", "decoder"]
129+
block_classes = [
130+
FluxTextEncoderStep,
131+
FluxAutoVaeEncoderStep,
132+
FluxAutoBeforeDenoiseStep,
133+
FluxAutoDenoiseStep,
134+
FluxAutoDecodeStep,
135+
]
136+
block_names = ["text_encoder", "image_encoder", "before_denoise", "denoise", "decoder"]
92137

93138
@property
94139
def description(self):
95140
return (
96-
"Auto Modular pipeline for text-to-image using Flux.\n"
97-
+ "- for text-to-image generation, all you need to provide is `prompt`"
141+
"Auto Modular pipeline for text-to-image and image-to-image using Flux.\n"
142+
+ "- for text-to-image generation, all you need to provide is `prompt`\n"
143+
+ "- for image-to-image generation, you need to provide either `image` or `image_latents`"
98144
)
99145

100146

@@ -111,15 +157,27 @@ def description(self):
111157
]
112158
)
113159

160+
IMAGE2IMAGE_BLOCKS = InsertableDict(
161+
[
162+
("text_encoder", FluxTextEncoderStep),
163+
("image_encoder", FluxVaeEncoderStep),
164+
("input", FluxInputStep),
165+
("prepare_latents", FluxImg2ImgPrepareLatentsStep),
166+
("set_timesteps", FluxImg2ImgSetTimestepsStep),
167+
("denoise", FluxDenoiseStep),
168+
("decode", FluxDecodeStep),
169+
]
170+
)
114171

115172
AUTO_BLOCKS = InsertableDict(
116173
[
117174
("text_encoder", FluxTextEncoderStep),
175+
("image_encoder", FluxAutoVaeEncoderStep),
118176
("before_denoise", FluxAutoBeforeDenoiseStep),
119177
("denoise", FluxAutoDenoiseStep),
120178
("decode", FluxAutoDecodeStep),
121179
]
122180
)
123181

124182

125-
ALL_BLOCKS = {"text2image": TEXT2IMAGE_BLOCKS, "auto": AUTO_BLOCKS}
183+
ALL_BLOCKS = {"text2image": TEXT2IMAGE_BLOCKS, "img2img": IMAGE2IMAGE_BLOCKS, "auto": AUTO_BLOCKS}

0 commit comments

Comments
 (0)