From 42c19fdd0d49fba6c17f7b9565e290444fdf70ad Mon Sep 17 00:00:00 2001 From: DN6 Date: Tue, 26 Aug 2025 08:35:26 +0530 Subject: [PATCH] update --- tests/conftest.py | 4 +- tests/hooks/__init__.py | 0 tests/hooks/test_group_offloading.py | 3 +- tests/hooks/test_hooks.py | 3 +- tests/lora/__init__.py | 0 tests/lora/test_lora_layers_auraflow.py | 5 +- tests/lora/test_lora_layers_cogvideox.py | 5 +- tests/lora/test_lora_layers_cogview4.py | 5 +- tests/lora/test_lora_layers_flux.py | 5 +- tests/lora/test_lora_layers_hunyuanvideo.py | 5 +- tests/lora/test_lora_layers_ltx_video.py | 5 +- tests/lora/test_lora_layers_lumina2.py | 5 +- tests/lora/test_lora_layers_mochi.py | 5 +- tests/lora/test_lora_layers_qwenimage.py | 5 +- tests/lora/test_lora_layers_sana.py | 5 +- tests/lora/test_lora_layers_sd.py | 5 +- tests/lora/test_lora_layers_sd3.py | 5 +- tests/lora/test_lora_layers_sdxl.py | 5 +- tests/lora/test_lora_layers_wan.py | 5 +- tests/lora/test_lora_layers_wanvace.py | 5 +- tests/lora/utils.py | 3 +- .../test_models_asymmetric_autoencoder_kl.py | 4 +- .../test_models_autoencoder_cosmos.py | 2 +- .../test_models_autoencoder_dc.py | 4 +- .../test_models_autoencoder_hunyuan_video.py | 4 +- .../test_models_autoencoder_kl.py | 4 +- .../test_models_autoencoder_kl_cogvideox.py | 4 +- ..._models_autoencoder_kl_temporal_decoder.py | 4 +- .../test_models_autoencoder_ltx_video.py | 4 +- .../test_models_autoencoder_magvit.py | 2 +- .../test_models_autoencoder_mochi.py | 4 +- .../test_models_autoencoder_oobleck.py | 4 +- .../test_models_autoencoder_tiny.py | 4 +- .../test_models_autoencoder_wan.py | 2 +- .../test_models_consistency_decoder_vae.py | 6 +- .../autoencoders/test_models_vae_flax.py | 2 +- tests/models/autoencoders/test_models_vq.py | 4 +- tests/models/test_attention_processor.py | 3 +- tests/models/test_layers_utils.py | 3 +- tests/models/test_modeling_common.py | 8 +- tests/models/test_modeling_common_flax.py | 3 +- .../test_models_dit_transformer2d.py | 4 +- .../test_models_pixart_transformer2d.py | 4 +- .../models/transformers/test_models_prior.py | 4 +- .../test_models_transformer_allegro.py | 4 +- .../test_models_transformer_aura_flow.py | 2 +- .../test_models_transformer_bria.py | 2 +- .../test_models_transformer_chroma.py | 2 +- .../test_models_transformer_cogvideox.py | 4 +- .../test_models_transformer_cogview3plus.py | 4 +- .../test_models_transformer_cogview4.py | 2 +- .../test_models_transformer_consisid.py | 4 +- .../test_models_transformer_cosmos.py | 2 +- .../test_models_transformer_easyanimate.py | 2 +- .../test_models_transformer_flux.py | 2 +- .../test_models_transformer_hidream.py | 4 +- .../test_models_transformer_hunyuan_dit.py | 4 +- .../test_models_transformer_hunyuan_video.py | 4 +- ...els_transformer_hunyuan_video_framepack.py | 4 +- .../test_models_transformer_latte.py | 4 +- .../test_models_transformer_ltx.py | 2 +- .../test_models_transformer_lumina.py | 4 +- .../test_models_transformer_lumina2.py | 4 +- .../test_models_transformer_mochi.py | 2 +- .../test_models_transformer_omnigen.py | 2 +- .../test_models_transformer_qwenimage.py | 2 +- .../test_models_transformer_sana.py | 4 +- .../test_models_transformer_sd3.py | 4 +- .../test_models_transformer_skyreels_v2.py | 4 +- .../test_models_transformer_temporal.py | 4 +- .../test_models_transformer_wan.py | 4 +- tests/models/unets/test_models_unet_1d.py | 4 +- tests/models/unets/test_models_unet_2d.py | 4 +- .../unets/test_models_unet_2d_condition.py | 4 +- .../models/unets/test_models_unet_2d_flax.py | 3 +- .../unets/test_models_unet_3d_condition.py | 2 +- .../unets/test_models_unet_controlnetxs.py | 2 +- tests/models/unets/test_models_unet_motion.py | 4 +- .../unets/test_models_unet_spatiotemporal.py | 4 +- tests/models/unets/test_unet_2d_blocks.py | 2 +- tests/models/unets/test_unet_blocks_common.py | 5 +- ...st_modular_pipeline_stable_diffusion_xl.py | 10 +- .../test_modular_pipelines_common.py | 3 +- tests/others/test_config.py | 3 +- tests/others/test_ema.py | 3 +- tests/others/test_outputs.py | 3 +- tests/others/test_training.py | 3 +- tests/others/test_utils.py | 3 +- tests/pipelines/allegro/test_allegro.py | 4 +- .../pipelines/animatediff/test_animatediff.py | 4 +- .../test_animatediff_controlnet.py | 2 +- .../animatediff/test_animatediff_sdxl.py | 2 +- .../test_animatediff_sparsectrl.py | 2 +- .../test_animatediff_video2video.py | 2 +- ...test_animatediff_video2video_controlnet.py | 2 +- tests/pipelines/audioldm2/test_audioldm2.py | 4 +- tests/pipelines/bria/test_pipeline_bria.py | 9 +- .../pipelines/chroma/test_pipeline_chroma.py | 2 +- .../chroma/test_pipeline_chroma_img2img.py | 2 +- tests/pipelines/cogvideo/test_cogvideox.py | 4 +- .../cogvideo/test_cogvideox_fun_control.py | 4 +- .../cogvideo/test_cogvideox_image2video.py | 4 +- .../cogvideo/test_cogvideox_video2video.py | 2 +- tests/pipelines/cogview3/test_cogview3plus.py | 4 +- tests/pipelines/cogview4/test_cogview4.py | 2 +- tests/pipelines/consisid/test_consisid.py | 4 +- .../test_consistency_models.py | 6 +- tests/pipelines/controlnet/test_controlnet.py | 6 +- .../controlnet/test_controlnet_img2img.py | 6 +- .../controlnet/test_controlnet_inpaint.py | 6 +- .../test_controlnet_inpaint_sdxl.py | 4 +- .../controlnet/test_controlnet_sdxl.py | 6 +- .../test_controlnet_sdxl_img2img.py | 4 +- .../controlnet/test_flax_controlnet.py | 3 +- .../controlnet_flux/test_controlnet_flux.py | 6 +- .../test_controlnet_flux_img2img.py | 6 +- .../test_controlnet_flux_inpaint.py | 6 +- .../test_controlnet_hunyuandit.py | 6 +- .../test_controlnet_inpaint_sd3.py | 6 +- .../controlnet_sd3/test_controlnet_sd3.py | 6 +- tests/pipelines/cosmos/test_cosmos.py | 2 +- .../cosmos/test_cosmos2_text2image.py | 2 +- .../cosmos/test_cosmos2_video2world.py | 2 +- .../cosmos/test_cosmos_video2world.py | 2 +- tests/pipelines/ddim/test_ddim.py | 2 +- tests/pipelines/ddpm/test_ddpm.py | 3 +- tests/pipelines/deepfloyd_if/__init__.py | 2 +- tests/pipelines/deepfloyd_if/test_if.py | 4 +- .../pipelines/deepfloyd_if/test_if_img2img.py | 4 +- .../test_if_img2img_superresolution.py | 4 +- .../deepfloyd_if/test_if_inpainting.py | 4 +- .../test_if_inpainting_superresolution.py | 4 +- .../deepfloyd_if/test_if_superresolution.py | 4 +- tests/pipelines/dit/test_dit.py | 4 +- .../pipelines/easyanimate/test_easyanimate.py | 4 +- tests/pipelines/flux/test_pipeline_flux.py | 4 +- .../flux/test_pipeline_flux_control.py | 2 +- .../test_pipeline_flux_control_img2img.py | 2 +- .../test_pipeline_flux_control_inpaint.py | 4 +- .../pipelines/flux/test_pipeline_flux_fill.py | 4 +- .../flux/test_pipeline_flux_img2img.py | 4 +- .../flux/test_pipeline_flux_inpaint.py | 4 +- .../flux/test_pipeline_flux_kontext.py | 2 +- .../test_pipeline_flux_kontext_inpaint.py | 2 +- .../flux/test_pipeline_flux_redux.py | 3 +- .../hidream_image/test_pipeline_hidream.py | 2 +- .../hunyuan_video/test_hunyuan_image2video.py | 2 +- .../test_hunyuan_skyreels_image2video.py | 2 +- .../hunyuan_video/test_hunyuan_video.py | 2 +- .../test_hunyuan_video_framepack.py | 4 +- .../pipelines/hunyuandit/test_hunyuan_dit.py | 4 +- tests/pipelines/ip_adapters/__init__.py | 0 .../test_ip_adapter_stable_diffusion.py | 3 +- tests/pipelines/kandinsky/test_kandinsky.py | 4 +- .../kandinsky/test_kandinsky_combined.py | 2 +- .../kandinsky/test_kandinsky_img2img.py | 4 +- .../kandinsky/test_kandinsky_inpaint.py | 4 +- .../kandinsky/test_kandinsky_prior.py | 2 +- .../pipelines/kandinsky2_2/test_kandinsky.py | 4 +- .../kandinsky2_2/test_kandinsky_combined.py | 2 +- .../kandinsky2_2/test_kandinsky_controlnet.py | 4 +- .../test_kandinsky_controlnet_img2img.py | 4 +- .../kandinsky2_2/test_kandinsky_img2img.py | 4 +- .../kandinsky2_2/test_kandinsky_inpaint.py | 4 +- .../kandinsky2_2/test_kandinsky_prior.py | 2 +- .../test_kandinsky_prior_emb2emb.py | 4 +- tests/pipelines/kandinsky3/test_kandinsky3.py | 4 +- .../kandinsky3/test_kandinsky3_img2img.py | 4 +- tests/pipelines/kolors/test_kolors.py | 2 +- tests/pipelines/kolors/test_kolors_img2img.py | 4 +- .../test_latent_consistency_models.py | 4 +- .../test_latent_consistency_models_img2img.py | 4 +- .../latent_diffusion/test_latent_diffusion.py | 4 +- .../test_latent_diffusion_superresolution.py | 3 +- tests/pipelines/latte/test_latte.py | 4 +- .../test_ledits_pp_stable_diffusion.py | 3 +- .../test_ledits_pp_stable_diffusion_xl.py | 2 +- tests/pipelines/ltx/test_ltx.py | 2 +- tests/pipelines/ltx/test_ltx_condition.py | 2 +- tests/pipelines/ltx/test_ltx_image2video.py | 2 +- .../pipelines/ltx/test_ltx_latent_upsample.py | 2 +- tests/pipelines/lumina/test_lumina_nextdit.py | 4 +- .../pipelines/marigold/test_marigold_depth.py | 4 +- .../marigold/test_marigold_intrinsics.py | 4 +- .../marigold/test_marigold_normals.py | 4 +- tests/pipelines/mochi/test_mochi.py | 4 +- .../omnigen/test_pipeline_omnigen.py | 4 +- tests/pipelines/pag/test_pag_animatediff.py | 2 +- tests/pipelines/pag/test_pag_controlnet_sd.py | 2 +- .../pag/test_pag_controlnet_sd_inpaint.py | 2 +- .../pipelines/pag/test_pag_controlnet_sdxl.py | 2 +- .../pag/test_pag_controlnet_sdxl_img2img.py | 2 +- tests/pipelines/pag/test_pag_hunyuan_dit.py | 2 +- tests/pipelines/pag/test_pag_kolors.py | 2 +- tests/pipelines/pag/test_pag_pixart_sigma.py | 4 +- tests/pipelines/pag/test_pag_sana.py | 2 +- tests/pipelines/pag/test_pag_sd.py | 4 +- tests/pipelines/pag/test_pag_sd3.py | 4 +- tests/pipelines/pag/test_pag_sd3_img2img.py | 4 +- tests/pipelines/pag/test_pag_sd_img2img.py | 4 +- tests/pipelines/pag/test_pag_sd_inpaint.py | 4 +- tests/pipelines/pag/test_pag_sdxl.py | 4 +- tests/pipelines/pag/test_pag_sdxl_img2img.py | 4 +- tests/pipelines/pag/test_pag_sdxl_inpaint.py | 4 +- tests/pipelines/pixart_alpha/test_pixart.py | 4 +- tests/pipelines/pixart_sigma/test_pixart.py | 4 +- tests/pipelines/pndm/test_pndm.py | 3 +- tests/pipelines/qwenimage/test_qwenimage.py | 2 +- .../qwenimage/test_qwenimage_edit.py | 2 +- .../qwenimage/test_qwenimage_img2img.py | 4 +- .../qwenimage/test_qwenimage_inpaint.py | 2 +- tests/pipelines/sana/test_sana.py | 4 +- tests/pipelines/sana/test_sana_controlnet.py | 6 +- tests/pipelines/sana/test_sana_sprint.py | 4 +- .../sana/test_sana_sprint_img2img.py | 6 +- tests/pipelines/shap_e/test_shap_e.py | 4 +- tests/pipelines/shap_e/test_shap_e_img2img.py | 4 +- .../pipelines/skyreels_v2/test_skyreels_v2.py | 4 +- .../skyreels_v2/test_skyreels_v2_df.py | 4 +- .../test_skyreels_v2_df_image_to_video.py | 2 +- .../test_skyreels_v2_df_video_to_video.py | 4 +- .../test_skyreels_v2_image_to_video.py | 2 +- .../stable_audio/test_stable_audio.py | 4 +- .../test_stable_cascade_combined.py | 2 +- .../test_stable_cascade_decoder.py | 6 +- .../test_stable_cascade_prior.py | 3 +- .../test_onnx_stable_diffusion.py | 2 +- .../test_onnx_stable_diffusion_img2img.py | 4 +- .../test_onnx_stable_diffusion_inpaint.py | 4 +- .../test_onnx_stable_diffusion_upscale.py | 4 +- .../stable_diffusion/test_stable_diffusion.py | 4 +- .../test_stable_diffusion_img2img.py | 4 +- .../test_stable_diffusion_inpaint.py | 4 +- ...st_stable_diffusion_instruction_pix2pix.py | 4 +- .../test_stable_diffusion.py | 4 +- .../test_stable_diffusion_depth.py | 4 +- .../test_stable_diffusion_flax.py | 3 +- .../test_stable_diffusion_flax_inpaint.py | 3 +- .../test_stable_diffusion_inpaint.py | 4 +- .../test_stable_diffusion_latent_upscale.py | 4 +- .../test_stable_diffusion_upscale.py | 3 +- .../test_stable_diffusion_v_pred.py | 3 +- .../test_pipeline_stable_diffusion_3.py | 4 +- ...est_pipeline_stable_diffusion_3_img2img.py | 4 +- ...est_pipeline_stable_diffusion_3_inpaint.py | 4 +- .../test_stable_diffusion_adapter.py | 4 +- .../test_stable_diffusion_image_variation.py | 4 +- .../test_stable_diffusion_xl.py | 4 +- .../test_stable_diffusion_xl_adapter.py | 4 +- .../test_stable_diffusion_xl_img2img.py | 4 +- .../test_stable_diffusion_xl_inpaint.py | 4 +- ...stable_diffusion_xl_instruction_pix2pix.py | 2 +- .../stable_unclip/test_stable_unclip.py | 4 +- .../test_stable_unclip_img2img.py | 4 +- .../test_stable_video_diffusion.py | 4 +- tests/pipelines/test_pipeline_utils.py | 3 +- tests/pipelines/test_pipelines.py | 5 +- tests/pipelines/test_pipelines_auto.py | 3 +- tests/pipelines/test_pipelines_common.py | 26 +- tests/pipelines/test_pipelines_flax.py | 3 +- tests/pipelines/test_pipelines_onnx_common.py | 2 +- .../test_pipeline_visualcloze_combined.py | 4 +- .../test_pipeline_visualcloze_generation.py | 4 +- tests/pipelines/wan/test_wan.py | 4 +- tests/pipelines/wan/test_wan_22.py | 4 +- .../wan/test_wan_22_image_to_video.py | 4 +- .../pipelines/wan/test_wan_image_to_video.py | 2 +- tests/pipelines/wan/test_wan_vace.py | 2 +- .../pipelines/wan/test_wan_video_to_video.py | 4 +- tests/quantization/bnb/test_4bit.py | 4 +- tests/quantization/bnb/test_mixed_int8.py | 4 +- tests/quantization/gguf/test_gguf.py | 4 +- tests/quantization/quanto/test_quanto.py | 3 +- .../test_pipeline_level_quantization.py | 3 +- .../quantization/test_torch_compile_utils.py | 3 +- tests/quantization/torchao/test_torchao.py | 4 +- tests/quantization/utils.py | 3 +- tests/remote/test_remote_decode.py | 5 +- tests/remote/test_remote_encode.py | 3 +- tests/schedulers/test_scheduler_dpm_sde.py | 2 +- tests/schedulers/test_scheduler_euler.py | 2 +- .../test_scheduler_euler_ancestral.py | 2 +- tests/schedulers/test_scheduler_flax.py | 3 +- tests/schedulers/test_scheduler_heun.py | 2 +- .../test_scheduler_kdpm2_ancestral.py | 2 +- .../test_scheduler_kdpm2_discrete.py | 2 +- tests/schedulers/test_scheduler_lcm.py | 2 +- tests/schedulers/test_scheduler_lms.py | 2 +- tests/schedulers/test_scheduler_sasolver.py | 2 +- tests/schedulers/test_schedulers.py | 2 +- .../single_file/single_file_testing_utils.py | 3 +- tests/single_file/test_lumina2_transformer.py | 3 +- .../test_model_autoencoder_dc_single_file.py | 3 +- .../test_model_controlnet_single_file.py | 3 +- ...test_model_flux_transformer_single_file.py | 3 +- .../test_model_motion_adapter_single_file.py | 3 +- .../test_model_sd_cascade_unet_single_file.py | 3 +- .../single_file/test_model_vae_single_file.py | 3 +- .../test_model_wan_autoencoder_single_file.py | 3 +- ...est_model_wan_transformer3d_single_file.py | 3 +- tests/single_file/test_sana_transformer.py | 3 +- ...iffusion_controlnet_img2img_single_file.py | 4 +- ...iffusion_controlnet_inpaint_single_file.py | 4 +- ...stable_diffusion_controlnet_single_file.py | 4 +- ...st_stable_diffusion_img2img_single_file.py | 4 +- ...st_stable_diffusion_inpaint_single_file.py | 4 +- .../test_stable_diffusion_single_file.py | 4 +- ...st_stable_diffusion_upscale_single_file.py | 4 +- ...stable_diffusion_xl_adapter_single_file.py | 4 +- ...ble_diffusion_xl_controlnet_single_file.py | 4 +- ...stable_diffusion_xl_img2img_single_file.py | 4 +- ...st_stable_diffusion_xl_instruct_pix2pix.py | 3 +- .../test_stable_diffusion_xl_single_file.py | 4 +- tests/testing_utils.py | 1557 +++++++++++++++++ 314 files changed, 2149 insertions(+), 527 deletions(-) create mode 100644 tests/hooks/__init__.py create mode 100644 tests/lora/__init__.py create mode 100644 tests/pipelines/ip_adapters/__init__.py create mode 100644 tests/testing_utils.py diff --git a/tests/conftest.py b/tests/conftest.py index 3237fb9c7b..fd76d1c84e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,13 +35,13 @@ def pytest_configure(config): def pytest_addoption(parser): - from diffusers.utils.testing_utils import pytest_addoption_shared + from .testing_utils import pytest_addoption_shared pytest_addoption_shared(parser) def pytest_terminal_summary(terminalreporter): - from diffusers.utils.testing_utils import pytest_terminal_summary_main + from .testing_utils import pytest_terminal_summary_main make_reports = terminalreporter.config.getoption("--make-reports") if make_reports: diff --git a/tests/hooks/__init__.py b/tests/hooks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/hooks/test_group_offloading.py b/tests/hooks/test_group_offloading.py index ea08dec19c..96cbecfbf5 100644 --- a/tests/hooks/test_group_offloading.py +++ b/tests/hooks/test_group_offloading.py @@ -24,7 +24,8 @@ from diffusers.models import ModelMixin from diffusers.pipelines.pipeline_utils import DiffusionPipeline from diffusers.utils import get_logger from diffusers.utils.import_utils import compare_versions -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_peak_memory_stats, diff --git a/tests/hooks/test_hooks.py b/tests/hooks/test_hooks.py index 7f60acf8d3..1e845cc40c 100644 --- a/tests/hooks/test_hooks.py +++ b/tests/hooks/test_hooks.py @@ -20,7 +20,8 @@ import torch from diffusers.hooks import HookRegistry, ModelHook from diffusers.training_utils import free_memory from diffusers.utils.logging import get_logger -from diffusers.utils.testing_utils import CaptureLogger, torch_device + +from ..testing_utils import CaptureLogger, torch_device logger = get_logger(__name__) # pylint: disable=invalid-name diff --git a/tests/lora/__init__.py b/tests/lora/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/lora/test_lora_layers_auraflow.py b/tests/lora/test_lora_layers_auraflow.py index d119feae20..67084dd6d0 100644 --- a/tests/lora/test_lora_layers_auraflow.py +++ b/tests/lora/test_lora_layers_auraflow.py @@ -23,7 +23,8 @@ from diffusers import ( AuraFlowTransformer2DModel, FlowMatchEulerDiscreteScheduler, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( floats_tensor, is_peft_available, require_peft_backend, @@ -35,7 +36,7 @@ if is_peft_available(): sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_cogvideox.py b/tests/lora/test_lora_layers_cogvideox.py index 565d6db697..16147f35c7 100644 --- a/tests/lora/test_lora_layers_cogvideox.py +++ b/tests/lora/test_lora_layers_cogvideox.py @@ -26,7 +26,8 @@ from diffusers import ( CogVideoXPipeline, CogVideoXTransformer3DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( floats_tensor, require_peft_backend, require_torch_accelerator, @@ -35,7 +36,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_cogview4.py b/tests/lora/test_lora_layers_cogview4.py index b7367d9b09..3b8a56c403 100644 --- a/tests/lora/test_lora_layers_cogview4.py +++ b/tests/lora/test_lora_layers_cogview4.py @@ -22,7 +22,8 @@ from parameterized import parameterized from transformers import AutoTokenizer, GlmModel from diffusers import AutoencoderKL, CogView4Pipeline, CogView4Transformer2DModel, FlowMatchEulerDiscreteScheduler -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( floats_tensor, require_peft_backend, require_torch_accelerator, @@ -33,7 +34,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 class TokenizerWrapper: diff --git a/tests/lora/test_lora_layers_flux.py b/tests/lora/test_lora_layers_flux.py index 95f1e137e9..7d99bcad80 100644 --- a/tests/lora/test_lora_layers_flux.py +++ b/tests/lora/test_lora_layers_flux.py @@ -28,7 +28,8 @@ from transformers import AutoTokenizer, CLIPTextModel, CLIPTokenizer, T5EncoderM from diffusers import FlowMatchEulerDiscreteScheduler, FluxControlPipeline, FluxPipeline, FluxTransformer2DModel from diffusers.utils import load_image, logging -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( CaptureLogger, backend_empty_cache, floats_tensor, @@ -48,7 +49,7 @@ if is_peft_available(): sys.path.append(".") -from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402 +from .utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_hunyuanvideo.py b/tests/lora/test_lora_layers_hunyuanvideo.py index 4cbd6523e7..62d045f836 100644 --- a/tests/lora/test_lora_layers_hunyuanvideo.py +++ b/tests/lora/test_lora_layers_hunyuanvideo.py @@ -26,7 +26,8 @@ from diffusers import ( HunyuanVideoPipeline, HunyuanVideoTransformer3DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( Expectations, backend_empty_cache, floats_tensor, @@ -42,7 +43,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_ltx_video.py b/tests/lora/test_lora_layers_ltx_video.py index 88949227cf..a8ad30e448 100644 --- a/tests/lora/test_lora_layers_ltx_video.py +++ b/tests/lora/test_lora_layers_ltx_video.py @@ -24,12 +24,13 @@ from diffusers import ( LTXPipeline, LTXVideoTransformer3DModel, ) -from diffusers.utils.testing_utils import floats_tensor, require_peft_backend + +from ..testing_utils import floats_tensor, require_peft_backend sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_lumina2.py b/tests/lora/test_lora_layers_lumina2.py index d7096e79b9..0ebc831b11 100644 --- a/tests/lora/test_lora_layers_lumina2.py +++ b/tests/lora/test_lora_layers_lumina2.py @@ -26,12 +26,13 @@ from diffusers import ( Lumina2Pipeline, Lumina2Transformer2DModel, ) -from diffusers.utils.testing_utils import floats_tensor, is_torch_version, require_peft_backend, skip_mps, torch_device + +from ..testing_utils import floats_tensor, is_torch_version, require_peft_backend, skip_mps, torch_device sys.path.append(".") -from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402 +from .utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_mochi.py b/tests/lora/test_lora_layers_mochi.py index 501a4b35f4..21cc5f11a3 100644 --- a/tests/lora/test_lora_layers_mochi.py +++ b/tests/lora/test_lora_layers_mochi.py @@ -19,7 +19,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLMochi, FlowMatchEulerDiscreteScheduler, MochiPipeline, MochiTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( floats_tensor, require_peft_backend, skip_mps, @@ -28,7 +29,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_qwenimage.py b/tests/lora/test_lora_layers_qwenimage.py index 5850626308..44ef9b0a37 100644 --- a/tests/lora/test_lora_layers_qwenimage.py +++ b/tests/lora/test_lora_layers_qwenimage.py @@ -24,12 +24,13 @@ from diffusers import ( QwenImagePipeline, QwenImageTransformer2DModel, ) -from diffusers.utils.testing_utils import floats_tensor, require_peft_backend + +from ..testing_utils import floats_tensor, require_peft_backend sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_sana.py b/tests/lora/test_lora_layers_sana.py index 24beb46b95..a08908c610 100644 --- a/tests/lora/test_lora_layers_sana.py +++ b/tests/lora/test_lora_layers_sana.py @@ -19,12 +19,13 @@ import torch from transformers import Gemma2Model, GemmaTokenizer from diffusers import AutoencoderDC, FlowMatchEulerDiscreteScheduler, SanaPipeline, SanaTransformer2DModel -from diffusers.utils.testing_utils import floats_tensor, require_peft_backend + +from ..testing_utils import floats_tensor, require_peft_backend sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_sd.py b/tests/lora/test_lora_layers_sd.py index 1c5a9b00e9..933bf2336a 100644 --- a/tests/lora/test_lora_layers_sd.py +++ b/tests/lora/test_lora_layers_sd.py @@ -32,7 +32,8 @@ from diffusers import ( StableDiffusionPipeline, ) from diffusers.utils.import_utils import is_accelerate_available -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( Expectations, backend_empty_cache, load_image, @@ -47,7 +48,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402 +from .utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402 if is_accelerate_available(): diff --git a/tests/lora/test_lora_layers_sd3.py b/tests/lora/test_lora_layers_sd3.py index 8928ccbac2..95f6f325e4 100644 --- a/tests/lora/test_lora_layers_sd3.py +++ b/tests/lora/test_lora_layers_sd3.py @@ -28,7 +28,8 @@ from diffusers import ( ) from diffusers.utils import load_image from diffusers.utils.import_utils import is_accelerate_available -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, is_flaky, nightly, @@ -42,7 +43,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 if is_accelerate_available(): diff --git a/tests/lora/test_lora_layers_sdxl.py b/tests/lora/test_lora_layers_sdxl.py index 267650056a..ac1d65abda 100644 --- a/tests/lora/test_lora_layers_sdxl.py +++ b/tests/lora/test_lora_layers_sdxl.py @@ -35,7 +35,8 @@ from diffusers import ( ) from diffusers.utils import logging from diffusers.utils.import_utils import is_accelerate_available -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( CaptureLogger, backend_empty_cache, is_flaky, @@ -51,7 +52,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set, state_dicts_almost_equal # noqa: E402 +from .utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set, state_dicts_almost_equal # noqa: E402 if is_accelerate_available(): diff --git a/tests/lora/test_lora_layers_wan.py b/tests/lora/test_lora_layers_wan.py index fe26a56e77..0ba80d2be1 100644 --- a/tests/lora/test_lora_layers_wan.py +++ b/tests/lora/test_lora_layers_wan.py @@ -24,7 +24,8 @@ from diffusers import ( WanPipeline, WanTransformer3DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( floats_tensor, require_peft_backend, skip_mps, @@ -33,7 +34,7 @@ from diffusers.utils.testing_utils import ( sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/test_lora_layers_wanvace.py b/tests/lora/test_lora_layers_wanvace.py index a0954fa4fa..d8dde32dd8 100644 --- a/tests/lora/test_lora_layers_wanvace.py +++ b/tests/lora/test_lora_layers_wanvace.py @@ -25,7 +25,8 @@ from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLWan, FlowMatchEulerDiscreteScheduler, WanVACEPipeline, WanVACETransformer3DModel from diffusers.utils.import_utils import is_peft_available -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( floats_tensor, is_flaky, require_peft_backend, @@ -40,7 +41,7 @@ if is_peft_available(): sys.path.append(".") -from utils import PeftLoraLoaderMixinTests # noqa: E402 +from .utils import PeftLoraLoaderMixinTests # noqa: E402 @require_peft_backend diff --git a/tests/lora/utils.py b/tests/lora/utils.py index f09f0d8ecb..72c1dddaa2 100644 --- a/tests/lora/utils.py +++ b/tests/lora/utils.py @@ -32,7 +32,8 @@ from diffusers import ( ) from diffusers.utils import logging from diffusers.utils.import_utils import is_peft_available -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( CaptureLogger, check_if_dicts_are_equal, floats_tensor, diff --git a/tests/models/autoencoders/test_models_asymmetric_autoencoder_kl.py b/tests/models/autoencoders/test_models_asymmetric_autoencoder_kl.py index 4741648359..7eb830cd50 100644 --- a/tests/models/autoencoders/test_models_asymmetric_autoencoder_kl.py +++ b/tests/models/autoencoders/test_models_asymmetric_autoencoder_kl.py @@ -21,7 +21,8 @@ from parameterized import parameterized from diffusers import AsymmetricAutoencoderKL from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, enable_full_determinism, @@ -34,7 +35,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_cosmos.py b/tests/models/autoencoders/test_models_autoencoder_cosmos.py index bc0011a2f0..ceccc2364e 100644 --- a/tests/models/autoencoders/test_models_autoencoder_cosmos.py +++ b/tests/models/autoencoders/test_models_autoencoder_cosmos.py @@ -15,8 +15,8 @@ import unittest from diffusers import AutoencoderKLCosmos -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, torch_device from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_dc.py b/tests/models/autoencoders/test_models_autoencoder_dc.py index 4d2c3dc663..56f172f1c8 100644 --- a/tests/models/autoencoders/test_models_autoencoder_dc.py +++ b/tests/models/autoencoders/test_models_autoencoder_dc.py @@ -16,12 +16,12 @@ import unittest from diffusers import AutoencoderDC -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_hunyuan_video.py b/tests/models/autoencoders/test_models_autoencoder_hunyuan_video.py index 40479991e9..6f91f8bfa9 100644 --- a/tests/models/autoencoders/test_models_autoencoder_hunyuan_video.py +++ b/tests/models/autoencoders/test_models_autoencoder_hunyuan_video.py @@ -19,12 +19,12 @@ import torch from diffusers import AutoencoderKLHunyuanVideo from diffusers.models.autoencoders.autoencoder_kl_hunyuan_video import prepare_causal_attention_mask -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_kl.py b/tests/models/autoencoders/test_models_autoencoder_kl.py index 2c323e4f03..662a3f1b80 100644 --- a/tests/models/autoencoders/test_models_autoencoder_kl.py +++ b/tests/models/autoencoders/test_models_autoencoder_kl.py @@ -21,7 +21,8 @@ from parameterized import parameterized from diffusers import AutoencoderKL from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -34,7 +35,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_kl_cogvideox.py b/tests/models/autoencoders/test_models_autoencoder_kl_cogvideox.py index 7ab9520ce6..739daf2a49 100644 --- a/tests/models/autoencoders/test_models_autoencoder_kl_cogvideox.py +++ b/tests/models/autoencoders/test_models_autoencoder_kl_cogvideox.py @@ -18,12 +18,12 @@ import unittest import torch from diffusers import AutoencoderKLCogVideoX -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_kl_temporal_decoder.py b/tests/models/autoencoders/test_models_autoencoder_kl_temporal_decoder.py index 618a448eca..6cb427bff8 100644 --- a/tests/models/autoencoders/test_models_autoencoder_kl_temporal_decoder.py +++ b/tests/models/autoencoders/test_models_autoencoder_kl_temporal_decoder.py @@ -16,12 +16,12 @@ import unittest from diffusers import AutoencoderKLTemporalDecoder -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_ltx_video.py b/tests/models/autoencoders/test_models_autoencoder_ltx_video.py index c056930a5e..21ab3896c8 100644 --- a/tests/models/autoencoders/test_models_autoencoder_ltx_video.py +++ b/tests/models/autoencoders/test_models_autoencoder_ltx_video.py @@ -18,12 +18,12 @@ import unittest import torch from diffusers import AutoencoderKLLTXVideo -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_magvit.py b/tests/models/autoencoders/test_models_autoencoder_magvit.py index c171176627..58cbfc05bd 100644 --- a/tests/models/autoencoders/test_models_autoencoder_magvit.py +++ b/tests/models/autoencoders/test_models_autoencoder_magvit.py @@ -16,8 +16,8 @@ import unittest from diffusers import AutoencoderKLMagvit -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, torch_device from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_mochi.py b/tests/models/autoencoders/test_models_autoencoder_mochi.py index d646693c57..b8c5aaaa1e 100755 --- a/tests/models/autoencoders/test_models_autoencoder_mochi.py +++ b/tests/models/autoencoders/test_models_autoencoder_mochi.py @@ -16,12 +16,12 @@ import unittest from diffusers import AutoencoderKLMochi -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_oobleck.py b/tests/models/autoencoders/test_models_autoencoder_oobleck.py index 5c1d7c8b71..eb7bd50f4a 100644 --- a/tests/models/autoencoders/test_models_autoencoder_oobleck.py +++ b/tests/models/autoencoders/test_models_autoencoder_oobleck.py @@ -21,7 +21,8 @@ from datasets import load_dataset from parameterized import parameterized from diffusers import AutoencoderOobleck -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -29,7 +30,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_tiny.py b/tests/models/autoencoders/test_models_autoencoder_tiny.py index fba2c9eb1b..4d1dc69cfa 100644 --- a/tests/models/autoencoders/test_models_autoencoder_tiny.py +++ b/tests/models/autoencoders/test_models_autoencoder_tiny.py @@ -21,7 +21,8 @@ import torch from parameterized import parameterized from diffusers import AutoencoderTiny -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -30,7 +31,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_autoencoder_wan.py b/tests/models/autoencoders/test_models_autoencoder_wan.py index c0af4f5834..cc9c888681 100644 --- a/tests/models/autoencoders/test_models_autoencoder_wan.py +++ b/tests/models/autoencoders/test_models_autoencoder_wan.py @@ -18,8 +18,8 @@ import unittest import torch from diffusers import AutoencoderKLWan -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, torch_device from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/autoencoders/test_models_consistency_decoder_vae.py b/tests/models/autoencoders/test_models_consistency_decoder_vae.py index cdce013cfb..7e44edba36 100644 --- a/tests/models/autoencoders/test_models_consistency_decoder_vae.py +++ b/tests/models/autoencoders/test_models_consistency_decoder_vae.py @@ -20,7 +20,9 @@ import numpy as np import torch from diffusers import ConsistencyDecoderVAE, StableDiffusionPipeline -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_image, @@ -28,8 +30,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/autoencoders/test_models_vae_flax.py b/tests/models/autoencoders/test_models_vae_flax.py index 8fedb85ecc..3023a7c32c 100644 --- a/tests/models/autoencoders/test_models_vae_flax.py +++ b/tests/models/autoencoders/test_models_vae_flax.py @@ -2,8 +2,8 @@ import unittest from diffusers import FlaxAutoencoderKL from diffusers.utils import is_flax_available -from diffusers.utils.testing_utils import require_flax +from ...testing_utils import require_flax from ..test_modeling_common_flax import FlaxModelTesterMixin diff --git a/tests/models/autoencoders/test_models_vq.py b/tests/models/autoencoders/test_models_vq.py index e8ed98f44a..1c636b0817 100644 --- a/tests/models/autoencoders/test_models_vq.py +++ b/tests/models/autoencoders/test_models_vq.py @@ -18,13 +18,13 @@ import unittest import torch from diffusers import VQModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_manual_seed, enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/test_attention_processor.py b/tests/models/test_attention_processor.py index d070f6ea33..ccf36b092b 100644 --- a/tests/models/test_attention_processor.py +++ b/tests/models/test_attention_processor.py @@ -7,7 +7,8 @@ import torch from diffusers import DiffusionPipeline from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor -from diffusers.utils.testing_utils import torch_device + +from ..testing_utils import torch_device class AttnAddedKVProcessorTests(unittest.TestCase): diff --git a/tests/models/test_layers_utils.py b/tests/models/test_layers_utils.py index ec8e01b4b7..eaeffa699d 100644 --- a/tests/models/test_layers_utils.py +++ b/tests/models/test_layers_utils.py @@ -24,7 +24,8 @@ from diffusers.models.attention import GEGLU, AdaLayerNorm, ApproximateGELU from diffusers.models.embeddings import get_timestep_embedding from diffusers.models.resnet import Downsample2D, ResnetBlock2D, Upsample2D from diffusers.models.transformers.transformer_2d import Transformer2DModel -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_manual_seed, require_torch_accelerator_with_fp64, require_torch_version_greater_equal, diff --git a/tests/models/test_modeling_common.py b/tests/models/test_modeling_common.py index 1e08191f56..36eb2c1ef4 100644 --- a/tests/models/test_modeling_common.py +++ b/tests/models/test_modeling_common.py @@ -59,7 +59,10 @@ from diffusers.utils import ( logging, ) from diffusers.utils.hub_utils import _add_variant -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import get_torch_cuda_device_capability + +from ..others.test_utils import TOKEN, USER, is_staging_test +from ..testing_utils import ( CaptureLogger, _check_safetensors_serialization, backend_empty_cache, @@ -82,9 +85,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) -from diffusers.utils.torch_utils import get_torch_cuda_device_capability - -from ..others.test_utils import TOKEN, USER, is_staging_test if is_peft_available(): diff --git a/tests/models/test_modeling_common_flax.py b/tests/models/test_modeling_common_flax.py index 8945aed7c9..41e970b566 100644 --- a/tests/models/test_modeling_common_flax.py +++ b/tests/models/test_modeling_common_flax.py @@ -1,7 +1,8 @@ import inspect from diffusers.utils import is_flax_available -from diffusers.utils.testing_utils import require_flax + +from ..testing_utils import require_flax if is_flax_available(): diff --git a/tests/models/transformers/test_models_dit_transformer2d.py b/tests/models/transformers/test_models_dit_transformer2d.py index 3070321673..473a876375 100644 --- a/tests/models/transformers/test_models_dit_transformer2d.py +++ b/tests/models/transformers/test_models_dit_transformer2d.py @@ -18,13 +18,13 @@ import unittest import torch from diffusers import DiTTransformer2DModel, Transformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, slow, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_pixart_transformer2d.py b/tests/models/transformers/test_models_pixart_transformer2d.py index 38fada0b4b..17c400cf19 100644 --- a/tests/models/transformers/test_models_pixart_transformer2d.py +++ b/tests/models/transformers/test_models_pixart_transformer2d.py @@ -18,13 +18,13 @@ import unittest import torch from diffusers import PixArtTransformer2DModel, Transformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, slow, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_prior.py b/tests/models/transformers/test_models_prior.py index 5d66aadb1b..af5ac4bbbd 100644 --- a/tests/models/transformers/test_models_prior.py +++ b/tests/models/transformers/test_models_prior.py @@ -21,7 +21,8 @@ import torch from parameterized import parameterized from diffusers import PriorTransformer -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -29,7 +30,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_allegro.py b/tests/models/transformers/test_models_transformer_allegro.py index 8a0c475583..7c002f8781 100644 --- a/tests/models/transformers/test_models_transformer_allegro.py +++ b/tests/models/transformers/test_models_transformer_allegro.py @@ -17,11 +17,11 @@ import unittest import torch from diffusers import AllegroTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_aura_flow.py b/tests/models/transformers/test_models_transformer_aura_flow.py index 8dff07373e..ae8c3b7234 100644 --- a/tests/models/transformers/test_models_transformer_aura_flow.py +++ b/tests/models/transformers/test_models_transformer_aura_flow.py @@ -18,8 +18,8 @@ import unittest import torch from diffusers import AuraFlowTransformer2DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_bria.py b/tests/models/transformers/test_models_transformer_bria.py index 8a8d0dcecf..9056590edf 100644 --- a/tests/models/transformers/test_models_transformer_bria.py +++ b/tests/models/transformers/test_models_transformer_bria.py @@ -20,8 +20,8 @@ import torch from diffusers import BriaTransformer2DModel from diffusers.models.attention_processor import FluxIPAdapterJointAttnProcessor2_0 from diffusers.models.embeddings import ImageProjection -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import LoraHotSwappingForModelTesterMixin, ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_chroma.py b/tests/models/transformers/test_models_transformer_chroma.py index e9fd5a0bfb..92ac8198ed 100644 --- a/tests/models/transformers/test_models_transformer_chroma.py +++ b/tests/models/transformers/test_models_transformer_chroma.py @@ -20,8 +20,8 @@ import torch from diffusers import ChromaTransformer2DModel from diffusers.models.attention_processor import FluxIPAdapterJointAttnProcessor2_0 from diffusers.models.embeddings import ImageProjection -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import LoraHotSwappingForModelTesterMixin, ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_cogvideox.py b/tests/models/transformers/test_models_transformer_cogvideox.py index 54d1242bf7..f632add7e5 100644 --- a/tests/models/transformers/test_models_transformer_cogvideox.py +++ b/tests/models/transformers/test_models_transformer_cogvideox.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import CogVideoXTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_cogview3plus.py b/tests/models/transformers/test_models_transformer_cogview3plus.py index 57131dc3f1..d38d77531d 100644 --- a/tests/models/transformers/test_models_transformer_cogview3plus.py +++ b/tests/models/transformers/test_models_transformer_cogview3plus.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import CogView3PlusTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_cogview4.py b/tests/models/transformers/test_models_transformer_cogview4.py index 798453e86d..084c3b7cea 100644 --- a/tests/models/transformers/test_models_transformer_cogview4.py +++ b/tests/models/transformers/test_models_transformer_cogview4.py @@ -17,8 +17,8 @@ import unittest import torch from diffusers import CogView4Transformer2DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_consisid.py b/tests/models/transformers/test_models_transformer_consisid.py index af2e1e6338..77fc172d07 100644 --- a/tests/models/transformers/test_models_transformer_consisid.py +++ b/tests/models/transformers/test_models_transformer_consisid.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import ConsisIDTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_cosmos.py b/tests/models/transformers/test_models_transformer_cosmos.py index 7d26004d75..d7390e105c 100644 --- a/tests/models/transformers/test_models_transformer_cosmos.py +++ b/tests/models/transformers/test_models_transformer_cosmos.py @@ -17,8 +17,8 @@ import unittest import torch from diffusers import CosmosTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_easyanimate.py b/tests/models/transformers/test_models_transformer_easyanimate.py index 0a255f4d4e..d7b90a47d9 100644 --- a/tests/models/transformers/test_models_transformer_easyanimate.py +++ b/tests/models/transformers/test_models_transformer_easyanimate.py @@ -18,8 +18,8 @@ import unittest import torch from diffusers import EasyAnimateTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_flux.py b/tests/models/transformers/test_models_transformer_flux.py index 14ef6f1514..3ab02f797b 100644 --- a/tests/models/transformers/test_models_transformer_flux.py +++ b/tests/models/transformers/test_models_transformer_flux.py @@ -20,8 +20,8 @@ import torch from diffusers import FluxTransformer2DModel from diffusers.models.attention_processor import FluxIPAdapterJointAttnProcessor2_0 from diffusers.models.embeddings import ImageProjection -from diffusers.utils.testing_utils import enable_full_determinism, is_peft_available, torch_device +from ...testing_utils import enable_full_determinism, is_peft_available, torch_device from ..test_modeling_common import LoraHotSwappingForModelTesterMixin, ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_hidream.py b/tests/models/transformers/test_models_transformer_hidream.py index fa0fa5123a..fdd5f8c7fd 100644 --- a/tests/models/transformers/test_models_transformer_hidream.py +++ b/tests/models/transformers/test_models_transformer_hidream.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import HiDreamImageTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_hunyuan_dit.py b/tests/models/transformers/test_models_transformer_hunyuan_dit.py index 242ce1f283..d82a62d58e 100644 --- a/tests/models/transformers/test_models_transformer_hunyuan_dit.py +++ b/tests/models/transformers/test_models_transformer_hunyuan_dit.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import HunyuanDiT2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_hunyuan_video.py b/tests/models/transformers/test_models_transformer_hunyuan_video.py index b42a3cb5dc..385a5eefd5 100644 --- a/tests/models/transformers/test_models_transformer_hunyuan_video.py +++ b/tests/models/transformers/test_models_transformer_hunyuan_video.py @@ -17,11 +17,11 @@ import unittest import torch from diffusers import HunyuanVideoTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_hunyuan_video_framepack.py b/tests/models/transformers/test_models_transformer_hunyuan_video_framepack.py index ddb79925a7..00a2b27e02 100644 --- a/tests/models/transformers/test_models_transformer_hunyuan_video_framepack.py +++ b/tests/models/transformers/test_models_transformer_hunyuan_video_framepack.py @@ -17,11 +17,11 @@ import unittest import torch from diffusers import HunyuanVideoFramepackTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_latte.py b/tests/models/transformers/test_models_transformer_latte.py index db93421b44..7bf2c52e62 100644 --- a/tests/models/transformers/test_models_transformer_latte.py +++ b/tests/models/transformers/test_models_transformer_latte.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import LatteTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_ltx.py b/tests/models/transformers/test_models_transformer_ltx.py index 2c61658f58..e912463bbf 100644 --- a/tests/models/transformers/test_models_transformer_ltx.py +++ b/tests/models/transformers/test_models_transformer_ltx.py @@ -18,8 +18,8 @@ import unittest import torch from diffusers import LTXVideoTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_lumina.py b/tests/models/transformers/test_models_transformer_lumina.py index d0103eb473..0024aa106c 100644 --- a/tests/models/transformers/test_models_transformer_lumina.py +++ b/tests/models/transformers/test_models_transformer_lumina.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import LuminaNextDiT2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_lumina2.py b/tests/models/transformers/test_models_transformer_lumina2.py index 731e2ff3d5..4efae3d4b7 100644 --- a/tests/models/transformers/test_models_transformer_lumina2.py +++ b/tests/models/transformers/test_models_transformer_lumina2.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers import Lumina2Transformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_mochi.py b/tests/models/transformers/test_models_transformer_mochi.py index db65c03292..931b5874ee 100644 --- a/tests/models/transformers/test_models_transformer_mochi.py +++ b/tests/models/transformers/test_models_transformer_mochi.py @@ -18,8 +18,8 @@ import unittest import torch from diffusers import MochiTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_omnigen.py b/tests/models/transformers/test_models_transformer_omnigen.py index 25f25a8d63..f1963ddb77 100644 --- a/tests/models/transformers/test_models_transformer_omnigen.py +++ b/tests/models/transformers/test_models_transformer_omnigen.py @@ -18,8 +18,8 @@ import unittest import torch from diffusers import OmniGenTransformer2DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_qwenimage.py b/tests/models/transformers/test_models_transformer_qwenimage.py index 498acb8d73..b24fa90503 100644 --- a/tests/models/transformers/test_models_transformer_qwenimage.py +++ b/tests/models/transformers/test_models_transformer_qwenimage.py @@ -19,8 +19,8 @@ import pytest import torch from diffusers import QwenImageTransformer2DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_sana.py b/tests/models/transformers/test_models_transformer_sana.py index 6586af0e82..2e316c3aed 100644 --- a/tests/models/transformers/test_models_transformer_sana.py +++ b/tests/models/transformers/test_models_transformer_sana.py @@ -17,11 +17,11 @@ import unittest import torch from diffusers import SanaTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_sd3.py b/tests/models/transformers/test_models_transformer_sd3.py index 10469c0ca9..c4ee7017a3 100644 --- a/tests/models/transformers/test_models_transformer_sd3.py +++ b/tests/models/transformers/test_models_transformer_sd3.py @@ -19,11 +19,11 @@ import torch from diffusers import SD3Transformer2DModel from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_skyreels_v2.py b/tests/models/transformers/test_models_transformer_skyreels_v2.py index 884f168308..8c36d8256e 100644 --- a/tests/models/transformers/test_models_transformer_skyreels_v2.py +++ b/tests/models/transformers/test_models_transformer_skyreels_v2.py @@ -17,11 +17,11 @@ import unittest import torch from diffusers import SkyReelsV2Transformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/transformers/test_models_transformer_temporal.py b/tests/models/transformers/test_models_transformer_temporal.py index 183ef22982..aff83be511 100644 --- a/tests/models/transformers/test_models_transformer_temporal.py +++ b/tests/models/transformers/test_models_transformer_temporal.py @@ -18,11 +18,11 @@ import unittest import torch from diffusers.models.transformers import TransformerTemporalModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin diff --git a/tests/models/transformers/test_models_transformer_wan.py b/tests/models/transformers/test_models_transformer_wan.py index 932f255984..9f248f990c 100644 --- a/tests/models/transformers/test_models_transformer_wan.py +++ b/tests/models/transformers/test_models_transformer_wan.py @@ -17,11 +17,11 @@ import unittest import torch from diffusers import WanTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin diff --git a/tests/models/unets/test_models_unet_1d.py b/tests/models/unets/test_models_unet_1d.py index e3dd608a25..bac017e7e7 100644 --- a/tests/models/unets/test_models_unet_1d.py +++ b/tests/models/unets/test_models_unet_1d.py @@ -19,13 +19,13 @@ import pytest import torch from diffusers import UNet1DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_manual_seed, floats_tensor, slow, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/unets/test_models_unet_2d.py b/tests/models/unets/test_models_unet_2d.py index f6fa82aeb7..e289f44303 100644 --- a/tests/models/unets/test_models_unet_2d.py +++ b/tests/models/unets/test_models_unet_2d.py @@ -21,7 +21,8 @@ import torch from diffusers import UNet2DModel from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -30,7 +31,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/unets/test_models_unet_2d_condition.py b/tests/models/unets/test_models_unet_2d_condition.py index 123dff16f8..4dbb8ca7c0 100644 --- a/tests/models/unets/test_models_unet_2d_condition.py +++ b/tests/models/unets/test_models_unet_2d_condition.py @@ -34,7 +34,8 @@ from diffusers.models.attention_processor import ( from diffusers.models.embeddings import ImageProjection, IPAdapterFaceIDImageProjection, IPAdapterPlusImageProjection from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -51,7 +52,6 @@ from diffusers.utils.testing_utils import ( torch_all_close, torch_device, ) - from ..test_modeling_common import ( LoraHotSwappingForModelTesterMixin, ModelTesterMixin, diff --git a/tests/models/unets/test_models_unet_2d_flax.py b/tests/models/unets/test_models_unet_2d_flax.py index 69a0704dca..3bc9a04b3c 100644 --- a/tests/models/unets/test_models_unet_2d_flax.py +++ b/tests/models/unets/test_models_unet_2d_flax.py @@ -5,7 +5,8 @@ from parameterized import parameterized from diffusers import FlaxUNet2DConditionModel from diffusers.utils import is_flax_available -from diffusers.utils.testing_utils import load_hf_numpy, require_flax, slow + +from ...testing_utils import load_hf_numpy, require_flax, slow if is_flax_available(): diff --git a/tests/models/unets/test_models_unet_3d_condition.py b/tests/models/unets/test_models_unet_3d_condition.py index 72d692b6e7..f73e3461c3 100644 --- a/tests/models/unets/test_models_unet_3d_condition.py +++ b/tests/models/unets/test_models_unet_3d_condition.py @@ -21,8 +21,8 @@ import torch from diffusers.models import ModelMixin, UNet3DConditionModel from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, skip_mps, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, skip_mps, torch_device from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/unets/test_models_unet_controlnetxs.py b/tests/models/unets/test_models_unet_controlnetxs.py index cebd18c10d..40773536df 100644 --- a/tests/models/unets/test_models_unet_controlnetxs.py +++ b/tests/models/unets/test_models_unet_controlnetxs.py @@ -21,8 +21,8 @@ from torch import nn from diffusers import ControlNetXSAdapter, UNet2DConditionModel, UNetControlNetXSModel from diffusers.utils import logging -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, is_flaky, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, is_flaky, torch_device from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/unets/test_models_unet_motion.py b/tests/models/unets/test_models_unet_motion.py index bf8d6bd007..d931b345fd 100644 --- a/tests/models/unets/test_models_unet_motion.py +++ b/tests/models/unets/test_models_unet_motion.py @@ -24,12 +24,12 @@ import torch from diffusers import MotionAdapter, UNet2DConditionModel, UNetMotionModel from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/unets/test_models_unet_spatiotemporal.py b/tests/models/unets/test_models_unet_spatiotemporal.py index 86aa0f6a0e..7df868c9e9 100644 --- a/tests/models/unets/test_models_unet_spatiotemporal.py +++ b/tests/models/unets/test_models_unet_spatiotemporal.py @@ -21,13 +21,13 @@ import torch from diffusers import UNetSpatioTemporalConditionModel from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, skip_mps, torch_device, ) - from ..test_modeling_common import ModelTesterMixin, UNetTesterMixin diff --git a/tests/models/unets/test_unet_2d_blocks.py b/tests/models/unets/test_unet_2d_blocks.py index 21c0c0f08b..5c006963e3 100644 --- a/tests/models/unets/test_unet_2d_blocks.py +++ b/tests/models/unets/test_unet_2d_blocks.py @@ -15,8 +15,8 @@ import unittest from diffusers.models.unets.unet_2d_blocks import * # noqa F403 -from diffusers.utils.testing_utils import torch_device +from ...testing_utils import torch_device from .test_unet_blocks_common import UNetBlockTesterMixin diff --git a/tests/models/unets/test_unet_blocks_common.py b/tests/models/unets/test_unet_blocks_common.py index ada7c83269..85f9bf8353 100644 --- a/tests/models/unets/test_unet_blocks_common.py +++ b/tests/models/unets/test_unet_blocks_common.py @@ -16,14 +16,15 @@ from typing import Tuple import torch -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( floats_tensor, require_torch, require_torch_accelerator_with_training, torch_all_close, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor @require_torch diff --git a/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py b/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py index 044cdd57da..86062394a0 100644 --- a/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py +++ b/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py @@ -27,11 +27,6 @@ from diffusers import ( StableDiffusionXLModularPipeline, ) from diffusers.loaders import ModularIPAdapterMixin -from diffusers.utils.testing_utils import ( - enable_full_determinism, - floats_tensor, - torch_device, -) from ...models.unets.test_models_unet_2d_condition import ( create_ip_adapter_state_dict, @@ -39,6 +34,11 @@ from ...models.unets.test_models_unet_2d_condition import ( from ..test_modular_pipelines_common import ( ModularPipelineTesterMixin, ) +from ..testing_utils import ( + enable_full_determinism, + floats_tensor, + torch_device, +) enable_full_determinism() diff --git a/tests/modular_pipelines/test_modular_pipelines_common.py b/tests/modular_pipelines/test_modular_pipelines_common.py index 36595b02a2..6e61272693 100644 --- a/tests/modular_pipelines/test_modular_pipelines_common.py +++ b/tests/modular_pipelines/test_modular_pipelines_common.py @@ -9,7 +9,8 @@ import torch import diffusers from diffusers import ComponentsManager, ModularPipeline, ModularPipelineBlocks from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, numpy_cosine_similarity_distance, require_accelerator, diff --git a/tests/others/test_config.py b/tests/others/test_config.py index a8f93024f7..232bf9d473 100644 --- a/tests/others/test_config.py +++ b/tests/others/test_config.py @@ -28,7 +28,8 @@ from diffusers import ( logging, ) from diffusers.configuration_utils import ConfigMixin, register_to_config -from diffusers.utils.testing_utils import CaptureLogger + +from ..testing_utils import CaptureLogger class SampleObject(ConfigMixin): diff --git a/tests/others/test_ema.py b/tests/others/test_ema.py index 14808b9e58..436bbe1d53 100644 --- a/tests/others/test_ema.py +++ b/tests/others/test_ema.py @@ -20,7 +20,8 @@ import torch from diffusers import UNet2DConditionModel from diffusers.training_utils import EMAModel -from diffusers.utils.testing_utils import enable_full_determinism, skip_mps, torch_device + +from ..testing_utils import enable_full_determinism, skip_mps, torch_device enable_full_determinism() diff --git a/tests/others/test_outputs.py b/tests/others/test_outputs.py index cf709d93f7..c8069e6916 100644 --- a/tests/others/test_outputs.py +++ b/tests/others/test_outputs.py @@ -7,7 +7,8 @@ import numpy as np import PIL.Image from diffusers.utils.outputs import BaseOutput -from diffusers.utils.testing_utils import require_torch + +from ..testing_utils import require_torch @dataclass diff --git a/tests/others/test_training.py b/tests/others/test_training.py index fb64205301..2038a98a81 100644 --- a/tests/others/test_training.py +++ b/tests/others/test_training.py @@ -19,7 +19,8 @@ import torch from diffusers import DDIMScheduler, DDPMScheduler, UNet2DModel from diffusers.training_utils import set_seed -from diffusers.utils.testing_utils import slow + +from ..testing_utils import slow torch.backends.cuda.matmul.allow_tf32 = False diff --git a/tests/others/test_utils.py b/tests/others/test_utils.py index 01b423f556..747b8d5840 100755 --- a/tests/others/test_utils.py +++ b/tests/others/test_utils.py @@ -20,7 +20,8 @@ import pytest from diffusers import __version__ from diffusers.utils import deprecate -from diffusers.utils.testing_utils import Expectations, str_to_bool + +from ..testing_utils import Expectations, str_to_bool # Used to test the hub diff --git a/tests/pipelines/allegro/test_allegro.py b/tests/pipelines/allegro/test_allegro.py index c33b48e7e9..b2e588de06 100644 --- a/tests/pipelines/allegro/test_allegro.py +++ b/tests/pipelines/allegro/test_allegro.py @@ -23,7 +23,8 @@ import torch from transformers import AutoTokenizer, T5Config, T5EncoderModel from diffusers import AllegroPipeline, AllegroTransformer3DModel, AutoencoderKLAllegro, DDIMScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -33,7 +34,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, PyramidAttentionBroadcastTesterMixin, to_np diff --git a/tests/pipelines/animatediff/test_animatediff.py b/tests/pipelines/animatediff/test_animatediff.py index 4088d46df5..8d4cd4cf2c 100644 --- a/tests/pipelines/animatediff/test_animatediff.py +++ b/tests/pipelines/animatediff/test_animatediff.py @@ -19,7 +19,8 @@ from diffusers import ( ) from diffusers.models.attention import FreeNoiseTransformerBlock from diffusers.utils import is_xformers_available, logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, numpy_cosine_similarity_distance, require_accelerator, @@ -27,7 +28,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( IPAdapterTesterMixin, diff --git a/tests/pipelines/animatediff/test_animatediff_controlnet.py b/tests/pipelines/animatediff/test_animatediff_controlnet.py index 7bde663b11..4b0eb01d06 100644 --- a/tests/pipelines/animatediff/test_animatediff_controlnet.py +++ b/tests/pipelines/animatediff/test_animatediff_controlnet.py @@ -21,8 +21,8 @@ from diffusers import ( from diffusers.models.attention import FreeNoiseTransformerBlock from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import require_accelerator, torch_device +from ...testing_utils import require_accelerator, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( IPAdapterTesterMixin, diff --git a/tests/pipelines/animatediff/test_animatediff_sdxl.py b/tests/pipelines/animatediff/test_animatediff_sdxl.py index f9686ec005..b5dcd87796 100644 --- a/tests/pipelines/animatediff/test_animatediff_sdxl.py +++ b/tests/pipelines/animatediff/test_animatediff_sdxl.py @@ -14,8 +14,8 @@ from diffusers import ( UNetMotionModel, ) from diffusers.utils import is_xformers_available, logging -from diffusers.utils.testing_utils import require_accelerator, torch_device +from ...testing_utils import require_accelerator, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( IPAdapterTesterMixin, diff --git a/tests/pipelines/animatediff/test_animatediff_sparsectrl.py b/tests/pipelines/animatediff/test_animatediff_sparsectrl.py index 3e33326c8a..6b9f672cc4 100644 --- a/tests/pipelines/animatediff/test_animatediff_sparsectrl.py +++ b/tests/pipelines/animatediff/test_animatediff_sparsectrl.py @@ -20,8 +20,8 @@ from diffusers import ( ) from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import require_accelerator, torch_device +from ...testing_utils import require_accelerator, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( IPAdapterTesterMixin, diff --git a/tests/pipelines/animatediff/test_animatediff_video2video.py b/tests/pipelines/animatediff/test_animatediff_video2video.py index bc771e148e..1adb13dc4c 100644 --- a/tests/pipelines/animatediff/test_animatediff_video2video.py +++ b/tests/pipelines/animatediff/test_animatediff_video2video.py @@ -19,8 +19,8 @@ from diffusers import ( ) from diffusers.models.attention import FreeNoiseTransformerBlock from diffusers.utils import is_xformers_available, logging -from diffusers.utils.testing_utils import require_accelerator, torch_device +from ...testing_utils import require_accelerator, torch_device from ..pipeline_params import TEXT_TO_IMAGE_PARAMS, VIDEO_TO_VIDEO_BATCH_PARAMS from ..test_pipelines_common import IPAdapterTesterMixin, PipelineFromPipeTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/animatediff/test_animatediff_video2video_controlnet.py b/tests/pipelines/animatediff/test_animatediff_video2video_controlnet.py index 3babbbe4ba..c71c8c8817 100644 --- a/tests/pipelines/animatediff/test_animatediff_video2video_controlnet.py +++ b/tests/pipelines/animatediff/test_animatediff_video2video_controlnet.py @@ -20,8 +20,8 @@ from diffusers import ( ) from diffusers.models.attention import FreeNoiseTransformerBlock from diffusers.utils import is_xformers_available, logging -from diffusers.utils.testing_utils import require_accelerator, torch_device +from ...testing_utils import require_accelerator, torch_device from ..pipeline_params import TEXT_TO_IMAGE_PARAMS, VIDEO_TO_VIDEO_BATCH_PARAMS from ..test_pipelines_common import IPAdapterTesterMixin, PipelineFromPipeTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/audioldm2/test_audioldm2.py b/tests/pipelines/audioldm2/test_audioldm2.py index 12b9694567..e4bc5cc110 100644 --- a/tests/pipelines/audioldm2/test_audioldm2.py +++ b/tests/pipelines/audioldm2/test_audioldm2.py @@ -46,14 +46,14 @@ from diffusers import ( PNDMScheduler, ) from diffusers.utils import is_transformers_version -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, is_torch_version, nightly, torch_device, ) - from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/bria/test_pipeline_bria.py b/tests/pipelines/bria/test_pipeline_bria.py index b290160a65..844488e76f 100644 --- a/tests/pipelines/bria/test_pipeline_bria.py +++ b/tests/pipelines/bria/test_pipeline_bria.py @@ -27,7 +27,11 @@ from diffusers import ( FlowMatchEulerDiscreteScheduler, ) from diffusers.pipelines.bria import BriaPipeline -from diffusers.utils.testing_utils import ( + +# from ..test_pipelines_common import PipelineTesterMixin, check_qkv_fused_layers_exist +from tests.pipelines.test_pipelines_common import PipelineTesterMixin, to_np + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -36,9 +40,6 @@ from diffusers.utils.testing_utils import ( torch_device, ) -# from ..test_pipelines_common import PipelineTesterMixin, check_qkv_fused_layers_exist -from tests.pipelines.test_pipelines_common import PipelineTesterMixin, to_np - enable_full_determinism() diff --git a/tests/pipelines/chroma/test_pipeline_chroma.py b/tests/pipelines/chroma/test_pipeline_chroma.py index 5121a2b52d..3edd58b75f 100644 --- a/tests/pipelines/chroma/test_pipeline_chroma.py +++ b/tests/pipelines/chroma/test_pipeline_chroma.py @@ -5,8 +5,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKL, ChromaPipeline, ChromaTransformer2DModel, FlowMatchEulerDiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ...testing_utils import torch_device from ..test_pipelines_common import FluxIPAdapterTesterMixin, PipelineTesterMixin, check_qkv_fused_layers_exist diff --git a/tests/pipelines/chroma/test_pipeline_chroma_img2img.py b/tests/pipelines/chroma/test_pipeline_chroma_img2img.py index d518e1b7b8..4ed1393037 100644 --- a/tests/pipelines/chroma/test_pipeline_chroma_img2img.py +++ b/tests/pipelines/chroma/test_pipeline_chroma_img2img.py @@ -6,8 +6,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKL, ChromaImg2ImgPipeline, ChromaTransformer2DModel, FlowMatchEulerDiscreteScheduler -from diffusers.utils.testing_utils import floats_tensor, torch_device +from ...testing_utils import floats_tensor, torch_device from ..test_pipelines_common import FluxIPAdapterTesterMixin, PipelineTesterMixin, check_qkv_fused_layers_exist diff --git a/tests/pipelines/cogvideo/test_cogvideox.py b/tests/pipelines/cogvideo/test_cogvideox.py index a6cb558513..dca1725d8a 100644 --- a/tests/pipelines/cogvideo/test_cogvideox.py +++ b/tests/pipelines/cogvideo/test_cogvideox.py @@ -21,7 +21,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCogVideoX, CogVideoXPipeline, CogVideoXTransformer3DModel, DDIMScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -29,7 +30,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( FasterCacheTesterMixin, diff --git a/tests/pipelines/cogvideo/test_cogvideox_fun_control.py b/tests/pipelines/cogvideo/test_cogvideox_fun_control.py index 685823dc06..097e8df7b3 100644 --- a/tests/pipelines/cogvideo/test_cogvideox_fun_control.py +++ b/tests/pipelines/cogvideo/test_cogvideox_fun_control.py @@ -21,11 +21,11 @@ from PIL import Image from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCogVideoX, CogVideoXFunControlPipeline, CogVideoXTransformer3DModel, DDIMScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/cogvideo/test_cogvideox_image2video.py b/tests/pipelines/cogvideo/test_cogvideox_image2video.py index 90f767f9a7..1dd5e2ae14 100644 --- a/tests/pipelines/cogvideo/test_cogvideox_image2video.py +++ b/tests/pipelines/cogvideo/test_cogvideox_image2video.py @@ -23,7 +23,8 @@ from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCogVideoX, CogVideoXImageToVideoPipeline, CogVideoXTransformer3DModel, DDIMScheduler from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -31,7 +32,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/cogvideo/test_cogvideox_video2video.py b/tests/pipelines/cogvideo/test_cogvideox_video2video.py index ba48079e74..3a1da7c4e7 100644 --- a/tests/pipelines/cogvideo/test_cogvideox_video2video.py +++ b/tests/pipelines/cogvideo/test_cogvideox_video2video.py @@ -21,8 +21,8 @@ from PIL import Image from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCogVideoX, CogVideoXTransformer3DModel, CogVideoXVideoToVideoPipeline, DDIMScheduler -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/cogview3/test_cogview3plus.py b/tests/pipelines/cogview3/test_cogview3plus.py index d868beffba..819d4b952f 100644 --- a/tests/pipelines/cogview3/test_cogview3plus.py +++ b/tests/pipelines/cogview3/test_cogview3plus.py @@ -21,7 +21,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKL, CogVideoXDDIMScheduler, CogView3PlusPipeline, CogView3PlusTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -29,7 +30,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/cogview4/test_cogview4.py b/tests/pipelines/cogview4/test_cogview4.py index 20d2afaea9..a1f0fc7a71 100644 --- a/tests/pipelines/cogview4/test_cogview4.py +++ b/tests/pipelines/cogview4/test_cogview4.py @@ -20,8 +20,8 @@ import torch from transformers import AutoTokenizer, GlmConfig, GlmForCausalLM from diffusers import AutoencoderKL, CogView4Pipeline, CogView4Transformer2DModel, FlowMatchEulerDiscreteScheduler -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/consisid/test_consisid.py b/tests/pipelines/consisid/test_consisid.py index 66bb7acf25..4fd9e536cd 100644 --- a/tests/pipelines/consisid/test_consisid.py +++ b/tests/pipelines/consisid/test_consisid.py @@ -23,7 +23,8 @@ from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCogVideoX, ConsisIDPipeline, ConsisIDTransformer3DModel, DDIMScheduler from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -31,7 +32,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/consistency_models/test_consistency_models.py b/tests/pipelines/consistency_models/test_consistency_models.py index 7c7cecdfb0..0ab0c0af25 100644 --- a/tests/pipelines/consistency_models/test_consistency_models.py +++ b/tests/pipelines/consistency_models/test_consistency_models.py @@ -10,7 +10,9 @@ from diffusers import ( ConsistencyModelPipeline, UNet2DModel, ) -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( Expectations, backend_empty_cache, enable_full_determinism, @@ -19,8 +21,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/controlnet/test_controlnet.py b/tests/pipelines/controlnet/test_controlnet.py index bd558a50cf..b142c2baf9 100644 --- a/tests/pipelines/controlnet/test_controlnet.py +++ b/tests/pipelines/controlnet/test_controlnet.py @@ -32,7 +32,9 @@ from diffusers import ( ) from diffusers.pipelines.controlnet.pipeline_controlnet import MultiControlNetModel from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -44,8 +46,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_BATCH_PARAMS, diff --git a/tests/pipelines/controlnet/test_controlnet_img2img.py b/tests/pipelines/controlnet/test_controlnet_img2img.py index dd7bb002a1..c5d438e934 100644 --- a/tests/pipelines/controlnet/test_controlnet_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_img2img.py @@ -35,7 +35,9 @@ from diffusers import ( from diffusers.pipelines.controlnet.pipeline_controlnet import MultiControlNetModel from diffusers.utils import load_image from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -44,8 +46,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/controlnet/test_controlnet_inpaint.py b/tests/pipelines/controlnet/test_controlnet_inpaint.py index c457c324c5..ebbe869e9e 100644 --- a/tests/pipelines/controlnet/test_controlnet_inpaint.py +++ b/tests/pipelines/controlnet/test_controlnet_inpaint.py @@ -35,7 +35,9 @@ from diffusers import ( from diffusers.pipelines.controlnet.pipeline_controlnet import MultiControlNetModel from diffusers.utils import load_image from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -45,8 +47,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py b/tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py index ee12ce1723..c91f2c700c 100644 --- a/tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py @@ -37,13 +37,13 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, require_torch_accelerator, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_BATCH_PARAMS, diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl.py b/tests/pipelines/controlnet/test_controlnet_sdxl.py index 47d0920b74..42ec446dbf 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl.py @@ -34,7 +34,9 @@ from diffusers import ( from diffusers.models.unets.unet_2d_blocks import UNetMidBlock2D from diffusers.pipelines.controlnet.pipeline_controlnet import MultiControlNetModel from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_image, @@ -42,8 +44,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_BATCH_PARAMS, diff --git a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py index 5a8dd10ad5..bd4a233741 100644 --- a/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py +++ b/tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py @@ -28,13 +28,13 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, require_torch_accelerator, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/controlnet/test_flax_controlnet.py b/tests/pipelines/controlnet/test_flax_controlnet.py index 07d3a09e5d..e9cff4c957 100644 --- a/tests/pipelines/controlnet/test_flax_controlnet.py +++ b/tests/pipelines/controlnet/test_flax_controlnet.py @@ -18,7 +18,8 @@ import unittest from diffusers import FlaxControlNetModel, FlaxStableDiffusionControlNetPipeline from diffusers.utils import is_flax_available, load_image -from diffusers.utils.testing_utils import require_flax, slow + +from ...testing_utils import require_flax, slow if is_flax_available(): diff --git a/tests/pipelines/controlnet_flux/test_controlnet_flux.py b/tests/pipelines/controlnet_flux/test_controlnet_flux.py index 5b336edc7a..0895d9de35 100644 --- a/tests/pipelines/controlnet_flux/test_controlnet_flux.py +++ b/tests/pipelines/controlnet_flux/test_controlnet_flux.py @@ -29,7 +29,9 @@ from diffusers import ( ) from diffusers.models import FluxControlNetModel from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, nightly, @@ -37,8 +39,6 @@ from diffusers.utils.testing_utils import ( require_big_accelerator, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_pipelines_common import FluxIPAdapterTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py b/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py index ab4cf32734..3d8378a578 100644 --- a/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py +++ b/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py @@ -11,11 +11,11 @@ from diffusers import ( FluxControlNetModel, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import ( - torch_device, -) from diffusers.utils.torch_utils import randn_tensor +from ...testing_utils import ( + torch_device, +) from ..test_pipelines_common import PipelineTesterMixin, check_qkv_fused_layers_exist diff --git a/tests/pipelines/controlnet_flux/test_controlnet_flux_inpaint.py b/tests/pipelines/controlnet_flux/test_controlnet_flux_inpaint.py index 94d97e9962..3ba475deb8 100644 --- a/tests/pipelines/controlnet_flux/test_controlnet_flux_inpaint.py +++ b/tests/pipelines/controlnet_flux/test_controlnet_flux_inpaint.py @@ -20,13 +20,13 @@ from diffusers import ( FluxControlNetModel, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/controlnet_hunyuandit/test_controlnet_hunyuandit.py b/tests/pipelines/controlnet_hunyuandit/test_controlnet_hunyuandit.py index d6e7af34bd..9619843779 100644 --- a/tests/pipelines/controlnet_hunyuandit/test_controlnet_hunyuandit.py +++ b/tests/pipelines/controlnet_hunyuandit/test_controlnet_hunyuandit.py @@ -28,15 +28,15 @@ from diffusers import ( ) from diffusers.models import HunyuanDiT2DControlNetModel, HunyuanDiT2DMultiControlNetModel from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/controlnet_sd3/test_controlnet_inpaint_sd3.py b/tests/pipelines/controlnet_sd3/test_controlnet_inpaint_sd3.py index fcf8cade67..34c34b7a2c 100644 --- a/tests/pipelines/controlnet_sd3/test_controlnet_inpaint_sd3.py +++ b/tests/pipelines/controlnet_sd3/test_controlnet_inpaint_sd3.py @@ -26,12 +26,12 @@ from diffusers import ( StableDiffusion3ControlNetInpaintingPipeline, ) from diffusers.models import SD3ControlNetModel -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( enable_full_determinism, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/controlnet_sd3/test_controlnet_sd3.py b/tests/pipelines/controlnet_sd3/test_controlnet_sd3.py index 1f1f800bcf..2b6cf8d1e8 100644 --- a/tests/pipelines/controlnet_sd3/test_controlnet_sd3.py +++ b/tests/pipelines/controlnet_sd3/test_controlnet_sd3.py @@ -29,7 +29,9 @@ from diffusers import ( ) from diffusers.models import SD3ControlNetModel, SD3MultiControlNetModel from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -37,8 +39,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/cosmos/test_cosmos.py b/tests/pipelines/cosmos/test_cosmos.py index 4d3202f785..32eea9c98c 100644 --- a/tests/pipelines/cosmos/test_cosmos.py +++ b/tests/pipelines/cosmos/test_cosmos.py @@ -23,8 +23,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCosmos, CosmosTextToWorldPipeline, CosmosTransformer3DModel, EDMEulerScheduler -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np from .cosmos_guardrail import DummyCosmosSafetyChecker diff --git a/tests/pipelines/cosmos/test_cosmos2_text2image.py b/tests/pipelines/cosmos/test_cosmos2_text2image.py index cc2fcec641..8e3c5e4c29 100644 --- a/tests/pipelines/cosmos/test_cosmos2_text2image.py +++ b/tests/pipelines/cosmos/test_cosmos2_text2image.py @@ -28,8 +28,8 @@ from diffusers import ( CosmosTransformer3DModel, FlowMatchEulerDiscreteScheduler, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np from .cosmos_guardrail import DummyCosmosSafetyChecker diff --git a/tests/pipelines/cosmos/test_cosmos2_video2world.py b/tests/pipelines/cosmos/test_cosmos2_video2world.py index b23c8aed17..b0ca0e160d 100644 --- a/tests/pipelines/cosmos/test_cosmos2_video2world.py +++ b/tests/pipelines/cosmos/test_cosmos2_video2world.py @@ -29,8 +29,8 @@ from diffusers import ( CosmosTransformer3DModel, FlowMatchEulerDiscreteScheduler, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np from .cosmos_guardrail import DummyCosmosSafetyChecker diff --git a/tests/pipelines/cosmos/test_cosmos_video2world.py b/tests/pipelines/cosmos/test_cosmos_video2world.py index d0dba5575b..2633c2007a 100644 --- a/tests/pipelines/cosmos/test_cosmos_video2world.py +++ b/tests/pipelines/cosmos/test_cosmos_video2world.py @@ -24,8 +24,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLCosmos, CosmosTransformer3DModel, CosmosVideoToWorldPipeline, EDMEulerScheduler -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np from .cosmos_guardrail import DummyCosmosSafetyChecker diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index 57b97b4649..731635bea6 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -19,8 +19,8 @@ import numpy as np import torch from diffusers import DDIMPipeline, DDIMScheduler, UNet2DModel -from diffusers.utils.testing_utils import enable_full_determinism, require_torch_accelerator, slow, torch_device +from ...testing_utils import enable_full_determinism, require_torch_accelerator, slow, torch_device from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 97bb53128d..04ee741d8e 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -19,7 +19,8 @@ import numpy as np import torch from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel -from diffusers.utils.testing_utils import enable_full_determinism, require_torch_accelerator, slow, torch_device + +from ...testing_utils import enable_full_determinism, require_torch_accelerator, slow, torch_device enable_full_determinism() diff --git a/tests/pipelines/deepfloyd_if/__init__.py b/tests/pipelines/deepfloyd_if/__init__.py index 094254a618..d47374b07e 100644 --- a/tests/pipelines/deepfloyd_if/__init__.py +++ b/tests/pipelines/deepfloyd_if/__init__.py @@ -7,8 +7,8 @@ from transformers import AutoTokenizer, T5EncoderModel from diffusers import DDPMScheduler, UNet2DConditionModel from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.pipelines.deepfloyd_if import IFWatermarker -from diffusers.utils.testing_utils import torch_device +from ...testing_utils import torch_device from ..test_pipelines_common import to_np diff --git a/tests/pipelines/deepfloyd_if/test_if.py b/tests/pipelines/deepfloyd_if/test_if.py index 633d802ab9..e1870ddcba 100644 --- a/tests/pipelines/deepfloyd_if/test_if.py +++ b/tests/pipelines/deepfloyd_if/test_if.py @@ -23,7 +23,8 @@ from diffusers import ( ) from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -37,7 +38,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference from . import IFPipelineTesterMixin diff --git a/tests/pipelines/deepfloyd_if/test_if_img2img.py b/tests/pipelines/deepfloyd_if/test_if_img2img.py index 739d2a0e16..9d3c96052b 100644 --- a/tests/pipelines/deepfloyd_if/test_if_img2img.py +++ b/tests/pipelines/deepfloyd_if/test_if_img2img.py @@ -22,7 +22,8 @@ import torch from diffusers import IFImg2ImgPipeline from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -37,7 +38,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS, diff --git a/tests/pipelines/deepfloyd_if/test_if_img2img_superresolution.py b/tests/pipelines/deepfloyd_if/test_if_img2img_superresolution.py index fb89aab8e2..e2114910ed 100644 --- a/tests/pipelines/deepfloyd_if/test_if_img2img_superresolution.py +++ b/tests/pipelines/deepfloyd_if/test_if_img2img_superresolution.py @@ -22,7 +22,8 @@ import torch from diffusers import IFImg2ImgSuperResolutionPipeline from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -37,7 +38,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS, diff --git a/tests/pipelines/deepfloyd_if/test_if_inpainting.py b/tests/pipelines/deepfloyd_if/test_if_inpainting.py index 127ae19aa6..2679e0b776 100644 --- a/tests/pipelines/deepfloyd_if/test_if_inpainting.py +++ b/tests/pipelines/deepfloyd_if/test_if_inpainting.py @@ -22,7 +22,8 @@ import torch from diffusers import IFInpaintingPipeline from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -37,7 +38,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/deepfloyd_if/test_if_inpainting_superresolution.py b/tests/pipelines/deepfloyd_if/test_if_inpainting_superresolution.py index 8b5210194a..3d64556c6e 100644 --- a/tests/pipelines/deepfloyd_if/test_if_inpainting_superresolution.py +++ b/tests/pipelines/deepfloyd_if/test_if_inpainting_superresolution.py @@ -22,7 +22,8 @@ import torch from diffusers import IFInpaintingSuperResolutionPipeline from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -37,7 +38,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/deepfloyd_if/test_if_superresolution.py b/tests/pipelines/deepfloyd_if/test_if_superresolution.py index c16b3d6a56..fa7c0fb2e0 100644 --- a/tests/pipelines/deepfloyd_if/test_if_superresolution.py +++ b/tests/pipelines/deepfloyd_if/test_if_superresolution.py @@ -22,7 +22,8 @@ import torch from diffusers import IFSuperResolutionPipeline from diffusers.models.attention_processor import AttnAddedKVProcessor from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -37,7 +38,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference from . import IFPipelineTesterMixin diff --git a/tests/pipelines/dit/test_dit.py b/tests/pipelines/dit/test_dit.py index 46e28a28e1..cd5c08ced3 100644 --- a/tests/pipelines/dit/test_dit.py +++ b/tests/pipelines/dit/test_dit.py @@ -21,7 +21,8 @@ import torch from diffusers import AutoencoderKL, DDIMScheduler, DiTPipeline, DiTTransformer2DModel, DPMSolverMultistepScheduler from diffusers.utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_numpy, @@ -30,7 +31,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..pipeline_params import ( CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS, CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS, diff --git a/tests/pipelines/easyanimate/test_easyanimate.py b/tests/pipelines/easyanimate/test_easyanimate.py index 161734a166..2dbb8639f1 100644 --- a/tests/pipelines/easyanimate/test_easyanimate.py +++ b/tests/pipelines/easyanimate/test_easyanimate.py @@ -26,7 +26,8 @@ from diffusers import ( EasyAnimateTransformer3DModel, FlowMatchEulerDiscreteScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -34,7 +35,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/flux/test_pipeline_flux.py b/tests/pipelines/flux/test_pipeline_flux.py index cc8266e1a5..c3e8517d64 100644 --- a/tests/pipelines/flux/test_pipeline_flux.py +++ b/tests/pipelines/flux/test_pipeline_flux.py @@ -13,7 +13,8 @@ from diffusers import ( FluxPipeline, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, nightly, numpy_cosine_similarity_distance, @@ -21,7 +22,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import ( FasterCacheTesterMixin, FirstBlockCacheTesterMixin, diff --git a/tests/pipelines/flux/test_pipeline_flux_control.py b/tests/pipelines/flux/test_pipeline_flux_control.py index 42283da6fd..7e966470a3 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control.py +++ b/tests/pipelines/flux/test_pipeline_flux_control.py @@ -6,8 +6,8 @@ from PIL import Image from transformers import AutoTokenizer, CLIPTextConfig, CLIPTextModel, CLIPTokenizer, T5EncoderModel from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, FluxControlPipeline, FluxTransformer2DModel -from diffusers.utils.testing_utils import torch_device +from ...testing_utils import torch_device from ..test_pipelines_common import PipelineTesterMixin, check_qkv_fused_layers_exist diff --git a/tests/pipelines/flux/test_pipeline_flux_control_img2img.py b/tests/pipelines/flux/test_pipeline_flux_control_img2img.py index 966543f63a..e56136f2e9 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control_img2img.py +++ b/tests/pipelines/flux/test_pipeline_flux_control_img2img.py @@ -11,8 +11,8 @@ from diffusers import ( FluxControlImg2ImgPipeline, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py b/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py index 0abd08e373..e42c5fc2aa 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py +++ b/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py @@ -11,10 +11,10 @@ from diffusers import ( FluxControlInpaintPipeline, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, check_qkv_fused_layers_exist diff --git a/tests/pipelines/flux/test_pipeline_flux_fill.py b/tests/pipelines/flux/test_pipeline_flux_fill.py index 04d4c68db8..25a4a33548 100644 --- a/tests/pipelines/flux/test_pipeline_flux_fill.py +++ b/tests/pipelines/flux/test_pipeline_flux_fill.py @@ -6,12 +6,12 @@ import torch from transformers import AutoTokenizer, CLIPTextConfig, CLIPTextModel, CLIPTokenizer, T5EncoderModel from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, FluxFillPipeline, FluxTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/flux/test_pipeline_flux_img2img.py b/tests/pipelines/flux/test_pipeline_flux_img2img.py index 6d33ca721b..6f435760ae 100644 --- a/tests/pipelines/flux/test_pipeline_flux_img2img.py +++ b/tests/pipelines/flux/test_pipeline_flux_img2img.py @@ -6,12 +6,12 @@ import torch from transformers import AutoTokenizer, CLIPTextConfig, CLIPTextModel, CLIPTokenizer, T5EncoderModel from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, FluxImg2ImgPipeline, FluxTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_pipelines_common import FluxIPAdapterTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/flux/test_pipeline_flux_inpaint.py b/tests/pipelines/flux/test_pipeline_flux_inpaint.py index 161348455c..6324ff236e 100644 --- a/tests/pipelines/flux/test_pipeline_flux_inpaint.py +++ b/tests/pipelines/flux/test_pipeline_flux_inpaint.py @@ -6,12 +6,12 @@ import torch from transformers import AutoTokenizer, CLIPTextConfig, CLIPTextModel, CLIPTokenizer, T5EncoderModel from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, FluxInpaintPipeline, FluxTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_pipelines_common import FluxIPAdapterTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/flux/test_pipeline_flux_kontext.py b/tests/pipelines/flux/test_pipeline_flux_kontext.py index 7471d78ad5..5c78964ea5 100644 --- a/tests/pipelines/flux/test_pipeline_flux_kontext.py +++ b/tests/pipelines/flux/test_pipeline_flux_kontext.py @@ -12,8 +12,8 @@ from diffusers import ( FluxKontextPipeline, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import torch_device +from ...testing_utils import torch_device from ..test_pipelines_common import ( FasterCacheTesterMixin, FluxIPAdapterTesterMixin, diff --git a/tests/pipelines/flux/test_pipeline_flux_kontext_inpaint.py b/tests/pipelines/flux/test_pipeline_flux_kontext_inpaint.py index 615209264d..9a2e32056d 100644 --- a/tests/pipelines/flux/test_pipeline_flux_kontext_inpaint.py +++ b/tests/pipelines/flux/test_pipeline_flux_kontext_inpaint.py @@ -12,8 +12,8 @@ from diffusers import ( FluxKontextInpaintPipeline, FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import floats_tensor, torch_device +from ...testing_utils import floats_tensor, torch_device from ..test_pipelines_common import ( FasterCacheTesterMixin, FluxIPAdapterTesterMixin, diff --git a/tests/pipelines/flux/test_pipeline_flux_redux.py b/tests/pipelines/flux/test_pipeline_flux_redux.py index b73050a64d..bbeee28e6a 100644 --- a/tests/pipelines/flux/test_pipeline_flux_redux.py +++ b/tests/pipelines/flux/test_pipeline_flux_redux.py @@ -6,7 +6,8 @@ import torch from diffusers import FluxPipeline, FluxPriorReduxPipeline from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, numpy_cosine_similarity_distance, diff --git a/tests/pipelines/hidream_image/test_pipeline_hidream.py b/tests/pipelines/hidream_image/test_pipeline_hidream.py index 1c5f30e870..ec8d36e1d3 100644 --- a/tests/pipelines/hidream_image/test_pipeline_hidream.py +++ b/tests/pipelines/hidream_image/test_pipeline_hidream.py @@ -32,8 +32,8 @@ from diffusers import ( HiDreamImagePipeline, HiDreamImageTransformer2DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/hunyuan_video/test_hunyuan_image2video.py b/tests/pipelines/hunyuan_video/test_hunyuan_image2video.py index 82281f28bc..27b5bde310 100644 --- a/tests/pipelines/hunyuan_video/test_hunyuan_image2video.py +++ b/tests/pipelines/hunyuan_video/test_hunyuan_image2video.py @@ -36,8 +36,8 @@ from diffusers import ( HunyuanVideoImageToVideoPipeline, HunyuanVideoTransformer3DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_pipelines_common import PipelineTesterMixin, PyramidAttentionBroadcastTesterMixin, to_np diff --git a/tests/pipelines/hunyuan_video/test_hunyuan_skyreels_image2video.py b/tests/pipelines/hunyuan_video/test_hunyuan_skyreels_image2video.py index fad159c06b..7ebe797feb 100644 --- a/tests/pipelines/hunyuan_video/test_hunyuan_skyreels_image2video.py +++ b/tests/pipelines/hunyuan_video/test_hunyuan_skyreels_image2video.py @@ -26,8 +26,8 @@ from diffusers import ( HunyuanSkyreelsImageToVideoPipeline, HunyuanVideoTransformer3DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_pipelines_common import PipelineTesterMixin, PyramidAttentionBroadcastTesterMixin, to_np diff --git a/tests/pipelines/hunyuan_video/test_hunyuan_video.py b/tests/pipelines/hunyuan_video/test_hunyuan_video.py index 26ec861522..4bdf3ee20e 100644 --- a/tests/pipelines/hunyuan_video/test_hunyuan_video.py +++ b/tests/pipelines/hunyuan_video/test_hunyuan_video.py @@ -26,8 +26,8 @@ from diffusers import ( HunyuanVideoPipeline, HunyuanVideoTransformer3DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..test_pipelines_common import ( FasterCacheTesterMixin, FirstBlockCacheTesterMixin, diff --git a/tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py b/tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py index 297c3df45a..51c258b15c 100644 --- a/tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py +++ b/tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py @@ -36,11 +36,11 @@ from diffusers import ( HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..test_pipelines_common import ( FasterCacheTesterMixin, PipelineTesterMixin, diff --git a/tests/pipelines/hunyuandit/test_hunyuan_dit.py b/tests/pipelines/hunyuandit/test_hunyuan_dit.py index 7a5f807213..2a329f10bc 100644 --- a/tests/pipelines/hunyuandit/test_hunyuan_dit.py +++ b/tests/pipelines/hunyuandit/test_hunyuan_dit.py @@ -22,7 +22,8 @@ import torch from transformers import AutoTokenizer, BertModel, T5EncoderModel from diffusers import AutoencoderKL, DDPMScheduler, HunyuanDiT2DModel, HunyuanDiTPipeline -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -30,7 +31,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/ip_adapters/__init__.py b/tests/pipelines/ip_adapters/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py b/tests/pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py index f5980f218a..32590111cd 100644 --- a/tests/pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py +++ b/tests/pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py @@ -33,7 +33,8 @@ from diffusers import ( ) from diffusers.image_processor import IPAdapterMaskProcessor from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, enable_full_determinism, diff --git a/tests/pipelines/kandinsky/test_kandinsky.py b/tests/pipelines/kandinsky/test_kandinsky.py index 65a5195a8b..911c6e49ae 100644 --- a/tests/pipelines/kandinsky/test_kandinsky.py +++ b/tests/pipelines/kandinsky/test_kandinsky.py @@ -23,7 +23,8 @@ from transformers import XLMRobertaTokenizerFast from diffusers import DDIMScheduler, KandinskyPipeline, KandinskyPriorPipeline, UNet2DConditionModel, VQModel from diffusers.pipelines.kandinsky.text_encoder import MCLIPConfig, MultilingualCLIP -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -32,7 +33,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference diff --git a/tests/pipelines/kandinsky/test_kandinsky_combined.py b/tests/pipelines/kandinsky/test_kandinsky_combined.py index 6dd8895952..d744d10821 100644 --- a/tests/pipelines/kandinsky/test_kandinsky_combined.py +++ b/tests/pipelines/kandinsky/test_kandinsky_combined.py @@ -18,8 +18,8 @@ import unittest import numpy as np from diffusers import KandinskyCombinedPipeline, KandinskyImg2ImgCombinedPipeline, KandinskyInpaintCombinedPipeline -from diffusers.utils.testing_utils import enable_full_determinism, require_torch_accelerator, torch_device +from ...testing_utils import enable_full_determinism, require_torch_accelerator, torch_device from ..test_pipelines_common import PipelineTesterMixin from .test_kandinsky import Dummies from .test_kandinsky_img2img import Dummies as Img2ImgDummies diff --git a/tests/pipelines/kandinsky/test_kandinsky_img2img.py b/tests/pipelines/kandinsky/test_kandinsky_img2img.py index 5a0107838a..4074c8db22 100644 --- a/tests/pipelines/kandinsky/test_kandinsky_img2img.py +++ b/tests/pipelines/kandinsky/test_kandinsky_img2img.py @@ -31,7 +31,8 @@ from diffusers import ( VQModel, ) from diffusers.pipelines.kandinsky.text_encoder import MCLIPConfig, MultilingualCLIP -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -42,7 +43,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference diff --git a/tests/pipelines/kandinsky/test_kandinsky_inpaint.py b/tests/pipelines/kandinsky/test_kandinsky_inpaint.py index 03b555b2f0..b789a63cdd 100644 --- a/tests/pipelines/kandinsky/test_kandinsky_inpaint.py +++ b/tests/pipelines/kandinsky/test_kandinsky_inpaint.py @@ -24,7 +24,8 @@ from transformers import XLMRobertaTokenizerFast from diffusers import DDIMScheduler, KandinskyInpaintPipeline, KandinskyPriorPipeline, UNet2DConditionModel, VQModel from diffusers.pipelines.kandinsky.text_encoder import MCLIPConfig, MultilingualCLIP -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -34,7 +35,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference diff --git a/tests/pipelines/kandinsky/test_kandinsky_prior.py b/tests/pipelines/kandinsky/test_kandinsky_prior.py index 8ecf2d855f..903a1e5dec 100644 --- a/tests/pipelines/kandinsky/test_kandinsky_prior.py +++ b/tests/pipelines/kandinsky/test_kandinsky_prior.py @@ -28,8 +28,8 @@ from transformers import ( ) from diffusers import KandinskyPriorPipeline, PriorTransformer, UnCLIPScheduler -from diffusers.utils.testing_utils import enable_full_determinism, skip_mps, torch_device +from ...testing_utils import enable_full_determinism, skip_mps, torch_device from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky.py b/tests/pipelines/kandinsky2_2/test_kandinsky.py index 0ad5620eee..38294aa4c1 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky.py @@ -21,7 +21,8 @@ import numpy as np import torch from diffusers import DDIMScheduler, KandinskyV22Pipeline, KandinskyV22PriorPipeline, UNet2DConditionModel, VQModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -31,7 +32,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_combined.py b/tests/pipelines/kandinsky2_2/test_kandinsky_combined.py index 1e064d3368..476fc584cc 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_combined.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_combined.py @@ -22,8 +22,8 @@ from diffusers import ( KandinskyV22Img2ImgCombinedPipeline, KandinskyV22InpaintCombinedPipeline, ) -from diffusers.utils.testing_utils import enable_full_determinism, require_torch_accelerator, torch_device +from ...testing_utils import enable_full_determinism, require_torch_accelerator, torch_device from ..test_pipelines_common import PipelineTesterMixin from .test_kandinsky import Dummies from .test_kandinsky_img2img import Dummies as Img2ImgDummies diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py b/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py index b2d6f0fc05..4054e38c56 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet.py @@ -27,7 +27,8 @@ from diffusers import ( UNet2DConditionModel, VQModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -38,7 +39,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet_img2img.py b/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet_img2img.py index 4f50f51819..a434660592 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet_img2img.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_controlnet_img2img.py @@ -28,7 +28,8 @@ from diffusers import ( UNet2DConditionModel, VQModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -39,7 +40,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_img2img.py b/tests/pipelines/kandinsky2_2/test_kandinsky_img2img.py index bc1477b97e..99f3fe0f40 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_img2img.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_img2img.py @@ -28,7 +28,8 @@ from diffusers import ( UNet2DConditionModel, VQModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -39,7 +40,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_inpaint.py b/tests/pipelines/kandinsky2_2/test_kandinsky_inpaint.py index 8b3d8f74ec..d4eb650263 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_inpaint.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_inpaint.py @@ -28,7 +28,8 @@ from diffusers import ( UNet2DConditionModel, VQModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -40,7 +41,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_prior.py b/tests/pipelines/kandinsky2_2/test_kandinsky_prior.py index f5c2d6037b..adcc6cc216 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_prior.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_prior.py @@ -29,8 +29,8 @@ from transformers import ( ) from diffusers import KandinskyV22PriorPipeline, PriorTransformer, UnCLIPScheduler -from diffusers.utils.testing_utils import enable_full_determinism, skip_mps, torch_device +from ...testing_utils import enable_full_determinism, skip_mps, torch_device from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky2_2/test_kandinsky_prior_emb2emb.py b/tests/pipelines/kandinsky2_2/test_kandinsky_prior_emb2emb.py index 54a9cf6d60..5377d91779 100644 --- a/tests/pipelines/kandinsky2_2/test_kandinsky_prior_emb2emb.py +++ b/tests/pipelines/kandinsky2_2/test_kandinsky_prior_emb2emb.py @@ -30,13 +30,13 @@ from transformers import ( ) from diffusers import KandinskyV22PriorEmb2EmbPipeline, PriorTransformer, UnCLIPScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, skip_mps, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/kandinsky3/test_kandinsky3.py b/tests/pipelines/kandinsky3/test_kandinsky3.py index 1acf076b3d..55500f729b 100644 --- a/tests/pipelines/kandinsky3/test_kandinsky3.py +++ b/tests/pipelines/kandinsky3/test_kandinsky3.py @@ -30,7 +30,8 @@ from diffusers import ( ) from diffusers.image_processor import VaeImageProcessor from diffusers.schedulers.scheduling_ddpm import DDPMScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_image, @@ -38,7 +39,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/kandinsky3/test_kandinsky3_img2img.py b/tests/pipelines/kandinsky3/test_kandinsky3_img2img.py index edad5b7d37..503fdb242d 100644 --- a/tests/pipelines/kandinsky3/test_kandinsky3_img2img.py +++ b/tests/pipelines/kandinsky3/test_kandinsky3_img2img.py @@ -30,7 +30,8 @@ from diffusers import ( ) from diffusers.image_processor import VaeImageProcessor from diffusers.schedulers.scheduling_ddpm import DDPMScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -39,7 +40,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/kolors/test_kolors.py b/tests/pipelines/kolors/test_kolors.py index 839d06ab93..f1d4982d4d 100644 --- a/tests/pipelines/kolors/test_kolors.py +++ b/tests/pipelines/kolors/test_kolors.py @@ -25,8 +25,8 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.pipelines.kolors import ChatGLMModel, ChatGLMTokenizer -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/kolors/test_kolors_img2img.py b/tests/pipelines/kolors/test_kolors_img2img.py index c8429322ca..5a5d31a464 100644 --- a/tests/pipelines/kolors/test_kolors_img2img.py +++ b/tests/pipelines/kolors/test_kolors_img2img.py @@ -26,11 +26,11 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.pipelines.kolors import ChatGLMModel, ChatGLMTokenizer -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py index 570fa8fadf..c7666244b3 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models.py @@ -12,14 +12,14 @@ from diffusers import ( LCMScheduler, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import IPAdapterTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py index 88e31a97aa..d8e7745b78 100644 --- a/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py +++ b/tests/pipelines/latent_consistency_models/test_latent_consistency_models_img2img.py @@ -13,7 +13,8 @@ from diffusers import ( LCMScheduler, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -22,7 +23,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index ec52f5aebf..21c5bcf5a5 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -21,7 +21,8 @@ import torch from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer from diffusers import AutoencoderKL, DDIMScheduler, LDMTextToImagePipeline, UNet2DConditionModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_numpy, @@ -29,7 +30,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 2884dd3508..b2cbdb9f5b 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -21,7 +21,8 @@ import torch from diffusers import DDIMScheduler, LDMSuperResolutionPipeline, UNet2DModel, VQModel from diffusers.utils import PIL_INTERPOLATION -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, load_image, diff --git a/tests/pipelines/latte/test_latte.py b/tests/pipelines/latte/test_latte.py index 97b7edeb6c..a40d4bf8ee 100644 --- a/tests/pipelines/latte/test_latte.py +++ b/tests/pipelines/latte/test_latte.py @@ -31,7 +31,8 @@ from diffusers import ( PyramidAttentionBroadcastConfig, ) from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -39,7 +40,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( FasterCacheTesterMixin, diff --git a/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py b/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py index ab0221dc81..6db20a464f 100644 --- a/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py +++ b/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion.py @@ -28,7 +28,8 @@ from diffusers import ( LEditsPPPipelineStableDiffusion, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, enable_full_determinism, diff --git a/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion_xl.py b/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion_xl.py index 75795a3342..06c1ceb0cf 100644 --- a/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion_xl.py +++ b/tests/pipelines/ledits_pp/test_ledits_pp_stable_diffusion_xl.py @@ -37,7 +37,7 @@ from diffusers import ( ) # from diffusers.image_processor import VaeImageProcessor -from diffusers.utils.testing_utils import ( +from ...testing_utils import ( enable_full_determinism, floats_tensor, load_image, diff --git a/tests/pipelines/ltx/test_ltx.py b/tests/pipelines/ltx/test_ltx.py index bf0c7fde59..aaf4161b51 100644 --- a/tests/pipelines/ltx/test_ltx.py +++ b/tests/pipelines/ltx/test_ltx.py @@ -20,8 +20,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLLTXVideo, FlowMatchEulerDiscreteScheduler, LTXPipeline, LTXVideoTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import FirstBlockCacheTesterMixin, PipelineTesterMixin, to_np diff --git a/tests/pipelines/ltx/test_ltx_condition.py b/tests/pipelines/ltx/test_ltx_condition.py index a586fadaa7..f5dfb01862 100644 --- a/tests/pipelines/ltx/test_ltx_condition.py +++ b/tests/pipelines/ltx/test_ltx_condition.py @@ -26,8 +26,8 @@ from diffusers import ( LTXVideoTransformer3DModel, ) from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/ltx/test_ltx_image2video.py b/tests/pipelines/ltx/test_ltx_image2video.py index f43f66df53..2702993d4a 100644 --- a/tests/pipelines/ltx/test_ltx_image2video.py +++ b/tests/pipelines/ltx/test_ltx_image2video.py @@ -25,8 +25,8 @@ from diffusers import ( LTXImageToVideoPipeline, LTXVideoTransformer3DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/ltx/test_ltx_latent_upsample.py b/tests/pipelines/ltx/test_ltx_latent_upsample.py index f9ddb12186..0044a85c64 100644 --- a/tests/pipelines/ltx/test_ltx_latent_upsample.py +++ b/tests/pipelines/ltx/test_ltx_latent_upsample.py @@ -19,8 +19,8 @@ import torch from diffusers import AutoencoderKLLTXVideo, LTXLatentUpsamplePipeline from diffusers.pipelines.ltx.modeling_latent_upsampler import LTXLatentUpsamplerModel -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/lumina/test_lumina_nextdit.py b/tests/pipelines/lumina/test_lumina_nextdit.py index c270a83841..d2c114825d 100644 --- a/tests/pipelines/lumina/test_lumina_nextdit.py +++ b/tests/pipelines/lumina/test_lumina_nextdit.py @@ -11,14 +11,14 @@ from diffusers import ( LuminaNextDiT2DModel, LuminaPipeline, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, numpy_cosine_similarity_distance, require_torch_accelerator, slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/marigold/test_marigold_depth.py b/tests/pipelines/marigold/test_marigold_depth.py index 13f9a42186..3e8ccbf5c0 100644 --- a/tests/pipelines/marigold/test_marigold_depth.py +++ b/tests/pipelines/marigold/test_marigold_depth.py @@ -31,7 +31,8 @@ from diffusers import ( MarigoldDepthPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -41,7 +42,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/marigold/test_marigold_intrinsics.py b/tests/pipelines/marigold/test_marigold_intrinsics.py index f00650634a..3f7ab9bf6e 100644 --- a/tests/pipelines/marigold/test_marigold_intrinsics.py +++ b/tests/pipelines/marigold/test_marigold_intrinsics.py @@ -32,7 +32,8 @@ from diffusers import ( MarigoldIntrinsicsPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -41,7 +42,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/marigold/test_marigold_normals.py b/tests/pipelines/marigold/test_marigold_normals.py index 1797f99b21..108163bf22 100644 --- a/tests/pipelines/marigold/test_marigold_normals.py +++ b/tests/pipelines/marigold/test_marigold_normals.py @@ -31,7 +31,8 @@ from diffusers import ( MarigoldNormalsPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -40,7 +41,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/mochi/test_mochi.py b/tests/pipelines/mochi/test_mochi.py index f1684cce72..5615720a93 100644 --- a/tests/pipelines/mochi/test_mochi.py +++ b/tests/pipelines/mochi/test_mochi.py @@ -21,7 +21,8 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLMochi, FlowMatchEulerDiscreteScheduler, MochiPipeline, MochiTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, nightly, @@ -30,7 +31,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import FasterCacheTesterMixin, FirstBlockCacheTesterMixin, PipelineTesterMixin, to_np diff --git a/tests/pipelines/omnigen/test_pipeline_omnigen.py b/tests/pipelines/omnigen/test_pipeline_omnigen.py index e8f84eb913..28648aa76f 100644 --- a/tests/pipelines/omnigen/test_pipeline_omnigen.py +++ b/tests/pipelines/omnigen/test_pipeline_omnigen.py @@ -6,7 +6,8 @@ import torch from transformers import AutoTokenizer from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, OmniGenPipeline, OmniGenTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, numpy_cosine_similarity_distance, @@ -14,7 +15,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/pag/test_pag_animatediff.py b/tests/pipelines/pag/test_pag_animatediff.py index b9ce29c70b..b1cbd82d76 100644 --- a/tests/pipelines/pag/test_pag_animatediff.py +++ b/tests/pipelines/pag/test_pag_animatediff.py @@ -19,8 +19,8 @@ from diffusers import ( ) from diffusers.models.attention import FreeNoiseTransformerBlock from diffusers.utils import is_xformers_available -from diffusers.utils.testing_utils import require_accelerator, torch_device +from ...testing_utils import require_accelerator, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( IPAdapterTesterMixin, diff --git a/tests/pipelines/pag/test_pag_controlnet_sd.py b/tests/pipelines/pag/test_pag_controlnet_sd.py index 378f0a130c..36d5ae100a 100644 --- a/tests/pipelines/pag/test_pag_controlnet_sd.py +++ b/tests/pipelines/pag/test_pag_controlnet_sd.py @@ -28,9 +28,9 @@ from diffusers import ( StableDiffusionControlNetPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device from diffusers.utils.torch_utils import randn_tensor +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/pag/test_pag_controlnet_sd_inpaint.py b/tests/pipelines/pag/test_pag_controlnet_sd_inpaint.py index 5eff71ed64..948381f976 100644 --- a/tests/pipelines/pag/test_pag_controlnet_sd_inpaint.py +++ b/tests/pipelines/pag/test_pag_controlnet_sd_inpaint.py @@ -32,9 +32,9 @@ from diffusers import ( StableDiffusionControlNetPAGInpaintPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device from diffusers.utils.torch_utils import randn_tensor +from ...testing_utils import enable_full_determinism, floats_tensor, torch_device from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/pag/test_pag_controlnet_sdxl.py b/tests/pipelines/pag/test_pag_controlnet_sdxl.py index 4d7e4f072e..51b00f6932 100644 --- a/tests/pipelines/pag/test_pag_controlnet_sdxl.py +++ b/tests/pipelines/pag/test_pag_controlnet_sdxl.py @@ -28,9 +28,9 @@ from diffusers import ( StableDiffusionXLControlNetPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import enable_full_determinism from diffusers.utils.torch_utils import randn_tensor +from ...testing_utils import enable_full_determinism from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/pag/test_pag_controlnet_sdxl_img2img.py b/tests/pipelines/pag/test_pag_controlnet_sdxl_img2img.py index dec029a499..3c1088adbc 100644 --- a/tests/pipelines/pag/test_pag_controlnet_sdxl_img2img.py +++ b/tests/pipelines/pag/test_pag_controlnet_sdxl_img2img.py @@ -29,8 +29,8 @@ from diffusers import ( StableDiffusionXLControlNetPAGImg2ImgPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor +from ...testing_utils import enable_full_determinism, floats_tensor from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/pag/test_pag_hunyuan_dit.py b/tests/pipelines/pag/test_pag_hunyuan_dit.py index 65f39f585d..f268a614f8 100644 --- a/tests/pipelines/pag/test_pag_hunyuan_dit.py +++ b/tests/pipelines/pag/test_pag_hunyuan_dit.py @@ -28,8 +28,8 @@ from diffusers import ( HunyuanDiTPAGPipeline, HunyuanDiTPipeline, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/pag/test_pag_kolors.py b/tests/pipelines/pag/test_pag_kolors.py index b504b77801..1bbb4e79e4 100644 --- a/tests/pipelines/pag/test_pag_kolors.py +++ b/tests/pipelines/pag/test_pag_kolors.py @@ -27,8 +27,8 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.pipelines.kolors import ChatGLMModel, ChatGLMTokenizer -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/pag/test_pag_pixart_sigma.py b/tests/pipelines/pag/test_pag_pixart_sigma.py index eb9399c9b3..c04ebad08f 100644 --- a/tests/pipelines/pag/test_pag_pixart_sigma.py +++ b/tests/pipelines/pag/test_pag_pixart_sigma.py @@ -30,12 +30,12 @@ from diffusers import ( PixArtTransformer2DModel, ) from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, enable_full_determinism, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sana.py b/tests/pipelines/pag/test_pag_sana.py index 31b384f3eb..5408595c72 100644 --- a/tests/pipelines/pag/test_pag_sana.py +++ b/tests/pipelines/pag/test_pag_sana.py @@ -26,8 +26,8 @@ from diffusers import ( SanaPipeline, SanaTransformer2DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/pag/test_pag_sd.py b/tests/pipelines/pag/test_pag_sd.py index ee9a74ed03..064815d136 100644 --- a/tests/pipelines/pag/test_pag_sd.py +++ b/tests/pipelines/pag/test_pag_sd.py @@ -29,14 +29,14 @@ from diffusers import ( StableDiffusionPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sd3.py b/tests/pipelines/pag/test_pag_sd3.py index 737e238e5f..26e6ca0992 100644 --- a/tests/pipelines/pag/test_pag_sd3.py +++ b/tests/pipelines/pag/test_pag_sd3.py @@ -12,10 +12,10 @@ from diffusers import ( StableDiffusion3PAGPipeline, StableDiffusion3Pipeline, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( torch_device, ) - from ..test_pipelines_common import ( PipelineTesterMixin, check_qkv_fusion_matches_attn_procs_length, diff --git a/tests/pipelines/pag/test_pag_sd3_img2img.py b/tests/pipelines/pag/test_pag_sd3_img2img.py index fe593d47dc..19a36e283d 100644 --- a/tests/pipelines/pag/test_pag_sd3_img2img.py +++ b/tests/pipelines/pag/test_pag_sd3_img2img.py @@ -15,7 +15,8 @@ from diffusers import ( StableDiffusion3Img2ImgPipeline, StableDiffusion3PAGImg2ImgPipeline, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -24,7 +25,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sd_img2img.py b/tests/pipelines/pag/test_pag_sd_img2img.py index 668e798463..0b440d5ec9 100644 --- a/tests/pipelines/pag/test_pag_sd_img2img.py +++ b/tests/pipelines/pag/test_pag_sd_img2img.py @@ -31,7 +31,8 @@ from diffusers import ( StableDiffusionPAGImg2ImgPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -40,7 +41,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sd_inpaint.py b/tests/pipelines/pag/test_pag_sd_inpaint.py index f856041422..709df68370 100644 --- a/tests/pipelines/pag/test_pag_sd_inpaint.py +++ b/tests/pipelines/pag/test_pag_sd_inpaint.py @@ -29,7 +29,8 @@ from diffusers import ( StableDiffusionPAGInpaintPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -38,7 +39,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sdxl.py b/tests/pipelines/pag/test_pag_sdxl.py index 5c1608d210..cca5c61651 100644 --- a/tests/pipelines/pag/test_pag_sdxl.py +++ b/tests/pipelines/pag/test_pag_sdxl.py @@ -29,14 +29,14 @@ from diffusers import ( StableDiffusionXLPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sdxl_img2img.py b/tests/pipelines/pag/test_pag_sdxl_img2img.py index 2e18fdcebb..d311500d3c 100644 --- a/tests/pipelines/pag/test_pag_sdxl_img2img.py +++ b/tests/pipelines/pag/test_pag_sdxl_img2img.py @@ -38,7 +38,8 @@ from diffusers import ( StableDiffusionXLPAGImg2ImgPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -47,7 +48,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/pag/test_pag_sdxl_inpaint.py b/tests/pipelines/pag/test_pag_sdxl_inpaint.py index e36716b603..00a07582e2 100644 --- a/tests/pipelines/pag/test_pag_sdxl_inpaint.py +++ b/tests/pipelines/pag/test_pag_sdxl_inpaint.py @@ -39,7 +39,8 @@ from diffusers import ( StableDiffusionXLPAGInpaintPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -48,7 +49,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/pixart_alpha/test_pixart.py b/tests/pipelines/pixart_alpha/test_pixart.py index 933a005c4a..fd41c9887d 100644 --- a/tests/pipelines/pixart_alpha/test_pixart.py +++ b/tests/pipelines/pixart_alpha/test_pixart.py @@ -27,7 +27,8 @@ from diffusers import ( PixArtAlphaPipeline, PixArtTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -35,7 +36,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/pixart_sigma/test_pixart.py b/tests/pipelines/pixart_sigma/test_pixart.py index cda7b442d7..2cb80df81a 100644 --- a/tests/pipelines/pixart_sigma/test_pixart.py +++ b/tests/pipelines/pixart_sigma/test_pixart.py @@ -27,7 +27,8 @@ from diffusers import ( PixArtSigmaPipeline, PixArtTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -35,7 +36,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/pndm/test_pndm.py b/tests/pipelines/pndm/test_pndm.py index 2c12690ad1..61d6efe88c 100644 --- a/tests/pipelines/pndm/test_pndm.py +++ b/tests/pipelines/pndm/test_pndm.py @@ -19,7 +19,8 @@ import numpy as np import torch from diffusers import PNDMPipeline, PNDMScheduler, UNet2DModel -from diffusers.utils.testing_utils import enable_full_determinism, nightly, require_torch, torch_device + +from ...testing_utils import enable_full_determinism, nightly, require_torch, torch_device enable_full_determinism() diff --git a/tests/pipelines/qwenimage/test_qwenimage.py b/tests/pipelines/qwenimage/test_qwenimage.py index a312d0658f..8ebfe7d08b 100644 --- a/tests/pipelines/qwenimage/test_qwenimage.py +++ b/tests/pipelines/qwenimage/test_qwenimage.py @@ -24,8 +24,8 @@ from diffusers import ( QwenImagePipeline, QwenImageTransformer2DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/qwenimage/test_qwenimage_edit.py b/tests/pipelines/qwenimage/test_qwenimage_edit.py index 647c65ada6..058548cf5f 100644 --- a/tests/pipelines/qwenimage/test_qwenimage_edit.py +++ b/tests/pipelines/qwenimage/test_qwenimage_edit.py @@ -26,8 +26,8 @@ from diffusers import ( QwenImageEditPipeline, QwenImageTransformer2DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/qwenimage/test_qwenimage_img2img.py b/tests/pipelines/qwenimage/test_qwenimage_img2img.py index 9f21257299..07e683ec7f 100644 --- a/tests/pipelines/qwenimage/test_qwenimage_img2img.py +++ b/tests/pipelines/qwenimage/test_qwenimage_img2img.py @@ -11,12 +11,12 @@ from diffusers import ( QwenImageImg2ImgPipeline, QwenImageTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/qwenimage/test_qwenimage_inpaint.py b/tests/pipelines/qwenimage/test_qwenimage_inpaint.py index 1a40630a2d..b564624540 100644 --- a/tests/pipelines/qwenimage/test_qwenimage_inpaint.py +++ b/tests/pipelines/qwenimage/test_qwenimage_inpaint.py @@ -25,8 +25,8 @@ from diffusers import ( QwenImageInpaintPipeline, QwenImageTransformer2DModel, ) -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/sana/test_sana.py b/tests/pipelines/sana/test_sana.py index 26c06c1c9e..34ea3079b1 100644 --- a/tests/pipelines/sana/test_sana.py +++ b/tests/pipelines/sana/test_sana.py @@ -21,14 +21,14 @@ import torch from transformers import Gemma2Config, Gemma2Model, GemmaTokenizer from diffusers import AutoencoderDC, FlowMatchEulerDiscreteScheduler, SanaPipeline, SanaTransformer2DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/sana/test_sana_controlnet.py b/tests/pipelines/sana/test_sana_controlnet.py index 9b5c9e439e..043e276fcb 100644 --- a/tests/pipelines/sana/test_sana_controlnet.py +++ b/tests/pipelines/sana/test_sana_controlnet.py @@ -26,12 +26,12 @@ from diffusers import ( SanaControlNetPipeline, SanaTransformer2DModel, ) -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( enable_full_determinism, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/sana/test_sana_sprint.py b/tests/pipelines/sana/test_sana_sprint.py index 021e559637..fee2304dce 100644 --- a/tests/pipelines/sana/test_sana_sprint.py +++ b/tests/pipelines/sana/test_sana_sprint.py @@ -20,11 +20,11 @@ import torch from transformers import Gemma2Config, Gemma2Model, GemmaTokenizer from diffusers import AutoencoderDC, SanaSprintPipeline, SanaTransformer2DModel, SCMScheduler -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/sana/test_sana_sprint_img2img.py b/tests/pipelines/sana/test_sana_sprint_img2img.py index c0e4bf8e35..c218abb8e9 100644 --- a/tests/pipelines/sana/test_sana_sprint_img2img.py +++ b/tests/pipelines/sana/test_sana_sprint_img2img.py @@ -20,12 +20,12 @@ import torch from transformers import Gemma2Config, Gemma2Model, GemmaTokenizer from diffusers import AutoencoderDC, SanaSprintImg2ImgPipeline, SanaTransformer2DModel, SCMScheduler -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( enable_full_determinism, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/shap_e/test_shap_e.py b/tests/pipelines/shap_e/test_shap_e.py index 47cc97844e..99fd286929 100644 --- a/tests/pipelines/shap_e/test_shap_e.py +++ b/tests/pipelines/shap_e/test_shap_e.py @@ -21,14 +21,14 @@ from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokeni from diffusers import HeunDiscreteScheduler, PriorTransformer, ShapEPipeline from diffusers.pipelines.shap_e import ShapERenderer -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, load_numpy, nightly, require_torch_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference diff --git a/tests/pipelines/shap_e/test_shap_e_img2img.py b/tests/pipelines/shap_e/test_shap_e_img2img.py index ba9f9fe521..b1867db249 100644 --- a/tests/pipelines/shap_e/test_shap_e_img2img.py +++ b/tests/pipelines/shap_e/test_shap_e_img2img.py @@ -22,7 +22,8 @@ from transformers import CLIPImageProcessor, CLIPVisionConfig, CLIPVisionModel from diffusers import HeunDiscreteScheduler, PriorTransformer, ShapEImg2ImgPipeline from diffusers.pipelines.shap_e import ShapERenderer -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, floats_tensor, load_image, @@ -31,7 +32,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference diff --git a/tests/pipelines/skyreels_v2/test_skyreels_v2.py b/tests/pipelines/skyreels_v2/test_skyreels_v2.py index adbbf05325..1bcec877c3 100644 --- a/tests/pipelines/skyreels_v2/test_skyreels_v2.py +++ b/tests/pipelines/skyreels_v2/test_skyreels_v2.py @@ -24,10 +24,10 @@ from diffusers import ( SkyReelsV2Transformer3DModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/skyreels_v2/test_skyreels_v2_df.py b/tests/pipelines/skyreels_v2/test_skyreels_v2_df.py index cf9070bb95..74235d59ef 100644 --- a/tests/pipelines/skyreels_v2/test_skyreels_v2_df.py +++ b/tests/pipelines/skyreels_v2/test_skyreels_v2_df.py @@ -24,10 +24,10 @@ from diffusers import ( SkyReelsV2Transformer3DModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/skyreels_v2/test_skyreels_v2_df_image_to_video.py b/tests/pipelines/skyreels_v2/test_skyreels_v2_df_image_to_video.py index 7b8a299281..f0cbc710df 100644 --- a/tests/pipelines/skyreels_v2/test_skyreels_v2_df_image_to_video.py +++ b/tests/pipelines/skyreels_v2/test_skyreels_v2_df_image_to_video.py @@ -28,8 +28,8 @@ from diffusers import ( SkyReelsV2Transformer3DModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/skyreels_v2/test_skyreels_v2_df_video_to_video.py b/tests/pipelines/skyreels_v2/test_skyreels_v2_df_video_to_video.py index bc6a9acbf7..1b0b23318e 100644 --- a/tests/pipelines/skyreels_v2/test_skyreels_v2_df_video_to_video.py +++ b/tests/pipelines/skyreels_v2/test_skyreels_v2_df_video_to_video.py @@ -26,11 +26,11 @@ from diffusers import ( SkyReelsV2Transformer3DModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/pipelines/skyreels_v2/test_skyreels_v2_image_to_video.py b/tests/pipelines/skyreels_v2/test_skyreels_v2_image_to_video.py index 3ca5862072..784f701a29 100644 --- a/tests/pipelines/skyreels_v2/test_skyreels_v2_image_to_video.py +++ b/tests/pipelines/skyreels_v2/test_skyreels_v2_image_to_video.py @@ -31,8 +31,8 @@ from diffusers import ( SkyReelsV2Transformer3DModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/stable_audio/test_stable_audio.py b/tests/pipelines/stable_audio/test_stable_audio.py index 5167dfdf0c..dd03f4d07f 100644 --- a/tests/pipelines/stable_audio/test_stable_audio.py +++ b/tests/pipelines/stable_audio/test_stable_audio.py @@ -32,7 +32,8 @@ from diffusers import ( StableAudioProjectionModel, ) from diffusers.utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, enable_full_determinism, @@ -40,7 +41,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/stable_cascade/test_stable_cascade_combined.py b/tests/pipelines/stable_cascade/test_stable_cascade_combined.py index 0a75b1e8b9..afa0db39f3 100644 --- a/tests/pipelines/stable_cascade/test_stable_cascade_combined.py +++ b/tests/pipelines/stable_cascade/test_stable_cascade_combined.py @@ -22,8 +22,8 @@ from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokeni from diffusers import DDPMWuerstchenScheduler, StableCascadeCombinedPipeline from diffusers.models import StableCascadeUNet from diffusers.pipelines.wuerstchen import PaellaVQModel -from diffusers.utils.testing_utils import enable_full_determinism, require_torch_accelerator, torch_device +from ...testing_utils import enable_full_determinism, require_torch_accelerator, torch_device from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py b/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py index d0c9fc891f..5b3acb8705 100644 --- a/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py +++ b/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py @@ -23,7 +23,9 @@ from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokeni from diffusers import DDPMWuerstchenScheduler, StableCascadeDecoderPipeline from diffusers.models import StableCascadeUNet from diffusers.pipelines.wuerstchen import PaellaVQModel -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import randn_tensor + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_numpy, @@ -34,8 +36,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import randn_tensor - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/stable_cascade/test_stable_cascade_prior.py b/tests/pipelines/stable_cascade/test_stable_cascade_prior.py index 90633adea9..f8267186db 100644 --- a/tests/pipelines/stable_cascade/test_stable_cascade_prior.py +++ b/tests/pipelines/stable_cascade/test_stable_cascade_prior.py @@ -23,7 +23,8 @@ from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokeni from diffusers import DDPMWuerstchenScheduler, StableCascadePriorPipeline from diffusers.models import StableCascadeUNet from diffusers.utils.import_utils import is_peft_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_numpy, diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index 69c105743b..62414f3f19 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -27,8 +27,8 @@ from diffusers import ( OnnxStableDiffusionPipeline, PNDMScheduler, ) -from diffusers.utils.testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu +from ...testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py index 8a470fc668..28d1d0f37f 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py @@ -26,7 +26,8 @@ from diffusers import ( OnnxStableDiffusionImg2ImgPipeline, PNDMScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( floats_tensor, is_onnx_available, load_image, @@ -34,7 +35,6 @@ from diffusers.utils.testing_utils import ( require_onnxruntime, require_torch_gpu, ) - from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py index 6bca7b288c..1d46ff9a2f 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py @@ -18,14 +18,14 @@ import unittest import numpy as np from diffusers import LMSDiscreteScheduler, OnnxStableDiffusionInpaintPipeline -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( is_onnx_available, load_image, nightly, require_onnxruntime, require_torch_gpu, ) - from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_upscale.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_upscale.py index e25118575f..55d9d38d64 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_upscale.py @@ -26,7 +26,8 @@ from diffusers import ( OnnxStableDiffusionUpscalePipeline, PNDMScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( floats_tensor, is_onnx_available, load_image, @@ -34,7 +35,6 @@ from diffusers.utils.testing_utils import ( require_onnxruntime, require_torch_gpu, ) - from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index bcad693501..c9d9525b2e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -41,7 +41,8 @@ from diffusers import ( UNet2DConditionModel, logging, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, backend_empty_cache, backend_max_memory_allocated, @@ -58,7 +59,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index c80667656e..a0b7268b9d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -33,7 +33,8 @@ from diffusers import ( StableDiffusionImg2ImgPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -48,7 +49,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 20a9848118..259806a947 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -35,7 +35,8 @@ from diffusers import ( StableDiffusionInpaintPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, backend_max_memory_allocated, @@ -50,7 +51,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py index 1654831a99..4758c5dab4 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -32,7 +32,8 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.image_processor import VaeImageProcessor -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -44,7 +45,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index b3b5ba3de4..3b2552b432 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -31,7 +31,8 @@ from diffusers import ( UNet2DConditionModel, logging, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, backend_empty_cache, backend_max_memory_allocated, @@ -45,7 +46,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py index 6f772e5df1..bea7c09904 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -36,7 +36,8 @@ from diffusers import ( StableDiffusionDepth2ImgPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -50,7 +51,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax.py index 77014bd7a5..92effcacad 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax.py @@ -18,7 +18,8 @@ import unittest from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline from diffusers.utils import is_flax_available -from diffusers.utils.testing_utils import nightly, require_flax + +from ...testing_utils import nightly, require_flax if is_flax_available(): diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax_inpaint.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax_inpaint.py index d83c696736..cdd088b531 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_flax_inpaint.py @@ -18,7 +18,8 @@ import unittest from diffusers import FlaxStableDiffusionInpaintPipeline from diffusers.utils import is_flax_available, load_image -from diffusers.utils.testing_utils import require_flax, slow + +from ...testing_utils import require_flax, slow if is_flax_available(): diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py index 238874c7f8..f010c1b03f 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -23,7 +23,8 @@ from PIL import Image from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer from diffusers import AutoencoderKL, PNDMScheduler, StableDiffusionInpaintPipeline, UNet2DConditionModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -36,7 +37,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_latent_upscale.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_latent_upscale.py index 50cb9aa4b7..2e4b428dfe 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_latent_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_latent_upscale.py @@ -30,7 +30,8 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.schedulers import KarrasDiffusionSchedulers -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -40,7 +41,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py index a0949db7ee..481ac7f2d1 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -24,7 +24,8 @@ from PIL import Image from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableDiffusionUpscalePipeline, UNet2DConditionModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py index 55d801fd6c..37b309c4ca 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py @@ -30,7 +30,8 @@ from diffusers import ( StableDiffusionPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, diff --git a/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py b/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py index 43d91d55c9..3ccefe3de3 100644 --- a/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py +++ b/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py @@ -6,14 +6,14 @@ import torch from transformers import AutoTokenizer, CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokenizer, T5EncoderModel from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, SD3Transformer2DModel, StableDiffusion3Pipeline -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, numpy_cosine_similarity_distance, require_big_accelerator, slow, torch_device, ) - from ..test_pipelines_common import ( PipelineTesterMixin, check_qkv_fusion_matches_attn_procs_length, diff --git a/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_img2img.py b/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_img2img.py index 6714fd1396..9025b1060c 100644 --- a/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_img2img.py +++ b/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_img2img.py @@ -13,7 +13,8 @@ from diffusers import ( StableDiffusion3Img2ImgPipeline, ) from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, floats_tensor, @@ -22,7 +23,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_inpaint.py b/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_inpaint.py index b537d6a0b6..6289303402 100644 --- a/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_inpaint.py +++ b/tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_inpaint.py @@ -11,12 +11,12 @@ from diffusers import ( SD3Transformer2DModel, StableDiffusion3InpaintPipeline, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/stable_diffusion_adapter/test_stable_diffusion_adapter.py b/tests/pipelines/stable_diffusion_adapter/test_stable_diffusion_adapter.py index 009c75df42..79b38d1cad 100644 --- a/tests/pipelines/stable_diffusion_adapter/test_stable_diffusion_adapter.py +++ b/tests/pipelines/stable_diffusion_adapter/test_stable_diffusion_adapter.py @@ -34,7 +34,8 @@ from diffusers import ( ) from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -45,7 +46,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS from ..test_pipelines_common import PipelineFromPipeTesterMixin, PipelineTesterMixin, assert_mean_pixel_difference diff --git a/tests/pipelines/stable_diffusion_image_variation/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion_image_variation/test_stable_diffusion_image_variation.py index 5eca6c2380..dbf5a7b68e 100644 --- a/tests/pipelines/stable_diffusion_image_variation/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion_image_variation/test_stable_diffusion_image_variation.py @@ -29,7 +29,8 @@ from diffusers import ( StableDiffusionImageVariationPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -44,7 +45,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import IMAGE_VARIATION_BATCH_PARAMS, IMAGE_VARIATION_PARAMS from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py index 966d864843..b318a505e9 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py @@ -34,7 +34,8 @@ from diffusers import ( UNet2DConditionModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, load_image, @@ -43,7 +44,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS, diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py index c39c9bedaf..3d72270dda 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py @@ -32,12 +32,12 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, torch_device, ) - from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS from ..test_pipelines_common import ( IPAdapterTesterMixin, diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py index 450891b257..c549984706 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_img2img.py @@ -38,7 +38,8 @@ from diffusers import ( StableDiffusionXLImg2ImgPipeline, UNet2DConditionModel, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, floats_tensor, @@ -47,7 +48,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py index 6ac820547d..d3f5779c76 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_inpaint.py @@ -41,14 +41,14 @@ from diffusers import ( UNet2DConditionModel, UniPCMultistepScheduler, ) -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, floats_tensor, require_torch_accelerator, slow, torch_device, ) - from ..pipeline_params import ( TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS, diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_instruction_pix2pix.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_instruction_pix2pix.py index 932a249689..20a03583e7 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_instruction_pix2pix.py @@ -29,8 +29,8 @@ from diffusers.image_processor import VaeImageProcessor from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl_instruct_pix2pix import ( StableDiffusionXLInstructPix2PixPipeline, ) -from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device +from ...testing_utils import enable_full_determinism, floats_tensor, torch_device from ..pipeline_params import ( IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, diff --git a/tests/pipelines/stable_unclip/test_stable_unclip.py b/tests/pipelines/stable_unclip/test_stable_unclip.py index e3cbb1891b..8923c2f63c 100644 --- a/tests/pipelines/stable_unclip/test_stable_unclip.py +++ b/tests/pipelines/stable_unclip/test_stable_unclip.py @@ -13,7 +13,8 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.pipelines.stable_diffusion.stable_unclip_image_normalizer import StableUnCLIPImageNormalizer -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -24,7 +25,6 @@ from diffusers.utils.testing_utils import ( require_torch_accelerator, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineKarrasSchedulerTesterMixin, diff --git a/tests/pipelines/stable_unclip/test_stable_unclip_img2img.py b/tests/pipelines/stable_unclip/test_stable_unclip_img2img.py index 8ca5723ce6..e7a0fbccef 100644 --- a/tests/pipelines/stable_unclip/test_stable_unclip_img2img.py +++ b/tests/pipelines/stable_unclip/test_stable_unclip_img2img.py @@ -17,7 +17,8 @@ from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableUnCLIPI from diffusers.pipelines.pipeline_utils import DiffusionPipeline from diffusers.pipelines.stable_diffusion.stable_unclip_image_normalizer import StableUnCLIPImageNormalizer from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_max_memory_allocated, @@ -31,7 +32,6 @@ from diffusers.utils.testing_utils import ( skip_mps, torch_device, ) - from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS from ..test_pipelines_common import ( PipelineKarrasSchedulerTesterMixin, diff --git a/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py b/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py index f77a5b1620..52595f7a8c 100644 --- a/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py +++ b/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py @@ -20,7 +20,8 @@ from diffusers import ( ) from diffusers.utils import load_image, logging from diffusers.utils.import_utils import is_xformers_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, backend_empty_cache, enable_full_determinism, @@ -32,7 +33,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/test_pipeline_utils.py b/tests/pipelines/test_pipeline_utils.py index f49ad282f3..6d9e681979 100644 --- a/tests/pipelines/test_pipeline_utils.py +++ b/tests/pipelines/test_pipeline_utils.py @@ -19,7 +19,8 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.pipelines.pipeline_loading_utils import is_safetensors_compatible, variant_compatible_siblings -from diffusers.utils.testing_utils import require_torch_accelerator, torch_device + +from ..testing_utils import require_torch_accelerator, torch_device class IsSafetensorsCompatibleTests(unittest.TestCase): diff --git a/tests/pipelines/test_pipelines.py b/tests/pipelines/test_pipelines.py index 6c342bcbe6..09df140f1a 100644 --- a/tests/pipelines/test_pipelines.py +++ b/tests/pipelines/test_pipelines.py @@ -66,7 +66,9 @@ from diffusers.utils import ( CONFIG_NAME, WEIGHTS_NAME, ) -from diffusers.utils.testing_utils import ( +from diffusers.utils.torch_utils import is_compiled_module + +from ..testing_utils import ( CaptureLogger, backend_empty_cache, enable_full_determinism, @@ -89,7 +91,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) -from diffusers.utils.torch_utils import is_compiled_module enable_full_determinism() diff --git a/tests/pipelines/test_pipelines_auto.py b/tests/pipelines/test_pipelines_auto.py index de4b447f66..f3c639c367 100644 --- a/tests/pipelines/test_pipelines_auto.py +++ b/tests/pipelines/test_pipelines_auto.py @@ -35,7 +35,8 @@ from diffusers.pipelines.auto_pipeline import ( AUTO_INPAINT_PIPELINES_MAPPING, AUTO_TEXT2IMAGE_PIPELINES_MAPPING, ) -from diffusers.utils.testing_utils import slow + +from ..testing_utils import slow PRETRAINED_MODEL_REPO_MAPPING = OrderedDict( diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index ed6a56c5fa..dcef33897e 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -48,19 +48,6 @@ from diffusers.schedulers import KarrasDiffusionSchedulers from diffusers.utils import logging from diffusers.utils.import_utils import is_xformers_available from diffusers.utils.source_code_parsing_utils import ReturnNameVisitor -from diffusers.utils.testing_utils import ( - CaptureLogger, - backend_empty_cache, - numpy_cosine_similarity_distance, - require_accelerate_version_greater, - require_accelerator, - require_hf_hub_version_greater, - require_torch, - require_torch_accelerator, - require_transformers_version_greater, - skip_mps, - torch_device, -) from ..models.autoencoders.vae import ( get_asym_autoencoder_kl_config, @@ -74,6 +61,19 @@ from ..models.unets.test_models_unet_2d_condition import ( create_ip_adapter_state_dict, ) from ..others.test_utils import TOKEN, USER, is_staging_test +from ..testing_utils import ( + CaptureLogger, + backend_empty_cache, + numpy_cosine_similarity_distance, + require_accelerate_version_greater, + require_accelerator, + require_hf_hub_version_greater, + require_torch, + require_torch_accelerator, + require_transformers_version_greater, + skip_mps, + torch_device, +) def to_np(tensor): diff --git a/tests/pipelines/test_pipelines_flax.py b/tests/pipelines/test_pipelines_flax.py index ffe43ac9d7..dbb5c7bfed 100644 --- a/tests/pipelines/test_pipelines_flax.py +++ b/tests/pipelines/test_pipelines_flax.py @@ -20,7 +20,8 @@ import unittest import numpy as np from diffusers.utils import is_flax_available -from diffusers.utils.testing_utils import require_flax, slow + +from ..testing_utils import require_flax, slow if is_flax_available(): diff --git a/tests/pipelines/test_pipelines_onnx_common.py b/tests/pipelines/test_pipelines_onnx_common.py index 575ecd0075..fa077efb8a 100644 --- a/tests/pipelines/test_pipelines_onnx_common.py +++ b/tests/pipelines/test_pipelines_onnx_common.py @@ -1,4 +1,4 @@ -from diffusers.utils.testing_utils import require_onnxruntime +from ..testing_utils import require_onnxruntime @require_onnxruntime diff --git a/tests/pipelines/visualcloze/test_pipeline_visualcloze_combined.py b/tests/pipelines/visualcloze/test_pipeline_visualcloze_combined.py index 7e2aa25709..00ae0441fe 100644 --- a/tests/pipelines/visualcloze/test_pipeline_visualcloze_combined.py +++ b/tests/pipelines/visualcloze/test_pipeline_visualcloze_combined.py @@ -10,14 +10,14 @@ from transformers import AutoTokenizer, CLIPTextConfig, CLIPTextModel, CLIPToken import diffusers from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler, FluxTransformer2DModel, VisualClozePipeline from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, enable_full_determinism, floats_tensor, require_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/visualcloze/test_pipeline_visualcloze_generation.py b/tests/pipelines/visualcloze/test_pipeline_visualcloze_generation.py index 0cd714af17..ab6b3ca5c5 100644 --- a/tests/pipelines/visualcloze/test_pipeline_visualcloze_generation.py +++ b/tests/pipelines/visualcloze/test_pipeline_visualcloze_generation.py @@ -15,14 +15,14 @@ from diffusers import ( VisualClozeGenerationPipeline, ) from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, enable_full_determinism, floats_tensor, require_accelerator, torch_device, ) - from ..test_pipelines_common import PipelineTesterMixin, to_np diff --git a/tests/pipelines/wan/test_wan.py b/tests/pipelines/wan/test_wan.py index 90b7978ec7..106a7b2946 100644 --- a/tests/pipelines/wan/test_wan.py +++ b/tests/pipelines/wan/test_wan.py @@ -21,14 +21,14 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLWan, FlowMatchEulerDiscreteScheduler, WanPipeline, WanTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/wan/test_wan_22.py b/tests/pipelines/wan/test_wan_22.py index 9fdae66980..56ef5ceb97 100644 --- a/tests/pipelines/wan/test_wan_22.py +++ b/tests/pipelines/wan/test_wan_22.py @@ -20,11 +20,11 @@ import torch from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLWan, UniPCMultistepScheduler, WanPipeline, WanTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/wan/test_wan_22_image_to_video.py b/tests/pipelines/wan/test_wan_22_image_to_video.py index 3f72a74e44..6294d62044 100644 --- a/tests/pipelines/wan/test_wan_22_image_to_video.py +++ b/tests/pipelines/wan/test_wan_22_image_to_video.py @@ -21,11 +21,11 @@ from PIL import Image from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLWan, UniPCMultistepScheduler, WanImageToVideoPipeline, WanTransformer3DModel -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, torch_device, ) - from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/wan/test_wan_image_to_video.py b/tests/pipelines/wan/test_wan_image_to_video.py index 1c938ce2de..07a9142f25 100644 --- a/tests/pipelines/wan/test_wan_image_to_video.py +++ b/tests/pipelines/wan/test_wan_image_to_video.py @@ -27,8 +27,8 @@ from transformers import ( ) from diffusers import AutoencoderKLWan, FlowMatchEulerDiscreteScheduler, WanImageToVideoPipeline, WanTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from ...testing_utils import enable_full_determinism, torch_device from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/wan/test_wan_vace.py b/tests/pipelines/wan/test_wan_vace.py index 885defcfb4..ed13d5649d 100644 --- a/tests/pipelines/wan/test_wan_vace.py +++ b/tests/pipelines/wan/test_wan_vace.py @@ -20,8 +20,8 @@ from PIL import Image from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLWan, FlowMatchEulerDiscreteScheduler, WanVACEPipeline, WanVACETransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism +from ...testing_utils import enable_full_determinism from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import PipelineTesterMixin diff --git a/tests/pipelines/wan/test_wan_video_to_video.py b/tests/pipelines/wan/test_wan_video_to_video.py index f4bb0960ac..27ada121ca 100644 --- a/tests/pipelines/wan/test_wan_video_to_video.py +++ b/tests/pipelines/wan/test_wan_video_to_video.py @@ -19,10 +19,10 @@ from PIL import Image from transformers import AutoTokenizer, T5EncoderModel from diffusers import AutoencoderKLWan, UniPCMultistepScheduler, WanTransformer3DModel, WanVideoToVideoPipeline -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( enable_full_determinism, ) - from ..pipeline_params import TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS from ..test_pipelines_common import ( PipelineTesterMixin, diff --git a/tests/quantization/bnb/test_4bit.py b/tests/quantization/bnb/test_4bit.py index 08c0fee43b..c1da8f1ece 100644 --- a/tests/quantization/bnb/test_4bit.py +++ b/tests/quantization/bnb/test_4bit.py @@ -32,7 +32,8 @@ from diffusers import ( ) from diffusers.quantizers import PipelineQuantizationConfig from diffusers.utils import is_accelerate_version, logging -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, backend_empty_cache, is_bitsandbytes_available, @@ -50,7 +51,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_torch_compile_utils import QuantCompileTests diff --git a/tests/quantization/bnb/test_mixed_int8.py b/tests/quantization/bnb/test_mixed_int8.py index 8ddbf11cfd..fde3966dec 100644 --- a/tests/quantization/bnb/test_mixed_int8.py +++ b/tests/quantization/bnb/test_mixed_int8.py @@ -32,7 +32,8 @@ from diffusers import ( ) from diffusers.quantizers import PipelineQuantizationConfig from diffusers.utils import is_accelerate_version -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( CaptureLogger, backend_empty_cache, is_bitsandbytes_available, @@ -51,7 +52,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_torch_compile_utils import QuantCompileTests diff --git a/tests/quantization/gguf/test_gguf.py b/tests/quantization/gguf/test_gguf.py index 3bd454c5a5..38322459e7 100644 --- a/tests/quantization/gguf/test_gguf.py +++ b/tests/quantization/gguf/test_gguf.py @@ -20,7 +20,8 @@ from diffusers import ( WanVACETransformer3DModel, ) from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( Expectations, backend_empty_cache, backend_max_memory_allocated, @@ -38,7 +39,6 @@ from diffusers.utils.testing_utils import ( require_torch_version_greater, torch_device, ) - from ..test_torch_compile_utils import QuantCompileTests diff --git a/tests/quantization/quanto/test_quanto.py b/tests/quantization/quanto/test_quanto.py index d7bde6591d..28555a6076 100644 --- a/tests/quantization/quanto/test_quanto.py +++ b/tests/quantization/quanto/test_quanto.py @@ -5,7 +5,8 @@ import unittest from diffusers import FluxPipeline, FluxTransformer2DModel, QuantoConfig from diffusers.models.attention_processor import Attention from diffusers.utils import is_optimum_quanto_available, is_torch_available -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_reset_peak_memory_stats, enable_full_determinism, diff --git a/tests/quantization/test_pipeline_level_quantization.py b/tests/quantization/test_pipeline_level_quantization.py index e91fe6d4cb..51cf4057d6 100644 --- a/tests/quantization/test_pipeline_level_quantization.py +++ b/tests/quantization/test_pipeline_level_quantization.py @@ -22,7 +22,8 @@ from parameterized import parameterized from diffusers import BitsAndBytesConfig, DiffusionPipeline, QuantoConfig from diffusers.quantizers import PipelineQuantizationConfig from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( CaptureLogger, is_transformers_available, require_accelerate, diff --git a/tests/quantization/test_torch_compile_utils.py b/tests/quantization/test_torch_compile_utils.py index 91ed173fc6..29758cbdd7 100644 --- a/tests/quantization/test_torch_compile_utils.py +++ b/tests/quantization/test_torch_compile_utils.py @@ -18,7 +18,8 @@ import inspect import torch from diffusers import DiffusionPipeline -from diffusers.utils.testing_utils import backend_empty_cache, require_torch_accelerator, slow, torch_device + +from ..testing_utils import backend_empty_cache, require_torch_accelerator, slow, torch_device @require_torch_accelerator diff --git a/tests/quantization/torchao/test_torchao.py b/tests/quantization/torchao/test_torchao.py index 5dcc207e65..920c3a55f5 100644 --- a/tests/quantization/torchao/test_torchao.py +++ b/tests/quantization/torchao/test_torchao.py @@ -31,7 +31,8 @@ from diffusers import ( ) from diffusers.models.attention_processor import Attention from diffusers.quantizers import PipelineQuantizationConfig -from diffusers.utils.testing_utils import ( + +from ...testing_utils import ( backend_empty_cache, backend_synchronize, enable_full_determinism, @@ -45,7 +46,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from ..test_torch_compile_utils import QuantCompileTests diff --git a/tests/quantization/utils.py b/tests/quantization/utils.py index d458a3e6d5..a74ece5a3a 100644 --- a/tests/quantization/utils.py +++ b/tests/quantization/utils.py @@ -1,5 +1,6 @@ from diffusers.utils import is_torch_available -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, backend_max_memory_allocated, backend_reset_peak_memory_stats, diff --git a/tests/remote/test_remote_decode.py b/tests/remote/test_remote_decode.py index cec96e729a..27170cba08 100644 --- a/tests/remote/test_remote_decode.py +++ b/tests/remote/test_remote_decode.py @@ -30,13 +30,14 @@ from diffusers.utils.constants import ( from diffusers.utils.remote_utils import ( remote_decode, ) -from diffusers.utils.testing_utils import ( +from diffusers.video_processor import VideoProcessor + +from ..testing_utils import ( enable_full_determinism, slow, torch_all_close, torch_device, ) -from diffusers.video_processor import VideoProcessor enable_full_determinism() diff --git a/tests/remote/test_remote_encode.py b/tests/remote/test_remote_encode.py index 62ed97ee8f..4c0daf08fd 100644 --- a/tests/remote/test_remote_encode.py +++ b/tests/remote/test_remote_encode.py @@ -31,7 +31,8 @@ from diffusers.utils.remote_utils import ( remote_decode, remote_encode, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( enable_full_determinism, slow, ) diff --git a/tests/schedulers/test_scheduler_dpm_sde.py b/tests/schedulers/test_scheduler_dpm_sde.py index 69b6111734..e4dde67344 100644 --- a/tests/schedulers/test_scheduler_dpm_sde.py +++ b/tests/schedulers/test_scheduler_dpm_sde.py @@ -1,8 +1,8 @@ import torch from diffusers import DPMSolverSDEScheduler -from diffusers.utils.testing_utils import require_torchsde, torch_device +from ..testing_utils import require_torchsde, torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_euler.py b/tests/schedulers/test_scheduler_euler.py index 01e173a631..ee99465abf 100644 --- a/tests/schedulers/test_scheduler_euler.py +++ b/tests/schedulers/test_scheduler_euler.py @@ -1,8 +1,8 @@ import torch from diffusers import EulerDiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_euler_ancestral.py b/tests/schedulers/test_scheduler_euler_ancestral.py index 9f22ab38dd..c4fe61bfc3 100644 --- a/tests/schedulers/test_scheduler_euler_ancestral.py +++ b/tests/schedulers/test_scheduler_euler_ancestral.py @@ -1,8 +1,8 @@ import torch from diffusers import EulerAncestralDiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_flax.py b/tests/schedulers/test_scheduler_flax.py index c8121d3341..e6e4fd7d76 100644 --- a/tests/schedulers/test_scheduler_flax.py +++ b/tests/schedulers/test_scheduler_flax.py @@ -19,7 +19,8 @@ from typing import Dict, List, Tuple from diffusers import FlaxDDIMScheduler, FlaxDDPMScheduler, FlaxPNDMScheduler from diffusers.utils import is_flax_available -from diffusers.utils.testing_utils import require_flax + +from ..testing_utils import require_flax if is_flax_available(): diff --git a/tests/schedulers/test_scheduler_heun.py b/tests/schedulers/test_scheduler_heun.py index 90012f5525..97bef50048 100644 --- a/tests/schedulers/test_scheduler_heun.py +++ b/tests/schedulers/test_scheduler_heun.py @@ -1,8 +1,8 @@ import torch from diffusers import HeunDiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_kdpm2_ancestral.py b/tests/schedulers/test_scheduler_kdpm2_ancestral.py index fa85c2be45..135534db45 100644 --- a/tests/schedulers/test_scheduler_kdpm2_ancestral.py +++ b/tests/schedulers/test_scheduler_kdpm2_ancestral.py @@ -1,8 +1,8 @@ import torch from diffusers import KDPM2AncestralDiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_kdpm2_discrete.py b/tests/schedulers/test_scheduler_kdpm2_discrete.py index 4d8923b694..370ba2253e 100644 --- a/tests/schedulers/test_scheduler_kdpm2_discrete.py +++ b/tests/schedulers/test_scheduler_kdpm2_discrete.py @@ -1,8 +1,8 @@ import torch from diffusers import KDPM2DiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_lcm.py b/tests/schedulers/test_scheduler_lcm.py index f3f6e9ba58..f54970e0eb 100644 --- a/tests/schedulers/test_scheduler_lcm.py +++ b/tests/schedulers/test_scheduler_lcm.py @@ -4,8 +4,8 @@ from typing import Dict, List, Tuple import torch from diffusers import LCMScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_lms.py b/tests/schedulers/test_scheduler_lms.py index 3bfcd57c1b..c4abca3ac9 100644 --- a/tests/schedulers/test_scheduler_lms.py +++ b/tests/schedulers/test_scheduler_lms.py @@ -1,8 +1,8 @@ import torch from diffusers import LMSDiscreteScheduler -from diffusers.utils.testing_utils import torch_device +from ..testing_utils import torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_scheduler_sasolver.py b/tests/schedulers/test_scheduler_sasolver.py index baa2736b2f..2c2d2c0397 100644 --- a/tests/schedulers/test_scheduler_sasolver.py +++ b/tests/schedulers/test_scheduler_sasolver.py @@ -1,8 +1,8 @@ import torch from diffusers import SASolverScheduler -from diffusers.utils.testing_utils import require_torchsde, torch_device +from ..testing_utils import require_torchsde, torch_device from .test_schedulers import SchedulerCommonTest diff --git a/tests/schedulers/test_schedulers.py b/tests/schedulers/test_schedulers.py index cd8dc5ccf1..5a8380e659 100755 --- a/tests/schedulers/test_schedulers.py +++ b/tests/schedulers/test_schedulers.py @@ -41,9 +41,9 @@ from diffusers import ( from diffusers.configuration_utils import ConfigMixin, register_to_config from diffusers.schedulers.scheduling_utils import SchedulerMixin from diffusers.utils import logging -from diffusers.utils.testing_utils import CaptureLogger, torch_device from ..others.test_utils import TOKEN, USER, is_staging_test +from ..testing_utils import CaptureLogger, torch_device torch.backends.cuda.matmul.allow_tf32 = False diff --git a/tests/single_file/single_file_testing_utils.py b/tests/single_file/single_file_testing_utils.py index 4e1713c9ce..3510d3371c 100644 --- a/tests/single_file/single_file_testing_utils.py +++ b/tests/single_file/single_file_testing_utils.py @@ -7,7 +7,8 @@ from huggingface_hub import hf_hub_download, snapshot_download from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.models.attention_processor import AttnProcessor -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( numpy_cosine_similarity_distance, torch_device, ) diff --git a/tests/single_file/test_lumina2_transformer.py b/tests/single_file/test_lumina2_transformer.py index 2ac681897d..99d9b71395 100644 --- a/tests/single_file/test_lumina2_transformer.py +++ b/tests/single_file/test_lumina2_transformer.py @@ -19,7 +19,8 @@ import unittest from diffusers import ( Lumina2Transformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_model_autoencoder_dc_single_file.py b/tests/single_file/test_model_autoencoder_dc_single_file.py index 184498ca2f..5195f8e52f 100644 --- a/tests/single_file/test_model_autoencoder_dc_single_file.py +++ b/tests/single_file/test_model_autoencoder_dc_single_file.py @@ -21,7 +21,8 @@ import torch from diffusers import ( AutoencoderDC, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, load_hf_numpy, diff --git a/tests/single_file/test_model_controlnet_single_file.py b/tests/single_file/test_model_controlnet_single_file.py index ade6f63a50..e5214fe3f2 100644 --- a/tests/single_file/test_model_controlnet_single_file.py +++ b/tests/single_file/test_model_controlnet_single_file.py @@ -21,7 +21,8 @@ import torch from diffusers import ( ControlNetModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_model_flux_transformer_single_file.py b/tests/single_file/test_model_flux_transformer_single_file.py index 2f837bd18e..a7e07e517f 100644 --- a/tests/single_file/test_model_flux_transformer_single_file.py +++ b/tests/single_file/test_model_flux_transformer_single_file.py @@ -19,7 +19,8 @@ import unittest from diffusers import ( FluxTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_model_motion_adapter_single_file.py b/tests/single_file/test_model_motion_adapter_single_file.py index dc08a95b84..7aaf4b577e 100644 --- a/tests/single_file/test_model_motion_adapter_single_file.py +++ b/tests/single_file/test_model_motion_adapter_single_file.py @@ -18,7 +18,8 @@ import unittest from diffusers import ( MotionAdapter, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( enable_full_determinism, ) diff --git a/tests/single_file/test_model_sd_cascade_unet_single_file.py b/tests/single_file/test_model_sd_cascade_unet_single_file.py index a16278c6b0..a5ec9dba30 100644 --- a/tests/single_file/test_model_sd_cascade_unet_single_file.py +++ b/tests/single_file/test_model_sd_cascade_unet_single_file.py @@ -20,7 +20,8 @@ import torch from diffusers import StableCascadeUNet from diffusers.utils import logging -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_model_vae_single_file.py b/tests/single_file/test_model_vae_single_file.py index 9d994b5b49..3b9e619f13 100644 --- a/tests/single_file/test_model_vae_single_file.py +++ b/tests/single_file/test_model_vae_single_file.py @@ -21,7 +21,8 @@ import torch from diffusers import ( AutoencoderKL, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, load_hf_numpy, diff --git a/tests/single_file/test_model_wan_autoencoder_single_file.py b/tests/single_file/test_model_wan_autoencoder_single_file.py index 7f0e1c1a4b..a1f7155c10 100644 --- a/tests/single_file/test_model_wan_autoencoder_single_file.py +++ b/tests/single_file/test_model_wan_autoencoder_single_file.py @@ -19,7 +19,8 @@ import unittest from diffusers import ( AutoencoderKLWan, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_model_wan_transformer3d_single_file.py b/tests/single_file/test_model_wan_transformer3d_single_file.py index 72b4b3a58a..d7c758d3d9 100644 --- a/tests/single_file/test_model_wan_transformer3d_single_file.py +++ b/tests/single_file/test_model_wan_transformer3d_single_file.py @@ -21,7 +21,8 @@ import torch from diffusers import ( WanTransformer3DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_big_accelerator, diff --git a/tests/single_file/test_sana_transformer.py b/tests/single_file/test_sana_transformer.py index e74c5be6ff..c1543ba171 100644 --- a/tests/single_file/test_sana_transformer.py +++ b/tests/single_file/test_sana_transformer.py @@ -4,7 +4,8 @@ import unittest from diffusers import ( SanaTransformer2DModel, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_stable_diffusion_controlnet_img2img_single_file.py b/tests/single_file/test_stable_diffusion_controlnet_img2img_single_file.py index 7589b48028..e558eeaf6f 100644 --- a/tests/single_file/test_stable_diffusion_controlnet_img2img_single_file.py +++ b/tests/single_file/test_stable_diffusion_controlnet_img2img_single_file.py @@ -7,7 +7,8 @@ import torch from diffusers import ControlNetModel, StableDiffusionControlNetPipeline from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -15,7 +16,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import ( SDSingleFileTesterMixin, download_diffusers_config, diff --git a/tests/single_file/test_stable_diffusion_controlnet_inpaint_single_file.py b/tests/single_file/test_stable_diffusion_controlnet_inpaint_single_file.py index 1555831db6..54224f51a9 100644 --- a/tests/single_file/test_stable_diffusion_controlnet_inpaint_single_file.py +++ b/tests/single_file/test_stable_diffusion_controlnet_inpaint_single_file.py @@ -7,7 +7,8 @@ import torch from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -15,7 +16,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import ( SDSingleFileTesterMixin, download_diffusers_config, diff --git a/tests/single_file/test_stable_diffusion_controlnet_single_file.py b/tests/single_file/test_stable_diffusion_controlnet_single_file.py index 2c1e414e5e..e90e648a9d 100644 --- a/tests/single_file/test_stable_diffusion_controlnet_single_file.py +++ b/tests/single_file/test_stable_diffusion_controlnet_single_file.py @@ -7,7 +7,8 @@ import torch from diffusers import ControlNetModel, StableDiffusionControlNetPipeline from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -15,7 +16,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import ( SDSingleFileTesterMixin, download_diffusers_config, diff --git a/tests/single_file/test_stable_diffusion_img2img_single_file.py b/tests/single_file/test_stable_diffusion_img2img_single_file.py index 9ad9355824..387f09471d 100644 --- a/tests/single_file/test_stable_diffusion_img2img_single_file.py +++ b/tests/single_file/test_stable_diffusion_img2img_single_file.py @@ -7,14 +7,14 @@ from diffusers import ( StableDiffusionImg2ImgPipeline, ) from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from .single_file_testing_utils import SDSingleFileTesterMixin diff --git a/tests/single_file/test_stable_diffusion_inpaint_single_file.py b/tests/single_file/test_stable_diffusion_inpaint_single_file.py index b05a098c0b..84636ec0f0 100644 --- a/tests/single_file/test_stable_diffusion_inpaint_single_file.py +++ b/tests/single_file/test_stable_diffusion_inpaint_single_file.py @@ -7,14 +7,14 @@ from diffusers import ( StableDiffusionInpaintPipeline, ) from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from .single_file_testing_utils import SDSingleFileTesterMixin diff --git a/tests/single_file/test_stable_diffusion_single_file.py b/tests/single_file/test_stable_diffusion_single_file.py index 78baeb9492..4601b75c3a 100644 --- a/tests/single_file/test_stable_diffusion_single_file.py +++ b/tests/single_file/test_stable_diffusion_single_file.py @@ -7,7 +7,8 @@ import torch from diffusers import EulerDiscreteScheduler, StableDiffusionInstructPix2PixPipeline, StableDiffusionPipeline from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, nightly, @@ -15,7 +16,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import ( SDSingleFileTesterMixin, download_original_config, diff --git a/tests/single_file/test_stable_diffusion_upscale_single_file.py b/tests/single_file/test_stable_diffusion_upscale_single_file.py index 398fc9ece3..39ec7b0194 100644 --- a/tests/single_file/test_stable_diffusion_upscale_single_file.py +++ b/tests/single_file/test_stable_diffusion_upscale_single_file.py @@ -8,7 +8,8 @@ from diffusers import ( StableDiffusionUpscalePipeline, ) from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -16,7 +17,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import SDSingleFileTesterMixin diff --git a/tests/single_file/test_stable_diffusion_xl_adapter_single_file.py b/tests/single_file/test_stable_diffusion_xl_adapter_single_file.py index fb5f8725b8..3de9ee7364 100644 --- a/tests/single_file/test_stable_diffusion_xl_adapter_single_file.py +++ b/tests/single_file/test_stable_diffusion_xl_adapter_single_file.py @@ -10,7 +10,8 @@ from diffusers import ( ) from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -18,7 +19,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import ( SDXLSingleFileTesterMixin, download_diffusers_config, diff --git a/tests/single_file/test_stable_diffusion_xl_controlnet_single_file.py b/tests/single_file/test_stable_diffusion_xl_controlnet_single_file.py index 6d8c4369e1..a0a1aba103 100644 --- a/tests/single_file/test_stable_diffusion_xl_controlnet_single_file.py +++ b/tests/single_file/test_stable_diffusion_xl_controlnet_single_file.py @@ -7,7 +7,8 @@ import torch from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -15,7 +16,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import ( SDXLSingleFileTesterMixin, download_diffusers_config, diff --git a/tests/single_file/test_stable_diffusion_xl_img2img_single_file.py b/tests/single_file/test_stable_diffusion_xl_img2img_single_file.py index 7df8b84bc2..810f412f8d 100644 --- a/tests/single_file/test_stable_diffusion_xl_img2img_single_file.py +++ b/tests/single_file/test_stable_diffusion_xl_img2img_single_file.py @@ -8,7 +8,8 @@ from diffusers import ( StableDiffusionXLImg2ImgPipeline, ) from diffusers.utils import load_image -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, numpy_cosine_similarity_distance, @@ -16,7 +17,6 @@ from diffusers.utils.testing_utils import ( slow, torch_device, ) - from .single_file_testing_utils import SDXLSingleFileTesterMixin diff --git a/tests/single_file/test_stable_diffusion_xl_instruct_pix2pix.py b/tests/single_file/test_stable_diffusion_xl_instruct_pix2pix.py index 5a01463863..011d59222a 100644 --- a/tests/single_file/test_stable_diffusion_xl_instruct_pix2pix.py +++ b/tests/single_file/test_stable_diffusion_xl_instruct_pix2pix.py @@ -4,7 +4,8 @@ import unittest import torch from diffusers import StableDiffusionXLInstructPix2PixPipeline -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, diff --git a/tests/single_file/test_stable_diffusion_xl_single_file.py b/tests/single_file/test_stable_diffusion_xl_single_file.py index 77f58d8592..0ad180de17 100644 --- a/tests/single_file/test_stable_diffusion_xl_single_file.py +++ b/tests/single_file/test_stable_diffusion_xl_single_file.py @@ -6,14 +6,14 @@ import torch from diffusers import ( StableDiffusionXLPipeline, ) -from diffusers.utils.testing_utils import ( + +from ..testing_utils import ( backend_empty_cache, enable_full_determinism, require_torch_accelerator, slow, torch_device, ) - from .single_file_testing_utils import SDXLSingleFileTesterMixin diff --git a/tests/testing_utils.py b/tests/testing_utils.py new file mode 100644 index 0000000000..7f849219c1 --- /dev/null +++ b/tests/testing_utils.py @@ -0,0 +1,1557 @@ +import functools +import glob +import importlib +import importlib.metadata +import inspect +import io +import logging +import multiprocessing +import os +import random +import re +import struct +import sys +import tempfile +import time +import unittest +import urllib.parse +from collections import UserDict +from contextlib import contextmanager +from io import BytesIO, StringIO +from pathlib import Path +from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple, Union + +import numpy as np +import PIL.Image +import PIL.ImageOps +import requests +from numpy.linalg import norm +from packaging import version + +from diffusers.utils.constants import DIFFUSERS_REQUEST_TIMEOUT +from diffusers.utils.import_utils import ( + BACKENDS_MAPPING, + is_accelerate_available, + is_bitsandbytes_available, + is_compel_available, + is_flax_available, + is_gguf_available, + is_kernels_available, + is_note_seq_available, + is_onnx_available, + is_opencv_available, + is_optimum_quanto_available, + is_peft_available, + is_timm_available, + is_torch_available, + is_torch_version, + is_torchao_available, + is_torchsde_available, + is_transformers_available, +) +from diffusers.utils.logging import get_logger + + +if is_torch_available(): + import torch + + IS_ROCM_SYSTEM = torch.version.hip is not None + IS_CUDA_SYSTEM = torch.version.cuda is not None + IS_XPU_SYSTEM = getattr(torch.version, "xpu", None) is not None +else: + IS_ROCM_SYSTEM = False + IS_CUDA_SYSTEM = False + IS_XPU_SYSTEM = False + +global_rng = random.Random() + +logger = get_logger(__name__) + +_required_peft_version = is_peft_available() and version.parse( + version.parse(importlib.metadata.version("peft")).base_version +) > version.parse("0.5") +_required_transformers_version = is_transformers_available() and version.parse( + version.parse(importlib.metadata.version("transformers")).base_version +) > version.parse("4.33") + +USE_PEFT_BACKEND = _required_peft_version and _required_transformers_version +BIG_GPU_MEMORY = int(os.getenv("BIG_GPU_MEMORY", 40)) + +if is_torch_available(): + import torch + + # Set a backend environment variable for any extra module import required for a custom accelerator + if "DIFFUSERS_TEST_BACKEND" in os.environ: + backend = os.environ["DIFFUSERS_TEST_BACKEND"] + try: + _ = importlib.import_module(backend) + except ModuleNotFoundError as e: + raise ModuleNotFoundError( + f"Failed to import `DIFFUSERS_TEST_BACKEND` '{backend}'! This should be the name of an installed module \ + to enable a specified backend.):\n{e}" + ) from e + + if "DIFFUSERS_TEST_DEVICE" in os.environ: + torch_device = os.environ["DIFFUSERS_TEST_DEVICE"] + try: + # try creating device to see if provided device is valid + _ = torch.device(torch_device) + except RuntimeError as e: + raise RuntimeError( + f"Unknown testing device specified by environment variable `DIFFUSERS_TEST_DEVICE`: {torch_device}" + ) from e + logger.info(f"torch_device overrode to {torch_device}") + else: + if torch.cuda.is_available(): + torch_device = "cuda" + elif torch.xpu.is_available(): + torch_device = "xpu" + else: + torch_device = "cpu" + is_torch_higher_equal_than_1_12 = version.parse( + version.parse(torch.__version__).base_version + ) >= version.parse("1.12") + + if is_torch_higher_equal_than_1_12: + # Some builds of torch 1.12 don't have the mps backend registered. See #892 for more details + mps_backend_registered = hasattr(torch.backends, "mps") + torch_device = "mps" if (mps_backend_registered and torch.backends.mps.is_available()) else torch_device + + from diffusers.utils.torch_utils import get_torch_cuda_device_capability + + +def torch_all_close(a, b, *args, **kwargs): + if not is_torch_available(): + raise ValueError("PyTorch needs to be installed to use this function.") + if not torch.allclose(a, b, *args, **kwargs): + assert False, f"Max diff is absolute {(a - b).abs().max()}. Diff tensor is {(a - b).abs()}." + return True + + +def numpy_cosine_similarity_distance(a, b): + similarity = np.dot(a, b) / (norm(a) * norm(b)) + distance = 1.0 - similarity.mean() + + return distance + + +def check_if_dicts_are_equal(dict1, dict2): + dict1, dict2 = dict1.copy(), dict2.copy() + + for key, value in dict1.items(): + if isinstance(value, set): + dict1[key] = sorted(value) + for key, value in dict2.items(): + if isinstance(value, set): + dict2[key] = sorted(value) + + for key in dict1: + if key not in dict2: + return False + if dict1[key] != dict2[key]: + return False + + for key in dict2: + if key not in dict1: + return False + + return True + + +def print_tensor_test( + tensor, + limit_to_slices=None, + max_torch_print=None, + filename="test_corrections.txt", + expected_tensor_name="expected_slice", +): + if max_torch_print: + torch.set_printoptions(threshold=10_000) + + test_name = os.environ.get("PYTEST_CURRENT_TEST") + if not torch.is_tensor(tensor): + tensor = torch.from_numpy(tensor) + if limit_to_slices: + tensor = tensor[0, -3:, -3:, -1] + + tensor_str = str(tensor.detach().cpu().flatten().to(torch.float32)).replace("\n", "") + # format is usually: + # expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.04663, -0.879, 0.76, -1.734, 0.1044, 1.161]) + output_str = tensor_str.replace("tensor", f"{expected_tensor_name} = np.array") + test_file, test_class, test_fn = test_name.split("::") + test_fn = test_fn.split()[0] + with open(filename, "a") as f: + print("::".join([test_file, test_class, test_fn, output_str]), file=f) + + +def get_tests_dir(append_path=None): + """ + Args: + append_path: optional path to append to the tests dir path + Return: + The full path to the `tests` dir, so that the tests can be invoked from anywhere. Optionally `append_path` is + joined after the `tests` dir the former is provided. + """ + # this function caller's __file__ + caller__file__ = inspect.stack()[1][1] + tests_dir = os.path.abspath(os.path.dirname(caller__file__)) + + while not tests_dir.endswith("tests"): + tests_dir = os.path.dirname(tests_dir) + + if append_path: + return Path(tests_dir, append_path).as_posix() + else: + return tests_dir + + +# Taken from the following PR: +# https://github.com/huggingface/accelerate/pull/1964 +def str_to_bool(value) -> int: + """ + Converts a string representation of truth to `True` (1) or `False` (0). True values are `y`, `yes`, `t`, `true`, + `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`; + """ + value = value.lower() + if value in ("y", "yes", "t", "true", "on", "1"): + return 1 + elif value in ("n", "no", "f", "false", "off", "0"): + return 0 + else: + raise ValueError(f"invalid truth value {value}") + + +def parse_flag_from_env(key, default=False): + try: + value = os.environ[key] + except KeyError: + # KEY isn't set, default to `default`. + _value = default + else: + # KEY is set, convert it to True or False. + try: + _value = str_to_bool(value) + except ValueError: + # More values are supported, but let's keep the message simple. + raise ValueError(f"If set, {key} must be yes or no.") + return _value + + +_run_slow_tests = parse_flag_from_env("RUN_SLOW", default=False) +_run_nightly_tests = parse_flag_from_env("RUN_NIGHTLY", default=False) +_run_compile_tests = parse_flag_from_env("RUN_COMPILE", default=False) + + +def floats_tensor(shape, scale=1.0, rng=None, name=None): + """Creates a random float32 tensor""" + if rng is None: + rng = global_rng + + total_dims = 1 + for dim in shape: + total_dims *= dim + + values = [] + for _ in range(total_dims): + values.append(rng.random() * scale) + + return torch.tensor(data=values, dtype=torch.float).view(shape).contiguous() + + +def slow(test_case): + """ + Decorator marking a test as slow. + + Slow tests are skipped by default. Set the RUN_SLOW environment variable to a truthy value to run them. + + """ + return unittest.skipUnless(_run_slow_tests, "test is slow")(test_case) + + +def nightly(test_case): + """ + Decorator marking a test that runs nightly in the diffusers CI. + + Slow tests are skipped by default. Set the RUN_NIGHTLY environment variable to a truthy value to run them. + + """ + return unittest.skipUnless(_run_nightly_tests, "test is nightly")(test_case) + + +def is_torch_compile(test_case): + """ + Decorator marking a test that runs compile tests in the diffusers CI. + + Compile tests are skipped by default. Set the RUN_COMPILE environment variable to a truthy value to run them. + + """ + return unittest.skipUnless(_run_compile_tests, "test is torch compile")(test_case) + + +def require_torch(test_case): + """ + Decorator marking a test that requires PyTorch. These tests are skipped when PyTorch isn't installed. + """ + return unittest.skipUnless(is_torch_available(), "test requires PyTorch")(test_case) + + +def require_torch_2(test_case): + """ + Decorator marking a test that requires PyTorch 2. These tests are skipped when it isn't installed. + """ + return unittest.skipUnless(is_torch_available() and is_torch_version(">=", "2.0.0"), "test requires PyTorch 2")( + test_case + ) + + +def require_torch_version_greater_equal(torch_version): + """Decorator marking a test that requires torch with a specific version or greater.""" + + def decorator(test_case): + correct_torch_version = is_torch_available() and is_torch_version(">=", torch_version) + return unittest.skipUnless( + correct_torch_version, f"test requires torch with the version greater than or equal to {torch_version}" + )(test_case) + + return decorator + + +def require_torch_version_greater(torch_version): + """Decorator marking a test that requires torch with a specific version greater.""" + + def decorator(test_case): + correct_torch_version = is_torch_available() and is_torch_version(">", torch_version) + return unittest.skipUnless( + correct_torch_version, f"test requires torch with the version greater than {torch_version}" + )(test_case) + + return decorator + + +def require_torch_gpu(test_case): + """Decorator marking a test that requires CUDA and PyTorch.""" + return unittest.skipUnless(is_torch_available() and torch_device == "cuda", "test requires PyTorch+CUDA")( + test_case + ) + + +def require_torch_cuda_compatibility(expected_compute_capability): + def decorator(test_case): + if torch.cuda.is_available(): + current_compute_capability = get_torch_cuda_device_capability() + return unittest.skipUnless( + float(current_compute_capability) == float(expected_compute_capability), + "Test not supported for this compute capability.", + ) + + return decorator + + +# These decorators are for accelerator-specific behaviours that are not GPU-specific +def require_torch_accelerator(test_case): + """Decorator marking a test that requires an accelerator backend and PyTorch.""" + return unittest.skipUnless(is_torch_available() and torch_device != "cpu", "test requires accelerator+PyTorch")( + test_case + ) + + +def require_torch_multi_gpu(test_case): + """ + Decorator marking a test that requires a multi-GPU setup (in PyTorch). These tests are skipped on a machine without + multiple GPUs. To run *only* the multi_gpu tests, assuming all test names contain multi_gpu: $ pytest -sv ./tests + -k "multi_gpu" + """ + if not is_torch_available(): + return unittest.skip("test requires PyTorch")(test_case) + + import torch + + return unittest.skipUnless(torch.cuda.device_count() > 1, "test requires multiple GPUs")(test_case) + + +def require_torch_multi_accelerator(test_case): + """ + Decorator marking a test that requires a multi-accelerator setup (in PyTorch). These tests are skipped on a machine + without multiple hardware accelerators. + """ + if not is_torch_available(): + return unittest.skip("test requires PyTorch")(test_case) + + import torch + + return unittest.skipUnless( + torch.cuda.device_count() > 1 or torch.xpu.device_count() > 1, "test requires multiple hardware accelerators" + )(test_case) + + +def require_torch_accelerator_with_fp16(test_case): + """Decorator marking a test that requires an accelerator with support for the FP16 data type.""" + return unittest.skipUnless(_is_torch_fp16_available(torch_device), "test requires accelerator with fp16 support")( + test_case + ) + + +def require_torch_accelerator_with_fp64(test_case): + """Decorator marking a test that requires an accelerator with support for the FP64 data type.""" + return unittest.skipUnless(_is_torch_fp64_available(torch_device), "test requires accelerator with fp64 support")( + test_case + ) + + +def require_big_gpu_with_torch_cuda(test_case): + """ + Decorator marking a test that requires a bigger GPU (24GB) for execution. Some example pipelines: Flux, SD3, Cog, + etc. + """ + if not is_torch_available(): + return unittest.skip("test requires PyTorch")(test_case) + + import torch + + if not torch.cuda.is_available(): + return unittest.skip("test requires PyTorch CUDA")(test_case) + + device_properties = torch.cuda.get_device_properties(0) + total_memory = device_properties.total_memory / (1024**3) + return unittest.skipUnless( + total_memory >= BIG_GPU_MEMORY, f"test requires a GPU with at least {BIG_GPU_MEMORY} GB memory" + )(test_case) + + +def require_big_accelerator(test_case): + """ + Decorator marking a test that requires a bigger hardware accelerator (24GB) for execution. Some example pipelines: + Flux, SD3, Cog, etc. + """ + import pytest + + test_case = pytest.mark.big_accelerator(test_case) + + if not is_torch_available(): + return unittest.skip("test requires PyTorch")(test_case) + + import torch + + if not (torch.cuda.is_available() or torch.xpu.is_available()): + return unittest.skip("test requires PyTorch CUDA")(test_case) + + if torch.xpu.is_available(): + device_properties = torch.xpu.get_device_properties(0) + else: + device_properties = torch.cuda.get_device_properties(0) + + total_memory = device_properties.total_memory / (1024**3) + return unittest.skipUnless( + total_memory >= BIG_GPU_MEMORY, + f"test requires a hardware accelerator with at least {BIG_GPU_MEMORY} GB memory", + )(test_case) + + +def require_torch_accelerator_with_training(test_case): + """Decorator marking a test that requires an accelerator with support for training.""" + return unittest.skipUnless( + is_torch_available() and backend_supports_training(torch_device), + "test requires accelerator with training support", + )(test_case) + + +def skip_mps(test_case): + """Decorator marking a test to skip if torch_device is 'mps'""" + return unittest.skipUnless(torch_device != "mps", "test requires non 'mps' device")(test_case) + + +def require_flax(test_case): + """ + Decorator marking a test that requires JAX & Flax. These tests are skipped when one / both are not installed + """ + return unittest.skipUnless(is_flax_available(), "test requires JAX & Flax")(test_case) + + +def require_compel(test_case): + """ + Decorator marking a test that requires compel: https://github.com/damian0815/compel. These tests are skipped when + the library is not installed. + """ + return unittest.skipUnless(is_compel_available(), "test requires compel")(test_case) + + +def require_onnxruntime(test_case): + """ + Decorator marking a test that requires onnxruntime. These tests are skipped when onnxruntime isn't installed. + """ + return unittest.skipUnless(is_onnx_available(), "test requires onnxruntime")(test_case) + + +def require_note_seq(test_case): + """ + Decorator marking a test that requires note_seq. These tests are skipped when note_seq isn't installed. + """ + return unittest.skipUnless(is_note_seq_available(), "test requires note_seq")(test_case) + + +def require_accelerator(test_case): + """ + Decorator marking a test that requires a hardware accelerator backend. These tests are skipped when there are no + hardware accelerator available. + """ + return unittest.skipUnless(torch_device != "cpu", "test requires a hardware accelerator")(test_case) + + +def require_torchsde(test_case): + """ + Decorator marking a test that requires torchsde. These tests are skipped when torchsde isn't installed. + """ + return unittest.skipUnless(is_torchsde_available(), "test requires torchsde")(test_case) + + +def require_peft_backend(test_case): + """ + Decorator marking a test that requires PEFT backend, this would require some specific versions of PEFT and + transformers. + """ + return unittest.skipUnless(USE_PEFT_BACKEND, "test requires PEFT backend")(test_case) + + +def require_timm(test_case): + """ + Decorator marking a test that requires timm. These tests are skipped when timm isn't installed. + """ + return unittest.skipUnless(is_timm_available(), "test requires timm")(test_case) + + +def require_bitsandbytes(test_case): + """ + Decorator marking a test that requires bitsandbytes. These tests are skipped when bitsandbytes isn't installed. + """ + return unittest.skipUnless(is_bitsandbytes_available(), "test requires bitsandbytes")(test_case) + + +def require_quanto(test_case): + """ + Decorator marking a test that requires quanto. These tests are skipped when quanto isn't installed. + """ + return unittest.skipUnless(is_optimum_quanto_available(), "test requires quanto")(test_case) + + +def require_accelerate(test_case): + """ + Decorator marking a test that requires accelerate. These tests are skipped when accelerate isn't installed. + """ + return unittest.skipUnless(is_accelerate_available(), "test requires accelerate")(test_case) + + +def require_peft_version_greater(peft_version): + """ + Decorator marking a test that requires PEFT backend with a specific version, this would require some specific + versions of PEFT and transformers. + """ + + def decorator(test_case): + correct_peft_version = is_peft_available() and version.parse( + version.parse(importlib.metadata.version("peft")).base_version + ) > version.parse(peft_version) + return unittest.skipUnless( + correct_peft_version, f"test requires PEFT backend with the version greater than {peft_version}" + )(test_case) + + return decorator + + +def require_transformers_version_greater(transformers_version): + """ + Decorator marking a test that requires transformers with a specific version, this would require some specific + versions of PEFT and transformers. + """ + + def decorator(test_case): + correct_transformers_version = is_transformers_available() and version.parse( + version.parse(importlib.metadata.version("transformers")).base_version + ) > version.parse(transformers_version) + return unittest.skipUnless( + correct_transformers_version, + f"test requires transformers with the version greater than {transformers_version}", + )(test_case) + + return decorator + + +def require_accelerate_version_greater(accelerate_version): + def decorator(test_case): + correct_accelerate_version = is_accelerate_available() and version.parse( + version.parse(importlib.metadata.version("accelerate")).base_version + ) > version.parse(accelerate_version) + return unittest.skipUnless( + correct_accelerate_version, f"Test requires accelerate with the version greater than {accelerate_version}." + )(test_case) + + return decorator + + +def require_bitsandbytes_version_greater(bnb_version): + def decorator(test_case): + correct_bnb_version = is_bitsandbytes_available() and version.parse( + version.parse(importlib.metadata.version("bitsandbytes")).base_version + ) > version.parse(bnb_version) + return unittest.skipUnless( + correct_bnb_version, f"Test requires bitsandbytes with the version greater than {bnb_version}." + )(test_case) + + return decorator + + +def require_hf_hub_version_greater(hf_hub_version): + def decorator(test_case): + correct_hf_hub_version = version.parse( + version.parse(importlib.metadata.version("huggingface_hub")).base_version + ) > version.parse(hf_hub_version) + return unittest.skipUnless( + correct_hf_hub_version, f"Test requires huggingface_hub with the version greater than {hf_hub_version}." + )(test_case) + + return decorator + + +def require_gguf_version_greater_or_equal(gguf_version): + def decorator(test_case): + correct_gguf_version = is_gguf_available() and version.parse( + version.parse(importlib.metadata.version("gguf")).base_version + ) >= version.parse(gguf_version) + return unittest.skipUnless( + correct_gguf_version, f"Test requires gguf with the version greater than {gguf_version}." + )(test_case) + + return decorator + + +def require_torchao_version_greater_or_equal(torchao_version): + def decorator(test_case): + correct_torchao_version = is_torchao_available() and version.parse( + version.parse(importlib.metadata.version("torchao")).base_version + ) >= version.parse(torchao_version) + return unittest.skipUnless( + correct_torchao_version, f"Test requires torchao with version greater than {torchao_version}." + )(test_case) + + return decorator + + +def require_kernels_version_greater_or_equal(kernels_version): + def decorator(test_case): + correct_kernels_version = is_kernels_available() and version.parse( + version.parse(importlib.metadata.version("kernels")).base_version + ) >= version.parse(kernels_version) + return unittest.skipUnless( + correct_kernels_version, f"Test requires kernels with version greater than {kernels_version}." + )(test_case) + + return decorator + + +def deprecate_after_peft_backend(test_case): + """ + Decorator marking a test that will be skipped after PEFT backend + """ + return unittest.skipUnless(not USE_PEFT_BACKEND, "test skipped in favor of PEFT backend")(test_case) + + +def get_python_version(): + sys_info = sys.version_info + major, minor = sys_info.major, sys_info.minor + return major, minor + + +def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray: + if isinstance(arry, str): + if local_path is not None: + # local_path can be passed to correct images of tests + return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix() + elif arry.startswith("http://") or arry.startswith("https://"): + response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT) + response.raise_for_status() + arry = np.load(BytesIO(response.content)) + elif os.path.isfile(arry): + arry = np.load(arry) + else: + raise ValueError( + f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path" + ) + elif isinstance(arry, np.ndarray): + pass + else: + raise ValueError( + "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a" + " ndarray." + ) + + return arry + + +def load_pt(url: str, map_location: Optional[str] = None, weights_only: Optional[bool] = True): + response = requests.get(url, timeout=DIFFUSERS_REQUEST_TIMEOUT) + response.raise_for_status() + arry = torch.load(BytesIO(response.content), map_location=map_location, weights_only=weights_only) + return arry + + +def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image: + """ + Loads `image` to a PIL Image. + + Args: + image (`str` or `PIL.Image.Image`): + The image to convert to the PIL Image format. + Returns: + `PIL.Image.Image`: + A PIL Image. + """ + if isinstance(image, str): + if image.startswith("http://") or image.startswith("https://"): + image = PIL.Image.open(requests.get(image, stream=True, timeout=DIFFUSERS_REQUEST_TIMEOUT).raw) + elif os.path.isfile(image): + image = PIL.Image.open(image) + else: + raise ValueError( + f"Incorrect path or url, URLs must start with `http://` or `https://`, and {image} is not a valid path" + ) + elif isinstance(image, PIL.Image.Image): + image = image + else: + raise ValueError( + "Incorrect format used for image. Should be an url linking to an image, a local path, or a PIL image." + ) + image = PIL.ImageOps.exif_transpose(image) + image = image.convert("RGB") + return image + + +def preprocess_image(image: PIL.Image, batch_size: int): + w, h = image.size + w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8 + image = image.resize((w, h), resample=PIL.Image.LANCZOS) + image = np.array(image).astype(np.float32) / 255.0 + image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size) + image = torch.from_numpy(image) + return 2.0 * image - 1.0 + + +def export_to_gif(image: List[PIL.Image.Image], output_gif_path: str = None) -> str: + if output_gif_path is None: + output_gif_path = tempfile.NamedTemporaryFile(suffix=".gif").name + + image[0].save( + output_gif_path, + save_all=True, + append_images=image[1:], + optimize=False, + duration=100, + loop=0, + ) + return output_gif_path + + +@contextmanager +def buffered_writer(raw_f): + f = io.BufferedWriter(raw_f) + yield f + f.flush() + + +def export_to_ply(mesh, output_ply_path: str = None): + """ + Write a PLY file for a mesh. + """ + if output_ply_path is None: + output_ply_path = tempfile.NamedTemporaryFile(suffix=".ply").name + + coords = mesh.verts.detach().cpu().numpy() + faces = mesh.faces.cpu().numpy() + rgb = np.stack([mesh.vertex_channels[x].detach().cpu().numpy() for x in "RGB"], axis=1) + + with buffered_writer(open(output_ply_path, "wb")) as f: + f.write(b"ply\n") + f.write(b"format binary_little_endian 1.0\n") + f.write(bytes(f"element vertex {len(coords)}\n", "ascii")) + f.write(b"property float x\n") + f.write(b"property float y\n") + f.write(b"property float z\n") + if rgb is not None: + f.write(b"property uchar red\n") + f.write(b"property uchar green\n") + f.write(b"property uchar blue\n") + if faces is not None: + f.write(bytes(f"element face {len(faces)}\n", "ascii")) + f.write(b"property list uchar int vertex_index\n") + f.write(b"end_header\n") + + if rgb is not None: + rgb = (rgb * 255.499).round().astype(int) + vertices = [ + (*coord, *rgb) + for coord, rgb in zip( + coords.tolist(), + rgb.tolist(), + ) + ] + format = struct.Struct("<3f3B") + for item in vertices: + f.write(format.pack(*item)) + else: + format = struct.Struct("<3f") + for vertex in coords.tolist(): + f.write(format.pack(*vertex)) + + if faces is not None: + format = struct.Struct(" str: + if is_opencv_available(): + import cv2 + else: + raise ImportError(BACKENDS_MAPPING["opencv"][1].format("export_to_video")) + if output_video_path is None: + output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name + + fourcc = cv2.VideoWriter_fourcc(*"mp4v") + h, w, c = video_frames[0].shape + video_writer = cv2.VideoWriter(output_video_path, fourcc, fps=8, frameSize=(w, h)) + for i in range(len(video_frames)): + img = cv2.cvtColor(video_frames[i], cv2.COLOR_RGB2BGR) + video_writer.write(img) + return output_video_path + + +def load_hf_numpy(path) -> np.ndarray: + base_url = "https://huggingface.co/datasets/fusing/diffusers-testing/resolve/main" + + if not path.startswith("http://") and not path.startswith("https://"): + path = os.path.join(base_url, urllib.parse.quote(path)) + + return load_numpy(path) + + +# --- pytest conf functions --- # + +# to avoid multiple invocation from tests/conftest.py and examples/conftest.py - make sure it's called only once +pytest_opt_registered = {} + + +def pytest_addoption_shared(parser): + """ + This function is to be called from `conftest.py` via `pytest_addoption` wrapper that has to be defined there. + + It allows loading both `conftest.py` files at once without causing a failure due to adding the same `pytest` + option. + + """ + option = "--make-reports" + if option not in pytest_opt_registered: + parser.addoption( + option, + action="store", + default=False, + help="generate report files. The value of this option is used as a prefix to report names", + ) + pytest_opt_registered[option] = 1 + + +def pytest_terminal_summary_main(tr, id): + """ + Generate multiple reports at the end of test suite run - each report goes into a dedicated file in the current + directory. The report files are prefixed with the test suite name. + + This function emulates --duration and -rA pytest arguments. + + This function is to be called from `conftest.py` via `pytest_terminal_summary` wrapper that has to be defined + there. + + Args: + - tr: `terminalreporter` passed from `conftest.py` + - id: unique id like `tests` or `examples` that will be incorporated into the final reports filenames - this is + needed as some jobs have multiple runs of pytest, so we can't have them overwrite each other. + + NB: this functions taps into a private _pytest API and while unlikely, it could break should + pytest do internal changes - also it calls default internal methods of terminalreporter which + can be hijacked by various `pytest-` plugins and interfere. + + """ + from _pytest.config import create_terminal_writer + + if not len(id): + id = "tests" + + config = tr.config + orig_writer = config.get_terminal_writer() + orig_tbstyle = config.option.tbstyle + orig_reportchars = tr.reportchars + + dir = "reports" + Path(dir).mkdir(parents=True, exist_ok=True) + report_files = { + k: f"{dir}/{id}_{k}.txt" + for k in [ + "durations", + "errors", + "failures_long", + "failures_short", + "failures_line", + "passes", + "stats", + "summary_short", + "warnings", + ] + } + + # custom durations report + # note: there is no need to call pytest --durations=XX to get this separate report + # adapted from https://github.com/pytest-dev/pytest/blob/897f151e/src/_pytest/runner.py#L66 + dlist = [] + for replist in tr.stats.values(): + for rep in replist: + if hasattr(rep, "duration"): + dlist.append(rep) + if dlist: + dlist.sort(key=lambda x: x.duration, reverse=True) + with open(report_files["durations"], "w") as f: + durations_min = 0.05 # sec + f.write("slowest durations\n") + for i, rep in enumerate(dlist): + if rep.duration < durations_min: + f.write(f"{len(dlist) - i} durations < {durations_min} secs were omitted") + break + f.write(f"{rep.duration:02.2f}s {rep.when:<8} {rep.nodeid}\n") + + def summary_failures_short(tr): + # expecting that the reports were --tb=long (default) so we chop them off here to the last frame + reports = tr.getreports("failed") + if not reports: + return + tr.write_sep("=", "FAILURES SHORT STACK") + for rep in reports: + msg = tr._getfailureheadline(rep) + tr.write_sep("_", msg, red=True, bold=True) + # chop off the optional leading extra frames, leaving only the last one + longrepr = re.sub(r".*_ _ _ (_ ){10,}_ _ ", "", rep.longreprtext, 0, re.M | re.S) + tr._tw.line(longrepr) + # note: not printing out any rep.sections to keep the report short + + # use ready-made report funcs, we are just hijacking the filehandle to log to a dedicated file each + # adapted from https://github.com/pytest-dev/pytest/blob/897f151e/src/_pytest/terminal.py#L814 + # note: some pytest plugins may interfere by hijacking the default `terminalreporter` (e.g. + # pytest-instafail does that) + + # report failures with line/short/long styles + config.option.tbstyle = "auto" # full tb + with open(report_files["failures_long"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.summary_failures() + + # config.option.tbstyle = "short" # short tb + with open(report_files["failures_short"], "w") as f: + tr._tw = create_terminal_writer(config, f) + summary_failures_short(tr) + + config.option.tbstyle = "line" # one line per error + with open(report_files["failures_line"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.summary_failures() + + with open(report_files["errors"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.summary_errors() + + with open(report_files["warnings"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.summary_warnings() # normal warnings + tr.summary_warnings() # final warnings + + tr.reportchars = "wPpsxXEf" # emulate -rA (used in summary_passes() and short_test_summary()) + with open(report_files["passes"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.summary_passes() + + with open(report_files["summary_short"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.short_test_summary() + + with open(report_files["stats"], "w") as f: + tr._tw = create_terminal_writer(config, f) + tr.summary_stats() + + # restore: + tr._tw = orig_writer + tr.reportchars = orig_reportchars + config.option.tbstyle = orig_tbstyle + + +# Adapted from https://github.com/huggingface/transformers/blob/000e52aec8850d3fe2f360adc6fd256e5b47fe4c/src/transformers..testing_utils.py#L1905 +def is_flaky(max_attempts: int = 5, wait_before_retry: Optional[float] = None, description: Optional[str] = None): + """ + To decorate flaky tests (methods or entire classes). They will be retried on failures. + + Args: + max_attempts (`int`, *optional*, defaults to 5): + The maximum number of attempts to retry the flaky test. + wait_before_retry (`float`, *optional*): + If provided, will wait that number of seconds before retrying the test. + description (`str`, *optional*): + A string to describe the situation (what / where / why is flaky, link to GH issue/PR comments, errors, + etc.) + """ + + def decorator(obj): + # If decorating a class, wrap each test method on it + if inspect.isclass(obj): + for attr_name, attr_value in list(obj.__dict__.items()): + if callable(attr_value) and attr_name.startswith("test"): + # recursively decorate the method + setattr(obj, attr_name, decorator(attr_value)) + return obj + + # Otherwise we're decorating a single test function / method + @functools.wraps(obj) + def wrapper(*args, **kwargs): + retry_count = 1 + while retry_count < max_attempts: + try: + return obj(*args, **kwargs) + except Exception as err: + msg = ( + f"[FLAKY] {description or obj.__name__!r} " + f"failed on attempt {retry_count}/{max_attempts}: {err}" + ) + print(msg, file=sys.stderr) + if wait_before_retry is not None: + time.sleep(wait_before_retry) + retry_count += 1 + + return obj(*args, **kwargs) + + return wrapper + + return decorator + + +# Taken from: https://github.com/huggingface/transformers/blob/3658488ff77ff8d45101293e749263acf437f4d5/src/transformers..testing_utils.py#L1787 +def run_test_in_subprocess(test_case, target_func, inputs=None, timeout=None): + """ + To run a test in a subprocess. In particular, this can avoid (GPU) memory issue. + + Args: + test_case (`unittest.TestCase`): + The test that will run `target_func`. + target_func (`Callable`): + The function implementing the actual testing logic. + inputs (`dict`, *optional*, defaults to `None`): + The inputs that will be passed to `target_func` through an (input) queue. + timeout (`int`, *optional*, defaults to `None`): + The timeout (in seconds) that will be passed to the input and output queues. If not specified, the env. + variable `PYTEST_TIMEOUT` will be checked. If still `None`, its value will be set to `600`. + """ + if timeout is None: + timeout = int(os.environ.get("PYTEST_TIMEOUT", 600)) + + start_methohd = "spawn" + ctx = multiprocessing.get_context(start_methohd) + + input_queue = ctx.Queue(1) + output_queue = ctx.JoinableQueue(1) + + # We can't send `unittest.TestCase` to the child, otherwise we get issues regarding pickle. + input_queue.put(inputs, timeout=timeout) + + process = ctx.Process(target=target_func, args=(input_queue, output_queue, timeout)) + process.start() + # Kill the child process if we can't get outputs from it in time: otherwise, the hanging subprocess prevents + # the test to exit properly. + try: + results = output_queue.get(timeout=timeout) + output_queue.task_done() + except Exception as e: + process.terminate() + test_case.fail(e) + process.join(timeout=timeout) + + if results["error"] is not None: + test_case.fail(f"{results['error']}") + + +class CaptureLogger: + """ + Args: + Context manager to capture `logging` streams + logger: 'logging` logger object + Returns: + The captured output is available via `self.out` + Example: + ```python + >>> from diffusers import logging + >>> from diffusers..testing_utils import CaptureLogger + + >>> msg = "Testing 1, 2, 3" + >>> logging.set_verbosity_info() + >>> logger = logging.get_logger("diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.py") + >>> with CaptureLogger(logger) as cl: + ... logger.info(msg) + >>> assert cl.out, msg + "\n" + ``` + """ + + def __init__(self, logger): + self.logger = logger + self.io = StringIO() + self.sh = logging.StreamHandler(self.io) + self.out = "" + + def __enter__(self): + self.logger.addHandler(self.sh) + return self + + def __exit__(self, *exc): + self.logger.removeHandler(self.sh) + self.out = self.io.getvalue() + + def __repr__(self): + return f"captured: {self.out}\n" + + +def enable_full_determinism(): + """ + Helper function for reproducible behavior during distributed training. See + - https://pytorch.org/docs/stable/notes/randomness.html for pytorch + """ + # Enable PyTorch deterministic mode. This potentially requires either the environment + # variable 'CUDA_LAUNCH_BLOCKING' or 'CUBLAS_WORKSPACE_CONFIG' to be set, + # depending on the CUDA version, so we set them both here + os.environ["CUDA_LAUNCH_BLOCKING"] = "1" + os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":16:8" + torch.use_deterministic_algorithms(True) + + # Enable CUDNN deterministic mode + torch.backends.cudnn.deterministic = True + torch.backends.cudnn.benchmark = False + torch.backends.cuda.matmul.allow_tf32 = False + + +def disable_full_determinism(): + os.environ["CUDA_LAUNCH_BLOCKING"] = "0" + os.environ["CUBLAS_WORKSPACE_CONFIG"] = "" + torch.use_deterministic_algorithms(False) + + +# Utils for custom and alternative accelerator devices +def _is_torch_fp16_available(device): + if not is_torch_available(): + return False + + import torch + + device = torch.device(device) + + try: + x = torch.zeros((2, 2), dtype=torch.float16).to(device) + _ = torch.mul(x, x) + return True + + except Exception as e: + if device.type == "cuda": + raise ValueError( + f"You have passed a device of type 'cuda' which should work with 'fp16', but 'cuda' does not seem to be correctly installed on your machine: {e}" + ) + + return False + + +def _is_torch_fp64_available(device): + if not is_torch_available(): + return False + + import torch + + device = torch.device(device) + + try: + x = torch.zeros((2, 2), dtype=torch.float64).to(device) + _ = torch.mul(x, x) + return True + + except Exception as e: + if device.type == "cuda": + raise ValueError( + f"You have passed a device of type 'cuda' which should work with 'fp64', but 'cuda' does not seem to be correctly installed on your machine: {e}" + ) + + return False + + +# Guard these lookups for when Torch is not used - alternative accelerator support is for PyTorch +if is_torch_available(): + # Behaviour flags + BACKEND_SUPPORTS_TRAINING = {"cuda": True, "xpu": True, "cpu": True, "mps": False, "default": True} + + # Function definitions + BACKEND_EMPTY_CACHE = { + "cuda": torch.cuda.empty_cache, + "xpu": torch.xpu.empty_cache, + "cpu": None, + "mps": torch.mps.empty_cache, + "default": None, + } + BACKEND_DEVICE_COUNT = { + "cuda": torch.cuda.device_count, + "xpu": torch.xpu.device_count, + "cpu": lambda: 0, + "mps": lambda: 0, + "default": 0, + } + BACKEND_MANUAL_SEED = { + "cuda": torch.cuda.manual_seed, + "xpu": torch.xpu.manual_seed, + "cpu": torch.manual_seed, + "mps": torch.mps.manual_seed, + "default": torch.manual_seed, + } + BACKEND_RESET_PEAK_MEMORY_STATS = { + "cuda": torch.cuda.reset_peak_memory_stats, + "xpu": getattr(torch.xpu, "reset_peak_memory_stats", None), + "cpu": None, + "mps": None, + "default": None, + } + BACKEND_RESET_MAX_MEMORY_ALLOCATED = { + "cuda": torch.cuda.reset_max_memory_allocated, + "xpu": getattr(torch.xpu, "reset_peak_memory_stats", None), + "cpu": None, + "mps": None, + "default": None, + } + BACKEND_MAX_MEMORY_ALLOCATED = { + "cuda": torch.cuda.max_memory_allocated, + "xpu": getattr(torch.xpu, "max_memory_allocated", None), + "cpu": 0, + "mps": 0, + "default": 0, + } + BACKEND_SYNCHRONIZE = { + "cuda": torch.cuda.synchronize, + "xpu": getattr(torch.xpu, "synchronize", None), + "cpu": None, + "mps": None, + "default": None, + } + + +# This dispatches a defined function according to the accelerator from the function definitions. +def _device_agnostic_dispatch(device: str, dispatch_table: Dict[str, Callable], *args, **kwargs): + if device not in dispatch_table: + return dispatch_table["default"](*args, **kwargs) + + fn = dispatch_table[device] + + # Some device agnostic functions return values. Need to guard against 'None' instead at + # user level + if not callable(fn): + return fn + + return fn(*args, **kwargs) + + +# These are callables which automatically dispatch the function specific to the accelerator +def backend_manual_seed(device: str, seed: int): + return _device_agnostic_dispatch(device, BACKEND_MANUAL_SEED, seed) + + +def backend_synchronize(device: str): + return _device_agnostic_dispatch(device, BACKEND_SYNCHRONIZE) + + +def backend_empty_cache(device: str): + return _device_agnostic_dispatch(device, BACKEND_EMPTY_CACHE) + + +def backend_device_count(device: str): + return _device_agnostic_dispatch(device, BACKEND_DEVICE_COUNT) + + +def backend_reset_peak_memory_stats(device: str): + return _device_agnostic_dispatch(device, BACKEND_RESET_PEAK_MEMORY_STATS) + + +def backend_reset_max_memory_allocated(device: str): + return _device_agnostic_dispatch(device, BACKEND_RESET_MAX_MEMORY_ALLOCATED) + + +def backend_max_memory_allocated(device: str): + return _device_agnostic_dispatch(device, BACKEND_MAX_MEMORY_ALLOCATED) + + +# These are callables which return boolean behaviour flags and can be used to specify some +# device agnostic alternative where the feature is unsupported. +def backend_supports_training(device: str): + if not is_torch_available(): + return False + + if device not in BACKEND_SUPPORTS_TRAINING: + device = "default" + + return BACKEND_SUPPORTS_TRAINING[device] + + +# Guard for when Torch is not available +if is_torch_available(): + # Update device function dict mapping + def update_mapping_from_spec(device_fn_dict: Dict[str, Callable], attribute_name: str): + try: + # Try to import the function directly + spec_fn = getattr(device_spec_module, attribute_name) + device_fn_dict[torch_device] = spec_fn + except AttributeError as e: + # If the function doesn't exist, and there is no default, throw an error + if "default" not in device_fn_dict: + raise AttributeError( + f"`{attribute_name}` not found in '{device_spec_path}' and no default fallback function found." + ) from e + + if "DIFFUSERS_TEST_DEVICE_SPEC" in os.environ: + device_spec_path = os.environ["DIFFUSERS_TEST_DEVICE_SPEC"] + if not Path(device_spec_path).is_file(): + raise ValueError(f"Specified path to device specification file is not found. Received {device_spec_path}") + + try: + import_name = device_spec_path[: device_spec_path.index(".py")] + except ValueError as e: + raise ValueError(f"Provided device spec file is not a Python file! Received {device_spec_path}") from e + + device_spec_module = importlib.import_module(import_name) + + try: + device_name = device_spec_module.DEVICE_NAME + except AttributeError: + raise AttributeError("Device spec file did not contain `DEVICE_NAME`") + + if "DIFFUSERS_TEST_DEVICE" in os.environ and torch_device != device_name: + msg = f"Mismatch between environment variable `DIFFUSERS_TEST_DEVICE` '{torch_device}' and device found in spec '{device_name}'\n" + msg += "Either unset `DIFFUSERS_TEST_DEVICE` or ensure it matches device spec name." + raise ValueError(msg) + + torch_device = device_name + + # Add one entry here for each `BACKEND_*` dictionary. + update_mapping_from_spec(BACKEND_MANUAL_SEED, "MANUAL_SEED_FN") + update_mapping_from_spec(BACKEND_EMPTY_CACHE, "EMPTY_CACHE_FN") + update_mapping_from_spec(BACKEND_DEVICE_COUNT, "DEVICE_COUNT_FN") + update_mapping_from_spec(BACKEND_SUPPORTS_TRAINING, "SUPPORTS_TRAINING") + update_mapping_from_spec(BACKEND_RESET_PEAK_MEMORY_STATS, "RESET_PEAK_MEMORY_STATS_FN") + update_mapping_from_spec(BACKEND_RESET_MAX_MEMORY_ALLOCATED, "RESET_MAX_MEMORY_ALLOCATED_FN") + update_mapping_from_spec(BACKEND_MAX_MEMORY_ALLOCATED, "MAX_MEMORY_ALLOCATED_FN") + + +# Modified from https://github.com/huggingface/transformers/blob/cdfb018d0300fef3b07d9220f3efe9c2a9974662/src/transformers..testing_utils.py#L3090 + +# Type definition of key used in `Expectations` class. +DeviceProperties = Tuple[Union[str, None], Union[int, None]] + + +@functools.lru_cache +def get_device_properties() -> DeviceProperties: + """ + Get environment device properties. + """ + if IS_CUDA_SYSTEM or IS_ROCM_SYSTEM: + import torch + + major, _ = torch.cuda.get_device_capability() + if IS_ROCM_SYSTEM: + return ("rocm", major) + else: + return ("cuda", major) + elif IS_XPU_SYSTEM: + import torch + + # To get more info of the architecture meaning and bit allocation, refer to https://github.com/intel/llvm/blob/sycl/sycl/include/sycl/ext/oneapi/experimental/device_architecture.def + arch = torch.xpu.get_device_capability()["architecture"] + gen_mask = 0x000000FF00000000 + gen = (arch & gen_mask) >> 32 + return ("xpu", gen) + else: + return (torch_device, None) + + +if TYPE_CHECKING: + DevicePropertiesUserDict = UserDict[DeviceProperties, Any] +else: + DevicePropertiesUserDict = UserDict + +if is_torch_available(): + from diffusers.hooks._common import _GO_LC_SUPPORTED_PYTORCH_LAYERS + from diffusers.hooks.group_offloading import ( + _GROUP_ID_LAZY_LEAF, + _compute_group_hash, + _find_parent_module_in_module_dict, + _gather_buffers_with_no_group_offloading_parent, + _gather_parameters_with_no_group_offloading_parent, + ) + + def _get_expected_safetensors_files( + module: torch.nn.Module, + offload_to_disk_path: str, + offload_type: str, + num_blocks_per_group: Optional[int] = None, + ) -> Set[str]: + expected_files = set() + + def get_hashed_filename(group_id: str) -> str: + short_hash = _compute_group_hash(group_id) + return os.path.join(offload_to_disk_path, f"group_{short_hash}.safetensors") + + if offload_type == "block_level": + if num_blocks_per_group is None: + raise ValueError("num_blocks_per_group must be provided for 'block_level' offloading.") + + # Handle groups of ModuleList and Sequential blocks + unmatched_modules = [] + for name, submodule in module.named_children(): + if not isinstance(submodule, (torch.nn.ModuleList, torch.nn.Sequential)): + unmatched_modules.append(module) + continue + + for i in range(0, len(submodule), num_blocks_per_group): + current_modules = submodule[i : i + num_blocks_per_group] + if not current_modules: + continue + group_id = f"{name}_{i}_{i + len(current_modules) - 1}" + expected_files.add(get_hashed_filename(group_id)) + + # Handle the group for unmatched top-level modules and parameters + for module in unmatched_modules: + expected_files.add(get_hashed_filename(f"{module.__class__.__name__}_unmatched_group")) + + elif offload_type == "leaf_level": + # Handle leaf-level module groups + for name, submodule in module.named_modules(): + if isinstance(submodule, _GO_LC_SUPPORTED_PYTORCH_LAYERS): + # These groups will always have parameters, so a file is expected + expected_files.add(get_hashed_filename(name)) + + # Handle groups for non-leaf parameters/buffers + modules_with_group_offloading = { + name for name, sm in module.named_modules() if isinstance(sm, _GO_LC_SUPPORTED_PYTORCH_LAYERS) + } + parameters = _gather_parameters_with_no_group_offloading_parent(module, modules_with_group_offloading) + buffers = _gather_buffers_with_no_group_offloading_parent(module, modules_with_group_offloading) + + all_orphans = parameters + buffers + if all_orphans: + parent_to_tensors = {} + module_dict = dict(module.named_modules()) + for tensor_name, _ in all_orphans: + parent_name = _find_parent_module_in_module_dict(tensor_name, module_dict) + if parent_name not in parent_to_tensors: + parent_to_tensors[parent_name] = [] + parent_to_tensors[parent_name].append(tensor_name) + + for parent_name in parent_to_tensors: + # A file is expected for each parent that gathers orphaned tensors + expected_files.add(get_hashed_filename(parent_name)) + expected_files.add(get_hashed_filename(_GROUP_ID_LAZY_LEAF)) + + else: + raise ValueError(f"Unsupported offload_type: {offload_type}") + + return expected_files + + def _check_safetensors_serialization( + module: torch.nn.Module, + offload_to_disk_path: str, + offload_type: str, + num_blocks_per_group: Optional[int] = None, + ) -> bool: + if not os.path.isdir(offload_to_disk_path): + return False, None, None + + expected_files = _get_expected_safetensors_files( + module, offload_to_disk_path, offload_type, num_blocks_per_group + ) + actual_files = set(glob.glob(os.path.join(offload_to_disk_path, "*.safetensors"))) + missing_files = expected_files - actual_files + extra_files = actual_files - expected_files + + is_correct = not missing_files and not extra_files + return is_correct, extra_files, missing_files + + +class Expectations(DevicePropertiesUserDict): + def get_expectation(self) -> Any: + """ + Find best matching expectation based on environment device properties. + """ + return self.find_expectation(get_device_properties()) + + @staticmethod + def is_default(key: DeviceProperties) -> bool: + return all(p is None for p in key) + + @staticmethod + def score(key: DeviceProperties, other: DeviceProperties) -> int: + """ + Returns score indicating how similar two instances of the `Properties` tuple are. Points are calculated using + bits, but documented as int. Rules are as follows: + * Matching `type` gives 8 points. + * Semi-matching `type`, for example cuda and rocm, gives 4 points. + * Matching `major` (compute capability major version) gives 2 points. + * Default expectation (if present) gives 1 points. + """ + (device_type, major) = key + (other_device_type, other_major) = other + + score = 0b0 + if device_type == other_device_type: + score |= 0b1000 + elif device_type in ["cuda", "rocm"] and other_device_type in ["cuda", "rocm"]: + score |= 0b100 + + if major == other_major and other_major is not None: + score |= 0b10 + + if Expectations.is_default(other): + score |= 0b1 + + return int(score) + + def find_expectation(self, key: DeviceProperties = (None, None)) -> Any: + """ + Find best matching expectation based on provided device properties. + """ + (result_key, result) = max(self.data.items(), key=lambda x: Expectations.score(key, x[0])) + + if Expectations.score(key, result_key) == 0: + raise ValueError(f"No matching expectation found for {key}") + + return result + + def __repr__(self): + return f"{self.data}"