From 559b6d61fed089639bceded5e2ac5998f9946c09 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Fri, 10 Feb 2023 13:58:26 +0200 Subject: [PATCH 1/5] correct some --- .../test_alt_diffusion_img2img.py | 9 ++-- .../test_stable_diffusion_depth.py | 47 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index ae7d70f92473..055dff047f38 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -27,7 +27,7 @@ RobertaSeriesModelWithTransformation, ) from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device -from diffusers.utils.testing_utils import require_torch_gpu +from diffusers.utils.testing_utils import require_torch_gpu, print_tensor_test torch.backends.cuda.matmul.allow_tf32 = False @@ -159,9 +159,8 @@ def test_stable_diffusion_img2img_default_case(self): image_from_tuple_slice = image_from_tuple[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) - expected_slice = np.array( - [0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448] - ) + print_tensor_test(image_slice) + expected_slice = np.array([0.4115, 0.3870, 0.4089, 0.4807, 0.4668, 0.4144, 0.4151, 0.4721, 0.4569]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1.5e-3 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1.5e-3 @@ -242,7 +241,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): image_slice = image[255:258, 383:386, -1] assert image.shape == (504, 760, 3) - expected_slice = np.array([0.9358, 0.9397, 0.9599, 0.9901, 1.0000, 1.0000, 0.9882, 1.0000, 1.0000]) + expected_slice = np.array([0.4115, 0.3870, 0.4089, 0.4807, 0.4668, 0.4144, 0.4151, 0.4721, 0.4569]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 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 09334afcdaaf..6bf8a9f317a2 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -41,7 +41,7 @@ ) from diffusers.utils import floats_tensor, load_image, load_numpy, nightly, slow, torch_device from diffusers.utils.import_utils import is_accelerate_available -from diffusers.utils.testing_utils import require_torch_gpu +from diffusers.utils.testing_utils import require_torch_gpu, print_tensor_test from ...test_pipelines_common import PipelineTesterMixin @@ -285,10 +285,12 @@ def test_stable_diffusion_depth2img_default_case(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) - if torch_device == "mps": - expected_slice = np.array([0.6071, 0.5035, 0.4378, 0.5776, 0.5753, 0.4316, 0.4513, 0.5263, 0.4546]) - else: - expected_slice = np.array([0.6854, 0.3740, 0.4857, 0.7130, 0.7403, 0.5536, 0.4829, 0.6182, 0.5053]) +# if torch_device == "mps": +# expected_slice = np.array([0.6071, 0.5035, 0.4378, 0.5776, 0.5753, 0.4316, 0.4513, 0.5263, 0.4546]) +# else: + expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) + + print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -306,10 +308,11 @@ def test_stable_diffusion_depth2img_negative_prompt(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) - if torch_device == "mps": - expected_slice = np.array([0.5825, 0.5135, 0.4095, 0.5452, 0.6059, 0.4211, 0.3994, 0.5177, 0.4335]) - else: - expected_slice = np.array([0.6074, 0.3096, 0.4802, 0.7463, 0.7388, 0.5393, 0.4531, 0.5928, 0.4972]) +# if torch_device == "mps": +# expected_slice = np.array([0.5825, 0.5135, 0.4095, 0.5452, 0.6059, 0.4211, 0.3994, 0.5177, 0.4335]) +# else: + expected_slice = np.array([0.6074, 0.3096, 0.4802, 0.7463, 0.7388, 0.5393, 0.4531, 0.5928, 0.4972]) + print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -328,10 +331,11 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) - if torch_device == "mps": - expected_slice = np.array([0.6501, 0.5150, 0.4939, 0.6688, 0.5437, 0.5758, 0.5115, 0.4406, 0.4551]) - else: - expected_slice = np.array([0.6681, 0.5023, 0.6611, 0.7605, 0.5724, 0.7959, 0.7240, 0.5871, 0.5383]) +# if torch_device == "mps": +# expected_slice = np.array([0.6501, 0.5150, 0.4939, 0.6688, 0.5437, 0.5758, 0.5115, 0.4406, 0.4551]) +# else: + expected_slice = np.array([0.6681, 0.5023, 0.6611, 0.7605, 0.5724, 0.7959, 0.7240, 0.5871, 0.5383]) + print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -383,10 +387,11 @@ def test_stable_diffusion_depth2img_pil(self): image = pipe(**inputs).images image_slice = image[0, -3:, -3:, -1] - if torch_device == "mps": - expected_slice = np.array([0.53232, 0.47015, 0.40868, 0.45651, 0.4891, 0.4668, 0.4287, 0.48822, 0.47439]) - else: - expected_slice = np.array([0.6853, 0.3740, 0.4856, 0.7130, 0.7402, 0.5535, 0.4828, 0.6182, 0.5053]) +# if torch_device == "mps": +# expected_slice = np.array([0.53232, 0.47015, 0.40868, 0.45651, 0.4891, 0.4668, 0.4287, 0.48822, 0.47439]) +# else: + expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) + print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -428,7 +433,7 @@ def test_stable_diffusion_depth2img_pipeline_default(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 480, 640, 3) - expected_slice = np.array([0.9057, 0.9365, 0.9258, 0.8937, 0.8555, 0.8541, 0.8260, 0.7747, 0.7421]) + expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) assert np.abs(expected_slice - image_slice).max() < 1e-4 @@ -464,7 +469,7 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 480, 640, 3) - expected_slice = np.array([0.6424, 0.6524, 0.6249, 0.6041, 0.6634, 0.6420, 0.6522, 0.6555, 0.6436]) + expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) assert np.abs(expected_slice - image_slice).max() < 1e-4 @@ -479,9 +484,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array( - [-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051] - ) + expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: From a9000cbb417c9b842f8f43faaa9387b93013c5af Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Fri, 10 Feb 2023 13:34:57 +0100 Subject: [PATCH 2/5] Apply suggestions from code review --- .../stable_diffusion_2/test_stable_diffusion_depth.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 6bf8a9f317a2..cfe84add0678 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -433,7 +433,7 @@ def test_stable_diffusion_depth2img_pipeline_default(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 480, 640, 3) - expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) + expected_slice = np.array([0.9057, 0.9365, 0.9258, 0.8937, 0.8555, 0.8541, 0.8260, 0.7747, 0.7421]) assert np.abs(expected_slice - image_slice).max() < 1e-4 @@ -469,7 +469,7 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 480, 640, 3) - expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) + expected_slice = np.array([0.6424, 0.6524, 0.6249, 0.6041, 0.6634, 0.6420, 0.6522, 0.6555, 0.6436]) assert np.abs(expected_slice - image_slice).max() < 1e-4 @@ -484,7 +484,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) + expected_slice = np.array( + [-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051] + ) assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: From 7eecad402f14bb93c7cd8f84c23007c9c3d3cbf8 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Fri, 10 Feb 2023 14:36:43 +0200 Subject: [PATCH 3/5] correct --- test_corrections.txt | 5 +++++ .../stable_diffusion_2/test_stable_diffusion_depth.py | 6 +++--- utils/overwrite_expected_slice.py | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 test_corrections.txt diff --git a/test_corrections.txt b/test_corrections.txt new file mode 100644 index 000000000000..f846c1eedb52 --- /dev/null +++ b/test_corrections.txt @@ -0,0 +1,5 @@ +tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py;AltDiffusionImg2ImgPipelineFastTests;test_stable_diffusion_img2img_default_case;expected_slice = np.array([0.4115, 0.3870, 0.4089, 0.4807, 0.4668, 0.4144, 0.4151, 0.4721, 0.4569]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_default_case;expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_multiple_init_images;expected_slice = np.array([0.6248, 0.5206, 0.6007, 0.6749, 0.5022, 0.6442, 0.5352, 0.4140, 0.4681]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_negative_prompt;expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_pil;expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) 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 cfe84add0678..5ac05e12bee8 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -311,7 +311,7 @@ def test_stable_diffusion_depth2img_negative_prompt(self): # if torch_device == "mps": # expected_slice = np.array([0.5825, 0.5135, 0.4095, 0.5452, 0.6059, 0.4211, 0.3994, 0.5177, 0.4335]) # else: - expected_slice = np.array([0.6074, 0.3096, 0.4802, 0.7463, 0.7388, 0.5393, 0.4531, 0.5928, 0.4972]) + expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -334,7 +334,7 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): # if torch_device == "mps": # expected_slice = np.array([0.6501, 0.5150, 0.4939, 0.6688, 0.5437, 0.5758, 0.5115, 0.4406, 0.4551]) # else: - expected_slice = np.array([0.6681, 0.5023, 0.6611, 0.7605, 0.5724, 0.7959, 0.7240, 0.5871, 0.5383]) + expected_slice = np.array([0.6248, 0.5206, 0.6007, 0.6749, 0.5022, 0.6442, 0.5352, 0.4140, 0.4681]) print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -390,7 +390,7 @@ def test_stable_diffusion_depth2img_pil(self): # if torch_device == "mps": # expected_slice = np.array([0.53232, 0.47015, 0.40868, 0.45651, 0.4891, 0.4668, 0.4287, 0.48822, 0.47439]) # else: - expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) + expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/utils/overwrite_expected_slice.py b/utils/overwrite_expected_slice.py index 974532e378db..20a8f4258547 100644 --- a/utils/overwrite_expected_slice.py +++ b/utils/overwrite_expected_slice.py @@ -17,7 +17,8 @@ def overwrite_file(file, class_name, test_name, correct_line, done_test): - done_test[file] += 1 + _id = f"{file}_{class_name}_{test_name}" + done_test[_id] += 1 with open(file, "r") as f: lines = f.readlines() @@ -43,7 +44,7 @@ def overwrite_file(file, class_name, test_name, correct_line, done_test): spaces = len(line.split(correct_line.split()[0])[0]) count += 1 - if count == done_test[file]: + if count == done_test[_id]: in_line = True if in_class and in_func and in_line: From c6e66212cc7564b533941dfeb110876e271d5038 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Fri, 10 Feb 2023 13:37:56 +0100 Subject: [PATCH 4/5] Update tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py --- tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 055dff047f38..bfe7dddb764f 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -241,7 +241,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): image_slice = image[255:258, 383:386, -1] assert image.shape == (504, 760, 3) - expected_slice = np.array([0.4115, 0.3870, 0.4089, 0.4807, 0.4668, 0.4144, 0.4151, 0.4721, 0.4569]) + expected_slice = np.array([0.9358, 0.9397, 0.9599, 0.9901, 1.0000, 1.0000, 0.9882, 1.0000, 1.0000]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 From 84058456db3dfa607149e85abd4b1e3f2c319de9 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Fri, 10 Feb 2023 14:39:54 +0200 Subject: [PATCH 5/5] Final --- test_corrections.txt | 5 --- .../test_alt_diffusion_img2img.py | 7 ++-- .../test_stable_diffusion_depth.py | 39 ++++++++----------- 3 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 test_corrections.txt diff --git a/test_corrections.txt b/test_corrections.txt deleted file mode 100644 index f846c1eedb52..000000000000 --- a/test_corrections.txt +++ /dev/null @@ -1,5 +0,0 @@ -tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py;AltDiffusionImg2ImgPipelineFastTests;test_stable_diffusion_img2img_default_case;expected_slice = np.array([0.4115, 0.3870, 0.4089, 0.4807, 0.4668, 0.4144, 0.4151, 0.4721, 0.4569]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_default_case;expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_multiple_init_images;expected_slice = np.array([0.6248, 0.5206, 0.6007, 0.6749, 0.5022, 0.6442, 0.5352, 0.4140, 0.4681]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_negative_prompt;expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineFastTests;test_stable_diffusion_depth2img_pil;expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index bfe7dddb764f..d34f8e15cd6a 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -27,7 +27,7 @@ RobertaSeriesModelWithTransformation, ) from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device -from diffusers.utils.testing_utils import require_torch_gpu, print_tensor_test +from diffusers.utils.testing_utils import require_torch_gpu torch.backends.cuda.matmul.allow_tf32 = False @@ -159,11 +159,10 @@ def test_stable_diffusion_img2img_default_case(self): image_from_tuple_slice = image_from_tuple[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) - print_tensor_test(image_slice) expected_slice = np.array([0.4115, 0.3870, 0.4089, 0.4807, 0.4668, 0.4144, 0.4151, 0.4721, 0.4569]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1.5e-3 - assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1.5e-3 + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3 + assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 5e-3 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") def test_stable_diffusion_img2img_fp16(self): 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 5ac05e12bee8..49d0e4dbdca2 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -41,7 +41,7 @@ ) from diffusers.utils import floats_tensor, load_image, load_numpy, nightly, slow, torch_device from diffusers.utils.import_utils import is_accelerate_available -from diffusers.utils.testing_utils import require_torch_gpu, print_tensor_test +from diffusers.utils.testing_utils import require_torch_gpu from ...test_pipelines_common import PipelineTesterMixin @@ -285,12 +285,10 @@ def test_stable_diffusion_depth2img_default_case(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) -# if torch_device == "mps": -# expected_slice = np.array([0.6071, 0.5035, 0.4378, 0.5776, 0.5753, 0.4316, 0.4513, 0.5263, 0.4546]) -# else: - expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) - - print_tensor_test(image_slice) + if torch_device == "mps": + expected_slice = np.array([0.6071, 0.5035, 0.4378, 0.5776, 0.5753, 0.4316, 0.4513, 0.5263, 0.4546]) + else: + expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -308,11 +306,10 @@ def test_stable_diffusion_depth2img_negative_prompt(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) -# if torch_device == "mps": -# expected_slice = np.array([0.5825, 0.5135, 0.4095, 0.5452, 0.6059, 0.4211, 0.3994, 0.5177, 0.4335]) -# else: - expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) - print_tensor_test(image_slice) + if torch_device == "mps": + expected_slice = np.array([0.5825, 0.5135, 0.4095, 0.5452, 0.6059, 0.4211, 0.3994, 0.5177, 0.4335]) + else: + expected_slice = np.array([0.6332, 0.5167, 0.3911, 0.4446, 0.5971, 0.4619, 0.3821, 0.5323, 0.4621]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -331,11 +328,10 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) -# if torch_device == "mps": -# expected_slice = np.array([0.6501, 0.5150, 0.4939, 0.6688, 0.5437, 0.5758, 0.5115, 0.4406, 0.4551]) -# else: - expected_slice = np.array([0.6248, 0.5206, 0.6007, 0.6749, 0.5022, 0.6442, 0.5352, 0.4140, 0.4681]) - print_tensor_test(image_slice) + if torch_device == "mps": + expected_slice = np.array([0.6501, 0.5150, 0.4939, 0.6688, 0.5437, 0.5758, 0.5115, 0.4406, 0.4551]) + else: + expected_slice = np.array([0.6248, 0.5206, 0.6007, 0.6749, 0.5022, 0.6442, 0.5352, 0.4140, 0.4681]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -387,11 +383,10 @@ def test_stable_diffusion_depth2img_pil(self): image = pipe(**inputs).images image_slice = image[0, -3:, -3:, -1] -# if torch_device == "mps": -# expected_slice = np.array([0.53232, 0.47015, 0.40868, 0.45651, 0.4891, 0.4668, 0.4287, 0.48822, 0.47439]) -# else: - expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) - print_tensor_test(image_slice) + if torch_device == "mps": + expected_slice = np.array([0.53232, 0.47015, 0.40868, 0.45651, 0.4891, 0.4668, 0.4287, 0.48822, 0.47439]) + else: + expected_slice = np.array([0.6374, 0.5039, 0.4199, 0.4819, 0.5563, 0.4617, 0.4028, 0.5381, 0.4711]) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3