1818from .before_denoise import (
1919 FluxImg2ImgPrepareLatentsStep ,
2020 FluxImg2ImgSetTimestepsStep ,
21- FluxInputStep ,
2221 FluxPrepareLatentsStep ,
2322 FluxSetTimestepsStep ,
2423)
2524from .decoders import FluxDecodeStep
2625from .denoise import FluxDenoiseStep
27- from .encoders import FluxTextEncoderStep , FluxVaeEncoderStep
26+ from .encoders import FluxTextEncoderStep , FluxVaeEncoderDynamicStep
27+ from .before_denoise import FluxRoPEInputsStep
28+ from .inputs import FluxTextInputStep , FluxInputsDynamicStep
29+
2830
2931
3032logger = logging .get_logger (__name__ ) # pylint: disable=invalid-name
3133
3234
3335# vae encoder (run before before_denoise)
36+ from .encoders import FluxProcessImagesInputStep
37+
38+ FluxImg2ImgVaeEncoderBlocks = InsertableDict (
39+ [
40+ ("preprocess" , FluxProcessImagesInputStep ()),
41+ ("encode" , FluxVaeEncoderDynamicStep ()),
42+ ]
43+ )
44+
45+ class FluxImg2ImgVaeEncoderStep (SequentialPipelineBlocks ):
46+ model_name = "flux"
47+
48+ block_classes = FluxImg2ImgVaeEncoderBlocks .values ()
49+ block_names = FluxImg2ImgVaeEncoderBlocks .keys ()
50+
51+ @property
52+ def description (self ) -> str :
53+ return "Vae encoder step that preprocess andencode the image inputs into their latent representations."
54+
55+
3456class FluxAutoVaeEncoderStep (AutoPipelineBlocks ):
35- block_classes = [FluxVaeEncoderStep ]
57+ block_classes = [FluxImg2ImgVaeEncoderStep ]
3658 block_names = ["img2img" ]
3759 block_trigger_inputs = ["image" ]
3860
@@ -41,44 +63,49 @@ def description(self):
4163 return (
4264 "Vae encoder step that encode the image inputs into their latent representations.\n "
4365 + "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."
66+ + " - `FluxImg2ImgVaeEncoderStep ` (img2img) is used when only `image` is provided."
67+ + " - if `image` is not provided, step will be skipped."
4668 )
4769
4870
49- # before_denoise: text2img, img2img
50- class FluxBeforeDenoiseStep (SequentialPipelineBlocks ):
51- block_classes = [
52- FluxInputStep ,
53- FluxPrepareLatentsStep ,
54- FluxSetTimestepsStep ,
71+
72+ # before_denoise: text2img
73+ FluxBeforeDenoiseBlocks = InsertableDict (
74+ [
75+ ("prepare_latents" , FluxPrepareLatentsStep ()),
76+ ("set_timesteps" , FluxSetTimestepsStep ()),
77+ ("prepare_rope_inputs" , FluxRoPEInputsStep ())
5578 ]
56- block_names = ["input" , "prepare_latents" , "set_timesteps" ]
79+ )
80+
81+ class FluxBeforeDenoiseStep (SequentialPipelineBlocks ):
82+ block_classes = FluxBeforeDenoiseBlocks .values ()
83+ block_names = FluxBeforeDenoiseBlocks .keys ()
5784
5885 @property
5986 def description (self ):
6087 return (
61- "Before denoise step that prepare the inputs for the denoise step.\n "
62- + "This is a sequential pipeline blocks:\n "
63- + " - `FluxInputStep` is used to adjust the batch size of the model inputs\n "
64- + " - `FluxPrepareLatentsStep` is used to prepare the latents\n "
65- + " - `FluxSetTimestepsStep` is used to set the timesteps\n "
88+ "Before denoise step that prepares the inputs for the denoise step in text-to-image generation."
6689 )
6790
6891
6992# before_denoise: img2img
93+ FluxImg2ImgBeforeDenoiseBlocks = InsertableDict (
94+ [
95+ ("prepare_latents" , FluxPrepareLatentsStep ()),
96+ ("set_timesteps" , FluxImg2ImgSetTimestepsStep ()),
97+ ("prepare_img2img_latents" , FluxImg2ImgPrepareLatentsStep ()),
98+ ("prepare_rope_inputs" , FluxRoPEInputsStep ())
99+ ]
100+ )
70101class FluxImg2ImgBeforeDenoiseStep (SequentialPipelineBlocks ):
71- block_classes = [ FluxInputStep , FluxImg2ImgSetTimestepsStep , FluxImg2ImgPrepareLatentsStep ]
72- block_names = [ "input" , "set_timesteps" , "prepare_latents" ]
102+ block_classes = FluxImg2ImgBeforeDenoiseBlocks . values ()
103+ block_names = FluxImg2ImgBeforeDenoiseBlocks . keys ()
73104
74105 @property
75106 def description (self ):
76107 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 "
108+ "Before denoise step that prepare the inputs for the denoise step for img2img task."
82109 )
83110
84111
@@ -113,7 +140,7 @@ def description(self) -> str:
113140 )
114141
115142
116- # decode: all task (text2img, img2img, inpainting )
143+ # decode: all task (text2img, img2img)
117144class FluxAutoDecodeStep (AutoPipelineBlocks ):
118145 block_classes = [FluxDecodeStep ]
119146 block_names = ["non-inpaint" ]
@@ -124,32 +151,73 @@ def description(self):
124151 return "Decode step that decode the denoised latents into image outputs.\n - `FluxDecodeStep`"
125152
126153
154+ # inputs: text2image/img2img
155+ FluxImg2ImgBlocks = InsertableDict (
156+ [
157+ ("text_inputs" , FluxTextInputStep ()),
158+ ("additional_inputs" , FluxInputsDynamicStep ())
159+ ]
160+ )
161+
162+ class FluxImg2ImgInputStep (SequentialPipelineBlocks ):
163+ model_name = "flux"
164+ block_classes = FluxImg2ImgBlocks .values ()
165+ block_names = FluxImg2ImgBlocks .keys ()
166+
167+ @property
168+ def description (self ):
169+ return "Input step that prepares the inputs for the img2img denoising step. It:\n "
170+ " - make sure the text embeddings have consistent batch size as well as the additional inputs (`image_latents`).\n "
171+ " - update height/width based `image_latents`, patchify `image_latents`."
172+
173+
174+ class FluxImageAutoInputStep (AutoPipelineBlocks ):
175+ block_classes = [FluxImg2ImgInputStep , FluxTextInputStep ]
176+ block_names = ["img2img" , "text2image" ]
177+ block_trigger_inputs = [ "image_latents" , None ]
178+
179+ @property
180+ def description (self ):
181+ return (
182+ "Input step that standardize the inputs for the denoising step, e.g. make sure inputs have consistent batch size, and patchified. \n "
183+ " This is an auto pipeline block that works for text2image/img2img tasks.\n "
184+ + " - `FluxImg2ImgInputStep` (img2img) is used when `image_latents` is provided.\n "
185+ + " - `FluxTextInputStep` (text2image) is used when `image_latents` are not provided.\n "
186+ )
187+
188+
127189class FluxCoreDenoiseStep (SequentialPipelineBlocks ):
128- block_classes = [FluxInputStep , FluxAutoBeforeDenoiseStep , FluxAutoDenoiseStep ]
190+ model_name = "flux"
191+ block_classes = [FluxImageAutoInputStep , FluxAutoBeforeDenoiseStep , FluxAutoDenoiseStep ]
129192 block_names = ["input" , "before_denoise" , "denoise" ]
130193
131194 @property
132195 def description (self ):
133196 return (
134197 "Core step that performs the denoising process. \n "
135- + " - `FluxInputStep ` (input) standardizes the inputs for the denoising step.\n "
198+ + " - `FluxImageAutoInputStep ` (input) standardizes the inputs for the denoising step.\n "
136199 + " - `FluxAutoBeforeDenoiseStep` (before_denoise) prepares the inputs for the denoising step.\n "
137200 + " - `FluxAutoDenoiseStep` (denoise) iteratively denoises the latents.\n "
138- + "This step support text-to-image and image-to-image tasks for Flux:\n "
201+ + "This step supports text-to-image and image-to-image tasks for Flux:\n "
139202 + " - for image-to-image generation, you need to provide `image_latents`\n "
140- + " - for text-to-image generation, all you need to provide is prompt embeddings"
203+ + " - for text-to-image generation, all you need to provide is prompt embeddings. "
141204 )
142205
143206
144- # text2image
145- class FluxAutoBlocks ( SequentialPipelineBlocks ):
146- block_classes = [
147- FluxTextEncoderStep ,
148- FluxAutoVaeEncoderStep ,
149- FluxCoreDenoiseStep ,
150- FluxAutoDecodeStep ,
207+ # Auto blocks ( text2image and img2img)
208+ AUTO_BLOCKS = InsertableDict (
209+ [
210+ ( "text_encoder" , FluxTextEncoderStep ()) ,
211+ ( "image_encoder" , FluxAutoVaeEncoderStep ()) ,
212+ ( "denoise" , FluxCoreDenoiseStep ()) ,
213+ ( "decode" , FluxDecodeStep ())
151214 ]
152- block_names = ["text_encoder" , "image_encoder" , "denoise" , "decode" ]
215+ )
216+ class FluxAutoBlocks (SequentialPipelineBlocks ):
217+ model_name = "flux"
218+
219+ block_classes = AUTO_BLOCKS .values ()
220+ block_names = AUTO_BLOCKS .keys ()
153221
154222 @property
155223 def description (self ):
@@ -162,35 +230,28 @@ def description(self):
162230
163231TEXT2IMAGE_BLOCKS = InsertableDict (
164232 [
165- ("text_encoder" , FluxTextEncoderStep ),
166- ("input" , FluxInputStep ),
167- ("prepare_latents" , FluxPrepareLatentsStep ),
168- ("set_timesteps" , FluxSetTimestepsStep ),
169- ("denoise" , FluxDenoiseStep ),
170- ("decode" , FluxDecodeStep ),
233+ ("text_encoder" , FluxTextEncoderStep ()),
234+ ("input" , FluxTextInputStep ()),
235+ ("prepare_latents" , FluxPrepareLatentsStep ()),
236+ ("set_timesteps" , FluxSetTimestepsStep ()),
237+ ("prepare_rope_inputs" , FluxRoPEInputsStep ()),
238+ ("denoise" , FluxDenoiseStep ()),
239+ ("decode" , FluxDecodeStep ()),
171240 ]
172241)
173242
174243IMAGE2IMAGE_BLOCKS = InsertableDict (
175244 [
176- ("text_encoder" , FluxTextEncoderStep ),
177- ("image_encoder" , FluxVaeEncoderStep ),
178- ("input" , FluxInputStep ),
179- ("set_timesteps" , FluxImg2ImgSetTimestepsStep ),
180- ("prepare_latents" , FluxImg2ImgPrepareLatentsStep ),
181- ("denoise" , FluxDenoiseStep ),
182- ("decode" , FluxDecodeStep ),
245+ ("text_encoder" , FluxTextEncoderStep ()),
246+ ("vae_encoder" , FluxVaeEncoderDynamicStep ()),
247+ ("input" , FluxImg2ImgInputStep ()),
248+ ("prepare_latents" , FluxPrepareLatentsStep ()),
249+ ("set_timesteps" , FluxImg2ImgSetTimestepsStep ()),
250+ ("prepare_img2img_latents" , FluxImg2ImgPrepareLatentsStep ()),
251+ ("prepare_rope_inputs" , FluxRoPEInputsStep ()),
252+ ("denoise" , FluxDenoiseStep ()),
253+ ("decode" , FluxDecodeStep ()),
183254 ]
184255)
185256
186- AUTO_BLOCKS = InsertableDict (
187- [
188- ("text_encoder" , FluxTextEncoderStep ),
189- ("image_encoder" , FluxAutoVaeEncoderStep ),
190- ("denoise" , FluxCoreDenoiseStep ),
191- ("decode" , FluxAutoDecodeStep ),
192- ]
193- )
194-
195-
196257ALL_BLOCKS = {"text2image" : TEXT2IMAGE_BLOCKS , "img2img" : IMAGE2IMAGE_BLOCKS , "auto" : AUTO_BLOCKS }
0 commit comments