Skip to content

Commit d8bcb33

Browse files
sayakpaulDN6
andauthored
[Tests] fix slices of 26 tests (first half) (#8959)
* check for assertions. * update with correct slices. * okay * style * get it ready * update * update * update --------- Co-authored-by: Dhruv Nair <[email protected]>
1 parent 4a782f4 commit d8bcb33

24 files changed

+78
-98
lines changed

tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737
UNet2DConditionModel,
3838
)
3939
from diffusers.utils.import_utils import is_xformers_available
40-
from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, require_torch_gpu, torch_device
40+
from diffusers.utils.testing_utils import (
41+
enable_full_determinism,
42+
floats_tensor,
43+
require_torch_gpu,
44+
torch_device,
45+
)
4146

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

231-
def test_dict_tuple_outputs_equivalent(self):
232-
expected_slice = None
233-
if torch_device == "cpu":
234-
expected_slice = np.array([0.5490, 0.5053, 0.4676, 0.5816, 0.5364, 0.4830, 0.5937, 0.5719, 0.4318])
235-
super().test_dict_tuple_outputs_equivalent(expected_slice=expected_slice)
236-
237236
@unittest.skipIf(
238237
torch_device != "cuda" or not is_xformers_available(),
239238
reason="XFormers attention is only available with CUDA and `xformers` installed",
@@ -341,7 +340,8 @@ def test_controlnet_sdxl_guess(self):
341340

342341
output = sd_pipe(**inputs)
343342
image_slice = output.images[0, -3:, -3:, -1]
344-
expected_slice = np.array([0.549, 0.5053, 0.4676, 0.5816, 0.5364, 0.483, 0.5937, 0.5719, 0.4318])
343+
344+
expected_slice = np.array([0.5460, 0.4943, 0.4635, 0.5832, 0.5366, 0.4815, 0.6034, 0.5741, 0.4341])
345345

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

tests/pipelines/controlnet/test_controlnet_sdxl.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_ip_adapter_single(self, from_ssd1b=False, expected_pipe_slice=None):
195195
expected_pipe_slice = None
196196
if torch_device == "cpu":
197197
expected_pipe_slice = np.array(
198-
[0.7331, 0.5907, 0.5667, 0.6029, 0.5679, 0.5968, 0.4033, 0.4761, 0.5090]
198+
[0.7335, 0.5866, 0.5623, 0.6242, 0.5751, 0.5999, 0.4091, 0.4590, 0.5054]
199199
)
200200
return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice)
201201

@@ -348,9 +348,8 @@ def test_controlnet_sdxl_guess(self):
348348

349349
output = sd_pipe(**inputs)
350350
image_slice = output.images[0, -3:, -3:, -1]
351-
expected_slice = np.array(
352-
[0.7330834, 0.590667, 0.5667336, 0.6029023, 0.5679491, 0.5968194, 0.4032986, 0.47612396, 0.5089609]
353-
)
351+
352+
expected_slice = np.array([0.7335, 0.5866, 0.5623, 0.6242, 0.5751, 0.5999, 0.4091, 0.4590, 0.5054])
354353

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

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

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

@@ -965,17 +964,17 @@ def test_controlnet_sdxl_guess(self):
965964

966965
output = sd_pipe(**inputs)
967966
image_slice = output.images[0, -3:, -3:, -1]
968-
expected_slice = np.array(
969-
[0.6831671, 0.5702532, 0.5459845, 0.6299793, 0.58563006, 0.6033695, 0.4493941, 0.46132287, 0.5035841]
970-
)
967+
968+
expected_slice = np.array([0.7212, 0.5890, 0.5491, 0.6425, 0.5970, 0.6091, 0.4418, 0.4556, 0.5032])
971969

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

975973
def test_ip_adapter_single(self):
976974
expected_pipe_slice = None
977975
if torch_device == "cpu":
978-
expected_pipe_slice = np.array([0.6832, 0.5703, 0.5460, 0.6300, 0.5856, 0.6034, 0.4494, 0.4613, 0.5036])
976+
expected_pipe_slice = np.array([0.7212, 0.5890, 0.5491, 0.6425, 0.5970, 0.6091, 0.4418, 0.4556, 0.5032])
977+
979978
return super().test_ip_adapter_single(from_ssd1b=True, expected_pipe_slice=expected_pipe_slice)
980979

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

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

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

tests/pipelines/controlnet/test_controlnet_sdxl_img2img.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def get_dummy_inputs(self, device, seed=0):
178178
def test_ip_adapter_single(self):
179179
expected_pipe_slice = None
180180
if torch_device == "cpu":
181-
expected_pipe_slice = np.array([0.6265, 0.5441, 0.5384, 0.5446, 0.5810, 0.5908, 0.5414, 0.5428, 0.5353])
181+
expected_pipe_slice = np.array([0.6276, 0.5271, 0.5205, 0.5393, 0.5774, 0.5872, 0.5456, 0.5415, 0.5354])
182+
# TODO: update after slices.p
182183
return super().test_ip_adapter_single(expected_pipe_slice=expected_pipe_slice)
183184

184185
def test_stable_diffusion_xl_controlnet_img2img(self):

tests/pipelines/controlnet_sd3/test_controlnet_sd3.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ def test_controlnet_sd3(self):
180180
image = output.images
181181

182182
image_slice = image[0, -3:, -3:, -1]
183+
183184
assert image.shape == (1, 32, 32, 3)
184185

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

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

tests/pipelines/i2vgen_xl/test_i2vgenxl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
enable_full_determinism,
4040
floats_tensor,
4141
numpy_cosine_similarity_distance,
42-
print_tensor_test,
4342
require_torch_gpu,
4443
skip_mps,
4544
slow,
@@ -265,6 +264,5 @@ def test_i2vgen_xl(self):
265264
assert image.shape == (num_frames, 704, 1280, 3)
266265

267266
image_slice = image[0, -3:, -3:, -1]
268-
print_tensor_test(image_slice.flatten())
269267
expected_slice = np.array([0.5482, 0.6244, 0.6274, 0.4584, 0.5935, 0.5937, 0.4579, 0.5767, 0.5892])
270268
assert numpy_cosine_similarity_distance(image_slice.flatten(), expected_slice.flatten()) < 1e-3

tests/pipelines/kandinsky/test_kandinsky_combined.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_kandinsky(self):
9494

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

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

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

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

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

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

307307
image_slice = image[0, -3:, -3:, -1]
308+
308309
image_from_tuple_slice = image_from_tuple[0, -3:, -3:, -1]
309310

311+
print(image_from_tuple_slice)
312+
310313
assert image.shape == (1, 64, 64, 3)
311314

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

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

tests/pipelines/kandinsky/test_kandinsky_prior.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,13 @@ def test_kandinsky_prior(self):
211211
)[0]
212212

213213
image_slice = image[0, -10:]
214+
214215
image_from_tuple_slice = image_from_tuple[0, -10:]
215216

216217
assert image.shape == (1, 32)
217218

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

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

tests/pipelines/kandinsky2_2/test_kandinsky_combined.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_kandinsky(self):
9999

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

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

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

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

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

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

tests/pipelines/kandinsky2_2/test_kandinsky_prior.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@ def test_kandinsky_prior(self):
213213
)[0]
214214

215215
image_slice = image[0, -10:]
216+
216217
image_from_tuple_slice = image_from_tuple[0, -10:]
217218

218219
assert image.shape == (1, 32)
219220

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

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

tests/pipelines/kandinsky2_2/test_kandinsky_prior_emb2emb.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
)
3131

3232
from diffusers import KandinskyV22PriorEmb2EmbPipeline, PriorTransformer, UnCLIPScheduler
33-
from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, skip_mps, torch_device
33+
from diffusers.utils.testing_utils import (
34+
enable_full_determinism,
35+
floats_tensor,
36+
skip_mps,
37+
torch_device,
38+
)
3439

3540
from ..test_pipelines_common import PipelineTesterMixin
3641

@@ -210,23 +215,13 @@ def test_kandinsky_prior_emb2emb(self):
210215
)[0]
211216

212217
image_slice = image[0, -10:]
218+
213219
image_from_tuple_slice = image_from_tuple[0, -10:]
214220

215221
assert image.shape == (1, 32)
216222

217223
expected_slice = np.array(
218-
[
219-
0.1071284,
220-
1.3330271,
221-
0.61260223,
222-
-0.6691065,
223-
-0.3846852,
224-
-1.0303661,
225-
0.22716111,
226-
0.03348901,
227-
0.30040675,
228-
-0.24805029,
229-
]
224+
[-0.8947, 0.7225, -0.2400, -1.4224, -1.9268, -1.1454, -1.8220, -0.7972, 1.0465, -0.5207]
230225
)
231226

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

0 commit comments

Comments
 (0)