diffusers 0.27.2__py3-none-any.whl → 0.28.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 +26 -1
- diffusers/callbacks.py +156 -0
- diffusers/commands/env.py +110 -6
- diffusers/configuration_utils.py +33 -11
- diffusers/dependency_versions_table.py +2 -1
- diffusers/image_processor.py +158 -45
- diffusers/loaders/__init__.py +2 -5
- diffusers/loaders/autoencoder.py +4 -4
- diffusers/loaders/controlnet.py +4 -4
- diffusers/loaders/ip_adapter.py +80 -22
- diffusers/loaders/lora.py +134 -20
- diffusers/loaders/lora_conversion_utils.py +46 -43
- diffusers/loaders/peft.py +4 -3
- diffusers/loaders/single_file.py +401 -170
- diffusers/loaders/single_file_model.py +290 -0
- diffusers/loaders/single_file_utils.py +616 -672
- diffusers/loaders/textual_inversion.py +41 -20
- diffusers/loaders/unet.py +168 -115
- diffusers/loaders/unet_loader_utils.py +163 -0
- diffusers/models/__init__.py +8 -0
- diffusers/models/activations.py +23 -3
- diffusers/models/attention.py +10 -11
- diffusers/models/attention_processor.py +475 -148
- diffusers/models/autoencoders/autoencoder_asym_kl.py +14 -16
- diffusers/models/autoencoders/autoencoder_kl.py +18 -19
- diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +11 -11
- diffusers/models/autoencoders/autoencoder_tiny.py +16 -16
- diffusers/models/autoencoders/consistency_decoder_vae.py +36 -11
- diffusers/models/autoencoders/vae.py +23 -24
- diffusers/models/controlnet.py +12 -9
- diffusers/models/controlnet_flax.py +4 -4
- diffusers/models/controlnet_xs.py +1915 -0
- diffusers/models/downsampling.py +17 -18
- diffusers/models/embeddings.py +363 -32
- diffusers/models/model_loading_utils.py +177 -0
- diffusers/models/modeling_flax_pytorch_utils.py +2 -1
- diffusers/models/modeling_flax_utils.py +4 -4
- diffusers/models/modeling_outputs.py +14 -0
- diffusers/models/modeling_pytorch_flax_utils.py +1 -1
- diffusers/models/modeling_utils.py +175 -99
- diffusers/models/normalization.py +2 -1
- diffusers/models/resnet.py +18 -23
- diffusers/models/transformer_temporal.py +3 -3
- diffusers/models/transformers/__init__.py +3 -0
- diffusers/models/transformers/dit_transformer_2d.py +240 -0
- diffusers/models/transformers/dual_transformer_2d.py +4 -4
- diffusers/models/transformers/hunyuan_transformer_2d.py +427 -0
- diffusers/models/transformers/pixart_transformer_2d.py +336 -0
- diffusers/models/transformers/prior_transformer.py +7 -7
- diffusers/models/transformers/t5_film_transformer.py +17 -19
- diffusers/models/transformers/transformer_2d.py +292 -184
- diffusers/models/transformers/transformer_temporal.py +10 -10
- diffusers/models/unets/unet_1d.py +5 -5
- diffusers/models/unets/unet_1d_blocks.py +29 -29
- diffusers/models/unets/unet_2d.py +6 -6
- diffusers/models/unets/unet_2d_blocks.py +137 -128
- diffusers/models/unets/unet_2d_condition.py +19 -15
- diffusers/models/unets/unet_2d_condition_flax.py +6 -5
- diffusers/models/unets/unet_3d_blocks.py +79 -77
- diffusers/models/unets/unet_3d_condition.py +13 -9
- diffusers/models/unets/unet_i2vgen_xl.py +14 -13
- diffusers/models/unets/unet_kandinsky3.py +1 -1
- diffusers/models/unets/unet_motion_model.py +114 -14
- diffusers/models/unets/unet_spatio_temporal_condition.py +15 -14
- diffusers/models/unets/unet_stable_cascade.py +16 -13
- diffusers/models/upsampling.py +17 -20
- diffusers/models/vq_model.py +16 -15
- diffusers/pipelines/__init__.py +27 -3
- diffusers/pipelines/amused/pipeline_amused.py +12 -12
- diffusers/pipelines/amused/pipeline_amused_img2img.py +14 -12
- diffusers/pipelines/amused/pipeline_amused_inpaint.py +13 -11
- diffusers/pipelines/animatediff/__init__.py +2 -0
- diffusers/pipelines/animatediff/pipeline_animatediff.py +24 -46
- diffusers/pipelines/animatediff/pipeline_animatediff_sdxl.py +1284 -0
- diffusers/pipelines/animatediff/pipeline_animatediff_video2video.py +82 -72
- diffusers/pipelines/animatediff/pipeline_output.py +3 -2
- diffusers/pipelines/audioldm/pipeline_audioldm.py +14 -14
- diffusers/pipelines/audioldm2/modeling_audioldm2.py +54 -35
- diffusers/pipelines/audioldm2/pipeline_audioldm2.py +120 -36
- diffusers/pipelines/auto_pipeline.py +21 -17
- diffusers/pipelines/blip_diffusion/blip_image_processing.py +1 -1
- diffusers/pipelines/blip_diffusion/modeling_blip2.py +5 -5
- diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py +1 -1
- diffusers/pipelines/blip_diffusion/pipeline_blip_diffusion.py +2 -2
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +5 -5
- diffusers/pipelines/controlnet/multicontrolnet.py +4 -8
- diffusers/pipelines/controlnet/pipeline_controlnet.py +87 -52
- diffusers/pipelines/controlnet/pipeline_controlnet_blip_diffusion.py +2 -2
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +50 -43
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +52 -40
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint_sd_xl.py +80 -47
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +147 -49
- diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +89 -55
- diffusers/pipelines/controlnet_xs/__init__.py +68 -0
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs.py +911 -0
- diffusers/pipelines/controlnet_xs/pipeline_controlnet_xs_sd_xl.py +1115 -0
- diffusers/pipelines/deepfloyd_if/pipeline_if.py +14 -28
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py +18 -33
- diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py +21 -39
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py +20 -36
- diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py +23 -39
- diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py +17 -32
- diffusers/pipelines/deprecated/alt_diffusion/modeling_roberta_series.py +11 -11
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion.py +43 -20
- diffusers/pipelines/deprecated/alt_diffusion/pipeline_alt_diffusion_img2img.py +36 -18
- diffusers/pipelines/deprecated/repaint/pipeline_repaint.py +2 -2
- diffusers/pipelines/deprecated/spectrogram_diffusion/pipeline_spectrogram_diffusion.py +7 -7
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_cycle_diffusion.py +12 -12
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_inpaint_legacy.py +18 -18
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_model_editing.py +20 -15
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_paradigms.py +20 -15
- diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_stable_diffusion_pix2pix_zero.py +30 -25
- diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py +69 -59
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion.py +13 -13
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_dual_guided.py +10 -5
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_image_variation.py +11 -6
- diffusers/pipelines/deprecated/versatile_diffusion/pipeline_versatile_diffusion_text_to_image.py +10 -5
- diffusers/pipelines/deprecated/vq_diffusion/pipeline_vq_diffusion.py +5 -5
- diffusers/pipelines/dit/pipeline_dit.py +7 -4
- diffusers/pipelines/free_init_utils.py +39 -38
- diffusers/pipelines/hunyuandit/__init__.py +48 -0
- diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py +881 -0
- diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py +33 -48
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +8 -8
- diffusers/pipelines/kandinsky/pipeline_kandinsky_combined.py +23 -20
- diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py +11 -11
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +12 -12
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +6 -6
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +32 -29
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +10 -10
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +6 -6
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +8 -8
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +7 -7
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py +6 -6
- diffusers/pipelines/kandinsky3/convert_kandinsky3_unet.py +3 -3
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3.py +20 -33
- diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py +24 -35
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_img2img.py +48 -30
- diffusers/pipelines/latent_consistency_models/pipeline_latent_consistency_text2img.py +50 -28
- diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py +11 -11
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion.py +61 -67
- diffusers/pipelines/ledits_pp/pipeline_leditspp_stable_diffusion_xl.py +70 -69
- diffusers/pipelines/ledits_pp/pipeline_output.py +2 -2
- diffusers/pipelines/marigold/__init__.py +50 -0
- diffusers/pipelines/marigold/marigold_image_processing.py +561 -0
- diffusers/pipelines/marigold/pipeline_marigold_depth.py +813 -0
- diffusers/pipelines/marigold/pipeline_marigold_normals.py +690 -0
- diffusers/pipelines/musicldm/pipeline_musicldm.py +14 -14
- diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py +17 -12
- diffusers/pipelines/pia/pipeline_pia.py +39 -125
- diffusers/pipelines/pipeline_flax_utils.py +4 -4
- diffusers/pipelines/pipeline_loading_utils.py +269 -23
- diffusers/pipelines/pipeline_utils.py +266 -37
- diffusers/pipelines/pixart_alpha/__init__.py +8 -1
- diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py +69 -79
- diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py +880 -0
- diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py +10 -5
- diffusers/pipelines/shap_e/pipeline_shap_e.py +3 -3
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +14 -14
- diffusers/pipelines/shap_e/renderer.py +1 -1
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py +18 -18
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py +23 -19
- diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py +33 -32
- diffusers/pipelines/stable_diffusion/__init__.py +0 -1
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +18 -11
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +2 -2
- diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +6 -6
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +73 -39
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py +24 -17
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_image_variation.py +13 -8
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +66 -36
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +82 -46
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +123 -28
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py +6 -6
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +16 -16
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip.py +24 -19
- diffusers/pipelines/stable_diffusion/pipeline_stable_unclip_img2img.py +37 -31
- diffusers/pipelines/stable_diffusion/safety_checker.py +2 -1
- diffusers/pipelines/stable_diffusion_attend_and_excite/pipeline_stable_diffusion_attend_and_excite.py +23 -15
- diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py +44 -39
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen.py +23 -18
- diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py +19 -14
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_k_diffusion.py +20 -15
- diffusers/pipelines/stable_diffusion_k_diffusion/pipeline_stable_diffusion_xl_k_diffusion.py +24 -19
- diffusers/pipelines/stable_diffusion_ldm3d/pipeline_stable_diffusion_ldm3d.py +65 -32
- diffusers/pipelines/stable_diffusion_panorama/pipeline_stable_diffusion_panorama.py +274 -38
- diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py +10 -5
- diffusers/pipelines/stable_diffusion_safe/safety_checker.py +1 -1
- diffusers/pipelines/stable_diffusion_sag/pipeline_stable_diffusion_sag.py +92 -25
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +88 -44
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +108 -56
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +96 -51
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py +45 -25
- diffusers/pipelines/stable_diffusion_xl/watermark.py +9 -3
- diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +110 -57
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py +59 -30
- diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py +71 -42
- diffusers/pipelines/text_to_video_synthesis/pipeline_output.py +3 -2
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +18 -41
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +21 -85
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +28 -19
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero_sdxl.py +39 -33
- diffusers/pipelines/unclip/pipeline_unclip.py +6 -6
- diffusers/pipelines/unclip/pipeline_unclip_image_variation.py +6 -6
- diffusers/pipelines/unidiffuser/modeling_text_decoder.py +1 -1
- diffusers/pipelines/unidiffuser/modeling_uvit.py +9 -9
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +23 -23
- diffusers/pipelines/wuerstchen/modeling_paella_vq_model.py +5 -5
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_common.py +5 -10
- diffusers/pipelines/wuerstchen/modeling_wuerstchen_prior.py +4 -6
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen.py +4 -4
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_combined.py +12 -12
- diffusers/pipelines/wuerstchen/pipeline_wuerstchen_prior.py +10 -10
- diffusers/schedulers/__init__.py +2 -2
- diffusers/schedulers/deprecated/__init__.py +1 -1
- diffusers/schedulers/deprecated/scheduling_karras_ve.py +25 -25
- diffusers/schedulers/scheduling_amused.py +5 -5
- diffusers/schedulers/scheduling_consistency_decoder.py +11 -11
- diffusers/schedulers/scheduling_consistency_models.py +20 -26
- diffusers/schedulers/scheduling_ddim.py +22 -24
- diffusers/schedulers/scheduling_ddim_flax.py +2 -1
- diffusers/schedulers/scheduling_ddim_inverse.py +16 -16
- diffusers/schedulers/scheduling_ddim_parallel.py +28 -30
- diffusers/schedulers/scheduling_ddpm.py +20 -22
- diffusers/schedulers/scheduling_ddpm_flax.py +7 -3
- diffusers/schedulers/scheduling_ddpm_parallel.py +26 -28
- diffusers/schedulers/scheduling_ddpm_wuerstchen.py +14 -14
- diffusers/schedulers/scheduling_deis_multistep.py +42 -42
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +103 -77
- diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +2 -2
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +46 -46
- diffusers/schedulers/scheduling_dpmsolver_sde.py +23 -23
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +86 -65
- diffusers/schedulers/scheduling_edm_dpmsolver_multistep.py +75 -54
- diffusers/schedulers/scheduling_edm_euler.py +50 -31
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +23 -29
- diffusers/schedulers/scheduling_euler_discrete.py +160 -68
- diffusers/schedulers/scheduling_heun_discrete.py +57 -39
- diffusers/schedulers/scheduling_ipndm.py +8 -8
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +19 -19
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +19 -19
- diffusers/schedulers/scheduling_karras_ve_flax.py +6 -6
- diffusers/schedulers/scheduling_lcm.py +21 -23
- diffusers/schedulers/scheduling_lms_discrete.py +24 -26
- diffusers/schedulers/scheduling_pndm.py +20 -20
- diffusers/schedulers/scheduling_repaint.py +20 -20
- diffusers/schedulers/scheduling_sasolver.py +55 -54
- diffusers/schedulers/scheduling_sde_ve.py +19 -19
- diffusers/schedulers/scheduling_tcd.py +39 -30
- diffusers/schedulers/scheduling_unclip.py +15 -15
- diffusers/schedulers/scheduling_unipc_multistep.py +111 -41
- diffusers/schedulers/scheduling_utils.py +14 -5
- diffusers/schedulers/scheduling_utils_flax.py +3 -3
- diffusers/schedulers/scheduling_vq_diffusion.py +10 -10
- diffusers/training_utils.py +56 -1
- diffusers/utils/__init__.py +7 -0
- diffusers/utils/doc_utils.py +1 -0
- diffusers/utils/dummy_pt_objects.py +75 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +105 -0
- diffusers/utils/dynamic_modules_utils.py +24 -11
- diffusers/utils/hub_utils.py +3 -2
- diffusers/utils/import_utils.py +91 -0
- diffusers/utils/loading_utils.py +2 -2
- diffusers/utils/logging.py +1 -1
- diffusers/utils/peft_utils.py +32 -5
- diffusers/utils/state_dict_utils.py +11 -2
- diffusers/utils/testing_utils.py +71 -6
- diffusers/utils/torch_utils.py +1 -0
- diffusers/video_processor.py +113 -0
- {diffusers-0.27.2.dist-info → diffusers-0.28.1.dist-info}/METADATA +7 -7
- diffusers-0.28.1.dist-info/RECORD +419 -0
- diffusers-0.27.2.dist-info/RECORD +0 -399
- {diffusers-0.27.2.dist-info → diffusers-0.28.1.dist-info}/LICENSE +0 -0
- {diffusers-0.27.2.dist-info → diffusers-0.28.1.dist-info}/WHEEL +0 -0
- {diffusers-0.27.2.dist-info → diffusers-0.28.1.dist-info}/entry_points.txt +0 -0
- {diffusers-0.27.2.dist-info → diffusers-0.28.1.dist-info}/top_level.txt +0 -0
diffusers/utils/testing_utils.py
CHANGED
@@ -14,7 +14,6 @@ import time
|
|
14
14
|
import unittest
|
15
15
|
import urllib.parse
|
16
16
|
from contextlib import contextmanager
|
17
|
-
from distutils.util import strtobool
|
18
17
|
from io import BytesIO, StringIO
|
19
18
|
from pathlib import Path
|
20
19
|
from typing import Callable, Dict, List, Optional, Union
|
@@ -34,6 +33,7 @@ from .import_utils import (
|
|
34
33
|
is_onnx_available,
|
35
34
|
is_opencv_available,
|
36
35
|
is_peft_available,
|
36
|
+
is_timm_available,
|
37
37
|
is_torch_available,
|
38
38
|
is_torch_version,
|
39
39
|
is_torchsde_available,
|
@@ -106,10 +106,21 @@ def numpy_cosine_similarity_distance(a, b):
|
|
106
106
|
return distance
|
107
107
|
|
108
108
|
|
109
|
-
def print_tensor_test(
|
109
|
+
def print_tensor_test(
|
110
|
+
tensor,
|
111
|
+
limit_to_slices=None,
|
112
|
+
max_torch_print=None,
|
113
|
+
filename="test_corrections.txt",
|
114
|
+
expected_tensor_name="expected_slice",
|
115
|
+
):
|
116
|
+
if max_torch_print:
|
117
|
+
torch.set_printoptions(threshold=10_000)
|
118
|
+
|
110
119
|
test_name = os.environ.get("PYTEST_CURRENT_TEST")
|
111
120
|
if not torch.is_tensor(tensor):
|
112
121
|
tensor = torch.from_numpy(tensor)
|
122
|
+
if limit_to_slices:
|
123
|
+
tensor = tensor[0, -3:, -3:, -1]
|
113
124
|
|
114
125
|
tensor_str = str(tensor.detach().cpu().flatten().to(torch.float32)).replace("\n", "")
|
115
126
|
# format is usually:
|
@@ -118,7 +129,7 @@ def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_n
|
|
118
129
|
test_file, test_class, test_fn = test_name.split("::")
|
119
130
|
test_fn = test_fn.split()[0]
|
120
131
|
with open(filename, "a") as f:
|
121
|
-
print("
|
132
|
+
print("::".join([test_file, test_class, test_fn, output_str]), file=f)
|
122
133
|
|
123
134
|
|
124
135
|
def get_tests_dir(append_path=None):
|
@@ -142,6 +153,22 @@ def get_tests_dir(append_path=None):
|
|
142
153
|
return tests_dir
|
143
154
|
|
144
155
|
|
156
|
+
# Taken from the following PR:
|
157
|
+
# https://github.com/huggingface/accelerate/pull/1964
|
158
|
+
def str_to_bool(value) -> int:
|
159
|
+
"""
|
160
|
+
Converts a string representation of truth to `True` (1) or `False` (0). True values are `y`, `yes`, `t`, `true`,
|
161
|
+
`on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
|
162
|
+
"""
|
163
|
+
value = value.lower()
|
164
|
+
if value in ("y", "yes", "t", "true", "on", "1"):
|
165
|
+
return 1
|
166
|
+
elif value in ("n", "no", "f", "false", "off", "0"):
|
167
|
+
return 0
|
168
|
+
else:
|
169
|
+
raise ValueError(f"invalid truth value {value}")
|
170
|
+
|
171
|
+
|
145
172
|
def parse_flag_from_env(key, default=False):
|
146
173
|
try:
|
147
174
|
value = os.environ[key]
|
@@ -151,7 +178,7 @@ def parse_flag_from_env(key, default=False):
|
|
151
178
|
else:
|
152
179
|
# KEY is set, convert it to True or False.
|
153
180
|
try:
|
154
|
-
_value =
|
181
|
+
_value = str_to_bool(value)
|
155
182
|
except ValueError:
|
156
183
|
# More values are supported, but let's keep the message simple.
|
157
184
|
raise ValueError(f"If set, {key} must be yes or no.")
|
@@ -229,6 +256,20 @@ def require_torch_accelerator(test_case):
|
|
229
256
|
)
|
230
257
|
|
231
258
|
|
259
|
+
def require_torch_multi_gpu(test_case):
|
260
|
+
"""
|
261
|
+
Decorator marking a test that requires a multi-GPU setup (in PyTorch). These tests are skipped on a machine without
|
262
|
+
multiple GPUs. To run *only* the multi_gpu tests, assuming all test names contain multi_gpu: $ pytest -sv ./tests
|
263
|
+
-k "multi_gpu"
|
264
|
+
"""
|
265
|
+
if not is_torch_available():
|
266
|
+
return unittest.skip("test requires PyTorch")(test_case)
|
267
|
+
|
268
|
+
import torch
|
269
|
+
|
270
|
+
return unittest.skipUnless(torch.cuda.device_count() > 1, "test requires multiple GPUs")(test_case)
|
271
|
+
|
272
|
+
|
232
273
|
def require_torch_accelerator_with_fp16(test_case):
|
233
274
|
"""Decorator marking a test that requires an accelerator with support for the FP16 data type."""
|
234
275
|
return unittest.skipUnless(_is_torch_fp16_available(torch_device), "test requires accelerator with fp16 support")(
|
@@ -300,6 +341,13 @@ def require_peft_backend(test_case):
|
|
300
341
|
return unittest.skipUnless(USE_PEFT_BACKEND, "test requires PEFT backend")(test_case)
|
301
342
|
|
302
343
|
|
344
|
+
def require_timm(test_case):
|
345
|
+
"""
|
346
|
+
Decorator marking a test that requires timm. These tests are skipped when timm isn't installed.
|
347
|
+
"""
|
348
|
+
return unittest.skipUnless(is_timm_available(), "test requires timm")(test_case)
|
349
|
+
|
350
|
+
|
303
351
|
def require_peft_version_greater(peft_version):
|
304
352
|
"""
|
305
353
|
Decorator marking a test that requires PEFT backend with a specific version, this would require some specific
|
@@ -317,6 +365,18 @@ def require_peft_version_greater(peft_version):
|
|
317
365
|
return decorator
|
318
366
|
|
319
367
|
|
368
|
+
def require_accelerate_version_greater(accelerate_version):
|
369
|
+
def decorator(test_case):
|
370
|
+
correct_accelerate_version = is_peft_available() and version.parse(
|
371
|
+
version.parse(importlib.metadata.version("accelerate")).base_version
|
372
|
+
) > version.parse(accelerate_version)
|
373
|
+
return unittest.skipUnless(
|
374
|
+
correct_accelerate_version, f"Test requires accelerate with the version greater than {accelerate_version}."
|
375
|
+
)(test_case)
|
376
|
+
|
377
|
+
return decorator
|
378
|
+
|
379
|
+
|
320
380
|
def deprecate_after_peft_backend(test_case):
|
321
381
|
"""
|
322
382
|
Decorator marking a test that will be skipped after PEFT backend
|
@@ -324,10 +384,15 @@ def deprecate_after_peft_backend(test_case):
|
|
324
384
|
return unittest.skipUnless(not USE_PEFT_BACKEND, "test skipped in favor of PEFT backend")(test_case)
|
325
385
|
|
326
386
|
|
387
|
+
def get_python_version():
|
388
|
+
sys_info = sys.version_info
|
389
|
+
major, minor = sys_info.major, sys_info.minor
|
390
|
+
return major, minor
|
391
|
+
|
392
|
+
|
327
393
|
def require_python39_or_higher(test_case):
|
328
394
|
def python39_available():
|
329
|
-
|
330
|
-
major, minor = sys_info.major, sys_info.minor
|
395
|
+
major, minor = get_python_version()
|
331
396
|
return major == 3 and minor >= 9
|
332
397
|
|
333
398
|
return unittest.skipUnless(python39_available(), "test requires Python 3.9 or higher")(test_case)
|
diffusers/utils/torch_utils.py
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright 2024 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
|
+
import warnings
|
16
|
+
from typing import List, Optional, Union
|
17
|
+
|
18
|
+
import numpy as np
|
19
|
+
import PIL
|
20
|
+
import torch
|
21
|
+
|
22
|
+
from .image_processor import VaeImageProcessor, is_valid_image, is_valid_image_imagelist
|
23
|
+
|
24
|
+
|
25
|
+
class VideoProcessor(VaeImageProcessor):
|
26
|
+
r"""Simple video processor."""
|
27
|
+
|
28
|
+
def preprocess_video(self, video, height: Optional[int] = None, width: Optional[int] = None) -> torch.Tensor:
|
29
|
+
r"""
|
30
|
+
Preprocesses input video(s).
|
31
|
+
|
32
|
+
Args:
|
33
|
+
video (`List[PIL.Image]`, `List[List[PIL.Image]]`, `torch.Tensor`, `np.array`, `List[torch.Tensor]`, `List[np.array]`):
|
34
|
+
The input video. It can be one of the following:
|
35
|
+
* List of the PIL images.
|
36
|
+
* List of list of PIL images.
|
37
|
+
* 4D Torch tensors (expected shape for each tensor `(num_frames, num_channels, height, width)`).
|
38
|
+
* 4D NumPy arrays (expected shape for each array `(num_frames, height, width, num_channels)`).
|
39
|
+
* List of 4D Torch tensors (expected shape for each tensor `(num_frames, num_channels, height,
|
40
|
+
width)`).
|
41
|
+
* List of 4D NumPy arrays (expected shape for each array `(num_frames, height, width, num_channels)`).
|
42
|
+
* 5D NumPy arrays: expected shape for each array `(batch_size, num_frames, height, width,
|
43
|
+
num_channels)`.
|
44
|
+
* 5D Torch tensors: expected shape for each array `(batch_size, num_frames, num_channels, height,
|
45
|
+
width)`.
|
46
|
+
height (`int`, *optional*, defaults to `None`):
|
47
|
+
The height in preprocessed frames of the video. If `None`, will use the `get_default_height_width()` to
|
48
|
+
get default height.
|
49
|
+
width (`int`, *optional*`, defaults to `None`):
|
50
|
+
The width in preprocessed frames of the video. If `None`, will use get_default_height_width()` to get
|
51
|
+
the default width.
|
52
|
+
"""
|
53
|
+
if isinstance(video, list) and isinstance(video[0], np.ndarray) and video[0].ndim == 5:
|
54
|
+
warnings.warn(
|
55
|
+
"Passing `video` as a list of 5d np.ndarray is deprecated."
|
56
|
+
"Please concatenate the list along the batch dimension and pass it as a single 5d np.ndarray",
|
57
|
+
FutureWarning,
|
58
|
+
)
|
59
|
+
video = np.concatenate(video, axis=0)
|
60
|
+
if isinstance(video, list) and isinstance(video[0], torch.Tensor) and video[0].ndim == 5:
|
61
|
+
warnings.warn(
|
62
|
+
"Passing `video` as a list of 5d torch.Tensor is deprecated."
|
63
|
+
"Please concatenate the list along the batch dimension and pass it as a single 5d torch.Tensor",
|
64
|
+
FutureWarning,
|
65
|
+
)
|
66
|
+
video = torch.cat(video, axis=0)
|
67
|
+
|
68
|
+
# ensure the input is a list of videos:
|
69
|
+
# - if it is a batch of videos (5d torch.Tensor or np.ndarray), it is converted to a list of videos (a list of 4d torch.Tensor or np.ndarray)
|
70
|
+
# - if it is is a single video, it is convereted to a list of one video.
|
71
|
+
if isinstance(video, (np.ndarray, torch.Tensor)) and video.ndim == 5:
|
72
|
+
video = list(video)
|
73
|
+
elif isinstance(video, list) and is_valid_image(video[0]) or is_valid_image_imagelist(video):
|
74
|
+
video = [video]
|
75
|
+
elif isinstance(video, list) and is_valid_image_imagelist(video[0]):
|
76
|
+
video = video
|
77
|
+
else:
|
78
|
+
raise ValueError(
|
79
|
+
"Input is in incorrect format. Currently, we only support numpy.ndarray, torch.Tensor, PIL.Image.Image"
|
80
|
+
)
|
81
|
+
|
82
|
+
video = torch.stack([self.preprocess(img, height=height, width=width) for img in video], dim=0)
|
83
|
+
|
84
|
+
# move the number of channels before the number of frames.
|
85
|
+
video = video.permute(0, 2, 1, 3, 4)
|
86
|
+
|
87
|
+
return video
|
88
|
+
|
89
|
+
def postprocess_video(
|
90
|
+
self, video: torch.Tensor, output_type: str = "np"
|
91
|
+
) -> Union[np.ndarray, torch.Tensor, List[PIL.Image.Image]]:
|
92
|
+
r"""
|
93
|
+
Converts a video tensor to a list of frames for export.
|
94
|
+
|
95
|
+
Args:
|
96
|
+
video (`torch.Tensor`): The video as a tensor.
|
97
|
+
output_type (`str`, defaults to `"np"`): Output type of the postprocessed `video` tensor.
|
98
|
+
"""
|
99
|
+
batch_size = video.shape[0]
|
100
|
+
outputs = []
|
101
|
+
for batch_idx in range(batch_size):
|
102
|
+
batch_vid = video[batch_idx].permute(1, 0, 2, 3)
|
103
|
+
batch_output = self.postprocess(batch_vid, output_type)
|
104
|
+
outputs.append(batch_output)
|
105
|
+
|
106
|
+
if output_type == "np":
|
107
|
+
outputs = np.stack(outputs)
|
108
|
+
elif output_type == "pt":
|
109
|
+
outputs = torch.stack(outputs)
|
110
|
+
elif not output_type == "pil":
|
111
|
+
raise ValueError(f"{output_type} does not exist. Please choose one of ['np', 'pt', 'pil']")
|
112
|
+
|
113
|
+
return outputs
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: diffusers
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.28.1
|
4
4
|
Summary: State-of-the-art diffusion in PyTorch and JAX.
|
5
5
|
Home-page: https://github.com/huggingface/diffusers
|
6
6
|
Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/diffusers/graphs/contributors)
|
@@ -51,7 +51,7 @@ Requires-Dist: sentencepiece !=0.1.92,>=0.1.91 ; extra == 'dev'
|
|
51
51
|
Requires-Dist: scipy ; extra == 'dev'
|
52
52
|
Requires-Dist: torchvision ; extra == 'dev'
|
53
53
|
Requires-Dist: transformers >=4.25.1 ; extra == 'dev'
|
54
|
-
Requires-Dist: accelerate >=0.
|
54
|
+
Requires-Dist: accelerate >=0.29.3 ; extra == 'dev'
|
55
55
|
Requires-Dist: protobuf <4,>=3.20.3 ; extra == 'dev'
|
56
56
|
Requires-Dist: tensorboard ; extra == 'dev'
|
57
57
|
Requires-Dist: peft >=0.6.0 ; extra == 'dev'
|
@@ -90,9 +90,9 @@ Requires-Dist: torchvision ; extra == 'test'
|
|
90
90
|
Requires-Dist: transformers >=4.25.1 ; extra == 'test'
|
91
91
|
Provides-Extra: torch
|
92
92
|
Requires-Dist: torch >=1.4 ; extra == 'torch'
|
93
|
-
Requires-Dist: accelerate >=0.
|
93
|
+
Requires-Dist: accelerate >=0.29.3 ; extra == 'torch'
|
94
94
|
Provides-Extra: training
|
95
|
-
Requires-Dist: accelerate >=0.
|
95
|
+
Requires-Dist: accelerate >=0.29.3 ; extra == 'training'
|
96
96
|
Requires-Dist: datasets ; extra == 'training'
|
97
97
|
Requires-Dist: protobuf <4,>=3.20.3 ; extra == 'training'
|
98
98
|
Requires-Dist: tensorboard ; extra == 'training'
|
@@ -178,7 +178,7 @@ Please refer to the [How to use Stable Diffusion in Apple Silicon](https://huggi
|
|
178
178
|
|
179
179
|
## Quickstart
|
180
180
|
|
181
|
-
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for
|
181
|
+
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 25.000+ checkpoints):
|
182
182
|
|
183
183
|
```python
|
184
184
|
from diffusers import DiffusionPipeline
|
@@ -320,7 +320,7 @@ Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz9
|
|
320
320
|
- https://github.com/deep-floyd/IF
|
321
321
|
- https://github.com/bentoml/BentoML
|
322
322
|
- https://github.com/bmaltais/kohya_ss
|
323
|
-
- +
|
323
|
+
- +11.000 other amazing GitHub repositories 💪
|
324
324
|
|
325
325
|
Thank you for using us ❤️.
|
326
326
|
|
@@ -339,7 +339,7 @@ We also want to thank @heejkoo for the very helpful overview of papers, code and
|
|
339
339
|
|
340
340
|
```bibtex
|
341
341
|
@misc{von-platen-etal-2022-diffusers,
|
342
|
-
author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Thomas Wolf},
|
342
|
+
author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Dhruv Nair and Sayak Paul and William Berman and Yiyi Xu and Steven Liu and Thomas Wolf},
|
343
343
|
title = {Diffusers: State-of-the-art diffusion models},
|
344
344
|
year = {2022},
|
345
345
|
publisher = {GitHub},
|