diffusers 0.34.0__py3-none-any.whl → 0.35.1__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 +849 -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.1.dist-info}/METADATA +6 -6
- {diffusers-0.34.0.dist-info → diffusers-0.35.1.dist-info}/RECORD +191 -127
- {diffusers-0.34.0.dist-info → diffusers-0.35.1.dist-info}/LICENSE +0 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.1.dist-info}/WHEEL +0 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.1.dist-info}/entry_points.txt +0 -0
- {diffusers-0.34.0.dist-info → diffusers-0.35.1.dist-info}/top_level.txt +0 -0
diffusers/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "0.
|
1
|
+
__version__ = "0.35.1"
|
2
2
|
|
3
3
|
from typing import TYPE_CHECKING
|
4
4
|
|
@@ -34,10 +34,13 @@ from .utils import (
|
|
34
34
|
|
35
35
|
_import_structure = {
|
36
36
|
"configuration_utils": ["ConfigMixin"],
|
37
|
+
"guiders": [],
|
37
38
|
"hooks": [],
|
38
39
|
"loaders": ["FromOriginalModelMixin"],
|
39
40
|
"models": [],
|
41
|
+
"modular_pipelines": [],
|
40
42
|
"pipelines": [],
|
43
|
+
"quantizers.pipe_quant_config": ["PipelineQuantizationConfig"],
|
41
44
|
"quantizers.quantization_config": [],
|
42
45
|
"schedulers": [],
|
43
46
|
"utils": [
|
@@ -130,12 +133,30 @@ except OptionalDependencyNotAvailable:
|
|
130
133
|
_import_structure["utils.dummy_pt_objects"] = [name for name in dir(dummy_pt_objects) if not name.startswith("_")]
|
131
134
|
|
132
135
|
else:
|
136
|
+
_import_structure["guiders"].extend(
|
137
|
+
[
|
138
|
+
"AdaptiveProjectedGuidance",
|
139
|
+
"AutoGuidance",
|
140
|
+
"ClassifierFreeGuidance",
|
141
|
+
"ClassifierFreeZeroStarGuidance",
|
142
|
+
"FrequencyDecoupledGuidance",
|
143
|
+
"PerturbedAttentionGuidance",
|
144
|
+
"SkipLayerGuidance",
|
145
|
+
"SmoothedEnergyGuidance",
|
146
|
+
"TangentialClassifierFreeGuidance",
|
147
|
+
]
|
148
|
+
)
|
133
149
|
_import_structure["hooks"].extend(
|
134
150
|
[
|
135
151
|
"FasterCacheConfig",
|
152
|
+
"FirstBlockCacheConfig",
|
136
153
|
"HookRegistry",
|
154
|
+
"LayerSkipConfig",
|
137
155
|
"PyramidAttentionBroadcastConfig",
|
156
|
+
"SmoothedEnergyGuidanceConfig",
|
138
157
|
"apply_faster_cache",
|
158
|
+
"apply_first_block_cache",
|
159
|
+
"apply_layer_skip",
|
139
160
|
"apply_pyramid_attention_broadcast",
|
140
161
|
]
|
141
162
|
)
|
@@ -143,6 +164,7 @@ else:
|
|
143
164
|
[
|
144
165
|
"AllegroTransformer3DModel",
|
145
166
|
"AsymmetricAutoencoderKL",
|
167
|
+
"AttentionBackendName",
|
146
168
|
"AuraFlowTransformer2DModel",
|
147
169
|
"AutoencoderDC",
|
148
170
|
"AutoencoderKL",
|
@@ -153,6 +175,7 @@ else:
|
|
153
175
|
"AutoencoderKLLTXVideo",
|
154
176
|
"AutoencoderKLMagvit",
|
155
177
|
"AutoencoderKLMochi",
|
178
|
+
"AutoencoderKLQwenImage",
|
156
179
|
"AutoencoderKLTemporalDecoder",
|
157
180
|
"AutoencoderKLWan",
|
158
181
|
"AutoencoderOobleck",
|
@@ -194,11 +217,13 @@ else:
|
|
194
217
|
"OmniGenTransformer2DModel",
|
195
218
|
"PixArtTransformer2DModel",
|
196
219
|
"PriorTransformer",
|
220
|
+
"QwenImageTransformer2DModel",
|
197
221
|
"SanaControlNetModel",
|
198
222
|
"SanaTransformer2DModel",
|
199
223
|
"SD3ControlNetModel",
|
200
224
|
"SD3MultiControlNetModel",
|
201
225
|
"SD3Transformer2DModel",
|
226
|
+
"SkyReelsV2Transformer3DModel",
|
202
227
|
"SparseControlNetModel",
|
203
228
|
"StableAudioDiTModel",
|
204
229
|
"StableCascadeUNet",
|
@@ -217,6 +242,15 @@ else:
|
|
217
242
|
"VQModel",
|
218
243
|
"WanTransformer3DModel",
|
219
244
|
"WanVACETransformer3DModel",
|
245
|
+
"attention_backend",
|
246
|
+
]
|
247
|
+
)
|
248
|
+
_import_structure["modular_pipelines"].extend(
|
249
|
+
[
|
250
|
+
"ComponentsManager",
|
251
|
+
"ComponentSpec",
|
252
|
+
"ModularPipeline",
|
253
|
+
"ModularPipelineBlocks",
|
220
254
|
]
|
221
255
|
)
|
222
256
|
_import_structure["optimization"] = [
|
@@ -331,6 +365,16 @@ except OptionalDependencyNotAvailable:
|
|
331
365
|
]
|
332
366
|
|
333
367
|
else:
|
368
|
+
_import_structure["modular_pipelines"].extend(
|
369
|
+
[
|
370
|
+
"FluxAutoBlocks",
|
371
|
+
"FluxModularPipeline",
|
372
|
+
"StableDiffusionXLAutoBlocks",
|
373
|
+
"StableDiffusionXLModularPipeline",
|
374
|
+
"WanAutoBlocks",
|
375
|
+
"WanModularPipeline",
|
376
|
+
]
|
377
|
+
)
|
334
378
|
_import_structure["pipelines"].extend(
|
335
379
|
[
|
336
380
|
"AllegroPipeline",
|
@@ -381,6 +425,8 @@ else:
|
|
381
425
|
"FluxFillPipeline",
|
382
426
|
"FluxImg2ImgPipeline",
|
383
427
|
"FluxInpaintPipeline",
|
428
|
+
"FluxKontextInpaintPipeline",
|
429
|
+
"FluxKontextPipeline",
|
384
430
|
"FluxPipeline",
|
385
431
|
"FluxPriorReduxPipeline",
|
386
432
|
"HiDreamImagePipeline",
|
@@ -443,6 +489,10 @@ else:
|
|
443
489
|
"PixArtAlphaPipeline",
|
444
490
|
"PixArtSigmaPAGPipeline",
|
445
491
|
"PixArtSigmaPipeline",
|
492
|
+
"QwenImageEditPipeline",
|
493
|
+
"QwenImageImg2ImgPipeline",
|
494
|
+
"QwenImageInpaintPipeline",
|
495
|
+
"QwenImagePipeline",
|
446
496
|
"ReduxImageEncoder",
|
447
497
|
"SanaControlNetPipeline",
|
448
498
|
"SanaPAGPipeline",
|
@@ -452,6 +502,11 @@ else:
|
|
452
502
|
"SemanticStableDiffusionPipeline",
|
453
503
|
"ShapEImg2ImgPipeline",
|
454
504
|
"ShapEPipeline",
|
505
|
+
"SkyReelsV2DiffusionForcingImageToVideoPipeline",
|
506
|
+
"SkyReelsV2DiffusionForcingPipeline",
|
507
|
+
"SkyReelsV2DiffusionForcingVideoToVideoPipeline",
|
508
|
+
"SkyReelsV2ImageToVideoPipeline",
|
509
|
+
"SkyReelsV2Pipeline",
|
455
510
|
"StableAudioPipeline",
|
456
511
|
"StableAudioProjectionModel",
|
457
512
|
"StableCascadeCombinedPipeline",
|
@@ -541,6 +596,7 @@ else:
|
|
541
596
|
]
|
542
597
|
)
|
543
598
|
|
599
|
+
|
544
600
|
try:
|
545
601
|
if not (is_torch_available() and is_transformers_available() and is_opencv_available()):
|
546
602
|
raise OptionalDependencyNotAvailable()
|
@@ -747,16 +803,33 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
747
803
|
except OptionalDependencyNotAvailable:
|
748
804
|
from .utils.dummy_pt_objects import * # noqa F403
|
749
805
|
else:
|
806
|
+
from .guiders import (
|
807
|
+
AdaptiveProjectedGuidance,
|
808
|
+
AutoGuidance,
|
809
|
+
ClassifierFreeGuidance,
|
810
|
+
ClassifierFreeZeroStarGuidance,
|
811
|
+
FrequencyDecoupledGuidance,
|
812
|
+
PerturbedAttentionGuidance,
|
813
|
+
SkipLayerGuidance,
|
814
|
+
SmoothedEnergyGuidance,
|
815
|
+
TangentialClassifierFreeGuidance,
|
816
|
+
)
|
750
817
|
from .hooks import (
|
751
818
|
FasterCacheConfig,
|
819
|
+
FirstBlockCacheConfig,
|
752
820
|
HookRegistry,
|
821
|
+
LayerSkipConfig,
|
753
822
|
PyramidAttentionBroadcastConfig,
|
823
|
+
SmoothedEnergyGuidanceConfig,
|
754
824
|
apply_faster_cache,
|
825
|
+
apply_first_block_cache,
|
826
|
+
apply_layer_skip,
|
755
827
|
apply_pyramid_attention_broadcast,
|
756
828
|
)
|
757
829
|
from .models import (
|
758
830
|
AllegroTransformer3DModel,
|
759
831
|
AsymmetricAutoencoderKL,
|
832
|
+
AttentionBackendName,
|
760
833
|
AuraFlowTransformer2DModel,
|
761
834
|
AutoencoderDC,
|
762
835
|
AutoencoderKL,
|
@@ -767,6 +840,7 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
767
840
|
AutoencoderKLLTXVideo,
|
768
841
|
AutoencoderKLMagvit,
|
769
842
|
AutoencoderKLMochi,
|
843
|
+
AutoencoderKLQwenImage,
|
770
844
|
AutoencoderKLTemporalDecoder,
|
771
845
|
AutoencoderKLWan,
|
772
846
|
AutoencoderOobleck,
|
@@ -808,11 +882,13 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
808
882
|
OmniGenTransformer2DModel,
|
809
883
|
PixArtTransformer2DModel,
|
810
884
|
PriorTransformer,
|
885
|
+
QwenImageTransformer2DModel,
|
811
886
|
SanaControlNetModel,
|
812
887
|
SanaTransformer2DModel,
|
813
888
|
SD3ControlNetModel,
|
814
889
|
SD3MultiControlNetModel,
|
815
890
|
SD3Transformer2DModel,
|
891
|
+
SkyReelsV2Transformer3DModel,
|
816
892
|
SparseControlNetModel,
|
817
893
|
StableAudioDiTModel,
|
818
894
|
T2IAdapter,
|
@@ -830,7 +906,9 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
830
906
|
VQModel,
|
831
907
|
WanTransformer3DModel,
|
832
908
|
WanVACETransformer3DModel,
|
909
|
+
attention_backend,
|
833
910
|
)
|
911
|
+
from .modular_pipelines import ComponentsManager, ComponentSpec, ModularPipeline, ModularPipelineBlocks
|
834
912
|
from .optimization import (
|
835
913
|
get_constant_schedule,
|
836
914
|
get_constant_schedule_with_warmup,
|
@@ -927,6 +1005,14 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
927
1005
|
except OptionalDependencyNotAvailable:
|
928
1006
|
from .utils.dummy_torch_and_transformers_objects import * # noqa F403
|
929
1007
|
else:
|
1008
|
+
from .modular_pipelines import (
|
1009
|
+
FluxAutoBlocks,
|
1010
|
+
FluxModularPipeline,
|
1011
|
+
StableDiffusionXLAutoBlocks,
|
1012
|
+
StableDiffusionXLModularPipeline,
|
1013
|
+
WanAutoBlocks,
|
1014
|
+
WanModularPipeline,
|
1015
|
+
)
|
930
1016
|
from .pipelines import (
|
931
1017
|
AllegroPipeline,
|
932
1018
|
AltDiffusionImg2ImgPipeline,
|
@@ -974,6 +1060,8 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
974
1060
|
FluxFillPipeline,
|
975
1061
|
FluxImg2ImgPipeline,
|
976
1062
|
FluxInpaintPipeline,
|
1063
|
+
FluxKontextInpaintPipeline,
|
1064
|
+
FluxKontextPipeline,
|
977
1065
|
FluxPipeline,
|
978
1066
|
FluxPriorReduxPipeline,
|
979
1067
|
HiDreamImagePipeline,
|
@@ -1036,6 +1124,10 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
1036
1124
|
PixArtAlphaPipeline,
|
1037
1125
|
PixArtSigmaPAGPipeline,
|
1038
1126
|
PixArtSigmaPipeline,
|
1127
|
+
QwenImageEditPipeline,
|
1128
|
+
QwenImageImg2ImgPipeline,
|
1129
|
+
QwenImageInpaintPipeline,
|
1130
|
+
QwenImagePipeline,
|
1039
1131
|
ReduxImageEncoder,
|
1040
1132
|
SanaControlNetPipeline,
|
1041
1133
|
SanaPAGPipeline,
|
@@ -1045,6 +1137,11 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
1045
1137
|
SemanticStableDiffusionPipeline,
|
1046
1138
|
ShapEImg2ImgPipeline,
|
1047
1139
|
ShapEPipeline,
|
1140
|
+
SkyReelsV2DiffusionForcingImageToVideoPipeline,
|
1141
|
+
SkyReelsV2DiffusionForcingPipeline,
|
1142
|
+
SkyReelsV2DiffusionForcingVideoToVideoPipeline,
|
1143
|
+
SkyReelsV2ImageToVideoPipeline,
|
1144
|
+
SkyReelsV2Pipeline,
|
1048
1145
|
StableAudioPipeline,
|
1049
1146
|
StableAudioProjectionModel,
|
1050
1147
|
StableCascadeCombinedPipeline,
|
diffusers/callbacks.py
CHANGED
@@ -207,3 +207,38 @@ class IPAdapterScaleCutoffCallback(PipelineCallback):
|
|
207
207
|
if step_index == cutoff_step:
|
208
208
|
pipeline.set_ip_adapter_scale(0.0)
|
209
209
|
return callback_kwargs
|
210
|
+
|
211
|
+
|
212
|
+
class SD3CFGCutoffCallback(PipelineCallback):
|
213
|
+
"""
|
214
|
+
Callback function for Stable Diffusion 3 Pipelines. After certain number of steps (set by `cutoff_step_ratio` or
|
215
|
+
`cutoff_step_index`), this callback will disable the CFG.
|
216
|
+
|
217
|
+
Note: This callback mutates the pipeline by changing the `_guidance_scale` attribute to 0.0 after the cutoff step.
|
218
|
+
"""
|
219
|
+
|
220
|
+
tensor_inputs = ["prompt_embeds", "pooled_prompt_embeds"]
|
221
|
+
|
222
|
+
def callback_fn(self, pipeline, step_index, timestep, callback_kwargs) -> Dict[str, Any]:
|
223
|
+
cutoff_step_ratio = self.config.cutoff_step_ratio
|
224
|
+
cutoff_step_index = self.config.cutoff_step_index
|
225
|
+
|
226
|
+
# Use cutoff_step_index if it's not None, otherwise use cutoff_step_ratio
|
227
|
+
cutoff_step = (
|
228
|
+
cutoff_step_index if cutoff_step_index is not None else int(pipeline.num_timesteps * cutoff_step_ratio)
|
229
|
+
)
|
230
|
+
|
231
|
+
if step_index == cutoff_step:
|
232
|
+
prompt_embeds = callback_kwargs[self.tensor_inputs[0]]
|
233
|
+
prompt_embeds = prompt_embeds[-1:] # "-1" denotes the embeddings for conditional text tokens.
|
234
|
+
|
235
|
+
pooled_prompt_embeds = callback_kwargs[self.tensor_inputs[1]]
|
236
|
+
pooled_prompt_embeds = pooled_prompt_embeds[
|
237
|
+
-1:
|
238
|
+
] # "-1" denotes the embeddings for conditional pooled text tokens.
|
239
|
+
|
240
|
+
pipeline._guidance_scale = 0.0
|
241
|
+
|
242
|
+
callback_kwargs[self.tensor_inputs[0]] = prompt_embeds
|
243
|
+
callback_kwargs[self.tensor_inputs[1]] = pooled_prompt_embeds
|
244
|
+
return callback_kwargs
|
@@ -0,0 +1,134 @@
|
|
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
|
+
"""
|
16
|
+
Usage example:
|
17
|
+
TODO
|
18
|
+
"""
|
19
|
+
|
20
|
+
import ast
|
21
|
+
import importlib.util
|
22
|
+
import os
|
23
|
+
from argparse import ArgumentParser, Namespace
|
24
|
+
from pathlib import Path
|
25
|
+
|
26
|
+
from ..utils import logging
|
27
|
+
from . import BaseDiffusersCLICommand
|
28
|
+
|
29
|
+
|
30
|
+
EXPECTED_PARENT_CLASSES = ["ModularPipelineBlocks"]
|
31
|
+
CONFIG = "config.json"
|
32
|
+
|
33
|
+
|
34
|
+
def conversion_command_factory(args: Namespace):
|
35
|
+
return CustomBlocksCommand(args.block_module_name, args.block_class_name)
|
36
|
+
|
37
|
+
|
38
|
+
class CustomBlocksCommand(BaseDiffusersCLICommand):
|
39
|
+
@staticmethod
|
40
|
+
def register_subcommand(parser: ArgumentParser):
|
41
|
+
conversion_parser = parser.add_parser("custom_blocks")
|
42
|
+
conversion_parser.add_argument(
|
43
|
+
"--block_module_name",
|
44
|
+
type=str,
|
45
|
+
default="block.py",
|
46
|
+
help="Module filename in which the custom block will be implemented.",
|
47
|
+
)
|
48
|
+
conversion_parser.add_argument(
|
49
|
+
"--block_class_name",
|
50
|
+
type=str,
|
51
|
+
default=None,
|
52
|
+
help="Name of the custom block. If provided None, we will try to infer it.",
|
53
|
+
)
|
54
|
+
conversion_parser.set_defaults(func=conversion_command_factory)
|
55
|
+
|
56
|
+
def __init__(self, block_module_name: str = "block.py", block_class_name: str = None):
|
57
|
+
self.logger = logging.get_logger("diffusers-cli/custom_blocks")
|
58
|
+
self.block_module_name = Path(block_module_name)
|
59
|
+
self.block_class_name = block_class_name
|
60
|
+
|
61
|
+
def run(self):
|
62
|
+
# determine the block to be saved.
|
63
|
+
out = self._get_class_names(self.block_module_name)
|
64
|
+
classes_found = list({cls for cls, _ in out})
|
65
|
+
|
66
|
+
if self.block_class_name is not None:
|
67
|
+
child_class, parent_class = self._choose_block(out, self.block_class_name)
|
68
|
+
if child_class is None and parent_class is None:
|
69
|
+
raise ValueError(
|
70
|
+
"`block_class_name` could not be retrieved. Available classes from "
|
71
|
+
f"{self.block_module_name}:\n{classes_found}"
|
72
|
+
)
|
73
|
+
else:
|
74
|
+
self.logger.info(
|
75
|
+
f"Found classes: {classes_found} will be using {classes_found[0]}. "
|
76
|
+
"If this needs to be changed, re-run the command specifying `block_class_name`."
|
77
|
+
)
|
78
|
+
child_class, parent_class = out[0][0], out[0][1]
|
79
|
+
|
80
|
+
# dynamically get the custom block and initialize it to call `save_pretrained` in the current directory.
|
81
|
+
# the user is responsible for running it, so I guess that is safe?
|
82
|
+
module_name = f"__dynamic__{self.block_module_name.stem}"
|
83
|
+
spec = importlib.util.spec_from_file_location(module_name, str(self.block_module_name))
|
84
|
+
module = importlib.util.module_from_spec(spec)
|
85
|
+
spec.loader.exec_module(module)
|
86
|
+
getattr(module, child_class)().save_pretrained(os.getcwd())
|
87
|
+
|
88
|
+
# or, we could create it manually.
|
89
|
+
# automap = self._create_automap(parent_class=parent_class, child_class=child_class)
|
90
|
+
# with open(CONFIG, "w") as f:
|
91
|
+
# json.dump(automap, f)
|
92
|
+
with open("requirements.txt", "w") as f:
|
93
|
+
f.write("")
|
94
|
+
|
95
|
+
def _choose_block(self, candidates, chosen=None):
|
96
|
+
for cls, base in candidates:
|
97
|
+
if cls == chosen:
|
98
|
+
return cls, base
|
99
|
+
return None, None
|
100
|
+
|
101
|
+
def _get_class_names(self, file_path):
|
102
|
+
source = file_path.read_text(encoding="utf-8")
|
103
|
+
try:
|
104
|
+
tree = ast.parse(source, filename=file_path)
|
105
|
+
except SyntaxError as e:
|
106
|
+
raise ValueError(f"Could not parse {file_path!r}: {e}") from e
|
107
|
+
|
108
|
+
results: list[tuple[str, str]] = []
|
109
|
+
for node in tree.body:
|
110
|
+
if not isinstance(node, ast.ClassDef):
|
111
|
+
continue
|
112
|
+
|
113
|
+
# extract all base names for this class
|
114
|
+
base_names = [bname for b in node.bases if (bname := self._get_base_name(b)) is not None]
|
115
|
+
|
116
|
+
# for each allowed base that appears in the class's bases, emit a tuple
|
117
|
+
for allowed in EXPECTED_PARENT_CLASSES:
|
118
|
+
if allowed in base_names:
|
119
|
+
results.append((node.name, allowed))
|
120
|
+
|
121
|
+
return results
|
122
|
+
|
123
|
+
def _get_base_name(self, node: ast.expr):
|
124
|
+
if isinstance(node, ast.Name):
|
125
|
+
return node.id
|
126
|
+
elif isinstance(node, ast.Attribute):
|
127
|
+
val = self._get_base_name(node.value)
|
128
|
+
return f"{val}.{node.attr}" if val else node.attr
|
129
|
+
return None
|
130
|
+
|
131
|
+
def _create_automap(self, parent_class, child_class):
|
132
|
+
module = str(self.block_module_name).replace(".py", "").rsplit(".", 1)[-1]
|
133
|
+
auto_map = {f"{parent_class}": f"{module}.{child_class}"}
|
134
|
+
return {"auto_map": auto_map}
|
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
from argparse import ArgumentParser
|
17
17
|
|
18
|
+
from .custom_blocks import CustomBlocksCommand
|
18
19
|
from .env import EnvironmentCommand
|
19
20
|
from .fp16_safetensors import FP16SafetensorsCommand
|
20
21
|
|
@@ -26,6 +27,7 @@ def main():
|
|
26
27
|
# Register commands
|
27
28
|
EnvironmentCommand.register_subcommand(commands_parser)
|
28
29
|
FP16SafetensorsCommand.register_subcommand(commands_parser)
|
30
|
+
CustomBlocksCommand.register_subcommand(commands_parser)
|
29
31
|
|
30
32
|
# Let's go
|
31
33
|
args = parser.parse_args()
|
@@ -59,7 +59,7 @@ class FP16SafetensorsCommand(BaseDiffusersCLICommand):
|
|
59
59
|
conversion_parser.add_argument(
|
60
60
|
"--use_auth_token",
|
61
61
|
action="store_true",
|
62
|
-
help="When working with checkpoints having private visibility. When used `
|
62
|
+
help="When working with checkpoints having private visibility. When used `hf auth login` needs to be run beforehand.",
|
63
63
|
)
|
64
64
|
conversion_parser.set_defaults(func=conversion_command_factory)
|
65
65
|
|
diffusers/configuration_utils.py
CHANGED
@@ -176,6 +176,7 @@ class ConfigMixin:
|
|
176
176
|
token = kwargs.pop("token", None)
|
177
177
|
repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1])
|
178
178
|
repo_id = create_repo(repo_id, exist_ok=True, private=private, token=token).repo_id
|
179
|
+
subfolder = kwargs.pop("subfolder", None)
|
179
180
|
|
180
181
|
self._upload_folder(
|
181
182
|
save_directory,
|
@@ -183,6 +184,7 @@ class ConfigMixin:
|
|
183
184
|
token=token,
|
184
185
|
commit_message=commit_message,
|
185
186
|
create_pr=create_pr,
|
187
|
+
subfolder=subfolder,
|
186
188
|
)
|
187
189
|
|
188
190
|
@classmethod
|
@@ -405,7 +407,7 @@ class ConfigMixin:
|
|
405
407
|
raise EnvironmentError(
|
406
408
|
f"{pretrained_model_name_or_path} is not a local folder and is not a valid model identifier"
|
407
409
|
" listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a"
|
408
|
-
" token having permission to this repo with `token` or log in with `
|
410
|
+
" token having permission to this repo with `token` or log in with `hf auth login`."
|
409
411
|
)
|
410
412
|
except RevisionNotFoundError:
|
411
413
|
raise EnvironmentError(
|
@@ -601,6 +603,10 @@ class ConfigMixin:
|
|
601
603
|
value = value.tolist()
|
602
604
|
elif isinstance(value, Path):
|
603
605
|
value = value.as_posix()
|
606
|
+
elif hasattr(value, "to_dict") and callable(value.to_dict):
|
607
|
+
value = value.to_dict()
|
608
|
+
elif isinstance(value, list):
|
609
|
+
value = [to_json_saveable(v) for v in value]
|
604
610
|
return value
|
605
611
|
|
606
612
|
if "quantization_config" in config_dict:
|
@@ -757,4 +763,7 @@ class LegacyConfigMixin(ConfigMixin):
|
|
757
763
|
# resolve remapping
|
758
764
|
remapped_class = _fetch_remapped_cls_from_config(config, cls)
|
759
765
|
|
760
|
-
|
766
|
+
if remapped_class is cls:
|
767
|
+
return super(LegacyConfigMixin, remapped_class).from_config(config, return_unused_kwargs, **kwargs)
|
768
|
+
else:
|
769
|
+
return remapped_class.from_config(config, return_unused_kwargs, **kwargs)
|
@@ -9,7 +9,7 @@ deps = {
|
|
9
9
|
"filelock": "filelock",
|
10
10
|
"flax": "flax>=0.4.1",
|
11
11
|
"hf-doc-builder": "hf-doc-builder>=0.3.0",
|
12
|
-
"huggingface-hub": "huggingface-hub>=0.
|
12
|
+
"huggingface-hub": "huggingface-hub>=0.34.0",
|
13
13
|
"requests-mock": "requests-mock==1.10.0",
|
14
14
|
"importlib_metadata": "importlib_metadata",
|
15
15
|
"invisible-watermark": "invisible-watermark>=0.2.0",
|
@@ -17,13 +17,13 @@ deps = {
|
|
17
17
|
"jax": "jax>=0.4.1",
|
18
18
|
"jaxlib": "jaxlib>=0.4.1",
|
19
19
|
"Jinja2": "Jinja2",
|
20
|
-
"k-diffusion": "k-diffusion
|
20
|
+
"k-diffusion": "k-diffusion==0.0.12",
|
21
21
|
"torchsde": "torchsde",
|
22
22
|
"note_seq": "note_seq",
|
23
23
|
"librosa": "librosa",
|
24
24
|
"numpy": "numpy",
|
25
25
|
"parameterized": "parameterized",
|
26
|
-
"peft": "peft>=0.
|
26
|
+
"peft": "peft>=0.17.0",
|
27
27
|
"protobuf": "protobuf>=3.20.3,<4",
|
28
28
|
"pytest": "pytest",
|
29
29
|
"pytest-timeout": "pytest-timeout",
|
@@ -0,0 +1,41 @@
|
|
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 typing import Union
|
16
|
+
|
17
|
+
from ..utils import is_torch_available
|
18
|
+
|
19
|
+
|
20
|
+
if is_torch_available():
|
21
|
+
from .adaptive_projected_guidance import AdaptiveProjectedGuidance
|
22
|
+
from .auto_guidance import AutoGuidance
|
23
|
+
from .classifier_free_guidance import ClassifierFreeGuidance
|
24
|
+
from .classifier_free_zero_star_guidance import ClassifierFreeZeroStarGuidance
|
25
|
+
from .frequency_decoupled_guidance import FrequencyDecoupledGuidance
|
26
|
+
from .perturbed_attention_guidance import PerturbedAttentionGuidance
|
27
|
+
from .skip_layer_guidance import SkipLayerGuidance
|
28
|
+
from .smoothed_energy_guidance import SmoothedEnergyGuidance
|
29
|
+
from .tangential_classifier_free_guidance import TangentialClassifierFreeGuidance
|
30
|
+
|
31
|
+
GuiderType = Union[
|
32
|
+
AdaptiveProjectedGuidance,
|
33
|
+
AutoGuidance,
|
34
|
+
ClassifierFreeGuidance,
|
35
|
+
ClassifierFreeZeroStarGuidance,
|
36
|
+
FrequencyDecoupledGuidance,
|
37
|
+
PerturbedAttentionGuidance,
|
38
|
+
SkipLayerGuidance,
|
39
|
+
SmoothedEnergyGuidance,
|
40
|
+
TangentialClassifierFreeGuidance,
|
41
|
+
]
|