Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions tests/pipelines/cogvideo/test_cogvideox.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import gc

import numpy as np
import pytest
import torch
from transformers import AutoConfig, AutoTokenizer, T5EncoderModel

from diffusers import AutoencoderKLCogVideoX, CogVideoXPipeline, CogVideoXTransformer3DModel, DDIMScheduler

from ...testing_utils import (
assert_tensors_close,
backend_empty_cache,
numpy_cosine_similarity_distance,
require_torch_accelerator,
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(batch_size=3, expected_max_diff=1e-3)
Expand Down Expand Up @@ -194,14 +194,26 @@ def test_fused_qkv_projections(self):
frames = pipe(**inputs).frames
image_slice_disabled = frames[0, -2:, -1, -3:, -3:]

assert np.allclose(original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3), (
"Fusion of QKV projections shouldn't affect the outputs."
assert_tensors_close(
original_image_slice,
image_slice_fused,
atol=1e-3,
rtol=1e-3,
msg="Fusion of QKV projections shouldn't affect the outputs.",
)
assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3), (
"Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
assert_tensors_close(
image_slice_fused,
image_slice_disabled,
atol=1e-3,
rtol=1e-3,
msg="Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled.",
)
assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
"Original outputs should match when fused QKV projections are disabled."
assert_tensors_close(
original_image_slice,
image_slice_disabled,
atol=1e-2,
rtol=1e-2,
msg="Original outputs should match when fused QKV projections are disabled.",
)


Expand Down
28 changes: 20 additions & 8 deletions tests/pipelines/cogvideo/test_cogvideox_fun_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.


import numpy as np
import torch
from PIL import Image
from transformers import AutoConfig, AutoTokenizer, T5EncoderModel

from diffusers import AutoencoderKLCogVideoX, CogVideoXFunControlPipeline, CogVideoXTransformer3DModel, DDIMScheduler

from ...testing_utils import assert_tensors_close
from ..testing_utils import (
BasePipelineTesterConfig,
MemoryTesterMixin,
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(batch_size=3, expected_max_diff=1e-3)
Expand Down Expand Up @@ -189,14 +189,26 @@ def test_fused_qkv_projections(self):
frames = pipe(**inputs).frames
image_slice_disabled = frames[0, -2:, -1, -3:, -3:]

assert np.allclose(original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3), (
"Fusion of QKV projections shouldn't affect the outputs."
assert_tensors_close(
original_image_slice,
image_slice_fused,
atol=1e-3,
rtol=1e-3,
msg="Fusion of QKV projections shouldn't affect the outputs.",
)
assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3), (
"Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
assert_tensors_close(
image_slice_fused,
image_slice_disabled,
atol=1e-3,
rtol=1e-3,
msg="Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled.",
)
assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
"Original outputs should match when fused QKV projections are disabled."
assert_tensors_close(
original_image_slice,
image_slice_disabled,
atol=1e-2,
rtol=1e-2,
msg="Original outputs should match when fused QKV projections are disabled.",
)


Expand Down
28 changes: 20 additions & 8 deletions tests/pipelines/cogvideo/test_cogvideox_image2video.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import gc

import numpy as np
import pytest
import torch
from PIL import Image
Expand All @@ -24,6 +23,7 @@
from diffusers.utils import load_image

from ...testing_utils import (
assert_tensors_close,
backend_empty_cache,
numpy_cosine_similarity_distance,
require_torch_accelerator,
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(batch_size=3, expected_max_diff=1e-3)
Expand Down Expand Up @@ -227,14 +227,26 @@ def test_fused_qkv_projections(self):
frames = pipe(**inputs).frames
image_slice_disabled = frames[0, -2:, -1, -3:, -3:]

assert np.allclose(original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3), (
"Fusion of QKV projections shouldn't affect the outputs."
assert_tensors_close(
original_image_slice,
image_slice_fused,
atol=1e-3,
rtol=1e-3,
msg="Fusion of QKV projections shouldn't affect the outputs.",
)
assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3), (
"Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
assert_tensors_close(
image_slice_fused,
image_slice_disabled,
atol=1e-3,
rtol=1e-3,
msg="Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled.",
)
assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
"Original outputs should match when fused QKV projections are disabled."
assert_tensors_close(
original_image_slice,
image_slice_disabled,
atol=1e-2,
rtol=1e-2,
msg="Original outputs should match when fused QKV projections are disabled.",
)


Expand Down
28 changes: 20 additions & 8 deletions tests/pipelines/cogvideo/test_cogvideox_video2video.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.


import numpy as np
import torch
from PIL import Image
from transformers import AutoConfig, AutoTokenizer, T5EncoderModel

from diffusers import AutoencoderKLCogVideoX, CogVideoXTransformer3DModel, CogVideoXVideoToVideoPipeline, DDIMScheduler

from ...testing_utils import assert_tensors_close
from ..testing_utils import (
BasePipelineTesterConfig,
MemoryTesterMixin,
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(batch_size=3, expected_max_diff=1e-3)
Expand Down Expand Up @@ -194,14 +194,26 @@ def test_fused_qkv_projections(self):
frames = pipe(**inputs).frames
image_slice_disabled = frames[0, -2:, -1, -3:, -3:]

assert np.allclose(original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3), (
"Fusion of QKV projections shouldn't affect the outputs."
assert_tensors_close(
original_image_slice,
image_slice_fused,
atol=1e-3,
rtol=1e-3,
msg="Fusion of QKV projections shouldn't affect the outputs.",
)
assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3), (
"Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
assert_tensors_close(
image_slice_fused,
image_slice_disabled,
atol=1e-3,
rtol=1e-3,
msg="Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled.",
)
assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
"Original outputs should match when fused QKV projections are disabled."
assert_tensors_close(
original_image_slice,
image_slice_disabled,
atol=1e-2,
rtol=1e-2,
msg="Original outputs should match when fused QKV projections are disabled.",
)


Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/qwenimage/test_qwenimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
QwenImageTransformer2DModel,
)

from ...testing_utils import torch_device
from ...testing_utils import assert_tensors_close, torch_device
from ..testing_utils import (
BasePipelineTesterConfig,
MemoryTesterMixin,
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_inference(self):

generated_slice = generated_image.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=5e-3)
assert_tensors_close(generated_slice, expected_slice, atol=5e-3)

def test_vae_tiling(self, expected_diff_max: float = 0.2):
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
Expand Down
6 changes: 3 additions & 3 deletions tests/pipelines/qwenimage/test_qwenimage_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
from diffusers.utils.torch_utils import randn_tensor

from ...testing_utils import torch_device
from ...testing_utils import assert_tensors_close, torch_device
from ..testing_utils import (
BasePipelineTesterConfig,
MemoryTesterMixin,
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_qwen_controlnet(self):

generated_slice = generated_image.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=5e-3)
assert_tensors_close(generated_slice, expected_slice, atol=5e-3)

def test_qwen_controlnet_multicondition(self):
# Run on CPU: the expected slice below is CPU-specific.
Expand All @@ -196,7 +196,7 @@ def test_qwen_controlnet_multicondition(self):

generated_slice = generated_image.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=5e-3)
assert_tensors_close(generated_slice, expected_slice, atol=5e-3)

def test_vae_tiling(self, expected_diff_max: float = 0.2):
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/qwenimage/test_qwenimage_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
QwenImageTransformer2DModel,
)

from ...testing_utils import torch_device
from ...testing_utils import assert_tensors_close, torch_device
from ..testing_utils import (
BasePipelineTesterConfig,
MemoryTesterMixin,
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_inference(self):

generated_slice = generated_image.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=5e-3)
assert_tensors_close(generated_slice, expected_slice, atol=5e-3)

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(batch_size=3, expected_max_diff=1e-1)
Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/qwenimage/test_qwenimage_edit_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
QwenImageTransformer2DModel,
)

from ...testing_utils import torch_device
from ...testing_utils import assert_tensors_close, torch_device
from ..testing_utils import BasePipelineTesterConfig, MemoryTesterMixin, PipelineTesterMixin


Expand Down Expand Up @@ -139,7 +139,7 @@ def test_inference(self):

generated_slice = generated_image.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_vae_tiling(self, expected_diff_max: float = 0.2):
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/qwenimage/test_qwenimage_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
QwenImageTransformer2DModel,
)

from ...testing_utils import floats_tensor, torch_device
from ...testing_utils import assert_tensors_close, floats_tensor, torch_device
from ..testing_utils import (
BasePipelineTesterConfig,
MemoryTesterMixin,
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_inference(self):

generated_slice = generated_image.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=5e-3)
assert_tensors_close(generated_slice, expected_slice, atol=5e-3)

def test_vae_tiling(self, expected_diff_max: float = 0.2):
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/wan/test_wan.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_save_load_optional_components(self, tmp_path, expected_max_difference=1e-4):
# `_optional_components` lists both `transformer` and `transformer_2`, but only `transformer_2` is optional
Expand Down
9 changes: 3 additions & 6 deletions tests/pipelines/wan/test_wan_22.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_save_load_optional_components(self, tmp_path, expected_max_difference=1e-4):
# For wan 2.2 14B, `transformer` is not used when `boundary_ratio` is 1.0, so only then is it optional.
Expand Down Expand Up @@ -246,15 +246,12 @@ def test_inference(self):
assert generated_video.shape == (9, 3, 32, 32)

# fmt: off
expected_slice = torch.tensor([[[0.4814, 0.4298, 0.5094, 0.4289, 0.5061, 0.4301, 0.5043, 0.4284, 0.5375,
0.5965, 0.5527, 0.6014, 0.5228, 0.6076, 0.6644, 0.5651]]])
expected_slice = torch.tensor([0.4814, 0.4298, 0.5094, 0.4289, 0.5061, 0.4301, 0.5043, 0.4284, 0.5375, 0.5965, 0.5527, 0.6014, 0.5228, 0.6076, 0.6644, 0.5651])
# fmt: on

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3), (
f"generated_slice: {generated_slice}, expected_slice: {expected_slice}"
)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_components_function(self):
init_components = self.get_dummy_components()
Expand Down
6 changes: 3 additions & 3 deletions tests/pipelines/wan/test_wan_22_image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_inference(self):

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_save_load_optional_components(self, tmp_path, expected_max_difference=1e-4):
# `_optional_components` lists `transformer`, `transformer_2`, `image_encoder` and `image_processor`. For the
Expand Down Expand Up @@ -264,12 +264,12 @@ def test_inference(self):
assert generated_video.shape == (9, 3, 32, 32)

# fmt: off
expected_slice = torch.tensor([[0.4833, 0.4305, 0.5100, 0.4299, 0.5056, 0.4298, 0.5052, 0.4332, 0.5550, 0.6092, 0.5536, 0.5928, 0.5199, 0.5864, 0.6705, 0.5493]])
expected_slice = torch.tensor([0.4833, 0.4305, 0.5100, 0.4299, 0.5056, 0.4298, 0.5052, 0.4332, 0.5550, 0.6092, 0.5536, 0.5928, 0.5199, 0.5864, 0.6705, 0.5493])
# fmt: on

generated_slice = generated_video.flatten()
generated_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
assert torch.allclose(generated_slice, expected_slice, atol=1e-3)
assert_tensors_close(generated_slice, expected_slice, atol=1e-3)

def test_components_function(self):
init_components = self.get_dummy_components()
Expand Down
Loading
Loading