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
@@ -0,0 +1,208 @@
|
|
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 Any, List, Tuple, Union
|
16
|
+
|
17
|
+
import numpy as np
|
18
|
+
import PIL
|
19
|
+
import torch
|
20
|
+
|
21
|
+
from ...configuration_utils import FrozenDict
|
22
|
+
from ...image_processor import VaeImageProcessor
|
23
|
+
from ...models import AutoencoderKL
|
24
|
+
from ...models.attention_processor import AttnProcessor2_0, XFormersAttnProcessor
|
25
|
+
from ...utils import logging
|
26
|
+
from ..modular_pipeline import (
|
27
|
+
ModularPipelineBlocks,
|
28
|
+
PipelineState,
|
29
|
+
)
|
30
|
+
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
31
|
+
|
32
|
+
|
33
|
+
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
34
|
+
|
35
|
+
|
36
|
+
class StableDiffusionXLDecodeStep(ModularPipelineBlocks):
|
37
|
+
model_name = "stable-diffusion-xl"
|
38
|
+
|
39
|
+
@property
|
40
|
+
def expected_components(self) -> List[ComponentSpec]:
|
41
|
+
return [
|
42
|
+
ComponentSpec("vae", AutoencoderKL),
|
43
|
+
ComponentSpec(
|
44
|
+
"image_processor",
|
45
|
+
VaeImageProcessor,
|
46
|
+
config=FrozenDict({"vae_scale_factor": 8}),
|
47
|
+
default_creation_method="from_config",
|
48
|
+
),
|
49
|
+
]
|
50
|
+
|
51
|
+
@property
|
52
|
+
def description(self) -> str:
|
53
|
+
return "Step that decodes the denoised latents into images"
|
54
|
+
|
55
|
+
@property
|
56
|
+
def inputs(self) -> List[Tuple[str, Any]]:
|
57
|
+
return [
|
58
|
+
InputParam("output_type", default="pil"),
|
59
|
+
InputParam(
|
60
|
+
"latents",
|
61
|
+
required=True,
|
62
|
+
type_hint=torch.Tensor,
|
63
|
+
description="The denoised latents from the denoising step",
|
64
|
+
),
|
65
|
+
]
|
66
|
+
|
67
|
+
@property
|
68
|
+
def intermediate_outputs(self) -> List[str]:
|
69
|
+
return [
|
70
|
+
OutputParam(
|
71
|
+
"images",
|
72
|
+
type_hint=Union[List[PIL.Image.Image], List[torch.Tensor], List[np.array]],
|
73
|
+
description="The generated images, can be a PIL.Image.Image, torch.Tensor or a numpy array",
|
74
|
+
)
|
75
|
+
]
|
76
|
+
|
77
|
+
@staticmethod
|
78
|
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae with self->components
|
79
|
+
def upcast_vae(components):
|
80
|
+
dtype = components.vae.dtype
|
81
|
+
components.vae.to(dtype=torch.float32)
|
82
|
+
use_torch_2_0_or_xformers = isinstance(
|
83
|
+
components.vae.decoder.mid_block.attentions[0].processor,
|
84
|
+
(
|
85
|
+
AttnProcessor2_0,
|
86
|
+
XFormersAttnProcessor,
|
87
|
+
),
|
88
|
+
)
|
89
|
+
# if xformers or torch_2_0 is used attention block does not need
|
90
|
+
# to be in float32 which can save lots of memory
|
91
|
+
if use_torch_2_0_or_xformers:
|
92
|
+
components.vae.post_quant_conv.to(dtype)
|
93
|
+
components.vae.decoder.conv_in.to(dtype)
|
94
|
+
components.vae.decoder.mid_block.to(dtype)
|
95
|
+
|
96
|
+
@torch.no_grad()
|
97
|
+
def __call__(self, components, state: PipelineState) -> PipelineState:
|
98
|
+
block_state = self.get_block_state(state)
|
99
|
+
|
100
|
+
if not block_state.output_type == "latent":
|
101
|
+
latents = block_state.latents
|
102
|
+
# make sure the VAE is in float32 mode, as it overflows in float16
|
103
|
+
block_state.needs_upcasting = components.vae.dtype == torch.float16 and components.vae.config.force_upcast
|
104
|
+
|
105
|
+
if block_state.needs_upcasting:
|
106
|
+
self.upcast_vae(components)
|
107
|
+
latents = latents.to(next(iter(components.vae.post_quant_conv.parameters())).dtype)
|
108
|
+
elif latents.dtype != components.vae.dtype:
|
109
|
+
if torch.backends.mps.is_available():
|
110
|
+
# some platforms (eg. apple mps) misbehave due to a pytorch bug: https://github.com/pytorch/pytorch/pull/99272
|
111
|
+
components.vae = components.vae.to(latents.dtype)
|
112
|
+
|
113
|
+
# unscale/denormalize the latents
|
114
|
+
# denormalize with the mean and std if available and not None
|
115
|
+
block_state.has_latents_mean = (
|
116
|
+
hasattr(components.vae.config, "latents_mean") and components.vae.config.latents_mean is not None
|
117
|
+
)
|
118
|
+
block_state.has_latents_std = (
|
119
|
+
hasattr(components.vae.config, "latents_std") and components.vae.config.latents_std is not None
|
120
|
+
)
|
121
|
+
if block_state.has_latents_mean and block_state.has_latents_std:
|
122
|
+
block_state.latents_mean = (
|
123
|
+
torch.tensor(components.vae.config.latents_mean).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
124
|
+
)
|
125
|
+
block_state.latents_std = (
|
126
|
+
torch.tensor(components.vae.config.latents_std).view(1, 4, 1, 1).to(latents.device, latents.dtype)
|
127
|
+
)
|
128
|
+
latents = (
|
129
|
+
latents * block_state.latents_std / components.vae.config.scaling_factor + block_state.latents_mean
|
130
|
+
)
|
131
|
+
else:
|
132
|
+
latents = latents / components.vae.config.scaling_factor
|
133
|
+
|
134
|
+
block_state.images = components.vae.decode(latents, return_dict=False)[0]
|
135
|
+
|
136
|
+
# cast back to fp16 if needed
|
137
|
+
if block_state.needs_upcasting:
|
138
|
+
components.vae.to(dtype=torch.float16)
|
139
|
+
else:
|
140
|
+
block_state.images = block_state.latents
|
141
|
+
|
142
|
+
# apply watermark if available
|
143
|
+
if hasattr(components, "watermark") and components.watermark is not None:
|
144
|
+
block_state.images = components.watermark.apply_watermark(block_state.images)
|
145
|
+
|
146
|
+
block_state.images = components.image_processor.postprocess(
|
147
|
+
block_state.images, output_type=block_state.output_type
|
148
|
+
)
|
149
|
+
|
150
|
+
self.set_block_state(state, block_state)
|
151
|
+
|
152
|
+
return components, state
|
153
|
+
|
154
|
+
|
155
|
+
class StableDiffusionXLInpaintOverlayMaskStep(ModularPipelineBlocks):
|
156
|
+
model_name = "stable-diffusion-xl"
|
157
|
+
|
158
|
+
@property
|
159
|
+
def description(self) -> str:
|
160
|
+
return (
|
161
|
+
"A post-processing step that overlays the mask on the image (inpainting task only).\n"
|
162
|
+
+ "only needed when you are using the `padding_mask_crop` option when pre-processing the image and mask"
|
163
|
+
)
|
164
|
+
|
165
|
+
@property
|
166
|
+
def expected_components(self) -> List[ComponentSpec]:
|
167
|
+
return [
|
168
|
+
ComponentSpec(
|
169
|
+
"image_processor",
|
170
|
+
VaeImageProcessor,
|
171
|
+
config=FrozenDict({"vae_scale_factor": 8}),
|
172
|
+
default_creation_method="from_config",
|
173
|
+
),
|
174
|
+
]
|
175
|
+
|
176
|
+
@property
|
177
|
+
def inputs(self) -> List[Tuple[str, Any]]:
|
178
|
+
return [
|
179
|
+
InputParam("image"),
|
180
|
+
InputParam("mask_image"),
|
181
|
+
InputParam("padding_mask_crop"),
|
182
|
+
InputParam(
|
183
|
+
"images",
|
184
|
+
type_hint=Union[List[PIL.Image.Image], List[torch.Tensor], List[np.array]],
|
185
|
+
description="The generated images from the decode step",
|
186
|
+
),
|
187
|
+
InputParam(
|
188
|
+
"crops_coords",
|
189
|
+
type_hint=Tuple[int, int],
|
190
|
+
description="The crop coordinates to use for preprocess/postprocess the image and mask, for inpainting task only. Can be generated in vae_encode step.",
|
191
|
+
),
|
192
|
+
]
|
193
|
+
|
194
|
+
@torch.no_grad()
|
195
|
+
def __call__(self, components, state: PipelineState) -> PipelineState:
|
196
|
+
block_state = self.get_block_state(state)
|
197
|
+
|
198
|
+
if block_state.padding_mask_crop is not None and block_state.crops_coords is not None:
|
199
|
+
block_state.images = [
|
200
|
+
components.image_processor.apply_overlay(
|
201
|
+
block_state.mask_image, block_state.image, i, block_state.crops_coords
|
202
|
+
)
|
203
|
+
for i in block_state.images
|
204
|
+
]
|
205
|
+
|
206
|
+
self.set_block_state(state, block_state)
|
207
|
+
|
208
|
+
return components, state
|