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
16 changes: 8 additions & 8 deletions tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
UNet2DConditionModel,
)
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, require_torch_gpu, torch_device
from diffusers.utils.testing_utils import (
enable_full_determinism,
floats_tensor,
require_torch_gpu,
torch_device,
)

from ..pipeline_params import (
IMAGE_TO_IMAGE_IMAGE_PARAMS,
Expand Down Expand Up @@ -228,12 +233,6 @@ def get_dummy_inputs(self, device, seed=0, img_res=64):
def test_attention_slicing_forward_pass(self):
return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3)

def test_dict_tuple_outputs_equivalent(self):
expected_slice = None
if torch_device == "cpu":
expected_slice = np.array([0.5490, 0.5053, 0.4676, 0.5816, 0.5364, 0.4830, 0.5937, 0.5719, 0.4318])
super().test_dict_tuple_outputs_equivalent(expected_slice=expected_slice)

@unittest.skipIf(
torch_device != "cuda" or not is_xformers_available(),
reason="XFormers attention is only available with CUDA and `xformers` installed",
Expand Down Expand Up @@ -341,7 +340,8 @@ def test_controlnet_sdxl_guess(self):

output = sd_pipe(**inputs)
image_slice = output.images[0, -3:, -3:, -1]
expected_slice = np.array([0.549, 0.5053, 0.4676, 0.5816, 0.5364, 0.483, 0.5937, 0.5719, 0.4318])

expected_slice = np.array([0.5460, 0.4943, 0.4635, 0.5832, 0.5366, 0.4815, 0.6034, 0.5741, 0.4341])

# make sure that it's equal
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4
Expand Down
19 changes: 9 additions & 10 deletions tests/pipelines/controlnet/test_controlnet_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_ip_adapter_single(self, from_ssd1b=False, expected_pipe_slice=None):
expected_pipe_slice = None
if torch_device == "cpu":
expected_pipe_slice = np.array(
[0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]
[0.7335, 0.5866, 0.5623, 0.6242, 0.5751, 0.5999, 0.4091, 0.4590, 0.5054]
)
return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice)

Expand Down Expand Up @@ -348,9 +348,8 @@ def test_controlnet_sdxl_guess(self):

output = sd_pipe(**inputs)
image_slice = output.images[0, -3:, -3:, -1]
expected_slice = np.array(
[0.7330834, 0.590667, 0.5667336, 0.6029023, 0.5679491, 0.5968194, 0.4032986, 0.47612396, 0.5089609]
)

expected_slice = np.array([0.7335, 0.5866, 0.5623, 0.6242, 0.5751, 0.5999, 0.4091, 0.4590, 0.5054])

# make sure that it's equal
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4
Expand All @@ -371,7 +370,7 @@ def test_controlnet_sdxl_lcm(self):
image_slice = image[0, -3:, -3:, -1]

assert image.shape == (1, 64, 64, 3)
expected_slice = np.array([0.7799, 0.614, 0.6162, 0.7082, 0.6662, 0.5833, 0.4148, 0.5182, 0.4866])
expected_slice = np.array([0.7820, 0.6195, 0.6193, 0.7045, 0.6706, 0.5837, 0.4147, 0.5232, 0.4868])

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

Expand Down Expand Up @@ -965,17 +964,17 @@ def test_controlnet_sdxl_guess(self):

output = sd_pipe(**inputs)
image_slice = output.images[0, -3:, -3:, -1]
expected_slice = np.array(
[0.6831671, 0.5702532, 0.5459845, 0.6299793, 0.58563006, 0.6033695, 0.4493941, 0.46132287, 0.5035841]
)

expected_slice = np.array([0.7212, 0.5890, 0.5491, 0.6425, 0.5970, 0.6091, 0.4418, 0.4556, 0.5032])

# make sure that it's equal
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-4

def test_ip_adapter_single(self):
expected_pipe_slice = None
if torch_device == "cpu":
expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036])
expected_pipe_slice = np.array([0.7212, 0.5890, 0.5491, 0.6425, 0.5970, 0.6091, 0.4418, 0.4556, 0.5032])

return super().test_ip_adapter_single(from_ssd1b=True, expected_pipe_slice=expected_pipe_slice)

def test_controlnet_sdxl_lcm(self):
Expand All @@ -994,7 +993,7 @@ def test_controlnet_sdxl_lcm(self):
image_slice = image[0, -3:, -3:, -1]

assert image.shape == (1, 64, 64, 3)
expected_slice = np.array([0.6850, 0.5135, 0.5545, 0.7033, 0.6617, 0.5971, 0.4165, 0.5480, 0.5070])
expected_slice = np.array([0.6787, 0.5117, 0.5558, 0.6963, 0.6571, 0.5928, 0.4121, 0.5468, 0.5057])

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

Expand Down
3 changes: 2 additions & 1 deletion tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def get_dummy_inputs(self, device, seed=0):
def test_ip_adapter_single(self):
expected_pipe_slice = None
if torch_device == "cpu":
expected_pipe_slice = np.array([0.6265, 0.5441, 0.5384, 0.5446, 0.5810, 0.5908, 0.5414, 0.5428, 0.5353])
expected_pipe_slice = np.array([0.6276, 0.5271, 0.5205, 0.5393, 0.5774, 0.5872, 0.5456, 0.5415, 0.5354])
# TODO: update after slices.p
return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice)

def test_stable_diffusion_xl_controlnet_img2img(self):
Expand Down
5 changes: 2 additions & 3 deletions tests/pipelines/controlnet_sd3/test_controlnet_sd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ def test_controlnet_sd3(self):
image = output.images

image_slice = image[0, -3:, -3:, -1]

assert image.shape == (1, 32, 32, 3)

expected_slice = np.array(
[0.5761719, 0.71777344, 0.59228516, 0.578125, 0.6020508, 0.39453125, 0.46728516, 0.51708984, 0.58984375]
)
expected_slice = np.array([0.5767, 0.7100, 0.5981, 0.5674, 0.5952, 0.4102, 0.5093, 0.5044, 0.6030])

assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down
2 changes: 0 additions & 2 deletions tests/pipelines/i2vgen_xl/test_i2vgenxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
enable_full_determinism,
floats_tensor,
numpy_cosine_similarity_distance,
print_tensor_test,
require_torch_gpu,
skip_mps,
slow,
Expand Down Expand Up @@ -265,6 +264,5 @@ def test_i2vgen_xl(self):
assert image.shape == (num_frames, 704, 1280, 3)

image_slice = image[0, -3:, -3:, -1]
print_tensor_test(image_slice.flatten())
expected_slice = np.array([0.5482, 0.6244, 0.6274, 0.4584, 0.5935, 0.5937, 0.4579, 0.5767, 0.5892])
assert numpy_cosine_similarity_distance(image_slice.flatten(), expected_slice.flatten()) < 1e-3
9 changes: 6 additions & 3 deletions tests/pipelines/kandinsky/test_kandinsky_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_kandinsky(self):

assert image.shape == (1, 64, 64, 3)

expected_slice = np.array([0.0000, 0.0000, 0.6777, 0.1363, 0.3624, 0.7868, 0.3869, 0.3395, 0.5068])
expected_slice = np.array([0.2893, 0.1464, 0.4603, 0.3529, 0.4612, 0.7701, 0.4027, 0.3051, 0.5155])

assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_kandinsky(self):

assert image.shape == (1, 64, 64, 3)

expected_slice = np.array([0.4260, 0.3596, 0.4571, 0.3890, 0.4087, 0.5137, 0.4819, 0.4116, 0.5053])
expected_slice = np.array([0.4852, 0.4136, 0.4539, 0.4781, 0.4680, 0.5217, 0.4973, 0.4089, 0.4977])

assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down Expand Up @@ -305,11 +305,14 @@ def test_kandinsky(self):
)[0]

image_slice = image[0, -3:, -3:, -1]

image_from_tuple_slice = image_from_tuple[0, -3:, -3:, -1]

print(image_from_tuple_slice)

assert image.shape == (1, 64, 64, 3)

expected_slice = np.array([0.0477, 0.0808, 0.2972, 0.2705, 0.3620, 0.6247, 0.4464, 0.2870, 0.3530])
expected_slice = np.array([0.0320, 0.0860, 0.4013, 0.0518, 0.2484, 0.5847, 0.4411, 0.2321, 0.4593])

assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down
3 changes: 2 additions & 1 deletion tests/pipelines/kandinsky/test_kandinsky_prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ def test_kandinsky_prior(self):
)[0]

image_slice = image[0, -10:]

image_from_tuple_slice = image_from_tuple[0, -10:]

assert image.shape == (1, 32)

expected_slice = np.array(
[-0.0532, 1.7120, 0.3656, -1.0852, -0.8946, -1.1756, 0.4348, 0.2482, 0.5146, -0.1156]
[-0.5948, 0.1875, -0.1523, -1.1995, -1.4061, -0.6367, -1.4607, -0.6406, 0.8793, -0.3891]
)

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/kandinsky2_2/test_kandinsky_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_kandinsky(self):

assert image.shape == (1, 64, 64, 3)

expected_slice = np.array([0.3013, 0.0471, 0.5176, 0.1817, 0.2566, 0.7076, 0.6712, 0.4421, 0.7503])
expected_slice = np.array([0.3076, 0.2729, 0.5668, 0.0522, 0.3384, 0.7028, 0.4908, 0.3659, 0.6243])

assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_kandinsky(self):

assert image.shape == (1, 64, 64, 3)

expected_slice = np.array([0.4353, 0.4710, 0.5128, 0.4806, 0.5054, 0.5348, 0.5224, 0.4603, 0.5025])
expected_slice = np.array([0.4445, 0.4287, 0.4596, 0.3919, 0.3730, 0.5039, 0.4834, 0.4269, 0.5521])

assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down
3 changes: 2 additions & 1 deletion tests/pipelines/kandinsky2_2/test_kandinsky_prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ def test_kandinsky_prior(self):
)[0]

image_slice = image[0, -10:]

image_from_tuple_slice = image_from_tuple[0, -10:]

assert image.shape == (1, 32)

expected_slice = np.array(
[-0.0532, 1.7120, 0.3656, -1.0852, -0.8946, -1.1756, 0.4348, 0.2482, 0.5146, -0.1156]
[-0.5948, 0.1875, -0.1523, -1.1995, -1.4061, -0.6367, -1.4607, -0.6406, 0.8793, -0.3891]
)

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down
21 changes: 8 additions & 13 deletions tests/pipelines/kandinsky2_2/test_kandinsky_prior_emb2emb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
)

from diffusers import KandinskyV22PriorEmb2EmbPipeline, PriorTransformer, UnCLIPScheduler
from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, skip_mps, torch_device
from diffusers.utils.testing_utils import (
enable_full_determinism,
floats_tensor,
skip_mps,
torch_device,
)

from ..test_pipelines_common import PipelineTesterMixin

Expand Down Expand Up @@ -210,23 +215,13 @@ def test_kandinsky_prior_emb2emb(self):
)[0]

image_slice = image[0, -10:]

image_from_tuple_slice = image_from_tuple[0, -10:]

assert image.shape == (1, 32)

expected_slice = np.array(
[
0.1071284,
1.3330271,
0.61260223,
-0.6691065,
-0.3846852,
-1.0303661,
0.22716111,
0.03348901,
0.30040675,
-0.24805029,
]
[-0.8947, 0.7225, -0.2400, -1.4224, -1.9268, -1.1454, -1.8220, -0.7972, 1.0465, -0.5207]
)

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
Expand Down
12 changes: 3 additions & 9 deletions tests/pipelines/pag/test_pag_controlnet_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
StableDiffusionXLControlNetPipeline,
UNet2DConditionModel,
)
from diffusers.utils.testing_utils import (
enable_full_determinism,
)
from diffusers.utils.testing_utils import enable_full_determinism
from diffusers.utils.torch_utils import randn_tensor

from ..pipeline_params import (
Expand Down Expand Up @@ -237,9 +235,7 @@ def test_pag_cfg(self):
64,
3,
), f"the shape of the output image should be (1, 64, 64, 3) but got {image.shape}"
expected_slice = np.array(
[0.6819614, 0.5551478, 0.5499094, 0.5769566, 0.53942275, 0.5707505, 0.41131154, 0.47833863, 0.49982738]
)
expected_slice = np.array([0.7036, 0.5613, 0.5526, 0.6129, 0.5610, 0.5842, 0.4228, 0.4612, 0.5017])

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"
Expand All @@ -263,9 +259,7 @@ def test_pag_uncond(self):
64,
3,
), f"the shape of the output image should be (1, 64, 64, 3) but got {image.shape}"
expected_slice = np.array(
[0.66685176, 0.53207266, 0.5541569, 0.5912994, 0.5368312, 0.58433825, 0.42607725, 0.46805605, 0.5098659]
)
expected_slice = np.array([0.6888, 0.5398, 0.5603, 0.6086, 0.5541, 0.5957, 0.4332, 0.4643, 0.5154])

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"
4 changes: 1 addition & 3 deletions tests/pipelines/pag/test_pag_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ def test_pag_inference(self):
64,
3,
), f"the shape of the output image should be (1, 64, 64, 3) but got {image.shape}"
expected_slice = np.array(
[0.55341685, 0.55503535, 0.47299808, 0.43274558, 0.4965323, 0.46310428, 0.51455414, 0.5015592, 0.46913484]
)
expected_slice = np.array([0.5382, 0.5439, 0.4704, 0.4569, 0.5234, 0.4834, 0.5289, 0.5039, 0.4764])

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
self.assertLessEqual(max_diff, 1e-3)
Expand Down
4 changes: 1 addition & 3 deletions tests/pipelines/pag/test_pag_sdxl_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ def test_pag_inference(self):
32,
3,
), f"the shape of the output image should be (1, 64, 64, 3) but got {image.shape}"
expected_slice = np.array(
[0.46703637, 0.4917526, 0.44394222, 0.6895079, 0.56251144, 0.45474228, 0.5957122, 0.6016377, 0.5276273]
)
expected_slice = np.array([0.4613, 0.4902, 0.4406, 0.6788, 0.5611, 0.4529, 0.5893, 0.5975, 0.5226])

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"
Expand Down
4 changes: 1 addition & 3 deletions tests/pipelines/pag/test_pag_sdxl_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ def test_pag_inference(self):
64,
3,
), f"the shape of the output image should be (1, 64, 64, 3) but got {image.shape}"
expected_slice = np.array(
[0.8115454, 0.53986573, 0.5825281, 0.6028964, 0.67128646, 0.7046922, 0.6418713, 0.5933924, 0.5154763]
)
expected_slice = np.array([0.8366, 0.5513, 0.6105, 0.6213, 0.6957, 0.7400, 0.6614, 0.6102, 0.5239])

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/shap_e/test_shap_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_shap_e(self):

assert image.shape == (32, 16)

expected_slice = np.array([-1.0000, -0.6241, 1.0000, -0.8978, -0.6866, 0.7876, -0.7473, -0.2874, 0.6103])
expected_slice = np.array([-1.0000, -0.6559, 1.0000, -0.9096, -0.7252, 0.8211, -0.7647, -0.3308, 0.6462])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

def test_inference_batch_consistent(self):
Expand Down
14 changes: 2 additions & 12 deletions tests/pipelines/stable_cascade/test_stable_cascade_prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,12 @@ def test_wuerstchen_prior(self):
image_from_tuple = pipe(**self.get_dummy_inputs(device), return_dict=False)[0]

image_slice = image[0, 0, 0, -10:]

image_from_tuple_slice = image_from_tuple[0, 0, 0, -10:]
assert image.shape == (1, 16, 24, 24)

expected_slice = np.array(
[
96.139565,
-20.213179,
-116.40341,
-191.57129,
39.350136,
74.80767,
39.782352,
-184.67352,
-46.426907,
168.41783,
]
[94.5498, -21.9481, -117.5025, -192.8760, 38.0117, 73.4709, 38.1142, -185.5593, -47.7869, 167.2853]
)

assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2
Expand Down
Loading