diffusers 0.34.0__py3-none-any.whl → 0.35.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffusers/__init__.py +98 -1
- diffusers/callbacks.py +35 -0
- diffusers/commands/custom_blocks.py +134 -0
- diffusers/commands/diffusers_cli.py +2 -0
- diffusers/commands/fp16_safetensors.py +1 -1
- diffusers/configuration_utils.py +11 -2
- diffusers/dependency_versions_table.py +3 -3
- diffusers/guiders/__init__.py +41 -0
- diffusers/guiders/adaptive_projected_guidance.py +188 -0
- diffusers/guiders/auto_guidance.py +190 -0
- diffusers/guiders/classifier_free_guidance.py +141 -0
- diffusers/guiders/classifier_free_zero_star_guidance.py +152 -0
- diffusers/guiders/frequency_decoupled_guidance.py +327 -0
- diffusers/guiders/guider_utils.py +309 -0
- diffusers/guiders/perturbed_attention_guidance.py +271 -0
- diffusers/guiders/skip_layer_guidance.py +262 -0
- diffusers/guiders/smoothed_energy_guidance.py +251 -0
- diffusers/guiders/tangential_classifier_free_guidance.py +143 -0
- diffusers/hooks/__init__.py +17 -0
- diffusers/hooks/_common.py +56 -0
- diffusers/hooks/_helpers.py +293 -0
- diffusers/hooks/faster_cache.py +7 -6
- diffusers/hooks/first_block_cache.py +259 -0
- diffusers/hooks/group_offloading.py +292 -286
- diffusers/hooks/hooks.py +56 -1
- diffusers/hooks/layer_skip.py +263 -0
- diffusers/hooks/layerwise_casting.py +2 -7
- diffusers/hooks/pyramid_attention_broadcast.py +14 -11
- diffusers/hooks/smoothed_energy_guidance_utils.py +167 -0
- diffusers/hooks/utils.py +43 -0
- diffusers/loaders/__init__.py +6 -0
- diffusers/loaders/ip_adapter.py +255 -4
- diffusers/loaders/lora_base.py +63 -30
- diffusers/loaders/lora_conversion_utils.py +434 -53
- diffusers/loaders/lora_pipeline.py +834 -37
- diffusers/loaders/peft.py +28 -5
- diffusers/loaders/single_file_model.py +44 -11
- diffusers/loaders/single_file_utils.py +170 -2
- diffusers/loaders/transformer_flux.py +9 -10
- diffusers/loaders/transformer_sd3.py +6 -1
- diffusers/loaders/unet.py +22 -5
- diffusers/loaders/unet_loader_utils.py +5 -2
- diffusers/models/__init__.py +8 -0
- diffusers/models/attention.py +484 -3
- diffusers/models/attention_dispatch.py +1218 -0
- diffusers/models/attention_processor.py +105 -663
- diffusers/models/auto_model.py +2 -2
- diffusers/models/autoencoders/__init__.py +1 -0
- diffusers/models/autoencoders/autoencoder_dc.py +14 -1
- diffusers/models/autoencoders/autoencoder_kl.py +1 -1
- diffusers/models/autoencoders/autoencoder_kl_cosmos.py +3 -1
- diffusers/models/autoencoders/autoencoder_kl_qwenimage.py +1070 -0
- diffusers/models/autoencoders/autoencoder_kl_wan.py +370 -40
- diffusers/models/cache_utils.py +31 -9
- diffusers/models/controlnets/controlnet_flux.py +5 -5
- diffusers/models/controlnets/controlnet_union.py +4 -4
- diffusers/models/embeddings.py +26 -34
- diffusers/models/model_loading_utils.py +233 -1
- diffusers/models/modeling_flax_utils.py +1 -2
- diffusers/models/modeling_utils.py +159 -94
- diffusers/models/transformers/__init__.py +2 -0
- diffusers/models/transformers/transformer_chroma.py +16 -117
- diffusers/models/transformers/transformer_cogview4.py +36 -2
- diffusers/models/transformers/transformer_cosmos.py +11 -4
- diffusers/models/transformers/transformer_flux.py +372 -132
- diffusers/models/transformers/transformer_hunyuan_video.py +6 -0
- diffusers/models/transformers/transformer_ltx.py +104 -23
- diffusers/models/transformers/transformer_qwenimage.py +645 -0
- diffusers/models/transformers/transformer_skyreels_v2.py +607 -0
- diffusers/models/transformers/transformer_wan.py +298 -85
- diffusers/models/transformers/transformer_wan_vace.py +15 -21
- diffusers/models/unets/unet_2d_condition.py +2 -1
- diffusers/modular_pipelines/__init__.py +83 -0
- diffusers/modular_pipelines/components_manager.py +1068 -0
- diffusers/modular_pipelines/flux/__init__.py +66 -0
- diffusers/modular_pipelines/flux/before_denoise.py +689 -0
- diffusers/modular_pipelines/flux/decoders.py +109 -0
- diffusers/modular_pipelines/flux/denoise.py +227 -0
- diffusers/modular_pipelines/flux/encoders.py +412 -0
- diffusers/modular_pipelines/flux/modular_blocks.py +181 -0
- diffusers/modular_pipelines/flux/modular_pipeline.py +59 -0
- diffusers/modular_pipelines/modular_pipeline.py +2446 -0
- diffusers/modular_pipelines/modular_pipeline_utils.py +672 -0
- diffusers/modular_pipelines/node_utils.py +665 -0
- diffusers/modular_pipelines/stable_diffusion_xl/__init__.py +77 -0
- diffusers/modular_pipelines/stable_diffusion_xl/before_denoise.py +1874 -0
- diffusers/modular_pipelines/stable_diffusion_xl/decoders.py +208 -0
- diffusers/modular_pipelines/stable_diffusion_xl/denoise.py +771 -0
- diffusers/modular_pipelines/stable_diffusion_xl/encoders.py +887 -0
- diffusers/modular_pipelines/stable_diffusion_xl/modular_blocks.py +380 -0
- diffusers/modular_pipelines/stable_diffusion_xl/modular_pipeline.py +365 -0
- diffusers/modular_pipelines/wan/__init__.py +66 -0
- diffusers/modular_pipelines/wan/before_denoise.py +365 -0
- diffusers/modular_pipelines/wan/decoders.py +105 -0
- diffusers/modular_pipelines/wan/denoise.py +261 -0
- diffusers/modular_pipelines/wan/encoders.py +242 -0
- diffusers/modular_pipelines/wan/modular_blocks.py +144 -0
- diffusers/modular_pipelines/wan/modular_pipeline.py +90 -0
- diffusers/pipelines/__init__.py +31 -0
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +2 -3
- diffusers/pipelines/auto_pipeline.py +17 -13
- diffusers/pipelines/chroma/pipeline_chroma.py +5 -5
- diffusers/pipelines/chroma/pipeline_chroma_img2img.py +5 -5
- diffusers/pipelines/cogvideo/pipeline_cogvideox.py +9 -8
- diffusers/pipelines/cogvideo/pipeline_cogvideox_fun_control.py +9 -8
- diffusers/pipelines/cogvideo/pipeline_cogvideox_image2video.py +10 -9
- diffusers/pipelines/cogvideo/pipeline_cogvideox_video2video.py +9 -8
- diffusers/pipelines/cogview4/pipeline_cogview4.py +16 -15
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +3 -2
- diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py +212 -93
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py +7 -3
- diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl_img2img.py +194 -92
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +1 -1
- diffusers/pipelines/dit/pipeline_dit.py +3 -1
- diffusers/pipelines/flux/__init__.py +4 -0
- diffusers/pipelines/flux/pipeline_flux.py +34 -26
- diffusers/pipelines/flux/pipeline_flux_control.py +8 -8
- diffusers/pipelines/flux/pipeline_flux_control_img2img.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_control_inpaint.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_controlnet.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_controlnet_image_to_image.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_controlnet_inpainting.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_fill.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_img2img.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_inpaint.py +1 -1
- diffusers/pipelines/flux/pipeline_flux_kontext.py +1134 -0
- diffusers/pipelines/flux/pipeline_flux_kontext_inpaint.py +1460 -0
- diffusers/pipelines/flux/pipeline_flux_prior_redux.py +1 -1
- diffusers/pipelines/flux/pipeline_output.py +6 -4
- diffusers/pipelines/hidream_image/pipeline_hidream_image.py +5 -5
- diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video.py +25 -24
- diffusers/pipelines/ltx/pipeline_ltx.py +13 -12
- diffusers/pipelines/ltx/pipeline_ltx_condition.py +10 -9
- diffusers/pipelines/ltx/pipeline_ltx_image2video.py +13 -12
- diffusers/pipelines/mochi/pipeline_mochi.py +9 -8
- diffusers/pipelines/pipeline_flax_utils.py +2 -2
- diffusers/pipelines/pipeline_loading_utils.py +24 -2
- diffusers/pipelines/pipeline_utils.py +22 -15
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +3 -1
- diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py +20 -0
- diffusers/pipelines/qwenimage/__init__.py +55 -0
- diffusers/pipelines/qwenimage/pipeline_output.py +21 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage.py +726 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage_edit.py +882 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage_img2img.py +829 -0
- diffusers/pipelines/qwenimage/pipeline_qwenimage_inpaint.py +1015 -0
- diffusers/pipelines/sana/pipeline_sana_sprint.py +5 -5
- diffusers/pipelines/skyreels_v2/__init__.py +59 -0
- diffusers/pipelines/skyreels_v2/pipeline_output.py +20 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2.py +610 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing.py +978 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_i2v.py +1059 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_v2v.py +1063 -0
- diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_i2v.py +745 -0
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +2 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +2 -1
- diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +6 -5
- diffusers/pipelines/wan/pipeline_wan.py +78 -20
- diffusers/pipelines/wan/pipeline_wan_i2v.py +112 -32
- diffusers/pipelines/wan/pipeline_wan_vace.py +1 -2
- diffusers/quantizers/__init__.py +1 -177
- diffusers/quantizers/base.py +11 -0
- diffusers/quantizers/gguf/utils.py +92 -3
- diffusers/quantizers/pipe_quant_config.py +202 -0
- diffusers/quantizers/torchao/torchao_quantizer.py +26 -0
- diffusers/schedulers/scheduling_deis_multistep.py +8 -1
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +6 -0
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +6 -0
- diffusers/schedulers/scheduling_scm.py +0 -1
- diffusers/schedulers/scheduling_unipc_multistep.py +10 -1
- diffusers/schedulers/scheduling_utils.py +2 -2
- diffusers/schedulers/scheduling_utils_flax.py +1 -1
- diffusers/training_utils.py +78 -0
- diffusers/utils/__init__.py +10 -0
- diffusers/utils/constants.py +4 -0
- diffusers/utils/dummy_pt_objects.py +312 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +255 -0
- diffusers/utils/dynamic_modules_utils.py +84 -25
- diffusers/utils/hub_utils.py +33 -17
- diffusers/utils/import_utils.py +70 -0
- diffusers/utils/peft_utils.py +11 -8
- diffusers/utils/testing_utils.py +136 -10
- diffusers/utils/torch_utils.py +18 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.0.dist-info}/METADATA +6 -6
- {diffusers-0.34.0.dist-info → diffusers-0.35.0.dist-info}/RECORD +191 -127
- {diffusers-0.34.0.dist-info → diffusers-0.35.0.dist-info}/LICENSE +0 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.0.dist-info}/WHEEL +0 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.0.dist-info}/entry_points.txt +0 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,380 @@
|
|
1
|
+
# Copyright 2025 The HuggingFace Team. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from ...utils import logging
|
16
|
+
from ..modular_pipeline import AutoPipelineBlocks, SequentialPipelineBlocks
|
17
|
+
from ..modular_pipeline_utils import InsertableDict
|
18
|
+
from .before_denoise import (
|
19
|
+
StableDiffusionXLControlNetInputStep,
|
20
|
+
StableDiffusionXLControlNetUnionInputStep,
|
21
|
+
StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep,
|
22
|
+
StableDiffusionXLImg2ImgPrepareLatentsStep,
|
23
|
+
StableDiffusionXLImg2ImgSetTimestepsStep,
|
24
|
+
StableDiffusionXLInpaintPrepareLatentsStep,
|
25
|
+
StableDiffusionXLInputStep,
|
26
|
+
StableDiffusionXLPrepareAdditionalConditioningStep,
|
27
|
+
StableDiffusionXLPrepareLatentsStep,
|
28
|
+
StableDiffusionXLSetTimestepsStep,
|
29
|
+
)
|
30
|
+
from .decoders import (
|
31
|
+
StableDiffusionXLDecodeStep,
|
32
|
+
StableDiffusionXLInpaintOverlayMaskStep,
|
33
|
+
)
|
34
|
+
from .denoise import (
|
35
|
+
StableDiffusionXLControlNetDenoiseStep,
|
36
|
+
StableDiffusionXLDenoiseStep,
|
37
|
+
StableDiffusionXLInpaintControlNetDenoiseStep,
|
38
|
+
StableDiffusionXLInpaintDenoiseStep,
|
39
|
+
)
|
40
|
+
from .encoders import (
|
41
|
+
StableDiffusionXLInpaintVaeEncoderStep,
|
42
|
+
StableDiffusionXLIPAdapterStep,
|
43
|
+
StableDiffusionXLTextEncoderStep,
|
44
|
+
StableDiffusionXLVaeEncoderStep,
|
45
|
+
)
|
46
|
+
|
47
|
+
|
48
|
+
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
49
|
+
|
50
|
+
|
51
|
+
# auto blocks & sequential blocks & mappings
|
52
|
+
|
53
|
+
|
54
|
+
# vae encoder (run before before_denoise)
|
55
|
+
class StableDiffusionXLAutoVaeEncoderStep(AutoPipelineBlocks):
|
56
|
+
block_classes = [StableDiffusionXLInpaintVaeEncoderStep, StableDiffusionXLVaeEncoderStep]
|
57
|
+
block_names = ["inpaint", "img2img"]
|
58
|
+
block_trigger_inputs = ["mask_image", "image"]
|
59
|
+
|
60
|
+
@property
|
61
|
+
def description(self):
|
62
|
+
return (
|
63
|
+
"Vae encoder step that encode the image inputs into their latent representations.\n"
|
64
|
+
+ "This is an auto pipeline block that works for both inpainting and img2img tasks.\n"
|
65
|
+
+ " - `StableDiffusionXLInpaintVaeEncoderStep` (inpaint) is used when `mask_image` is provided.\n"
|
66
|
+
+ " - `StableDiffusionXLVaeEncoderStep` (img2img) is used when only `image` is provided."
|
67
|
+
+ " - if neither `mask_image` nor `image` is provided, step will be skipped."
|
68
|
+
)
|
69
|
+
|
70
|
+
|
71
|
+
# optional ip-adapter (run before input step)
|
72
|
+
class StableDiffusionXLAutoIPAdapterStep(AutoPipelineBlocks):
|
73
|
+
block_classes = [StableDiffusionXLIPAdapterStep]
|
74
|
+
block_names = ["ip_adapter"]
|
75
|
+
block_trigger_inputs = ["ip_adapter_image"]
|
76
|
+
|
77
|
+
@property
|
78
|
+
def description(self):
|
79
|
+
return "Run IP Adapter step if `ip_adapter_image` is provided. This step should be placed before the 'input' step.\n"
|
80
|
+
|
81
|
+
|
82
|
+
# before_denoise: text2img
|
83
|
+
class StableDiffusionXLBeforeDenoiseStep(SequentialPipelineBlocks):
|
84
|
+
block_classes = [
|
85
|
+
StableDiffusionXLInputStep,
|
86
|
+
StableDiffusionXLSetTimestepsStep,
|
87
|
+
StableDiffusionXLPrepareLatentsStep,
|
88
|
+
StableDiffusionXLPrepareAdditionalConditioningStep,
|
89
|
+
]
|
90
|
+
block_names = ["input", "set_timesteps", "prepare_latents", "prepare_add_cond"]
|
91
|
+
|
92
|
+
@property
|
93
|
+
def description(self):
|
94
|
+
return (
|
95
|
+
"Before denoise step that prepare the inputs for the denoise step.\n"
|
96
|
+
+ "This is a sequential pipeline blocks:\n"
|
97
|
+
+ " - `StableDiffusionXLInputStep` is used to adjust the batch size of the model inputs\n"
|
98
|
+
+ " - `StableDiffusionXLSetTimestepsStep` is used to set the timesteps\n"
|
99
|
+
+ " - `StableDiffusionXLPrepareLatentsStep` is used to prepare the latents\n"
|
100
|
+
+ " - `StableDiffusionXLPrepareAdditionalConditioningStep` is used to prepare the additional conditioning\n"
|
101
|
+
)
|
102
|
+
|
103
|
+
|
104
|
+
# before_denoise: img2img
|
105
|
+
class StableDiffusionXLImg2ImgBeforeDenoiseStep(SequentialPipelineBlocks):
|
106
|
+
block_classes = [
|
107
|
+
StableDiffusionXLInputStep,
|
108
|
+
StableDiffusionXLImg2ImgSetTimestepsStep,
|
109
|
+
StableDiffusionXLImg2ImgPrepareLatentsStep,
|
110
|
+
StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep,
|
111
|
+
]
|
112
|
+
block_names = ["input", "set_timesteps", "prepare_latents", "prepare_add_cond"]
|
113
|
+
|
114
|
+
@property
|
115
|
+
def description(self):
|
116
|
+
return (
|
117
|
+
"Before denoise step that prepare the inputs for the denoise step for img2img task.\n"
|
118
|
+
+ "This is a sequential pipeline blocks:\n"
|
119
|
+
+ " - `StableDiffusionXLInputStep` is used to adjust the batch size of the model inputs\n"
|
120
|
+
+ " - `StableDiffusionXLImg2ImgSetTimestepsStep` is used to set the timesteps\n"
|
121
|
+
+ " - `StableDiffusionXLImg2ImgPrepareLatentsStep` is used to prepare the latents\n"
|
122
|
+
+ " - `StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep` is used to prepare the additional conditioning\n"
|
123
|
+
)
|
124
|
+
|
125
|
+
|
126
|
+
# before_denoise: inpainting
|
127
|
+
class StableDiffusionXLInpaintBeforeDenoiseStep(SequentialPipelineBlocks):
|
128
|
+
block_classes = [
|
129
|
+
StableDiffusionXLInputStep,
|
130
|
+
StableDiffusionXLImg2ImgSetTimestepsStep,
|
131
|
+
StableDiffusionXLInpaintPrepareLatentsStep,
|
132
|
+
StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep,
|
133
|
+
]
|
134
|
+
block_names = ["input", "set_timesteps", "prepare_latents", "prepare_add_cond"]
|
135
|
+
|
136
|
+
@property
|
137
|
+
def description(self):
|
138
|
+
return (
|
139
|
+
"Before denoise step that prepare the inputs for the denoise step for inpainting task.\n"
|
140
|
+
+ "This is a sequential pipeline blocks:\n"
|
141
|
+
+ " - `StableDiffusionXLInputStep` is used to adjust the batch size of the model inputs\n"
|
142
|
+
+ " - `StableDiffusionXLImg2ImgSetTimestepsStep` is used to set the timesteps\n"
|
143
|
+
+ " - `StableDiffusionXLInpaintPrepareLatentsStep` is used to prepare the latents\n"
|
144
|
+
+ " - `StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep` is used to prepare the additional conditioning\n"
|
145
|
+
)
|
146
|
+
|
147
|
+
|
148
|
+
# before_denoise: all task (text2img, img2img, inpainting)
|
149
|
+
class StableDiffusionXLAutoBeforeDenoiseStep(AutoPipelineBlocks):
|
150
|
+
block_classes = [
|
151
|
+
StableDiffusionXLInpaintBeforeDenoiseStep,
|
152
|
+
StableDiffusionXLImg2ImgBeforeDenoiseStep,
|
153
|
+
StableDiffusionXLBeforeDenoiseStep,
|
154
|
+
]
|
155
|
+
block_names = ["inpaint", "img2img", "text2img"]
|
156
|
+
block_trigger_inputs = ["mask", "image_latents", None]
|
157
|
+
|
158
|
+
@property
|
159
|
+
def description(self):
|
160
|
+
return (
|
161
|
+
"Before denoise step that prepare the inputs for the denoise step.\n"
|
162
|
+
+ "This is an auto pipeline block that works for text2img, img2img and inpainting tasks as well as controlnet, controlnet_union.\n"
|
163
|
+
+ " - `StableDiffusionXLInpaintBeforeDenoiseStep` (inpaint) is used when both `mask` and `image_latents` are provided.\n"
|
164
|
+
+ " - `StableDiffusionXLImg2ImgBeforeDenoiseStep` (img2img) is used when only `image_latents` is provided.\n"
|
165
|
+
+ " - `StableDiffusionXLBeforeDenoiseStep` (text2img) is used when both `image_latents` and `mask` are not provided.\n"
|
166
|
+
)
|
167
|
+
|
168
|
+
|
169
|
+
# optional controlnet input step (after before_denoise, before denoise)
|
170
|
+
# works for both controlnet and controlnet_union
|
171
|
+
class StableDiffusionXLAutoControlNetInputStep(AutoPipelineBlocks):
|
172
|
+
block_classes = [StableDiffusionXLControlNetUnionInputStep, StableDiffusionXLControlNetInputStep]
|
173
|
+
block_names = ["controlnet_union", "controlnet"]
|
174
|
+
block_trigger_inputs = ["control_mode", "control_image"]
|
175
|
+
|
176
|
+
@property
|
177
|
+
def description(self):
|
178
|
+
return (
|
179
|
+
"Controlnet Input step that prepare the controlnet input.\n"
|
180
|
+
+ "This is an auto pipeline block that works for both controlnet and controlnet_union.\n"
|
181
|
+
+ " (it should be called right before the denoise step)"
|
182
|
+
+ " - `StableDiffusionXLControlNetUnionInputStep` is called to prepare the controlnet input when `control_mode` and `control_image` are provided.\n"
|
183
|
+
+ " - `StableDiffusionXLControlNetInputStep` is called to prepare the controlnet input when `control_image` is provided."
|
184
|
+
+ " - if neither `control_mode` nor `control_image` is provided, step will be skipped."
|
185
|
+
)
|
186
|
+
|
187
|
+
|
188
|
+
# denoise: controlnet (text2img, img2img, inpainting)
|
189
|
+
class StableDiffusionXLAutoControlNetDenoiseStep(AutoPipelineBlocks):
|
190
|
+
block_classes = [StableDiffusionXLInpaintControlNetDenoiseStep, StableDiffusionXLControlNetDenoiseStep]
|
191
|
+
block_names = ["inpaint_controlnet_denoise", "controlnet_denoise"]
|
192
|
+
block_trigger_inputs = ["mask", "controlnet_cond"]
|
193
|
+
|
194
|
+
@property
|
195
|
+
def description(self) -> str:
|
196
|
+
return (
|
197
|
+
"Denoise step that iteratively denoise the latents with controlnet. "
|
198
|
+
"This is a auto pipeline block that using controlnet for text2img, img2img and inpainting tasks."
|
199
|
+
"This block should not be used without a controlnet_cond input"
|
200
|
+
" - `StableDiffusionXLInpaintControlNetDenoiseStep` (inpaint_controlnet_denoise) is used when mask is provided."
|
201
|
+
" - `StableDiffusionXLControlNetDenoiseStep` (controlnet_denoise) is used when mask is not provided but controlnet_cond is provided."
|
202
|
+
" - If neither mask nor controlnet_cond are provided, step will be skipped."
|
203
|
+
)
|
204
|
+
|
205
|
+
|
206
|
+
# denoise: all task with or without controlnet (text2img, img2img, inpainting)
|
207
|
+
class StableDiffusionXLAutoDenoiseStep(AutoPipelineBlocks):
|
208
|
+
block_classes = [
|
209
|
+
StableDiffusionXLAutoControlNetDenoiseStep,
|
210
|
+
StableDiffusionXLInpaintDenoiseStep,
|
211
|
+
StableDiffusionXLDenoiseStep,
|
212
|
+
]
|
213
|
+
block_names = ["controlnet_denoise", "inpaint_denoise", "denoise"]
|
214
|
+
block_trigger_inputs = ["controlnet_cond", "mask", None]
|
215
|
+
|
216
|
+
@property
|
217
|
+
def description(self) -> str:
|
218
|
+
return (
|
219
|
+
"Denoise step that iteratively denoise the latents. "
|
220
|
+
"This is a auto pipeline block that works for text2img, img2img and inpainting tasks. And can be used with or without controlnet."
|
221
|
+
" - `StableDiffusionXLAutoControlNetDenoiseStep` (controlnet_denoise) is used when controlnet_cond is provided (support controlnet withtext2img, img2img and inpainting tasks)."
|
222
|
+
" - `StableDiffusionXLInpaintDenoiseStep` (inpaint_denoise) is used when mask is provided (support inpainting tasks)."
|
223
|
+
" - `StableDiffusionXLDenoiseStep` (denoise) is used when neither mask nor controlnet_cond are provided (support text2img and img2img tasks)."
|
224
|
+
)
|
225
|
+
|
226
|
+
|
227
|
+
# decode: inpaint
|
228
|
+
class StableDiffusionXLInpaintDecodeStep(SequentialPipelineBlocks):
|
229
|
+
block_classes = [StableDiffusionXLDecodeStep, StableDiffusionXLInpaintOverlayMaskStep]
|
230
|
+
block_names = ["decode", "mask_overlay"]
|
231
|
+
|
232
|
+
@property
|
233
|
+
def description(self):
|
234
|
+
return (
|
235
|
+
"Inpaint decode step that decode the denoised latents into images outputs.\n"
|
236
|
+
+ "This is a sequential pipeline blocks:\n"
|
237
|
+
+ " - `StableDiffusionXLDecodeStep` is used to decode the denoised latents into images\n"
|
238
|
+
+ " - `StableDiffusionXLInpaintOverlayMaskStep` is used to overlay the mask on the image"
|
239
|
+
)
|
240
|
+
|
241
|
+
|
242
|
+
# decode: all task (text2img, img2img, inpainting)
|
243
|
+
class StableDiffusionXLAutoDecodeStep(AutoPipelineBlocks):
|
244
|
+
block_classes = [StableDiffusionXLInpaintDecodeStep, StableDiffusionXLDecodeStep]
|
245
|
+
block_names = ["inpaint", "non-inpaint"]
|
246
|
+
block_trigger_inputs = ["padding_mask_crop", None]
|
247
|
+
|
248
|
+
@property
|
249
|
+
def description(self):
|
250
|
+
return (
|
251
|
+
"Decode step that decode the denoised latents into images outputs.\n"
|
252
|
+
+ "This is an auto pipeline block that works for inpainting and non-inpainting tasks.\n"
|
253
|
+
+ " - `StableDiffusionXLInpaintDecodeStep` (inpaint) is used when `padding_mask_crop` is provided.\n"
|
254
|
+
+ " - `StableDiffusionXLDecodeStep` (non-inpaint) is used when `padding_mask_crop` is not provided."
|
255
|
+
)
|
256
|
+
|
257
|
+
|
258
|
+
# ip-adapter, controlnet, text2img, img2img, inpainting
|
259
|
+
class StableDiffusionXLAutoBlocks(SequentialPipelineBlocks):
|
260
|
+
block_classes = [
|
261
|
+
StableDiffusionXLTextEncoderStep,
|
262
|
+
StableDiffusionXLAutoIPAdapterStep,
|
263
|
+
StableDiffusionXLAutoVaeEncoderStep,
|
264
|
+
StableDiffusionXLAutoBeforeDenoiseStep,
|
265
|
+
StableDiffusionXLAutoControlNetInputStep,
|
266
|
+
StableDiffusionXLAutoDenoiseStep,
|
267
|
+
StableDiffusionXLAutoDecodeStep,
|
268
|
+
]
|
269
|
+
block_names = [
|
270
|
+
"text_encoder",
|
271
|
+
"ip_adapter",
|
272
|
+
"image_encoder",
|
273
|
+
"before_denoise",
|
274
|
+
"controlnet_input",
|
275
|
+
"denoise",
|
276
|
+
"decoder",
|
277
|
+
]
|
278
|
+
|
279
|
+
@property
|
280
|
+
def description(self):
|
281
|
+
return (
|
282
|
+
"Auto Modular pipeline for text-to-image, image-to-image, inpainting, and controlnet tasks using Stable Diffusion XL.\n"
|
283
|
+
+ "- for image-to-image generation, you need to provide either `image` or `image_latents`\n"
|
284
|
+
+ "- for inpainting, you need to provide `mask_image` and `image`, optionally you can provide `padding_mask_crop` \n"
|
285
|
+
+ "- to run the controlnet workflow, you need to provide `control_image`\n"
|
286
|
+
+ "- to run the controlnet_union workflow, you need to provide `control_image` and `control_mode`\n"
|
287
|
+
+ "- to run the ip_adapter workflow, you need to provide `ip_adapter_image`\n"
|
288
|
+
+ "- for text-to-image generation, all you need to provide is `prompt`"
|
289
|
+
)
|
290
|
+
|
291
|
+
|
292
|
+
# controlnet (input + denoise step)
|
293
|
+
class StableDiffusionXLAutoControlnetStep(SequentialPipelineBlocks):
|
294
|
+
block_classes = [
|
295
|
+
StableDiffusionXLAutoControlNetInputStep,
|
296
|
+
StableDiffusionXLAutoControlNetDenoiseStep,
|
297
|
+
]
|
298
|
+
block_names = ["controlnet_input", "controlnet_denoise"]
|
299
|
+
|
300
|
+
@property
|
301
|
+
def description(self):
|
302
|
+
return (
|
303
|
+
"Controlnet auto step that prepare the controlnet input and denoise the latents. "
|
304
|
+
+ "It works for both controlnet and controlnet_union and supports text2img, img2img and inpainting tasks."
|
305
|
+
+ " (it should be replace at 'denoise' step)"
|
306
|
+
)
|
307
|
+
|
308
|
+
|
309
|
+
TEXT2IMAGE_BLOCKS = InsertableDict(
|
310
|
+
[
|
311
|
+
("text_encoder", StableDiffusionXLTextEncoderStep),
|
312
|
+
("input", StableDiffusionXLInputStep),
|
313
|
+
("set_timesteps", StableDiffusionXLSetTimestepsStep),
|
314
|
+
("prepare_latents", StableDiffusionXLPrepareLatentsStep),
|
315
|
+
("prepare_add_cond", StableDiffusionXLPrepareAdditionalConditioningStep),
|
316
|
+
("denoise", StableDiffusionXLDenoiseStep),
|
317
|
+
("decode", StableDiffusionXLDecodeStep),
|
318
|
+
]
|
319
|
+
)
|
320
|
+
|
321
|
+
IMAGE2IMAGE_BLOCKS = InsertableDict(
|
322
|
+
[
|
323
|
+
("text_encoder", StableDiffusionXLTextEncoderStep),
|
324
|
+
("image_encoder", StableDiffusionXLVaeEncoderStep),
|
325
|
+
("input", StableDiffusionXLInputStep),
|
326
|
+
("set_timesteps", StableDiffusionXLImg2ImgSetTimestepsStep),
|
327
|
+
("prepare_latents", StableDiffusionXLImg2ImgPrepareLatentsStep),
|
328
|
+
("prepare_add_cond", StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep),
|
329
|
+
("denoise", StableDiffusionXLDenoiseStep),
|
330
|
+
("decode", StableDiffusionXLDecodeStep),
|
331
|
+
]
|
332
|
+
)
|
333
|
+
|
334
|
+
INPAINT_BLOCKS = InsertableDict(
|
335
|
+
[
|
336
|
+
("text_encoder", StableDiffusionXLTextEncoderStep),
|
337
|
+
("image_encoder", StableDiffusionXLInpaintVaeEncoderStep),
|
338
|
+
("input", StableDiffusionXLInputStep),
|
339
|
+
("set_timesteps", StableDiffusionXLImg2ImgSetTimestepsStep),
|
340
|
+
("prepare_latents", StableDiffusionXLInpaintPrepareLatentsStep),
|
341
|
+
("prepare_add_cond", StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep),
|
342
|
+
("denoise", StableDiffusionXLInpaintDenoiseStep),
|
343
|
+
("decode", StableDiffusionXLInpaintDecodeStep),
|
344
|
+
]
|
345
|
+
)
|
346
|
+
|
347
|
+
CONTROLNET_BLOCKS = InsertableDict(
|
348
|
+
[
|
349
|
+
("denoise", StableDiffusionXLAutoControlnetStep),
|
350
|
+
]
|
351
|
+
)
|
352
|
+
|
353
|
+
|
354
|
+
IP_ADAPTER_BLOCKS = InsertableDict(
|
355
|
+
[
|
356
|
+
("ip_adapter", StableDiffusionXLAutoIPAdapterStep),
|
357
|
+
]
|
358
|
+
)
|
359
|
+
|
360
|
+
AUTO_BLOCKS = InsertableDict(
|
361
|
+
[
|
362
|
+
("text_encoder", StableDiffusionXLTextEncoderStep),
|
363
|
+
("ip_adapter", StableDiffusionXLAutoIPAdapterStep),
|
364
|
+
("image_encoder", StableDiffusionXLAutoVaeEncoderStep),
|
365
|
+
("before_denoise", StableDiffusionXLAutoBeforeDenoiseStep),
|
366
|
+
("controlnet_input", StableDiffusionXLAutoControlNetInputStep),
|
367
|
+
("denoise", StableDiffusionXLAutoDenoiseStep),
|
368
|
+
("decode", StableDiffusionXLAutoDecodeStep),
|
369
|
+
]
|
370
|
+
)
|
371
|
+
|
372
|
+
|
373
|
+
ALL_BLOCKS = {
|
374
|
+
"text2img": TEXT2IMAGE_BLOCKS,
|
375
|
+
"img2img": IMAGE2IMAGE_BLOCKS,
|
376
|
+
"inpaint": INPAINT_BLOCKS,
|
377
|
+
"controlnet": CONTROLNET_BLOCKS,
|
378
|
+
"ip_adapter": IP_ADAPTER_BLOCKS,
|
379
|
+
"auto": AUTO_BLOCKS,
|
380
|
+
}
|