diffusers 0.23.0__py3-none-any.whl → 0.24.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +16 -2
- diffusers/configuration_utils.py +1 -0
- diffusers/dependency_versions_check.py +1 -14
- diffusers/dependency_versions_table.py +5 -4
- diffusers/image_processor.py +186 -14
- diffusers/loaders/__init__.py +82 -0
- diffusers/loaders/ip_adapter.py +157 -0
- diffusers/loaders/lora.py +1415 -0
- diffusers/loaders/lora_conversion_utils.py +284 -0
- diffusers/loaders/single_file.py +631 -0
- diffusers/loaders/textual_inversion.py +459 -0
- diffusers/loaders/unet.py +735 -0
- diffusers/loaders/utils.py +59 -0
- diffusers/models/__init__.py +12 -1
- diffusers/models/attention.py +165 -14
- diffusers/models/attention_flax.py +9 -1
- diffusers/models/attention_processor.py +286 -1
- diffusers/models/autoencoder_asym_kl.py +14 -9
- diffusers/models/autoencoder_kl.py +3 -18
- diffusers/models/autoencoder_kl_temporal_decoder.py +402 -0
- diffusers/models/autoencoder_tiny.py +20 -24
- diffusers/models/consistency_decoder_vae.py +37 -30
- diffusers/models/controlnet.py +59 -39
- diffusers/models/controlnet_flax.py +19 -18
- diffusers/models/embeddings_flax.py +2 -0
- diffusers/models/lora.py +131 -1
- diffusers/models/modeling_flax_utils.py +2 -1
- diffusers/models/modeling_outputs.py +17 -0
- diffusers/models/modeling_utils.py +27 -19
- diffusers/models/normalization.py +2 -2
- diffusers/models/resnet.py +390 -59
- diffusers/models/transformer_2d.py +20 -3
- diffusers/models/transformer_temporal.py +183 -1
- diffusers/models/unet_2d_blocks_flax.py +5 -0
- diffusers/models/unet_2d_condition.py +9 -0
- diffusers/models/unet_2d_condition_flax.py +13 -13
- diffusers/models/unet_3d_blocks.py +957 -173
- diffusers/models/unet_3d_condition.py +16 -8
- diffusers/models/unet_kandi3.py +589 -0
- diffusers/models/unet_motion_model.py +48 -33
- diffusers/models/unet_spatio_temporal_condition.py +489 -0
- diffusers/models/vae.py +63 -13
- diffusers/models/vae_flax.py +7 -0
- diffusers/models/vq_model.py +3 -1
- diffusers/optimization.py +16 -9
- diffusers/pipelines/__init__.py +65 -12
- diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +93 -23
- diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +97 -25
- diffusers/pipelines/animatediff/pipeline_animatediff.py +34 -4
- diffusers/pipelines/audioldm/pipeline_audioldm.py +1 -0
- diffusers/pipelines/auto_pipeline.py +6 -0
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +1 -0
- diffusers/pipelines/controlnet/pipeline_controlnet.py +217 -31
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +101 -32
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +136 -39
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +119 -37
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +196 -35
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +102 -31
- diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py +1 -0
- diffusers/pipelines/ddim/pipeline_ddim.py +1 -0
- diffusers/pipelines/ddpm/pipeline_ddpm.py +1 -0
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +13 -1
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +13 -1
- diffusers/pipelines/dit/pipeline_dit.py +1 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +3 -3
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +1 -1
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +1 -1
- diffusers/pipelines/kandinsky3/__init__.py +49 -0
- diffusers/pipelines/kandinsky3/kandinsky3_pipeline.py +452 -0
- diffusers/pipelines/kandinsky3/kandinsky3img2img_pipeline.py +460 -0
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +65 -6
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +55 -3
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +1 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +1 -1
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +7 -2
- diffusers/pipelines/pipeline_flax_utils.py +4 -2
- diffusers/pipelines/pipeline_utils.py +33 -13
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +196 -36
- diffusers/pipelines/score_sde_ve/pipeline_score_sde_ve.py +1 -0
- diffusers/pipelines/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +1 -0
- diffusers/pipelines/stable_diffusion/__init__.py +64 -21
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +8 -3
- diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py +18 -2
- diffusers/pipelines/stable_diffusion/pipeline_flax_stable_diffusion.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py +2 -4
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint_legacy.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +88 -9
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_attend_and_excite.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +8 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_gligen_text_image.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +92 -9
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +92 -9
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +17 -13
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_k_diffusion.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_ldm3d.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_paradigms.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py +1 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +1 -0
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +103 -8
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +113 -8
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +115 -9
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +16 -12
- diffusers/pipelines/stable_video_diffusion/__init__.py +58 -0
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +649 -0
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +108 -12
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +109 -14
- diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +1 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +18 -3
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +4 -2
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +872 -0
- diffusers/pipelines/versatile_diffusion/modeling_text_unet.py +29 -40
- diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +1 -0
- diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +1 -0
- diffusers/pipelines/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +1 -0
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +14 -4
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +9 -5
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +1 -1
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +2 -2
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +1 -1
- diffusers/schedulers/__init__.py +2 -4
- diffusers/schedulers/deprecated/__init__.py +50 -0
- diffusers/schedulers/{scheduling_karras_ve.py → deprecated/scheduling_karras_ve.py} +4 -4
- diffusers/schedulers/{scheduling_sde_vp.py → deprecated/scheduling_sde_vp.py} +4 -6
- diffusers/schedulers/scheduling_ddim.py +1 -3
- diffusers/schedulers/scheduling_ddim_inverse.py +1 -3
- diffusers/schedulers/scheduling_ddim_parallel.py +1 -3
- diffusers/schedulers/scheduling_ddpm.py +1 -3
- diffusers/schedulers/scheduling_ddpm_parallel.py +1 -3
- diffusers/schedulers/scheduling_deis_multistep.py +15 -5
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +15 -5
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +15 -5
- diffusers/schedulers/scheduling_dpmsolver_sde.py +1 -3
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +15 -5
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +1 -3
- diffusers/schedulers/scheduling_euler_discrete.py +40 -13
- diffusers/schedulers/scheduling_heun_discrete.py +15 -5
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +15 -5
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +15 -5
- diffusers/schedulers/scheduling_lcm.py +123 -29
- diffusers/schedulers/scheduling_lms_discrete.py +1 -3
- diffusers/schedulers/scheduling_pndm.py +1 -3
- diffusers/schedulers/scheduling_repaint.py +1 -3
- diffusers/schedulers/scheduling_unipc_multistep.py +15 -5
- diffusers/utils/__init__.py +1 -0
- diffusers/utils/constants.py +11 -6
- diffusers/utils/dummy_pt_objects.py +45 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +60 -0
- diffusers/utils/dynamic_modules_utils.py +4 -4
- diffusers/utils/export_utils.py +8 -3
- diffusers/utils/logging.py +10 -10
- diffusers/utils/outputs.py +5 -5
- diffusers/utils/peft_utils.py +88 -44
- diffusers/utils/torch_utils.py +2 -2
- diffusers/utils/versions.py +117 -0
- {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/METADATA +83 -64
- {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/RECORD +176 -157
- {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/WHEEL +1 -1
- {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/entry_points.txt +1 -0
- diffusers/loaders.py +0 -3336
- {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/LICENSE +0 -0
- {diffusers-0.23.0.dist-info → diffusers-0.24.0.dist-info}/top_level.txt +0 -0
diffusers/models/vae_flax.py
CHANGED
@@ -214,6 +214,7 @@ class FlaxAttentionBlock(nn.Module):
|
|
214
214
|
Parameters `dtype`
|
215
215
|
|
216
216
|
"""
|
217
|
+
|
217
218
|
channels: int
|
218
219
|
num_head_channels: int = None
|
219
220
|
num_groups: int = 32
|
@@ -291,6 +292,7 @@ class FlaxDownEncoderBlock2D(nn.Module):
|
|
291
292
|
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
292
293
|
Parameters `dtype`
|
293
294
|
"""
|
295
|
+
|
294
296
|
in_channels: int
|
295
297
|
out_channels: int
|
296
298
|
dropout: float = 0.0
|
@@ -347,6 +349,7 @@ class FlaxUpDecoderBlock2D(nn.Module):
|
|
347
349
|
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
348
350
|
Parameters `dtype`
|
349
351
|
"""
|
352
|
+
|
350
353
|
in_channels: int
|
351
354
|
out_channels: int
|
352
355
|
dropout: float = 0.0
|
@@ -401,6 +404,7 @@ class FlaxUNetMidBlock2D(nn.Module):
|
|
401
404
|
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
402
405
|
Parameters `dtype`
|
403
406
|
"""
|
407
|
+
|
404
408
|
in_channels: int
|
405
409
|
dropout: float = 0.0
|
406
410
|
num_layers: int = 1
|
@@ -488,6 +492,7 @@ class FlaxEncoder(nn.Module):
|
|
488
492
|
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
489
493
|
Parameters `dtype`
|
490
494
|
"""
|
495
|
+
|
491
496
|
in_channels: int = 3
|
492
497
|
out_channels: int = 3
|
493
498
|
down_block_types: Tuple[str] = ("DownEncoderBlock2D",)
|
@@ -600,6 +605,7 @@ class FlaxDecoder(nn.Module):
|
|
600
605
|
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
601
606
|
parameters `dtype`
|
602
607
|
"""
|
608
|
+
|
603
609
|
in_channels: int = 3
|
604
610
|
out_channels: int = 3
|
605
611
|
up_block_types: Tuple[str] = ("UpDecoderBlock2D",)
|
@@ -767,6 +773,7 @@ class FlaxAutoencoderKL(nn.Module, FlaxModelMixin, ConfigMixin):
|
|
767
773
|
dtype (`jnp.dtype`, *optional*, defaults to `jnp.float32`):
|
768
774
|
The `dtype` of the parameters.
|
769
775
|
"""
|
776
|
+
|
770
777
|
in_channels: int = 3
|
771
778
|
out_channels: int = 3
|
772
779
|
down_block_types: Tuple[str] = ("DownEncoderBlock2D",)
|
diffusers/models/vq_model.py
CHANGED
@@ -148,7 +148,9 @@ class VQModel(ModelMixin, ConfigMixin):
|
|
148
148
|
|
149
149
|
return DecoderOutput(sample=dec)
|
150
150
|
|
151
|
-
def forward(
|
151
|
+
def forward(
|
152
|
+
self, sample: torch.FloatTensor, return_dict: bool = True
|
153
|
+
) -> Union[DecoderOutput, Tuple[torch.FloatTensor, ...]]:
|
152
154
|
r"""
|
153
155
|
The [`VQModel`] forward method.
|
154
156
|
|
diffusers/optimization.py
CHANGED
@@ -37,7 +37,7 @@ class SchedulerType(Enum):
|
|
37
37
|
PIECEWISE_CONSTANT = "piecewise_constant"
|
38
38
|
|
39
39
|
|
40
|
-
def get_constant_schedule(optimizer: Optimizer, last_epoch: int = -1):
|
40
|
+
def get_constant_schedule(optimizer: Optimizer, last_epoch: int = -1) -> LambdaLR:
|
41
41
|
"""
|
42
42
|
Create a schedule with a constant learning rate, using the learning rate set in optimizer.
|
43
43
|
|
@@ -53,7 +53,7 @@ def get_constant_schedule(optimizer: Optimizer, last_epoch: int = -1):
|
|
53
53
|
return LambdaLR(optimizer, lambda _: 1, last_epoch=last_epoch)
|
54
54
|
|
55
55
|
|
56
|
-
def get_constant_schedule_with_warmup(optimizer: Optimizer, num_warmup_steps: int, last_epoch: int = -1):
|
56
|
+
def get_constant_schedule_with_warmup(optimizer: Optimizer, num_warmup_steps: int, last_epoch: int = -1) -> LambdaLR:
|
57
57
|
"""
|
58
58
|
Create a schedule with a constant learning rate preceded by a warmup period during which the learning rate
|
59
59
|
increases linearly between 0 and the initial lr set in the optimizer.
|
@@ -78,7 +78,7 @@ def get_constant_schedule_with_warmup(optimizer: Optimizer, num_warmup_steps: in
|
|
78
78
|
return LambdaLR(optimizer, lr_lambda, last_epoch=last_epoch)
|
79
79
|
|
80
80
|
|
81
|
-
def get_piecewise_constant_schedule(optimizer: Optimizer, step_rules: str, last_epoch: int = -1):
|
81
|
+
def get_piecewise_constant_schedule(optimizer: Optimizer, step_rules: str, last_epoch: int = -1) -> LambdaLR:
|
82
82
|
"""
|
83
83
|
Create a schedule with a constant learning rate, using the learning rate set in optimizer.
|
84
84
|
|
@@ -120,7 +120,9 @@ def get_piecewise_constant_schedule(optimizer: Optimizer, step_rules: str, last_
|
|
120
120
|
return LambdaLR(optimizer, rules_func, last_epoch=last_epoch)
|
121
121
|
|
122
122
|
|
123
|
-
def get_linear_schedule_with_warmup(
|
123
|
+
def get_linear_schedule_with_warmup(
|
124
|
+
optimizer: Optimizer, num_warmup_steps: int, num_training_steps: int, last_epoch: int = -1
|
125
|
+
) -> LambdaLR:
|
124
126
|
"""
|
125
127
|
Create a schedule with a learning rate that decreases linearly from the initial lr set in the optimizer to 0, after
|
126
128
|
a warmup period during which it increases linearly from 0 to the initial lr set in the optimizer.
|
@@ -151,7 +153,7 @@ def get_linear_schedule_with_warmup(optimizer, num_warmup_steps, num_training_st
|
|
151
153
|
|
152
154
|
def get_cosine_schedule_with_warmup(
|
153
155
|
optimizer: Optimizer, num_warmup_steps: int, num_training_steps: int, num_cycles: float = 0.5, last_epoch: int = -1
|
154
|
-
):
|
156
|
+
) -> LambdaLR:
|
155
157
|
"""
|
156
158
|
Create a schedule with a learning rate that decreases following the values of the cosine function between the
|
157
159
|
initial lr set in the optimizer to 0, after a warmup period during which it increases linearly between 0 and the
|
@@ -185,7 +187,7 @@ def get_cosine_schedule_with_warmup(
|
|
185
187
|
|
186
188
|
def get_cosine_with_hard_restarts_schedule_with_warmup(
|
187
189
|
optimizer: Optimizer, num_warmup_steps: int, num_training_steps: int, num_cycles: int = 1, last_epoch: int = -1
|
188
|
-
):
|
190
|
+
) -> LambdaLR:
|
189
191
|
"""
|
190
192
|
Create a schedule with a learning rate that decreases following the values of the cosine function between the
|
191
193
|
initial lr set in the optimizer to 0, with several hard restarts, after a warmup period during which it increases
|
@@ -219,8 +221,13 @@ def get_cosine_with_hard_restarts_schedule_with_warmup(
|
|
219
221
|
|
220
222
|
|
221
223
|
def get_polynomial_decay_schedule_with_warmup(
|
222
|
-
optimizer
|
223
|
-
|
224
|
+
optimizer: Optimizer,
|
225
|
+
num_warmup_steps: int,
|
226
|
+
num_training_steps: int,
|
227
|
+
lr_end: float = 1e-7,
|
228
|
+
power: float = 1.0,
|
229
|
+
last_epoch: int = -1,
|
230
|
+
) -> LambdaLR:
|
224
231
|
"""
|
225
232
|
Create a schedule with a learning rate that decreases as a polynomial decay from the initial lr set in the
|
226
233
|
optimizer to end lr defined by *lr_end*, after a warmup period during which it increases linearly from 0 to the
|
@@ -288,7 +295,7 @@ def get_scheduler(
|
|
288
295
|
num_cycles: int = 1,
|
289
296
|
power: float = 1.0,
|
290
297
|
last_epoch: int = -1,
|
291
|
-
):
|
298
|
+
) -> LambdaLR:
|
292
299
|
"""
|
293
300
|
Unified API to get any scheduler from its name.
|
294
301
|
|
diffusers/pipelines/__init__.py
CHANGED
@@ -17,7 +17,12 @@ from ..utils import (
|
|
17
17
|
|
18
18
|
# These modules contain pipelines from multiple libraries/frameworks
|
19
19
|
_dummy_objects = {}
|
20
|
-
_import_structure = {
|
20
|
+
_import_structure = {
|
21
|
+
"controlnet": [],
|
22
|
+
"latent_diffusion": [],
|
23
|
+
"stable_diffusion": [],
|
24
|
+
"stable_diffusion_xl": [],
|
25
|
+
}
|
21
26
|
|
22
27
|
try:
|
23
28
|
if not is_torch_available():
|
@@ -39,7 +44,11 @@ else:
|
|
39
44
|
_import_structure["dit"] = ["DiTPipeline"]
|
40
45
|
_import_structure["latent_diffusion"].extend(["LDMSuperResolutionPipeline"])
|
41
46
|
_import_structure["latent_diffusion_uncond"] = ["LDMPipeline"]
|
42
|
-
_import_structure["pipeline_utils"] = [
|
47
|
+
_import_structure["pipeline_utils"] = [
|
48
|
+
"AudioPipelineOutput",
|
49
|
+
"DiffusionPipeline",
|
50
|
+
"ImagePipelineOutput",
|
51
|
+
]
|
43
52
|
_import_structure["pndm"] = ["PNDMPipeline"]
|
44
53
|
_import_structure["repaint"] = ["RePaintPipeline"]
|
45
54
|
_import_structure["score_sde_ve"] = ["ScoreSdeVePipeline"]
|
@@ -61,7 +70,10 @@ except OptionalDependencyNotAvailable:
|
|
61
70
|
|
62
71
|
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
|
63
72
|
else:
|
64
|
-
_import_structure["alt_diffusion"] = [
|
73
|
+
_import_structure["alt_diffusion"] = [
|
74
|
+
"AltDiffusionImg2ImgPipeline",
|
75
|
+
"AltDiffusionPipeline",
|
76
|
+
]
|
65
77
|
_import_structure["animatediff"] = ["AnimateDiffPipeline"]
|
66
78
|
_import_structure["audioldm"] = ["AudioLDMPipeline"]
|
67
79
|
_import_structure["audioldm2"] = [
|
@@ -110,6 +122,10 @@ else:
|
|
110
122
|
"KandinskyV22PriorEmb2EmbPipeline",
|
111
123
|
"KandinskyV22PriorPipeline",
|
112
124
|
]
|
125
|
+
_import_structure["kandinsky3"] = [
|
126
|
+
"Kandinsky3Img2ImgPipeline",
|
127
|
+
"Kandinsky3Pipeline",
|
128
|
+
]
|
113
129
|
_import_structure["latent_consistency_models"] = [
|
114
130
|
"LatentConsistencyModelImg2ImgPipeline",
|
115
131
|
"LatentConsistencyModelPipeline",
|
@@ -149,6 +165,7 @@ else:
|
|
149
165
|
]
|
150
166
|
)
|
151
167
|
_import_structure["stable_diffusion_safe"] = ["StableDiffusionPipelineSafe"]
|
168
|
+
_import_structure["stable_video_diffusion"] = ["StableVideoDiffusionPipeline"]
|
152
169
|
_import_structure["stable_diffusion_xl"].extend(
|
153
170
|
[
|
154
171
|
"StableDiffusionXLImg2ImgPipeline",
|
@@ -157,10 +174,14 @@ else:
|
|
157
174
|
"StableDiffusionXLPipeline",
|
158
175
|
]
|
159
176
|
)
|
160
|
-
_import_structure["t2i_adapter"] = [
|
177
|
+
_import_structure["t2i_adapter"] = [
|
178
|
+
"StableDiffusionAdapterPipeline",
|
179
|
+
"StableDiffusionXLAdapterPipeline",
|
180
|
+
]
|
161
181
|
_import_structure["text_to_video_synthesis"] = [
|
162
182
|
"TextToVideoSDPipeline",
|
163
183
|
"TextToVideoZeroPipeline",
|
184
|
+
"TextToVideoZeroSDXLPipeline",
|
164
185
|
"VideoToVideoSDPipeline",
|
165
186
|
]
|
166
187
|
_import_structure["unclip"] = ["UnCLIPImageVariationPipeline", "UnCLIPPipeline"]
|
@@ -214,7 +235,9 @@ try:
|
|
214
235
|
if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
|
215
236
|
raise OptionalDependencyNotAvailable()
|
216
237
|
except OptionalDependencyNotAvailable:
|
217
|
-
from ..utils import
|
238
|
+
from ..utils import (
|
239
|
+
dummy_torch_and_transformers_and_k_diffusion_objects,
|
240
|
+
)
|
218
241
|
|
219
242
|
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_and_k_diffusion_objects))
|
220
243
|
else:
|
@@ -257,7 +280,10 @@ except OptionalDependencyNotAvailable:
|
|
257
280
|
|
258
281
|
_dummy_objects.update(get_objects_from_module(dummy_transformers_and_torch_and_note_seq_objects))
|
259
282
|
else:
|
260
|
-
_import_structure["spectrogram_diffusion"] = [
|
283
|
+
_import_structure["spectrogram_diffusion"] = [
|
284
|
+
"MidiProcessor",
|
285
|
+
"SpectrogramDiffusionPipeline",
|
286
|
+
]
|
261
287
|
|
262
288
|
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
263
289
|
try:
|
@@ -267,7 +293,11 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
267
293
|
from ..utils.dummy_pt_objects import * # noqa F403
|
268
294
|
|
269
295
|
else:
|
270
|
-
from .auto_pipeline import
|
296
|
+
from .auto_pipeline import (
|
297
|
+
AutoPipelineForImage2Image,
|
298
|
+
AutoPipelineForInpainting,
|
299
|
+
AutoPipelineForText2Image,
|
300
|
+
)
|
271
301
|
from .consistency_models import ConsistencyModelPipeline
|
272
302
|
from .dance_diffusion import DanceDiffusionPipeline
|
273
303
|
from .ddim import DDIMPipeline
|
@@ -275,7 +305,11 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
275
305
|
from .dit import DiTPipeline
|
276
306
|
from .latent_diffusion import LDMSuperResolutionPipeline
|
277
307
|
from .latent_diffusion_uncond import LDMPipeline
|
278
|
-
from .pipeline_utils import
|
308
|
+
from .pipeline_utils import (
|
309
|
+
AudioPipelineOutput,
|
310
|
+
DiffusionPipeline,
|
311
|
+
ImagePipelineOutput,
|
312
|
+
)
|
279
313
|
from .pndm import PNDMPipeline
|
280
314
|
from .repaint import RePaintPipeline
|
281
315
|
from .score_sde_ve import ScoreSdeVePipeline
|
@@ -298,7 +332,11 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
298
332
|
from .alt_diffusion import AltDiffusionImg2ImgPipeline, AltDiffusionPipeline
|
299
333
|
from .animatediff import AnimateDiffPipeline
|
300
334
|
from .audioldm import AudioLDMPipeline
|
301
|
-
from .audioldm2 import
|
335
|
+
from .audioldm2 import (
|
336
|
+
AudioLDM2Pipeline,
|
337
|
+
AudioLDM2ProjectionModel,
|
338
|
+
AudioLDM2UNet2DConditionModel,
|
339
|
+
)
|
302
340
|
from .blip_diffusion import BlipDiffusionPipeline
|
303
341
|
from .controlnet import (
|
304
342
|
BlipDiffusionControlNetPipeline,
|
@@ -338,7 +376,14 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
338
376
|
KandinskyV22PriorEmb2EmbPipeline,
|
339
377
|
KandinskyV22PriorPipeline,
|
340
378
|
)
|
341
|
-
from .
|
379
|
+
from .kandinsky3 import (
|
380
|
+
Kandinsky3Img2ImgPipeline,
|
381
|
+
Kandinsky3Pipeline,
|
382
|
+
)
|
383
|
+
from .latent_consistency_models import (
|
384
|
+
LatentConsistencyModelImg2ImgPipeline,
|
385
|
+
LatentConsistencyModelPipeline,
|
386
|
+
)
|
342
387
|
from .latent_diffusion import LDMTextToImagePipeline
|
343
388
|
from .musicldm import MusicLDMPipeline
|
344
389
|
from .paint_by_example import PaintByExamplePipeline
|
@@ -377,10 +422,15 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
377
422
|
StableDiffusionXLInstructPix2PixPipeline,
|
378
423
|
StableDiffusionXLPipeline,
|
379
424
|
)
|
380
|
-
from .
|
425
|
+
from .stable_video_diffusion import StableVideoDiffusionPipeline
|
426
|
+
from .t2i_adapter import (
|
427
|
+
StableDiffusionAdapterPipeline,
|
428
|
+
StableDiffusionXLAdapterPipeline,
|
429
|
+
)
|
381
430
|
from .text_to_video_synthesis import (
|
382
431
|
TextToVideoSDPipeline,
|
383
432
|
TextToVideoZeroPipeline,
|
433
|
+
TextToVideoZeroSDXLPipeline,
|
384
434
|
VideoToVideoSDPipeline,
|
385
435
|
)
|
386
436
|
from .unclip import UnCLIPImageVariationPipeline, UnCLIPPipeline
|
@@ -466,7 +516,10 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|
466
516
|
from ..utils.dummy_transformers_and_torch_and_note_seq_objects import * # noqa F403
|
467
517
|
|
468
518
|
else:
|
469
|
-
from .spectrogram_diffusion import
|
519
|
+
from .spectrogram_diffusion import (
|
520
|
+
MidiProcessor,
|
521
|
+
SpectrogramDiffusionPipeline,
|
522
|
+
)
|
470
523
|
|
471
524
|
else:
|
472
525
|
import sys
|
@@ -17,11 +17,11 @@ from typing import Any, Callable, Dict, List, Optional, Union
|
|
17
17
|
|
18
18
|
import torch
|
19
19
|
from packaging import version
|
20
|
-
from transformers import CLIPImageProcessor, XLMRobertaTokenizer
|
20
|
+
from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection, XLMRobertaTokenizer
|
21
21
|
|
22
22
|
from ...configuration_utils import FrozenDict
|
23
|
-
from ...image_processor import VaeImageProcessor
|
24
|
-
from ...loaders import LoraLoaderMixin, TextualInversionLoaderMixin
|
23
|
+
from ...image_processor import PipelineImageInput, VaeImageProcessor
|
24
|
+
from ...loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
25
25
|
from ...models import AutoencoderKL, UNet2DConditionModel
|
26
26
|
from ...models.lora import adjust_lora_scale_text_encoder
|
27
27
|
from ...schedulers import KarrasDiffusionSchedulers
|
@@ -73,8 +73,55 @@ def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
|
|
73
73
|
return noise_cfg
|
74
74
|
|
75
75
|
|
76
|
+
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.retrieve_timesteps
|
77
|
+
def retrieve_timesteps(
|
78
|
+
scheduler,
|
79
|
+
num_inference_steps: Optional[int] = None,
|
80
|
+
device: Optional[Union[str, torch.device]] = None,
|
81
|
+
timesteps: Optional[List[int]] = None,
|
82
|
+
**kwargs,
|
83
|
+
):
|
84
|
+
"""
|
85
|
+
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
|
86
|
+
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
|
87
|
+
|
88
|
+
Args:
|
89
|
+
scheduler (`SchedulerMixin`):
|
90
|
+
The scheduler to get timesteps from.
|
91
|
+
num_inference_steps (`int`):
|
92
|
+
The number of diffusion steps used when generating samples with a pre-trained model. If used,
|
93
|
+
`timesteps` must be `None`.
|
94
|
+
device (`str` or `torch.device`, *optional*):
|
95
|
+
The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
|
96
|
+
timesteps (`List[int]`, *optional*):
|
97
|
+
Custom timesteps used to support arbitrary spacing between timesteps. If `None`, then the default
|
98
|
+
timestep spacing strategy of the scheduler is used. If `timesteps` is passed, `num_inference_steps`
|
99
|
+
must be `None`.
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
`Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
|
103
|
+
second element is the number of inference steps.
|
104
|
+
"""
|
105
|
+
if timesteps is not None:
|
106
|
+
accepts_timesteps = "timesteps" in set(inspect.signature(scheduler.set_timesteps).parameters.keys())
|
107
|
+
if not accepts_timesteps:
|
108
|
+
raise ValueError(
|
109
|
+
f"The current scheduler class {scheduler.__class__}'s `set_timesteps` does not support custom"
|
110
|
+
f" timestep schedules. Please check whether you are using the correct scheduler."
|
111
|
+
)
|
112
|
+
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
|
113
|
+
timesteps = scheduler.timesteps
|
114
|
+
num_inference_steps = len(timesteps)
|
115
|
+
else:
|
116
|
+
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
|
117
|
+
timesteps = scheduler.timesteps
|
118
|
+
return timesteps, num_inference_steps
|
119
|
+
|
120
|
+
|
76
121
|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline with Stable->Alt, CLIPTextModel->RobertaSeriesModelWithTransformation, CLIPTokenizer->XLMRobertaTokenizer, AltDiffusionSafetyChecker->StableDiffusionSafetyChecker
|
77
|
-
class AltDiffusionPipeline(
|
122
|
+
class AltDiffusionPipeline(
|
123
|
+
DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, IPAdapterMixin, FromSingleFileMixin
|
124
|
+
):
|
78
125
|
r"""
|
79
126
|
Pipeline for text-to-image generation using Alt Diffusion.
|
80
127
|
|
@@ -86,6 +133,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
86
133
|
- [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
|
87
134
|
- [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
|
88
135
|
- [`~loaders.FromSingleFileMixin.from_single_file`] for loading `.ckpt` files
|
136
|
+
- [`~loaders.IPAdapterMixin.load_ip_adapter`] for loading IP Adapters
|
89
137
|
|
90
138
|
Args:
|
91
139
|
vae ([`AutoencoderKL`]):
|
@@ -108,7 +156,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
108
156
|
"""
|
109
157
|
|
110
158
|
model_cpu_offload_seq = "text_encoder->unet->vae"
|
111
|
-
_optional_components = ["safety_checker", "feature_extractor"]
|
159
|
+
_optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
|
112
160
|
_exclude_from_cpu_offload = ["safety_checker"]
|
113
161
|
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
|
114
162
|
|
@@ -121,6 +169,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
121
169
|
scheduler: KarrasDiffusionSchedulers,
|
122
170
|
safety_checker: StableDiffusionSafetyChecker,
|
123
171
|
feature_extractor: CLIPImageProcessor,
|
172
|
+
image_encoder: CLIPVisionModelWithProjection = None,
|
124
173
|
requires_safety_checker: bool = True,
|
125
174
|
):
|
126
175
|
super().__init__()
|
@@ -197,6 +246,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
197
246
|
scheduler=scheduler,
|
198
247
|
safety_checker=safety_checker,
|
199
248
|
feature_extractor=feature_extractor,
|
249
|
+
image_encoder=image_encoder,
|
200
250
|
)
|
201
251
|
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
202
252
|
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
|
@@ -243,10 +293,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
243
293
|
lora_scale: Optional[float] = None,
|
244
294
|
**kwargs,
|
245
295
|
):
|
246
|
-
deprecation_message = (
|
247
|
-
"`_encode_prompt()` is deprecated and it will be removed in a future version. Use `encode_prompt()`"
|
248
|
-
" instead. Also, be aware that the output format changed from a concatenated tensor to a tuple."
|
249
|
-
)
|
296
|
+
deprecation_message = "`_encode_prompt()` is deprecated and it will be removed in a future version. Use `encode_prompt()` instead. Also, be aware that the output format changed from a concatenated tensor to a tuple."
|
250
297
|
deprecate("_encode_prompt()", "1.0.0", deprecation_message, standard_warn=False)
|
251
298
|
|
252
299
|
prompt_embeds_tuple = self.encode_prompt(
|
@@ -447,6 +494,19 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
447
494
|
|
448
495
|
return prompt_embeds, negative_prompt_embeds
|
449
496
|
|
497
|
+
def encode_image(self, image, device, num_images_per_prompt):
|
498
|
+
dtype = next(self.image_encoder.parameters()).dtype
|
499
|
+
|
500
|
+
if not isinstance(image, torch.Tensor):
|
501
|
+
image = self.feature_extractor(image, return_tensors="pt").pixel_values
|
502
|
+
|
503
|
+
image = image.to(device=device, dtype=dtype)
|
504
|
+
image_embeds = self.image_encoder(image).image_embeds
|
505
|
+
image_embeds = image_embeds.repeat_interleave(num_images_per_prompt, dim=0)
|
506
|
+
|
507
|
+
uncond_image_embeds = torch.zeros_like(image_embeds)
|
508
|
+
return image_embeds, uncond_image_embeds
|
509
|
+
|
450
510
|
def run_safety_checker(self, image, device, dtype):
|
451
511
|
if self.safety_checker is None:
|
452
512
|
has_nsfw_concept = None
|
@@ -462,10 +522,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
462
522
|
return image, has_nsfw_concept
|
463
523
|
|
464
524
|
def decode_latents(self, latents):
|
465
|
-
deprecation_message = (
|
466
|
-
"The decode_latents method is deprecated and will be removed in 1.0.0. Please use"
|
467
|
-
" VaeImageProcessor.postprocess(...) instead"
|
468
|
-
)
|
525
|
+
deprecation_message = "The decode_latents method is deprecated and will be removed in 1.0.0. Please use VaeImageProcessor.postprocess(...) instead"
|
469
526
|
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)
|
470
527
|
|
471
528
|
latents = 1 / self.vae.config.scaling_factor * latents
|
@@ -515,8 +572,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
515
572
|
k in self._callback_tensor_inputs for k in callback_on_step_end_tensor_inputs
|
516
573
|
):
|
517
574
|
raise ValueError(
|
518
|
-
f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found"
|
519
|
-
f" {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
|
575
|
+
f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
|
520
576
|
)
|
521
577
|
|
522
578
|
if prompt is not None and prompt_embeds is not None:
|
@@ -651,6 +707,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
651
707
|
height: Optional[int] = None,
|
652
708
|
width: Optional[int] = None,
|
653
709
|
num_inference_steps: int = 50,
|
710
|
+
timesteps: List[int] = None,
|
654
711
|
guidance_scale: float = 7.5,
|
655
712
|
negative_prompt: Optional[Union[str, List[str]]] = None,
|
656
713
|
num_images_per_prompt: Optional[int] = 1,
|
@@ -659,6 +716,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
659
716
|
latents: Optional[torch.FloatTensor] = None,
|
660
717
|
prompt_embeds: Optional[torch.FloatTensor] = None,
|
661
718
|
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
719
|
+
ip_adapter_image: Optional[PipelineImageInput] = None,
|
662
720
|
output_type: Optional[str] = "pil",
|
663
721
|
return_dict: bool = True,
|
664
722
|
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
@@ -681,6 +739,10 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
681
739
|
num_inference_steps (`int`, *optional*, defaults to 50):
|
682
740
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
683
741
|
expense of slower inference.
|
742
|
+
timesteps (`List[int]`, *optional*):
|
743
|
+
Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
|
744
|
+
in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
|
745
|
+
passed will be used. Must be in descending order.
|
684
746
|
guidance_scale (`float`, *optional*, defaults to 7.5):
|
685
747
|
A higher guidance scale value encourages the model to generate images closely linked to the text
|
686
748
|
`prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`.
|
@@ -705,6 +767,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
705
767
|
negative_prompt_embeds (`torch.FloatTensor`, *optional*):
|
706
768
|
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
|
707
769
|
not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
|
770
|
+
ip_adapter_image: (`PipelineImageInput`, *optional*): Optional image input to work with IP Adapters.
|
708
771
|
output_type (`str`, *optional*, defaults to `"pil"`):
|
709
772
|
The output format of the generated image. Choose between `PIL.Image` or `np.array`.
|
710
773
|
return_dict (`bool`, *optional*, defaults to `True`):
|
@@ -728,7 +791,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
728
791
|
callback_on_step_end_tensor_inputs (`List`, *optional*):
|
729
792
|
The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
|
730
793
|
will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
|
731
|
-
`._callback_tensor_inputs` attribute of your
|
794
|
+
`._callback_tensor_inputs` attribute of your pipeline class.
|
732
795
|
|
733
796
|
Examples:
|
734
797
|
|
@@ -747,15 +810,13 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
747
810
|
deprecate(
|
748
811
|
"callback",
|
749
812
|
"1.0.0",
|
750
|
-
"Passing `callback` as an input argument to `__call__` is deprecated, consider using"
|
751
|
-
" `callback_on_step_end`",
|
813
|
+
"Passing `callback` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
|
752
814
|
)
|
753
815
|
if callback_steps is not None:
|
754
816
|
deprecate(
|
755
817
|
"callback_steps",
|
756
818
|
"1.0.0",
|
757
|
-
"Passing `callback_steps` as an input argument to `__call__` is deprecated, consider using"
|
758
|
-
" `callback_on_step_end`",
|
819
|
+
"Passing `callback_steps` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
|
759
820
|
)
|
760
821
|
|
761
822
|
# 0. Default height and width to unet
|
@@ -806,15 +867,20 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
806
867
|
lora_scale=lora_scale,
|
807
868
|
clip_skip=self.clip_skip,
|
808
869
|
)
|
870
|
+
|
809
871
|
# For classifier free guidance, we need to do two forward passes.
|
810
872
|
# Here we concatenate the unconditional and text embeddings into a single batch
|
811
873
|
# to avoid doing two forward passes
|
812
874
|
if self.do_classifier_free_guidance:
|
813
875
|
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
814
876
|
|
877
|
+
if ip_adapter_image is not None:
|
878
|
+
image_embeds, negative_image_embeds = self.encode_image(ip_adapter_image, device, num_images_per_prompt)
|
879
|
+
if self.do_classifier_free_guidance:
|
880
|
+
image_embeds = torch.cat([negative_image_embeds, image_embeds])
|
881
|
+
|
815
882
|
# 4. Prepare timesteps
|
816
|
-
self.scheduler
|
817
|
-
timesteps = self.scheduler.timesteps
|
883
|
+
timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps)
|
818
884
|
|
819
885
|
# 5. Prepare latent variables
|
820
886
|
num_channels_latents = self.unet.config.in_channels
|
@@ -832,7 +898,10 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
832
898
|
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
833
899
|
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
834
900
|
|
835
|
-
# 6.
|
901
|
+
# 6.1 Add image embeds for IP-Adapter
|
902
|
+
added_cond_kwargs = {"image_embeds": image_embeds} if ip_adapter_image is not None else None
|
903
|
+
|
904
|
+
# 6.2 Optionally get Guidance Scale Embedding
|
836
905
|
timestep_cond = None
|
837
906
|
if self.unet.config.time_cond_proj_dim is not None:
|
838
907
|
guidance_scale_tensor = torch.tensor(self.guidance_scale - 1).repeat(batch_size * num_images_per_prompt)
|
@@ -856,6 +925,7 @@ class AltDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin, LoraL
|
|
856
925
|
encoder_hidden_states=prompt_embeds,
|
857
926
|
timestep_cond=timestep_cond,
|
858
927
|
cross_attention_kwargs=self.cross_attention_kwargs,
|
928
|
+
added_cond_kwargs=added_cond_kwargs,
|
859
929
|
return_dict=False,
|
860
930
|
)[0]
|
861
931
|
|