Skip to content

Commit 4bf07e5

Browse files
committed
update
1 parent 571cea6 commit 4bf07e5

File tree

8 files changed

+231
-495
lines changed

8 files changed

+231
-495
lines changed

src/diffusers/modular_pipelines/modular_pipeline.py

Lines changed: 201 additions & 376 deletions
Large diffs are not rendered by default.

src/diffusers/modular_pipelines/stable_diffusion_xl/before_denoise.py

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ...utils import logging
2828
from ...utils.torch_utils import randn_tensor, unwrap_module
2929
from ..modular_pipeline import (
30-
PipelineBlock,
30+
ModularPipelineBlocks,
3131
PipelineState,
3232
)
3333
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
@@ -195,7 +195,7 @@ def prepare_latents_img2img(
195195
return latents
196196

197197

198-
class StableDiffusionXLInputStep(PipelineBlock):
198+
class StableDiffusionXLInputStep(ModularPipelineBlocks):
199199
model_name = "stable-diffusion-xl"
200200

201201
@property
@@ -213,11 +213,6 @@ def description(self) -> str:
213213
def inputs(self) -> List[InputParam]:
214214
return [
215215
InputParam("num_images_per_prompt", default=1),
216-
]
217-
218-
@property
219-
def intermediate_inputs(self) -> List[str]:
220-
return [
221216
InputParam(
222217
"prompt_embeds",
223218
required=True,
@@ -394,7 +389,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
394389
return components, state
395390

396391

397-
class StableDiffusionXLImg2ImgSetTimestepsStep(PipelineBlock):
392+
class StableDiffusionXLImg2ImgSetTimestepsStep(ModularPipelineBlocks):
398393
model_name = "stable-diffusion-xl"
399394

400395
@property
@@ -421,11 +416,6 @@ def inputs(self) -> List[InputParam]:
421416
InputParam("denoising_start"),
422417
# YiYi TODO: do we need num_images_per_prompt here?
423418
InputParam("num_images_per_prompt", default=1),
424-
]
425-
426-
@property
427-
def intermediate_inputs(self) -> List[str]:
428-
return [
429419
InputParam(
430420
"batch_size",
431421
required=True,
@@ -543,7 +533,7 @@ def denoising_value_valid(dnv):
543533
return components, state
544534

545535

546-
class StableDiffusionXLSetTimestepsStep(PipelineBlock):
536+
class StableDiffusionXLSetTimestepsStep(ModularPipelineBlocks):
547537
model_name = "stable-diffusion-xl"
548538

549539
@property
@@ -611,7 +601,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
611601
return components, state
612602

613603

614-
class StableDiffusionXLInpaintPrepareLatentsStep(PipelineBlock):
604+
class StableDiffusionXLInpaintPrepareLatentsStep(ModularPipelineBlocks):
615605
model_name = "stable-diffusion-xl"
616606

617607
@property
@@ -640,11 +630,6 @@ def inputs(self) -> List[Tuple[str, Any]]:
640630
"`num_inference_steps`. A value of 1, therefore, essentially ignores `image`. Note that in the case of "
641631
"`denoising_start` being declared as an integer, the value of `strength` will be ignored.",
642632
),
643-
]
644-
645-
@property
646-
def intermediate_inputs(self) -> List[str]:
647-
return [
648633
InputParam("generator"),
649634
InputParam(
650635
"batch_size",
@@ -890,7 +875,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
890875
return components, state
891876

892877

893-
class StableDiffusionXLImg2ImgPrepareLatentsStep(PipelineBlock):
878+
class StableDiffusionXLImg2ImgPrepareLatentsStep(ModularPipelineBlocks):
894879
model_name = "stable-diffusion-xl"
895880

896881
@property
@@ -910,11 +895,6 @@ def inputs(self) -> List[Tuple[str, Any]]:
910895
InputParam("latents"),
911896
InputParam("num_images_per_prompt", default=1),
912897
InputParam("denoising_start"),
913-
]
914-
915-
@property
916-
def intermediate_inputs(self) -> List[InputParam]:
917-
return [
918898
InputParam("generator"),
919899
InputParam(
920900
"latent_timestep",
@@ -971,7 +951,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
971951
return components, state
972952

973953

974-
class StableDiffusionXLPrepareLatentsStep(PipelineBlock):
954+
class StableDiffusionXLPrepareLatentsStep(ModularPipelineBlocks):
975955
model_name = "stable-diffusion-xl"
976956

977957
@property
@@ -992,11 +972,6 @@ def inputs(self) -> List[InputParam]:
992972
InputParam("width"),
993973
InputParam("latents"),
994974
InputParam("num_images_per_prompt", default=1),
995-
]
996-
997-
@property
998-
def intermediate_inputs(self) -> List[InputParam]:
999-
return [
1000975
InputParam("generator"),
1001976
InputParam(
1002977
"batch_size",
@@ -1082,7 +1057,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
10821057
return components, state
10831058

10841059

1085-
class StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep(PipelineBlock):
1060+
class StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep(ModularPipelineBlocks):
10861061
model_name = "stable-diffusion-xl"
10871062

10881063
@property
@@ -1119,11 +1094,6 @@ def inputs(self) -> List[Tuple[str, Any]]:
11191094
InputParam("num_images_per_prompt", default=1),
11201095
InputParam("aesthetic_score", default=6.0),
11211096
InputParam("negative_aesthetic_score", default=2.0),
1122-
]
1123-
1124-
@property
1125-
def intermediate_inputs(self) -> List[InputParam]:
1126-
return [
11271097
InputParam(
11281098
"latents",
11291099
required=True,
@@ -1306,7 +1276,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
13061276
return components, state
13071277

13081278

1309-
class StableDiffusionXLPrepareAdditionalConditioningStep(PipelineBlock):
1279+
class StableDiffusionXLPrepareAdditionalConditioningStep(ModularPipelineBlocks):
13101280
model_name = "stable-diffusion-xl"
13111281

13121282
@property
@@ -1335,11 +1305,6 @@ def inputs(self) -> List[Tuple[str, Any]]:
13351305
InputParam("crops_coords_top_left", default=(0, 0)),
13361306
InputParam("negative_crops_coords_top_left", default=(0, 0)),
13371307
InputParam("num_images_per_prompt", default=1),
1338-
]
1339-
1340-
@property
1341-
def intermediate_inputs(self) -> List[InputParam]:
1342-
return [
13431308
InputParam(
13441309
"latents",
13451310
required=True,
@@ -1489,7 +1454,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
14891454
return components, state
14901455

14911456

1492-
class StableDiffusionXLControlNetInputStep(PipelineBlock):
1457+
class StableDiffusionXLControlNetInputStep(ModularPipelineBlocks):
14931458
model_name = "stable-diffusion-xl"
14941459

14951460
@property
@@ -1517,11 +1482,6 @@ def inputs(self) -> List[Tuple[str, Any]]:
15171482
InputParam("controlnet_conditioning_scale", default=1.0),
15181483
InputParam("guess_mode", default=False),
15191484
InputParam("num_images_per_prompt", default=1),
1520-
]
1521-
1522-
@property
1523-
def intermediate_inputs(self) -> List[str]:
1524-
return [
15251485
InputParam(
15261486
"latents",
15271487
required=True,
@@ -1708,7 +1668,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, state: Pipeline
17081668
return components, state
17091669

17101670

1711-
class StableDiffusionXLControlNetUnionInputStep(PipelineBlock):
1671+
class StableDiffusionXLControlNetUnionInputStep(ModularPipelineBlocks):
17121672
model_name = "stable-diffusion-xl"
17131673

17141674
@property

src/diffusers/modular_pipelines/stable_diffusion_xl/decoders.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ...models.attention_processor import AttnProcessor2_0, XFormersAttnProcessor
2525
from ...utils import logging
2626
from ..modular_pipeline import (
27-
PipelineBlock,
27+
ModularPipelineBlocks,
2828
PipelineState,
2929
)
3030
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
@@ -33,7 +33,7 @@
3333
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
3434

3535

36-
class StableDiffusionXLDecodeStep(PipelineBlock):
36+
class StableDiffusionXLDecodeStep(ModularPipelineBlocks):
3737
model_name = "stable-diffusion-xl"
3838

3939
@property
@@ -56,11 +56,6 @@ def description(self) -> str:
5656
def inputs(self) -> List[Tuple[str, Any]]:
5757
return [
5858
InputParam("output_type", default="pil"),
59-
]
60-
61-
@property
62-
def intermediate_inputs(self) -> List[str]:
63-
return [
6459
InputParam(
6560
"latents",
6661
required=True,
@@ -157,7 +152,7 @@ def __call__(self, components, state: PipelineState) -> PipelineState:
157152
return components, state
158153

159154

160-
class StableDiffusionXLInpaintOverlayMaskStep(PipelineBlock):
155+
class StableDiffusionXLInpaintOverlayMaskStep(ModularPipelineBlocks):
161156
model_name = "stable-diffusion-xl"
162157

163158
@property

src/diffusers/modular_pipelines/stable_diffusion_xl/denoise.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ..modular_pipeline import (
2626
BlockState,
2727
LoopSequentialPipelineBlocks,
28-
PipelineBlock,
28+
ModularPipelineBlocks,
2929
PipelineState,
3030
)
3131
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
@@ -37,7 +37,7 @@
3737

3838
# YiYi experimenting composible denoise loop
3939
# loop step (1): prepare latent input for denoiser
40-
class StableDiffusionXLLoopBeforeDenoiser(PipelineBlock):
40+
class StableDiffusionXLLoopBeforeDenoiser(ModularPipelineBlocks):
4141
model_name = "stable-diffusion-xl"
4242

4343
@property
@@ -55,7 +55,7 @@ def description(self) -> str:
5555
)
5656

5757
@property
58-
def intermediate_inputs(self) -> List[str]:
58+
def inputs(self) -> List[str]:
5959
return [
6060
InputParam(
6161
"latents",
@@ -73,7 +73,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, block_state: Bl
7373

7474

7575
# loop step (1): prepare latent input for denoiser (with inpainting)
76-
class StableDiffusionXLInpaintLoopBeforeDenoiser(PipelineBlock):
76+
class StableDiffusionXLInpaintLoopBeforeDenoiser(ModularPipelineBlocks):
7777
model_name = "stable-diffusion-xl"
7878

7979
@property
@@ -91,7 +91,7 @@ def description(self) -> str:
9191
)
9292

9393
@property
94-
def intermediate_inputs(self) -> List[str]:
94+
def inputs(self) -> List[str]:
9595
return [
9696
InputParam(
9797
"latents",
@@ -144,7 +144,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, block_state: Bl
144144

145145

146146
# loop step (2): denoise the latents with guidance
147-
class StableDiffusionXLLoopDenoiser(PipelineBlock):
147+
class StableDiffusionXLLoopDenoiser(ModularPipelineBlocks):
148148
model_name = "stable-diffusion-xl"
149149

150150
@property
@@ -171,11 +171,6 @@ def description(self) -> str:
171171
def inputs(self) -> List[Tuple[str, Any]]:
172172
return [
173173
InputParam("cross_attention_kwargs"),
174-
]
175-
176-
@property
177-
def intermediate_inputs(self) -> List[str]:
178-
return [
179174
InputParam(
180175
"num_inference_steps",
181176
required=True,
@@ -249,7 +244,7 @@ def __call__(
249244

250245

251246
# loop step (2): denoise the latents with guidance (with controlnet)
252-
class StableDiffusionXLControlNetLoopDenoiser(PipelineBlock):
247+
class StableDiffusionXLControlNetLoopDenoiser(ModularPipelineBlocks):
253248
model_name = "stable-diffusion-xl"
254249

255250
@property
@@ -277,11 +272,6 @@ def description(self) -> str:
277272
def inputs(self) -> List[Tuple[str, Any]]:
278273
return [
279274
InputParam("cross_attention_kwargs"),
280-
]
281-
282-
@property
283-
def intermediate_inputs(self) -> List[str]:
284-
return [
285275
InputParam(
286276
"controlnet_cond",
287277
required=True,
@@ -449,7 +439,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, block_state: Bl
449439

450440

451441
# loop step (3): scheduler step to update latents
452-
class StableDiffusionXLLoopAfterDenoiser(PipelineBlock):
442+
class StableDiffusionXLLoopAfterDenoiser(ModularPipelineBlocks):
453443
model_name = "stable-diffusion-xl"
454444

455445
@property
@@ -470,11 +460,6 @@ def description(self) -> str:
470460
def inputs(self) -> List[Tuple[str, Any]]:
471461
return [
472462
InputParam("eta", default=0.0),
473-
]
474-
475-
@property
476-
def intermediate_inputs(self) -> List[str]:
477-
return [
478463
InputParam("generator"),
479464
]
480465

@@ -520,7 +505,7 @@ def __call__(self, components: StableDiffusionXLModularPipeline, block_state: Bl
520505

521506

522507
# loop step (3): scheduler step to update latents (with inpainting)
523-
class StableDiffusionXLInpaintLoopAfterDenoiser(PipelineBlock):
508+
class StableDiffusionXLInpaintLoopAfterDenoiser(ModularPipelineBlocks):
524509
model_name = "stable-diffusion-xl"
525510

526511
@property
@@ -542,11 +527,6 @@ def description(self) -> str:
542527
def inputs(self) -> List[Tuple[str, Any]]:
543528
return [
544529
InputParam("eta", default=0.0),
545-
]
546-
547-
@property
548-
def intermediate_inputs(self) -> List[str]:
549-
return [
550530
InputParam("generator"),
551531
InputParam(
552532
"timesteps",
@@ -660,7 +640,7 @@ def loop_expected_components(self) -> List[ComponentSpec]:
660640
]
661641

662642
@property
663-
def loop_intermediate_inputs(self) -> List[InputParam]:
643+
def loop_inputs(self) -> List[InputParam]:
664644
return [
665645
InputParam(
666646
"timesteps",

0 commit comments

Comments
 (0)