From 92818ef6f93742e2efca2434d3b7fef377419c3d Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Thu, 5 Jan 2023 08:24:26 +0000 Subject: [PATCH 01/39] make tests deterministic --- .../stable_diffusion/test_cycle_diffusion.py | 4 ++-- .../stable_diffusion/test_stable_diffusion.py | 8 +++---- .../test_stable_diffusion_image_variation.py | 8 +++---- .../test_stable_diffusion_img2img.py | 8 +++---- .../test_stable_diffusion_inpaint.py | 8 +++---- .../test_stable_diffusion_inpaint_legacy.py | 8 +++---- .../test_stable_diffusion_k_diffusion.py | 4 ++-- .../test_stable_diffusion.py | 8 +++---- .../test_stable_diffusion_depth.py | 22 +++++++++---------- .../test_stable_diffusion_inpaint.py | 6 ++--- .../test_stable_diffusion_upscale.py | 8 +++---- .../test_stable_diffusion_v_pred.py | 22 +++++++++---------- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index ae0a13936603..8bfebac852f0 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -182,7 +182,7 @@ def test_cycle_diffusion_pipeline_fp16(self): source_prompt = "A black colored car" prompt = "A blue colored car" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, source_prompt=source_prompt, @@ -221,7 +221,7 @@ def test_cycle_diffusion_pipeline(self): source_prompt = "A black colored car" prompt = "A blue colored car" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, source_prompt=source_prompt, diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 3c2c3fcb136a..bceb17730033 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -443,8 +443,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 64, 64)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { @@ -674,8 +674,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 64, 64)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index bfe56dfb89bb..e997e817a6b0 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -183,8 +183,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_imgvar/input_image_vermeer.png" @@ -282,8 +282,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_imgvar/input_image_vermeer.png" diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index fe6dc729e63e..bcdff0ff9c6b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -218,8 +218,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/sketch-mountains-input.png" @@ -342,8 +342,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/sketch-mountains-input.png" diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index c763eff2b32d..ce8c11be0d07 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -172,8 +172,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/input_bench_image.png" @@ -288,8 +288,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/input_bench_image.png" diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 0b63ab6dc85e..fe483296fb1a 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -347,8 +347,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/input_bench_image.png" @@ -445,8 +445,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/input_bench_image.png" diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 3c9a54f7efeb..2c055723a289 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -44,7 +44,7 @@ def test_stable_diffusion_1(self): sd_pipe.set_scheduler("sample_euler") prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=9.0, num_inference_steps=20, output_type="np") image = output.images @@ -63,7 +63,7 @@ def test_stable_diffusion_2(self): sd_pipe.set_scheduler("sample_euler") prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=9.0, num_inference_steps=20, output_type="np") image = output.images diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 14571f0fe4fe..1ee2f6c71615 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -246,8 +246,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 64, 64)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { @@ -392,8 +392,8 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): + generator = torch.Generator(device=generator_device).manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 64, 64)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { 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 184d91c48742..ea8ffe224716 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -395,7 +395,7 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): + def get_inputs(self, device="cpu", dtype=torch.float32, seed=0): generator = torch.Generator(device=device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/depth2img/two_cats.png" @@ -419,7 +419,7 @@ def test_stable_diffusion_depth2img_pipeline_default(self): pipe.set_progress_bar_config(disable=None) pipe.enable_attention_slicing() - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() image = pipe(**inputs).images image_slice = image[0, 253:256, 253:256, -1].flatten() @@ -436,7 +436,7 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self): pipe.set_progress_bar_config(disable=None) pipe.enable_attention_slicing() - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() image = pipe(**inputs).images image_slice = image[0, 253:256, 253:256, -1].flatten() @@ -453,7 +453,7 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): pipe.set_progress_bar_config(disable=None) pipe.enable_attention_slicing() - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() image = pipe(**inputs).images image_slice = image[0, 253:256, 253:256, -1].flatten() @@ -490,7 +490,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: pipe.set_progress_bar_config(disable=None) pipe.enable_attention_slicing() - inputs = self.get_inputs(torch_device, dtype=torch.float16) + inputs = self.get_inputs(dtype=torch.float16) pipe(**inputs, callback=callback_fn, callback_steps=1) assert callback_fn.has_been_called assert number_of_steps == 2 @@ -508,7 +508,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): pipe.enable_attention_slicing(1) pipe.enable_sequential_cpu_offload() - inputs = self.get_inputs(torch_device, dtype=torch.float16) + inputs = self.get_inputs(dtype=torch.float16) _ = pipe(**inputs) mem_bytes = torch.cuda.max_memory_allocated() @@ -524,7 +524,7 @@ def tearDown(self): gc.collect() torch.cuda.empty_cache() - def get_inputs(self, device, dtype=torch.float32, seed=0): + def get_inputs(self, device="cpu", dtype=torch.float32, seed=0): generator = torch.Generator(device=device).manual_seed(seed) init_image = load_image( "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/depth2img/two_cats.png" @@ -545,7 +545,7 @@ def test_depth2img_pndm(self): pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() image = pipe(**inputs).images[0] expected_image = load_numpy( @@ -561,7 +561,7 @@ def test_depth2img_ddim(self): pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() image = pipe(**inputs).images[0] expected_image = load_numpy( @@ -577,7 +577,7 @@ def test_img2img_lms(self): pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() image = pipe(**inputs).images[0] expected_image = load_numpy( @@ -593,7 +593,7 @@ def test_img2img_dpm(self): pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - inputs = self.get_inputs(torch_device) + inputs = self.get_inputs() inputs["num_inference_steps"] = 30 image = pipe(**inputs).images[0] 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 756442600ef1..1ace38b5b9ae 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -158,7 +158,7 @@ def test_stable_diffusion_inpaint_pipeline(self): prompt = "Face of a yellow cat, high resolution, sitting on a park bench" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, image=init_image, @@ -196,7 +196,7 @@ def test_stable_diffusion_inpaint_pipeline_fp16(self): prompt = "Face of a yellow cat, high resolution, sitting on a park bench" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, image=init_image, @@ -237,7 +237,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): prompt = "Face of a yellow cat, high resolution, sitting on a park bench" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) _ = pipe( prompt=prompt, image=init_image, 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 7db23808ae94..6120a7b3bc63 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -241,7 +241,7 @@ def test_stable_diffusion_upscale_fp16(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = sd_pipe( [prompt], image=low_res_image, @@ -281,7 +281,7 @@ def test_stable_diffusion_upscale_pipeline(self): prompt = "a cat sitting on a park bench" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, image=image, @@ -314,7 +314,7 @@ def test_stable_diffusion_upscale_pipeline_fp16(self): prompt = "a cat sitting on a park bench" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, image=image, @@ -348,7 +348,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): prompt = "a cat sitting on a park bench" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) _ = pipe( prompt=prompt, image=image, 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 3f96480d2ee7..feff759f3293 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 @@ -233,7 +233,7 @@ def test_stable_diffusion_v_pred_fp16(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = sd_pipe([prompt], generator=generator, num_inference_steps=2, output_type="np").images assert image.shape == (1, 64, 64, 3) @@ -255,7 +255,7 @@ def test_stable_diffusion_v_pred_default(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=7.5, num_inference_steps=20, output_type="np") image = output.images @@ -274,7 +274,7 @@ def test_stable_diffusion_v_pred_upcast_attention(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=7.5, num_inference_steps=20, output_type="np") image = output.images @@ -292,7 +292,7 @@ def test_stable_diffusion_v_pred_euler(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = sd_pipe([prompt], generator=generator, num_inference_steps=5, output_type="numpy") image = output.images @@ -316,7 +316,7 @@ def test_stable_diffusion_v_pred_dpm(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "a photograph of an astronaut riding a horse" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = sd_pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=5, output_type="numpy" ).images @@ -337,7 +337,7 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # make attention efficient pipe.enable_attention_slicing() - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) with torch.autocast(torch_device): output_chunked = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" @@ -351,7 +351,7 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # disable slicing pipe.disable_attention_slicing() - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) with torch.autocast(torch_device): output = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" @@ -376,7 +376,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_default(self): prompt = "astronaut riding a horse" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe(prompt=prompt, guidance_scale=7.5, generator=generator, output_type="np") image = output.images[0] @@ -395,7 +395,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): prompt = "astronaut riding a horse" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe(prompt=prompt, guidance_scale=7.5, generator=generator, output_type="np") image = output.images[0] @@ -435,7 +435,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No prompt = "Andromeda galaxy in a bottle" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) with torch.autocast(torch_device): pipe( prompt=prompt, @@ -475,7 +475,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading_v_pred(self): pipeline.enable_attention_slicing(1) pipeline.enable_sequential_cpu_offload() - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) _ = pipeline(prompt, generator=generator, num_inference_steps=5) mem_bytes = torch.cuda.max_memory_allocated() From 745b167c87775f117f02a50ebea1d4b22a1444f3 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Thu, 5 Jan 2023 08:42:09 +0000 Subject: [PATCH 02/39] run slow tests --- .github/workflows/nightly_tests.yml | 3 +++ .github/workflows/push_tests.yml | 3 +++ .../pipelines/altdiffusion/test_alt_diffusion.py | 8 ++++---- .../altdiffusion/test_alt_diffusion_img2img.py | 4 ++-- .../dance_diffusion/test_dance_diffusion.py | 4 ++-- tests/pipelines/ddim/test_ddim.py | 4 ++-- tests/pipelines/ddpm/test_ddpm.py | 2 +- .../latent_diffusion/test_latent_diffusion.py | 4 ++-- .../test_latent_diffusion_superresolution.py | 2 +- .../paint_by_example/test_paint_by_example.py | 2 +- tests/pipelines/repaint/test_repaint.py | 2 +- .../stable_diffusion_safe/test_safe_diffusion.py | 16 ++++++++-------- .../test_versatile_diffusion_dual_guided.py | 4 ++-- .../test_versatile_diffusion_image_variation.py | 2 +- .../test_versatile_diffusion_mega.py | 6 +++--- .../test_versatile_diffusion_text_to_image.py | 4 ++-- .../pipelines/vq_diffusion/test_vq_diffusion.py | 2 +- 17 files changed, 39 insertions(+), 33 deletions(-) diff --git a/.github/workflows/nightly_tests.yml b/.github/workflows/nightly_tests.yml index fb0ce92cb61c..110fdbc2581a 100644 --- a/.github/workflows/nightly_tests.yml +++ b/.github/workflows/nightly_tests.yml @@ -3,6 +3,9 @@ name: Nightly tests on main on: schedule: - cron: "0 0 * * *" # every day at midnight + pull_request: # TODO: only for debugging, remove before merging! + branches: + - main env: DIFFUSERS_IS_CI: yes diff --git a/.github/workflows/push_tests.yml b/.github/workflows/push_tests.yml index 2d4875b80ced..88681a1875ea 100644 --- a/.github/workflows/push_tests.yml +++ b/.github/workflows/push_tests.yml @@ -4,6 +4,9 @@ on: push: branches: - main + pull_request: # TODO: only for debugging, remove before merging! + branches: + - main env: DIFFUSERS_IS_CI: yes diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index 1d1d47bf5025..19d0eca2c617 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -207,7 +207,7 @@ def test_alt_diffusion(self): alt_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) with torch.autocast("cuda"): output = alt_pipe( [prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np" @@ -231,7 +231,7 @@ def test_alt_diffusion_fast_ddim(self): alt_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) with torch.autocast("cuda"): output = alt_pipe([prompt], generator=generator, num_inference_steps=2, output_type="numpy") @@ -254,13 +254,13 @@ def test_alt_diffusion_text2img_pipeline_fp16(self): prompt = "a photograph of an astronaut riding a horse" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output_chunked = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" ) image_chunked = output_chunked.images - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) with torch.autocast(torch_device): output = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 761b2c013401..d6f528cd4a6f 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -196,7 +196,7 @@ def test_stable_diffusion_img2img_fp16(self): alt_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = alt_pipe( [prompt], generator=generator, @@ -238,7 +238,7 @@ def test_stable_diffusion_img2img_pipeline_default(self): prompt = "A fantasy landscape, trending on artstation" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, image=init_image, diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index b5188e904033..7c34a72f8c3d 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -104,7 +104,7 @@ def test_dance_diffusion(self): pipe = pipe.to(device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator(device=device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096) audio = output.audios @@ -121,7 +121,7 @@ def test_dance_diffusion_fp16(self): pipe = pipe.to(device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator(device=device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096) audio = output.audios diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index 38ff4fefe60b..43d94cd26ca1 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -92,7 +92,7 @@ def test_inference_ema_bedroom(self): ddpm.to(torch_device) ddpm.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = ddpm(generator=generator, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] @@ -111,7 +111,7 @@ def test_inference_cifar10(self): ddim.to(torch_device) ddim.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = ddim(generator=generator, eta=0.0, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 4652048d1aac..168e0be24f5b 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -139,7 +139,7 @@ def test_inference_cifar10(self): ddpm.to(torch_device) ddpm.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = ddpm(generator=generator, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index ef790f28e498..55ad2aabe602 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -126,7 +126,7 @@ def tearDown(self): torch.cuda.empty_cache() def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { @@ -162,7 +162,7 @@ def tearDown(self): torch.cuda.empty_cache() def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator(device=device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 89356f85728f..b227817b9178 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -121,7 +121,7 @@ def test_inference_superresolution(self): ldm.to(torch_device) ldm.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = ldm(image=init_image, generator=generator, num_inference_steps=20, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index 953fa44625c1..e9246df709e5 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -205,7 +205,7 @@ def test_paint_by_example(self): pipe = pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(321) + generator = torch.Generator().manual_seed(321) output = pipe( image=init_image, mask_image=mask_image, diff --git a/tests/pipelines/repaint/test_repaint.py b/tests/pipelines/repaint/test_repaint.py index 2288fa63bf5e..7e4229c7714a 100644 --- a/tests/pipelines/repaint/test_repaint.py +++ b/tests/pipelines/repaint/test_repaint.py @@ -113,7 +113,7 @@ def test_celebahq(self): repaint.set_progress_bar_config(disable=None) repaint.enable_attention_slicing() - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = repaint( original_image, mask_image, diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index aa143bd63b96..db5ba6d7405c 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -23,7 +23,7 @@ from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNet2DConditionModel from diffusers.pipelines.stable_diffusion_safe import StableDiffusionPipelineSafe as StableDiffusionPipeline -from diffusers.utils import floats_tensor, slow, torch_device +from diffusers.utils import floats_tensor, nightly, torch_device from diffusers.utils.testing_utils import require_torch_gpu from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer @@ -259,7 +259,7 @@ def test_stable_diffusion_fp16(self): assert image.shape == (1, 64, 64, 3) -@slow +@nightly @require_torch_gpu class SafeDiffusionPipelineIntegrationTests(unittest.TestCase): def tearDown(self): @@ -284,7 +284,7 @@ def test_harm_safe_stable_diffusion(self): guidance_scale = 7 # without safety guidance (sld_guidance_scale = 0) - generator = torch.Generator(device=torch_device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -304,7 +304,7 @@ def test_harm_safe_stable_diffusion(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 # without safety guidance (strong configuration) - generator = torch.Generator(device=torch_device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -337,7 +337,7 @@ def test_nudity_safe_stable_diffusion(self): seed = 2734971755 guidance_scale = 7 - generator = torch.Generator(device=torch_device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -356,7 +356,7 @@ def test_nudity_safe_stable_diffusion(self): assert image.shape == (1, 512, 512, 3) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 - generator = torch.Generator(device=torch_device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -391,7 +391,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): seed = 1044355234 guidance_scale = 12 - generator = torch.Generator(device=torch_device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -410,7 +410,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): assert image.shape == (1, 512, 512, 3) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 - generator = torch.Generator(device=torch_device).manual_seed(seed) + generator = torch.Generator().manual_seed(seed) output = sd_pipe( [prompt], generator=generator, diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index b8595378a58a..2b563627e6bc 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -51,7 +51,7 @@ def test_remove_unused_weights_save_load(self): "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe( prompt="first prompt", image=second_prompt, @@ -92,7 +92,7 @@ def test_inference_dual_guided(self): second_prompt = load_image( "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe( prompt=first_prompt, image=second_prompt, diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index 4c8bef0e71b3..6c21c3afeaef 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -40,7 +40,7 @@ def test_inference_image_variations(self): image_prompt = load_image( "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe( image=image_prompt, generator=generator, diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 3670894ed7d6..b09c607098bb 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -49,7 +49,7 @@ def test_from_save_pretrained(self): "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe.dual_guided( prompt="first prompt", image=prompt_image, @@ -88,7 +88,7 @@ def test_inference_dual_guided_then_text_to_image(self): init_image = load_image( "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe.dual_guided( prompt=prompt, image=init_image, @@ -106,7 +106,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe.text_to_image( prompt=prompt, generator=generator, guidance_scale=7.5, num_inference_steps=50, output_type="numpy" ).images diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index 44514da0108b..d296a39cd823 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -48,7 +48,7 @@ def test_remove_unused_weights_save_load(self): pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger " - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe( prompt=prompt, generator=generator, guidance_scale=7.5, num_inference_steps=2, output_type="numpy" ).images @@ -72,7 +72,7 @@ def test_inference_text2img(self): pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger " - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) image = pipe( prompt=prompt, generator=generator, guidance_scale=7.5, num_inference_steps=50, output_type="numpy" ).images diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index d992a5215298..17a2974687e5 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -212,7 +212,7 @@ def test_vq_diffusion_classifier_free_sampling(self): pipeline = pipeline.to(torch_device) pipeline.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipeline( "teddy bear playing in the pool", num_images_per_prompt=1, From ae219a80ad1b5486d83039f096fd29de7d0ba97e Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 23 Jan 2023 16:23:16 +0200 Subject: [PATCH 03/39] prepare for testing --- src/diffusers/utils/__init__.py | 1 + src/diffusers/utils/testing_utils.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/diffusers/utils/__init__.py b/src/diffusers/utils/__init__.py index c8cc25ae10f8..d53cf9d634a5 100644 --- a/src/diffusers/utils/__init__.py +++ b/src/diffusers/utils/__init__.py @@ -76,6 +76,7 @@ load_numpy, nightly, parse_flag_from_env, + print_tensor_test, require_torch_gpu, slow, torch_all_close, diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index a604aed605ce..3f04431ca559 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -45,6 +45,18 @@ def torch_all_close(a, b, *args, **kwargs): return True +def print_tensor_test(tensor): + test_name = os.environ.get("PYTEST_CURRENT_TEST") + if not torch.is_tensor(tensor): + tensor = torch.from_numpy(tensor) + + tensor_str = str(tensor.detach().cpu().flatten()) + # 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", "expected_slice = np.array") + print(50 * "-" + "\n" + test_name + "\n" + output_str + "\n" + 50 * "-") + + def get_tests_dir(append_path=None): """ Args: From d5d80b8fbb75d8935a074d919d9f49b00e6851cd Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 09:52:11 +0000 Subject: [PATCH 04/39] finish --- .../test_alt_diffusion_img2img.py | 2 +- tests/pipelines/ddpm/test_ddpm.py | 14 +--- .../test_latent_diffusion_superresolution.py | 3 +- .../test_stable_diffusion_img2img.py | 2 +- .../test_safe_diffusion.py | 3 +- tests/pipelines/unclip/test_unclip.py | 2 - tests/test_pipelines.py | 76 +++++-------------- tests/test_scheduler.py | 52 +++---------- 8 files changed, 33 insertions(+), 121 deletions(-) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index f418e67fcddd..f055c0cb764e 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -227,7 +227,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): prompt = "A fantasy landscape, trending on artstation" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=init_image, diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 168e0be24f5b..e3bfddb3908c 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -79,14 +79,10 @@ def test_inference_deprecated_predict_epsilon(self): if torch_device == "mps": _ = ddpm(num_inference_steps=1) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images - generator = generator.manual_seed(0) + generator = torch.manual_seed(0) image_eps = ddpm(generator=generator, num_inference_steps=2, output_type="numpy", predict_epsilon=False)[0] image_slice = image[0, -3:, -3:, -1] @@ -108,11 +104,7 @@ def test_inference_predict_sample(self): if torch_device == "mps": _ = ddpm(num_inference_steps=1) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images generator = generator.manual_seed(0) diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index b227817b9178..5c88a5dae0cf 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -101,8 +101,7 @@ def test_inference_superresolution_fp16(self): init_image = self.dummy_image.to(torch_device) - generator = torch.Generator(device=torch_device).manual_seed(0) - image = ldm(init_image, generator=generator, num_inference_steps=2, output_type="numpy").images + image = ldm(init_image, num_inference_steps=2, output_type="numpy").images assert image.shape == (1, 64, 64, 3) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 031c9b2fa59b..c64b3d52bf85 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -352,7 +352,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): prompt = "A fantasy landscape, trending on artstation" - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.Generator().manual_seed(0) output = pipe( prompt=prompt, image=init_image, diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index db5ba6d7405c..a894f07fe64e 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -253,8 +253,7 @@ def test_stable_diffusion_fp16(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator(device=torch_device).manual_seed(0) - image = sd_pipe([prompt], generator=generator, num_inference_steps=2, output_type="np").images + image = sd_pipe([prompt], num_inference_steps=2, output_type="np").images assert image.shape == (1, 64, 64, 3) diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 1a3b970dd2f9..06ad4203f020 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -460,11 +460,9 @@ def test_unclip_pipeline_with_sequential_cpu_offloading(self): pipe.enable_attention_slicing() pipe.enable_sequential_cpu_offload() - generator = torch.Generator(device=torch_device).manual_seed(0) _ = pipe( "horse", num_images_per_prompt=1, - generator=generator, prior_num_inference_steps=2, decoder_num_inference_steps=2, super_res_num_inference_steps=2, diff --git a/tests/test_pipelines.py b/tests/test_pipelines.py index 9e44ee6e7cd3..d6b080797292 100644 --- a/tests/test_pipelines.py +++ b/tests/test_pipelines.py @@ -86,19 +86,11 @@ def test_returned_cached_folder(self): pipe = pipe.to(torch_device) pipe_2 = pipe_2.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out = pipe(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out_2 = pipe_2(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images assert np.max(np.abs(out - out_2)) < 1e-3 @@ -125,20 +117,12 @@ def test_download_no_safety_checker(self): "hf-internal-testing/tiny-stable-diffusion-torch", safety_checker=None ) pipe = pipe.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out = pipe(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images pipe_2 = StableDiffusionPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-torch") pipe_2 = pipe_2.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out_2 = pipe_2(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images assert np.max(np.abs(out - out_2)) < 1e-3 @@ -149,11 +133,7 @@ def test_load_no_safety_checker_explicit_locally(self): "hf-internal-testing/tiny-stable-diffusion-torch", safety_checker=None ) pipe = pipe.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out = pipe(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images with tempfile.TemporaryDirectory() as tmpdirname: @@ -161,11 +141,7 @@ def test_load_no_safety_checker_explicit_locally(self): pipe_2 = StableDiffusionPipeline.from_pretrained(tmpdirname, safety_checker=None) pipe_2 = pipe_2.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out_2 = pipe_2(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images @@ -175,11 +151,8 @@ def test_load_no_safety_checker_default_locally(self): prompt = "hello" pipe = StableDiffusionPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-torch") pipe = pipe.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + + generator = torch.manual_seed(0) out = pipe(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images with tempfile.TemporaryDirectory() as tmpdirname: @@ -187,11 +160,7 @@ def test_load_no_safety_checker_default_locally(self): pipe_2 = StableDiffusionPipeline.from_pretrained(tmpdirname) pipe_2 = pipe_2.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) out_2 = pipe_2(prompt, num_inference_steps=2, generator=generator, output_type="numpy").images @@ -401,12 +370,7 @@ def test_uncond_unet_components(self, scheduler_fn=DDPMScheduler, pipeline_fn=DD scheduler = scheduler_fn() pipeline = pipeline_fn(unet, scheduler).to(torch_device) - # Device type MPS is not supported for torch.Generator() api. - if torch_device == "mps": - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) - + generator = torch.manual_seed(0) out_image = pipeline( generator=generator, num_inference_steps=2, @@ -442,12 +406,7 @@ def test_stable_diffusion_components(self): prompt = "A painting of a squirrel eating a burger" - # Device type MPS is not supported for torch.Generator() api. - if torch_device == "mps": - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) - + generator = torch.manual_seed(0) image_inpaint = inpaint( [prompt], generator=generator, @@ -798,7 +757,7 @@ def test_from_save_pretrained(self): generator = torch.Generator(device=torch_device).manual_seed(0) image = ddpm(generator=generator, num_inference_steps=5, output_type="numpy").images - generator = generator.manual_seed(0) + generator = torch.Generator(device=torch_device).manual_seed(0) new_image = new_ddpm(generator=generator, num_inference_steps=5, output_type="numpy").images assert np.abs(image - new_image).sum() < 1e-5, "Models don't give the same forward pass" @@ -819,7 +778,7 @@ def test_from_pretrained_hub(self): generator = torch.Generator(device=torch_device).manual_seed(0) image = ddpm(generator=generator, num_inference_steps=5, output_type="numpy").images - generator = generator.manual_seed(0) + generator = torch.Generator(device=torch_device).manual_seed(0) new_image = ddpm_from_hub(generator=generator, num_inference_steps=5, output_type="numpy").images assert np.abs(image - new_image).sum() < 1e-5, "Models don't give the same forward pass" @@ -842,7 +801,7 @@ def test_from_pretrained_hub_pass_model(self): generator = torch.Generator(device=torch_device).manual_seed(0) image = ddpm_from_hub_custom_model(generator=generator, num_inference_steps=5, output_type="numpy").images - generator = generator.manual_seed(0) + generator = torch.Generator(device=torch_device).manual_seed(0) new_image = ddpm_from_hub(generator=generator, num_inference_steps=5, output_type="numpy").images assert np.abs(image - new_image).sum() < 1e-5, "Models don't give the same forward pass" @@ -855,18 +814,17 @@ def test_output_format(self): pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator(device=torch_device).manual_seed(0) - images = pipe(generator=generator, output_type="numpy").images + images = pipe(output_type="numpy").images assert images.shape == (1, 32, 32, 3) assert isinstance(images, np.ndarray) - images = pipe(generator=generator, output_type="pil", num_inference_steps=4).images + images = pipe(output_type="pil", num_inference_steps=4).images assert isinstance(images, list) assert len(images) == 1 assert isinstance(images[0], PIL.Image.Image) # use PIL by default - images = pipe(generator=generator, num_inference_steps=4).images + images = pipe(num_inference_steps=4).images assert isinstance(images, list) assert isinstance(images[0], PIL.Image.Image) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 69831dee1bed..54307f97c696 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -1822,11 +1822,7 @@ def test_full_loop_no_noise(self): scheduler.set_timesteps(self.num_inference_steps) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -1853,11 +1849,7 @@ def test_full_loop_with_v_prediction(self): scheduler.set_timesteps(self.num_inference_steps) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -1884,11 +1876,7 @@ def test_full_loop_device(self): scheduler.set_timesteps(self.num_inference_steps, device=torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -1947,11 +1935,7 @@ def test_full_loop_no_noise(self): scheduler.set_timesteps(self.num_inference_steps) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -1983,11 +1967,7 @@ def test_full_loop_with_v_prediction(self): scheduler.set_timesteps(self.num_inference_steps) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -2018,12 +1998,7 @@ def test_full_loop_device(self): scheduler = scheduler_class(**scheduler_config) scheduler.set_timesteps(self.num_inference_steps, device=torch_device) - - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -2745,7 +2720,7 @@ def test_full_loop_no_noise(self): scheduler.set_timesteps(self.num_inference_steps) - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter * scheduler.init_noise_sigma @@ -2787,11 +2762,7 @@ def test_full_loop_with_v_prediction(self): sample = self.dummy_sample_deter * scheduler.init_noise_sigma sample = sample.to(torch_device) - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) for i, t in enumerate(scheduler.timesteps): sample = scheduler.scale_model_input(sample, t) @@ -2820,12 +2791,7 @@ def test_full_loop_device(self): scheduler = scheduler_class(**scheduler_config) scheduler.set_timesteps(self.num_inference_steps, device=torch_device) - - if torch_device == "mps": - # device type MPS is not supported for torch.Generator() api. - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=torch_device).manual_seed(0) + generator = torch.manual_seed(0) model = self.dummy_model() sample = self.dummy_sample_deter.to(torch_device) * scheduler.init_noise_sigma From 2458069acf58dbc17f7ae66c00bfe0a77a48d2fe Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 09:55:14 +0000 Subject: [PATCH 05/39] refactor --- tests/models/test_models_vae.py | 2 +- .../altdiffusion/test_alt_diffusion.py | 8 +++---- .../test_alt_diffusion_img2img.py | 4 ++-- .../dance_diffusion/test_dance_diffusion.py | 4 ++-- tests/pipelines/ddim/test_ddim.py | 4 ++-- tests/pipelines/ddpm/test_ddpm.py | 2 +- .../latent_diffusion/test_latent_diffusion.py | 4 ++-- .../test_latent_diffusion_superresolution.py | 2 +- .../paint_by_example/test_paint_by_example.py | 2 +- tests/pipelines/repaint/test_repaint.py | 2 +- .../stable_diffusion/test_cycle_diffusion.py | 4 ++-- .../test_stable_diffusion_img2img.py | 2 +- .../test_stable_diffusion_k_diffusion.py | 4 ++-- .../test_stable_diffusion_inpaint.py | 6 ++--- .../test_stable_diffusion_upscale.py | 8 +++---- .../test_stable_diffusion_v_pred.py | 22 +++++++++---------- .../test_safe_diffusion.py | 12 +++++----- .../test_versatile_diffusion_dual_guided.py | 4 ++-- ...est_versatile_diffusion_image_variation.py | 2 +- .../test_versatile_diffusion_mega.py | 6 ++--- .../test_versatile_diffusion_text_to_image.py | 4 ++-- .../vq_diffusion/test_vq_diffusion.py | 2 +- tests/test_scheduler.py | 20 ++++++++--------- 23 files changed, 65 insertions(+), 65 deletions(-) diff --git a/tests/models/test_models_vae.py b/tests/models/test_models_vae.py index 75481ecbbb8c..c0181ef03c5c 100644 --- a/tests/models/test_models_vae.py +++ b/tests/models/test_models_vae.py @@ -166,7 +166,7 @@ def get_sd_vae_model(self, model_id="CompVis/stable-diffusion-v1-4", fp16=False) def get_generator(self, seed=0): if torch_device == "mps": - return torch.Generator().manual_seed(seed) + return torch.manual_seed(seed) return torch.Generator(device=torch_device).manual_seed(seed) @parameterized.expand( diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index 19d0eca2c617..2603f92388a5 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -207,7 +207,7 @@ def test_alt_diffusion(self): alt_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) with torch.autocast("cuda"): output = alt_pipe( [prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np" @@ -231,7 +231,7 @@ def test_alt_diffusion_fast_ddim(self): alt_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) with torch.autocast("cuda"): output = alt_pipe([prompt], generator=generator, num_inference_steps=2, output_type="numpy") @@ -254,13 +254,13 @@ def test_alt_diffusion_text2img_pipeline_fp16(self): prompt = "a photograph of an astronaut riding a horse" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output_chunked = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" ) image_chunked = output_chunked.images - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) with torch.autocast(torch_device): output = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index f055c0cb764e..17c13511c747 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -196,7 +196,7 @@ def test_stable_diffusion_img2img_fp16(self): alt_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = alt_pipe( [prompt], generator=generator, @@ -275,7 +275,7 @@ def test_stable_diffusion_img2img_pipeline_default(self): prompt = "A fantasy landscape, trending on artstation" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=init_image, diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index 7c34a72f8c3d..4fee47bcd9cd 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -104,7 +104,7 @@ def test_dance_diffusion(self): pipe = pipe.to(device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096) audio = output.audios @@ -121,7 +121,7 @@ def test_dance_diffusion_fp16(self): pipe = pipe.to(device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096) audio = output.audios diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index 43d94cd26ca1..3d1859cfa7dc 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -92,7 +92,7 @@ def test_inference_ema_bedroom(self): ddpm.to(torch_device) ddpm.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = ddpm(generator=generator, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] @@ -111,7 +111,7 @@ def test_inference_cifar10(self): ddim.to(torch_device) ddim.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = ddim(generator=generator, eta=0.0, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index e3bfddb3908c..26e45494dca4 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -131,7 +131,7 @@ def test_inference_cifar10(self): ddpm.to(torch_device) ddpm.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = ddpm(generator=generator, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index 55ad2aabe602..244987f89819 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -126,7 +126,7 @@ def tearDown(self): torch.cuda.empty_cache() def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { @@ -162,7 +162,7 @@ def tearDown(self): torch.cuda.empty_cache() def get_inputs(self, device, dtype=torch.float32, seed=0): - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32)) latents = torch.from_numpy(latents).to(device=device, dtype=dtype) inputs = { diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 5c88a5dae0cf..da2d8865fa77 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -120,7 +120,7 @@ def test_inference_superresolution(self): ldm.to(torch_device) ldm.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = ldm(image=init_image, generator=generator, num_inference_steps=20, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index e9246df709e5..599b69168a76 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -205,7 +205,7 @@ def test_paint_by_example(self): pipe = pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(321) + generator = torch.manual_seed(321) output = pipe( image=init_image, mask_image=mask_image, diff --git a/tests/pipelines/repaint/test_repaint.py b/tests/pipelines/repaint/test_repaint.py index 7e4229c7714a..59675306627f 100644 --- a/tests/pipelines/repaint/test_repaint.py +++ b/tests/pipelines/repaint/test_repaint.py @@ -113,7 +113,7 @@ def test_celebahq(self): repaint.set_progress_bar_config(disable=None) repaint.enable_attention_slicing() - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = repaint( original_image, mask_image, diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 8bfebac852f0..5c088f191773 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -182,7 +182,7 @@ def test_cycle_diffusion_pipeline_fp16(self): source_prompt = "A black colored car" prompt = "A blue colored car" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, source_prompt=source_prompt, @@ -221,7 +221,7 @@ def test_cycle_diffusion_pipeline(self): source_prompt = "A black colored car" prompt = "A blue colored car" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, source_prompt=source_prompt, diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index c64b3d52bf85..84bd809764af 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -352,7 +352,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): prompt = "A fantasy landscape, trending on artstation" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=init_image, diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 2c055723a289..2351e99b6c9e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -44,7 +44,7 @@ def test_stable_diffusion_1(self): sd_pipe.set_scheduler("sample_euler") prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=9.0, num_inference_steps=20, output_type="np") image = output.images @@ -63,7 +63,7 @@ def test_stable_diffusion_2(self): sd_pipe.set_scheduler("sample_euler") prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=9.0, num_inference_steps=20, output_type="np") image = output.images 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 1ace38b5b9ae..096c083bef6c 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -158,7 +158,7 @@ def test_stable_diffusion_inpaint_pipeline(self): prompt = "Face of a yellow cat, high resolution, sitting on a park bench" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=init_image, @@ -196,7 +196,7 @@ def test_stable_diffusion_inpaint_pipeline_fp16(self): prompt = "Face of a yellow cat, high resolution, sitting on a park bench" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=init_image, @@ -237,7 +237,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): prompt = "Face of a yellow cat, high resolution, sitting on a park bench" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) _ = pipe( prompt=prompt, image=init_image, 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 6120a7b3bc63..9e70f1e55c4a 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -241,7 +241,7 @@ def test_stable_diffusion_upscale_fp16(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = sd_pipe( [prompt], image=low_res_image, @@ -281,7 +281,7 @@ def test_stable_diffusion_upscale_pipeline(self): prompt = "a cat sitting on a park bench" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=image, @@ -314,7 +314,7 @@ def test_stable_diffusion_upscale_pipeline_fp16(self): prompt = "a cat sitting on a park bench" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe( prompt=prompt, image=image, @@ -348,7 +348,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): prompt = "a cat sitting on a park bench" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) _ = pipe( prompt=prompt, image=image, 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 feff759f3293..5cc81b574601 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 @@ -233,7 +233,7 @@ def test_stable_diffusion_v_pred_fp16(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = sd_pipe([prompt], generator=generator, num_inference_steps=2, output_type="np").images assert image.shape == (1, 64, 64, 3) @@ -255,7 +255,7 @@ def test_stable_diffusion_v_pred_default(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=7.5, num_inference_steps=20, output_type="np") image = output.images @@ -274,7 +274,7 @@ def test_stable_diffusion_v_pred_upcast_attention(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = sd_pipe([prompt], generator=generator, guidance_scale=7.5, num_inference_steps=20, output_type="np") image = output.images @@ -292,7 +292,7 @@ def test_stable_diffusion_v_pred_euler(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = sd_pipe([prompt], generator=generator, num_inference_steps=5, output_type="numpy") image = output.images @@ -316,7 +316,7 @@ def test_stable_diffusion_v_pred_dpm(self): sd_pipe.set_progress_bar_config(disable=None) prompt = "a photograph of an astronaut riding a horse" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = sd_pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=5, output_type="numpy" ).images @@ -337,7 +337,7 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # make attention efficient pipe.enable_attention_slicing() - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) with torch.autocast(torch_device): output_chunked = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" @@ -351,7 +351,7 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # disable slicing pipe.disable_attention_slicing() - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) with torch.autocast(torch_device): output = pipe( [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" @@ -376,7 +376,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_default(self): prompt = "astronaut riding a horse" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe(prompt=prompt, guidance_scale=7.5, generator=generator, output_type="np") image = output.images[0] @@ -395,7 +395,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): prompt = "astronaut riding a horse" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipe(prompt=prompt, guidance_scale=7.5, generator=generator, output_type="np") image = output.images[0] @@ -435,7 +435,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No prompt = "Andromeda galaxy in a bottle" - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) with torch.autocast(torch_device): pipe( prompt=prompt, @@ -475,7 +475,7 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading_v_pred(self): pipeline.enable_attention_slicing(1) pipeline.enable_sequential_cpu_offload() - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) _ = pipeline(prompt, generator=generator, num_inference_steps=5) mem_bytes = torch.cuda.max_memory_allocated() diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index a894f07fe64e..1691511b72b9 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -283,7 +283,7 @@ def test_harm_safe_stable_diffusion(self): guidance_scale = 7 # without safety guidance (sld_guidance_scale = 0) - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -303,7 +303,7 @@ def test_harm_safe_stable_diffusion(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 # without safety guidance (strong configuration) - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -336,7 +336,7 @@ def test_nudity_safe_stable_diffusion(self): seed = 2734971755 guidance_scale = 7 - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -355,7 +355,7 @@ def test_nudity_safe_stable_diffusion(self): assert image.shape == (1, 512, 512, 3) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -390,7 +390,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): seed = 1044355234 guidance_scale = 12 - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) output = sd_pipe( [prompt], generator=generator, @@ -409,7 +409,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): assert image.shape == (1, 512, 512, 3) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 - generator = torch.Generator().manual_seed(seed) + generator = torch.manual_seed(seed) output = sd_pipe( [prompt], generator=generator, diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index 2b563627e6bc..49697ba4298e 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -51,7 +51,7 @@ def test_remove_unused_weights_save_load(self): "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe( prompt="first prompt", image=second_prompt, @@ -92,7 +92,7 @@ def test_inference_dual_guided(self): second_prompt = load_image( "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe( prompt=first_prompt, image=second_prompt, diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index 6c21c3afeaef..05d871f75319 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -40,7 +40,7 @@ def test_inference_image_variations(self): image_prompt = load_image( "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe( image=image_prompt, generator=generator, diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index b09c607098bb..0e1fc83c8265 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -49,7 +49,7 @@ def test_from_save_pretrained(self): "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe.dual_guided( prompt="first prompt", image=prompt_image, @@ -88,7 +88,7 @@ def test_inference_dual_guided_then_text_to_image(self): init_image = load_image( "https://raw.githubusercontent.com/SHI-Labs/Versatile-Diffusion/master/assets/benz.jpg" ) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe.dual_guided( prompt=prompt, image=init_image, @@ -106,7 +106,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe.text_to_image( prompt=prompt, generator=generator, guidance_scale=7.5, num_inference_steps=50, output_type="numpy" ).images diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index d296a39cd823..e035f90254b9 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -48,7 +48,7 @@ def test_remove_unused_weights_save_load(self): pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger " - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe( prompt=prompt, generator=generator, guidance_scale=7.5, num_inference_steps=2, output_type="numpy" ).images @@ -72,7 +72,7 @@ def test_inference_text2img(self): pipe.set_progress_bar_config(disable=None) prompt = "A painting of a squirrel eating a burger " - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) image = pipe( prompt=prompt, generator=generator, guidance_scale=7.5, num_inference_steps=50, output_type="numpy" ).images diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index 17a2974687e5..b3513dff4dae 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -212,7 +212,7 @@ def test_vq_diffusion_classifier_free_sampling(self): pipeline = pipeline.to(torch_device) pipeline.set_progress_bar_config(disable=None) - generator = torch.Generator().manual_seed(0) + generator = torch.manual_seed(0) output = pipeline( "teddy bear playing in the pool", num_images_per_prompt=1, diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 54307f97c696..67bebe4b675e 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -288,11 +288,11 @@ def check_over_configs(self, time_step=0, **config): # Set the seed before step() as some schedulers are stochastic like EulerAncestralDiscreteScheduler, EulerDiscreteScheduler if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) output = scheduler.step(residual, time_step, sample, **kwargs).prev_sample if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) new_output = new_scheduler.step(residual, time_step, sample, **kwargs).prev_sample assert torch.sum(torch.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical" @@ -330,11 +330,11 @@ def check_over_forward(self, time_step=0, **forward_kwargs): kwargs["num_inference_steps"] = num_inference_steps if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) output = scheduler.step(residual, time_step, sample, **kwargs).prev_sample if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) new_output = new_scheduler.step(residual, time_step, sample, **kwargs).prev_sample assert torch.sum(torch.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical" @@ -372,11 +372,11 @@ def test_from_save_pretrained(self): kwargs["num_inference_steps"] = num_inference_steps if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) output = scheduler.step(residual, timestep, sample, **kwargs).prev_sample if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) new_output = new_scheduler.step(residual, timestep, sample, **kwargs).prev_sample assert torch.sum(torch.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical" @@ -510,7 +510,7 @@ def recursive_check(tuple_object, dict_object): # Set the seed before state as some schedulers are stochastic like EulerAncestralDiscreteScheduler, EulerDiscreteScheduler if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) outputs_dict = scheduler.step(residual, timestep, sample, **kwargs) if num_inference_steps is not None and hasattr(scheduler, "set_timesteps"): @@ -520,7 +520,7 @@ def recursive_check(tuple_object, dict_object): # Set the seed before state as some schedulers are stochastic like EulerAncestralDiscreteScheduler, EulerDiscreteScheduler if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) outputs_tuple = scheduler.step(residual, timestep, sample, return_dict=False, **kwargs) recursive_check(outputs_tuple, outputs_dict) @@ -664,12 +664,12 @@ def test_deprecated_epsilon(self): kwargs = {} if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) output = scheduler.step(residual, time_step, sample, predict_epsilon=False, **kwargs).prev_sample kwargs = {} if "generator" in set(inspect.signature(scheduler.step).parameters.keys()): - kwargs["generator"] = torch.Generator().manual_seed(0) + kwargs["generator"] = torch.manual_seed(0) output_eps = scheduler_eps.step(residual, time_step, sample, predict_epsilon=False, **kwargs).prev_sample assert (output - output_eps).abs().sum() < 1e-5 From db9dc5ddb8b9b282a287a3f9b34b24bfef29ad92 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 18:09:54 +0000 Subject: [PATCH 06/39] add print statements --- src/diffusers/utils/testing_utils.py | 7 ++- test_failures.txt | 1 + .../altdiffusion/test_alt_diffusion.py | 46 ++++-------------- .../test_alt_diffusion_img2img.py | 4 +- .../audio_diffusion/test_audio_diffusion.py | 8 ++-- tests/pipelines/ddim/test_ddim.py | 4 +- tests/pipelines/ddpm/test_ddpm.py | 4 +- tests/pipelines/karras_ve/test_karras_ve.py | 4 +- .../latent_diffusion/test_latent_diffusion.py | 2 +- .../test_latent_diffusion_superresolution.py | 4 +- .../test_latent_diffusion_uncond.py | 4 +- .../paint_by_example/test_paint_by_example.py | 4 +- tests/pipelines/pndm/test_pndm.py | 4 +- tests/pipelines/repaint/test_repaint.py | 2 +- .../score_sde_ve/test_score_sde_ve.py | 4 +- .../stable_diffusion/test_cycle_diffusion.py | 4 +- .../test_onnx_stable_diffusion.py | 18 +++---- .../test_onnx_stable_diffusion_img2img.py | 14 +++--- .../test_onnx_stable_diffusion_inpaint.py | 4 +- .../stable_diffusion/test_stable_diffusion.py | 16 ++++--- .../test_stable_diffusion_image_variation.py | 4 +- .../test_stable_diffusion_img2img.py | 10 ++-- .../test_stable_diffusion_inpaint.py | 2 +- .../test_stable_diffusion_inpaint_legacy.py | 4 +- ...st_stable_diffusion_instruction_pix2pix.py | 10 ++-- .../test_stable_diffusion_k_diffusion.py | 4 +- .../test_stable_diffusion.py | 10 ++-- .../test_stable_diffusion_depth.py | 8 ++-- .../test_stable_diffusion_inpaint.py | 2 +- .../test_stable_diffusion_upscale.py | 2 +- .../test_stable_diffusion_v_pred.py | 47 +++++++++---------- .../test_safe_diffusion.py | 16 +++---- tests/pipelines/unclip/test_unclip.py | 2 +- .../unclip/test_unclip_image_variation.py | 8 ++-- .../test_versatile_diffusion_dual_guided.py | 2 +- ...est_versatile_diffusion_image_variation.py | 2 +- .../test_versatile_diffusion_mega.py | 6 +-- .../test_versatile_diffusion_text_to_image.py | 2 +- .../vq_diffusion/test_vq_diffusion.py | 4 +- 39 files changed, 138 insertions(+), 165 deletions(-) create mode 100644 test_failures.txt diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 3f04431ca559..6c3dea541409 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -45,7 +45,7 @@ def torch_all_close(a, b, *args, **kwargs): return True -def print_tensor_test(tensor): +def print_tensor_test(tensor, filename="test_failures.txt"): test_name = os.environ.get("PYTEST_CURRENT_TEST") if not torch.is_tensor(tensor): tensor = torch.from_numpy(tensor) @@ -54,7 +54,10 @@ def print_tensor_test(tensor): # 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", "expected_slice = np.array") - print(50 * "-" + "\n" + test_name + "\n" + output_str + "\n" + 50 * "-") + 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): diff --git a/test_failures.txt b/test_failures.txt new file mode 100644 index 000000000000..733877e90171 --- /dev/null +++ b/test_failures.txt @@ -0,0 +1 @@ +tests/pipelines/audio_diffusion/test_audio_diffusion.py;PipelineIntegrationTests;test_audio_diffusion;expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26], dtype=torch.uint8) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index 2603f92388a5..efb83e916df2 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -155,7 +155,7 @@ def test_alt_diffusion_ddim(self): [0.5748162, 0.60447145, 0.48821217, 0.50100636, 0.5431185, 0.45763683, 0.49657696, 0.48132733, 0.47573093] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_pndm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -188,7 +188,7 @@ def test_alt_diffusion_pndm(self): expected_slice = np.array( [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @slow @@ -208,10 +208,9 @@ def test_alt_diffusion(self): prompt = "A painting of a squirrel eating a burger" generator = torch.manual_seed(0) - with torch.autocast("cuda"): - output = alt_pipe( - [prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np" - ) + output = alt_pipe( + [prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np" + ) image = output.images @@ -221,7 +220,7 @@ def test_alt_diffusion(self): expected_slice = np.array( [0.8720703, 0.87109375, 0.87402344, 0.87109375, 0.8779297, 0.8925781, 0.8823242, 0.8808594, 0.8613281] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_fast_ddim(self): scheduler = DDIMScheduler.from_pretrained("BAAI/AltDiffusion", subfolder="scheduler") @@ -233,8 +232,7 @@ def test_alt_diffusion_fast_ddim(self): prompt = "A painting of a squirrel eating a burger" generator = torch.manual_seed(0) - with torch.autocast("cuda"): - output = alt_pipe([prompt], generator=generator, num_inference_steps=2, output_type="numpy") + output = alt_pipe([prompt], generator=generator, num_inference_steps=2, output_type="numpy") image = output.images image_slice = image[0, -3:, -3:, -1] @@ -243,32 +241,4 @@ def test_alt_diffusion_fast_ddim(self): expected_slice = np.array( [0.9267578, 0.9301758, 0.9013672, 0.9345703, 0.92578125, 0.94433594, 0.9423828, 0.9423828, 0.9160156] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 - - def test_alt_diffusion_text2img_pipeline_fp16(self): - torch.cuda.reset_peak_memory_stats() - model_id = "BAAI/AltDiffusion" - pipe = AltDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None) - pipe = pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - prompt = "a photograph of an astronaut riding a horse" - - generator = torch.manual_seed(0) - output_chunked = pipe( - [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" - ) - image_chunked = output_chunked.images - - generator = torch.manual_seed(0) - with torch.autocast(torch_device): - output = pipe( - [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" - ) - image = output.images - - # Make sure results are close enough - diff = np.abs(image_chunked.flatten() - image.flatten()) - # They ARE different since ops are not run always at the same precision - # however, they should be extremely close. - assert diff.mean() < 2e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 17c13511c747..35dcecdd7604 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -162,7 +162,7 @@ def test_stable_diffusion_img2img_default_case(self): expected_slice = np.array( [0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1.5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); 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 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -242,7 +242,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): assert image.shape == (504, 760, 3) expected_slice = np.array([0.3252, 0.3340, 0.3418, 0.3263, 0.3346, 0.3300, 0.3163, 0.3470, 0.3427]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @slow diff --git a/tests/pipelines/audio_diffusion/test_audio_diffusion.py b/tests/pipelines/audio_diffusion/test_audio_diffusion.py index b9d180863a75..0a9ed6df1200 100644 --- a/tests/pipelines/audio_diffusion/test_audio_diffusion.py +++ b/tests/pipelines/audio_diffusion/test_audio_diffusion.py @@ -119,7 +119,7 @@ def test_audio_diffusion(self): image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_from_tuple_slice = np.frombuffer(image_from_tuple.tobytes(), dtype="uint8")[:10] expected_slice = np.array([255, 255, 255, 0, 181, 0, 124, 0, 15, 255]) - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0 scheduler = DDIMScheduler() @@ -142,7 +142,7 @@ def test_audio_diffusion(self): ) image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]) - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 dummy_unet_condition = self.dummy_unet_condition pipe = AudioDiffusionPipeline( @@ -155,7 +155,7 @@ def test_audio_diffusion(self): image = output.images[0] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 139, 147, 123, 124, 96, 115, 121, 126, 144]) - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 @slow @@ -183,4 +183,4 @@ def test_audio_diffusion(self): assert image.height == pipe.unet.sample_size[0] and image.width == pipe.unet.sample_size[1] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]) - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index 3d1859cfa7dc..e8222c87705b 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -99,7 +99,7 @@ def test_inference_ema_bedroom(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_cifar10(self): model_id = "google/ddpm-cifar10-32" @@ -118,4 +118,4 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.2060, 0.2042, 0.2022, 0.2193, 0.2146, 0.2110, 0.2471, 0.2446, 0.2388]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 26e45494dca4..228e8339cbfc 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -63,7 +63,7 @@ def test_inference(self): expected_slice = np.array( [5.589e-01, 7.089e-01, 2.632e-01, 6.841e-01, 1.000e-04, 9.999e-01, 1.973e-01, 1.000e-04, 8.010e-02] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_deprecated_predict_epsilon(self): @@ -138,4 +138,4 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4454, 0.2025, 0.0315, 0.3023, 0.2575, 0.1031, 0.0953, 0.1604, 0.2020]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/karras_ve/test_karras_ve.py b/tests/pipelines/karras_ve/test_karras_ve.py index 9806e8bf373e..a40be566025c 100644 --- a/tests/pipelines/karras_ve/test_karras_ve.py +++ b/tests/pipelines/karras_ve/test_karras_ve.py @@ -59,7 +59,7 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -81,4 +81,4 @@ def test_inference(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index 244987f89819..ff51c0afcf2a 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -114,7 +114,7 @@ def test_inference_text2img(self): assert image.shape == (1, 16, 16, 3) expected_slice = np.array([0.59450, 0.64078, 0.55509, 0.51229, 0.69640, 0.36960, 0.59296, 0.60801, 0.49332]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @slow diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index da2d8865fa77..4e623c8a3c54 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -83,7 +83,7 @@ def test_inference_superresolution(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") def test_inference_superresolution_fp16(self): @@ -127,4 +127,4 @@ def test_inference_superresolution(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.7418, 0.7472, 0.7424, 0.7422, 0.7463, 0.726, 0.7382, 0.7248, 0.6828]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py index 39ad12254e09..4cae4818392b 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py @@ -96,7 +96,7 @@ def test_inference_uncond(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance @@ -116,4 +116,4 @@ def test_inference_uncond(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index 599b69168a76..009b486e041f 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -134,7 +134,7 @@ def test_paint_by_example_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4701, 0.5555, 0.3994, 0.5107, 0.5691, 0.4517, 0.5125, 0.4769, 0.4539]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_paint_by_example_image_tensor(self): device = "cpu" @@ -224,4 +224,4 @@ def test_paint_by_example(self): expected_slice = np.array( [0.47455794, 0.47086594, 0.47683704, 0.51024145, 0.5064255, 0.5123164, 0.532502, 0.5328063, 0.5428694] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/pndm/test_pndm.py b/tests/pipelines/pndm/test_pndm.py index 8851607ccc07..85515b1fa76b 100644 --- a/tests/pipelines/pndm/test_pndm.py +++ b/tests/pipelines/pndm/test_pndm.py @@ -59,7 +59,7 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -82,4 +82,4 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/repaint/test_repaint.py b/tests/pipelines/repaint/test_repaint.py index 59675306627f..15a1d0d65994 100644 --- a/tests/pipelines/repaint/test_repaint.py +++ b/tests/pipelines/repaint/test_repaint.py @@ -81,7 +81,7 @@ def test_repaint(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0000, 0.5426, 0.5497, 0.2200, 1.0000, 1.0000, 0.5623, 1.0000, 0.6274]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @nightly diff --git a/tests/pipelines/score_sde_ve/test_score_sde_ve.py b/tests/pipelines/score_sde_ve/test_score_sde_ve.py index 4379bd146f9b..cb730fead620 100644 --- a/tests/pipelines/score_sde_ve/test_score_sde_ve.py +++ b/tests/pipelines/score_sde_ve/test_score_sde_ve.py @@ -61,7 +61,7 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -86,4 +86,4 @@ def test_inference(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 5c088f191773..d426ef4cc896 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -126,7 +126,7 @@ def test_stable_diffusion_cycle(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.4459, 0.4943, 0.4544, 0.6643, 0.5474, 0.4327, 0.5701, 0.5959, 0.5179]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") def test_stable_diffusion_cycle_fp16(self): @@ -147,7 +147,7 @@ def test_stable_diffusion_cycle_fp16(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.3506, 0.4543, 0.446, 0.4575, 0.5195, 0.4155, 0.5273, 0.518, 0.4116]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @slow diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index f076d726060f..8766858eb0c8 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -60,7 +60,7 @@ def test_pipeline_default_ddim(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65072, 0.58492, 0.48219, 0.55521, 0.53180, 0.55939, 0.50697, 0.39800, 0.46455]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_pndm(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -73,7 +73,7 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65863, 0.59425, 0.49326, 0.56313, 0.53875, 0.56627, 0.51065, 0.39777, 0.46330]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_lms(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -86,7 +86,7 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -99,7 +99,7 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler_ancestral(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -112,7 +112,7 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53817, 0.60812, 0.47384, 0.49530, 0.51894, 0.49814, 0.47984, 0.38958, 0.44271]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_dpm_multistep(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -125,7 +125,7 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53895, 0.60808, 0.47933, 0.49608, 0.51886, 0.49950, 0.48053, 0.38957, 0.44200]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @nightly @@ -169,7 +169,7 @@ def test_inference_default_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_ddim(self): ddim_scheduler = DDIMScheduler.from_pretrained( @@ -194,7 +194,7 @@ def test_inference_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): lms_scheduler = LMSDiscreteScheduler.from_pretrained( @@ -219,7 +219,7 @@ def test_inference_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_intermediate_state(self): number_of_steps = 0 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 ad33dda680fe..07d41c9367dd 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py @@ -82,7 +82,7 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.61710, 0.53390, 0.49310, 0.55622, 0.50982, 0.58240, 0.50716, 0.38629, 0.46856]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_lms(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -98,7 +98,7 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52761, 0.59977, 0.49033, 0.49619, 0.54282, 0.50311, 0.47600, 0.40918, 0.45203]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -111,7 +111,7 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler_ancestral(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -124,7 +124,7 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_dpm_multistep(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -137,7 +137,7 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65331, 0.58277, 0.48204, 0.56059, 0.53665, 0.56235, 0.50969, 0.40009, 0.46552]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 @nightly @@ -195,7 +195,7 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.4909, 0.5059, 0.5372, 0.4623, 0.4876, 0.5049, 0.4820, 0.4956, 0.5019]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 def test_inference_k_lms(self): init_image = load_image( @@ -235,4 +235,4 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.8043, 0.926, 0.9581, 0.8119, 0.8954, 0.913, 0.7209, 0.7463, 0.7431]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 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 cec4394b3452..e9ad71843823 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py @@ -94,7 +94,7 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.2514, 0.3007, 0.3517, 0.1790, 0.2382, 0.3167, 0.1944, 0.2273, 0.2464]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): init_image = load_image( @@ -136,4 +136,4 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index bceb17730033..b92a03c867bb 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -132,7 +132,7 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5643, 0.6017, 0.4799, 0.5267, 0.5584, 0.4641, 0.5159, 0.4963, 0.4791]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_ddim_factor_8(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -151,7 +151,7 @@ def test_stable_diffusion_ddim_factor_8(self): assert image.shape == (1, 136, 136, 3) expected_slice = np.array([0.5524, 0.5626, 0.6069, 0.4727, 0.386, 0.3995, 0.4613, 0.4328, 0.4269]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -168,7 +168,7 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5094, 0.5674, 0.4667, 0.5125, 0.5696, 0.4674, 0.5277, 0.4964, 0.4945]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_no_safety_checker(self): pipe = StableDiffusionPipeline.from_pretrained( @@ -219,7 +219,7 @@ def test_stable_diffusion_k_lms(self): 0.5042197108268738, ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -249,7 +249,7 @@ def test_stable_diffusion_k_euler_ancestral(self): 0.504422664642334, ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -279,7 +279,7 @@ def test_stable_diffusion_k_euler(self): 0.5042197108268738, ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_vae_slicing(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -333,7 +333,7 @@ def test_stable_diffusion_negative_prompt(self): 0.4899061322212219, ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -584,6 +584,8 @@ def test_stable_diffusion_vae_slicing(self): assert np.abs(image_sliced - image).max() < 4e-3 def test_stable_diffusion_fp16_vs_autocast(self): + # this test makes sure that the original model with autocast + # and the new model with fp16 yield the same result pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16) pipe = pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index e997e817a6b0..a2389bbc74ff 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -117,7 +117,7 @@ def test_stable_diffusion_img_variation_default_case(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5167, 0.5746, 0.4835, 0.4914, 0.5605, 0.4691, 0.5201, 0.4898, 0.4958]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_multiple_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -136,7 +136,7 @@ def test_stable_diffusion_img_variation_multiple_images(self): assert image.shape == (2, 64, 64, 3) expected_slice = np.array([0.6568, 0.5470, 0.5684, 0.5444, 0.5945, 0.6221, 0.5508, 0.5531, 0.5263]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_num_images_per_prompt(self): device = "cpu" diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 84bd809764af..688af4d2b0a6 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -119,7 +119,7 @@ def test_stable_diffusion_img2img_default_case(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4492, 0.3865, 0.4222, 0.5854, 0.5139, 0.4379, 0.4193, 0.48, 0.4218]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_negative_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -136,7 +136,7 @@ def test_stable_diffusion_img2img_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4065, 0.3783, 0.4050, 0.5266, 0.4781, 0.4252, 0.4203, 0.4692, 0.4365]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -153,7 +153,7 @@ def test_stable_diffusion_img2img_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.5144, 0.4447, 0.4735, 0.6676, 0.5526, 0.5454, 0.645, 0.5149, 0.4689]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -171,7 +171,7 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4367, 0.4986, 0.4372, 0.6706, 0.5665, 0.444, 0.5864, 0.6019, 0.5203]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -367,7 +367,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): assert image.shape == (504, 760, 3) expected_slice = np.array([0.7124, 0.7105, 0.6993, 0.7140, 0.7106, 0.6945, 0.7198, 0.7172, 0.7031]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @nightly diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index ce8c11be0d07..9f040b185ed5 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -125,7 +125,7 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4723, 0.5731, 0.3939, 0.5441, 0.5922, 0.4392, 0.5059, 0.4651, 0.4474]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_image_tensor(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index fe483296fb1a..4a4c989f4496 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -213,7 +213,7 @@ def test_stable_diffusion_inpaint_legacy(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4731, 0.5346, 0.4531, 0.6251, 0.5446, 0.4057, 0.5527, 0.5896, 0.5153]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_legacy_negative_prompt(self): @@ -260,7 +260,7 @@ def test_stable_diffusion_inpaint_legacy_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4765, 0.5339, 0.4541, 0.6240, 0.5439, 0.4055, 0.5503, 0.5891, 0.5150]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_legacy_num_images_per_prompt(self): device = "cpu" 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 ee9263cc87cf..9ab18ac37f11 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -122,7 +122,7 @@ def test_stable_diffusion_pix2pix_default_case(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7318, 0.3723, 0.4662, 0.623, 0.5770, 0.5014, 0.4281, 0.5550, 0.4813]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_negative_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -139,7 +139,7 @@ def test_stable_diffusion_pix2pix_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7323, 0.3688, 0.4611, 0.6255, 0.5746, 0.5017, 0.433, 0.5553, 0.4827]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -161,7 +161,7 @@ def test_stable_diffusion_pix2pix_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.606, 0.5712, 0.5099, 0.598, 0.5805, 0.7205, 0.6793, 0.554, 0.5607]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_euler(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -182,7 +182,7 @@ def test_stable_diffusion_pix2pix_euler(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.726, 0.3902, 0.4868, 0.585, 0.5672, 0.511, 0.3906, 0.551, 0.4846]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -370,4 +370,4 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): assert image.shape == (504, 504, 3) expected_slice = np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.259]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 2351e99b6c9e..4e2de63db05b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -53,7 +53,7 @@ def test_stable_diffusion_1(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.8887, 0.915, 0.91, 0.894, 0.909, 0.912, 0.919, 0.925, 0.883]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_2(self): sd_pipe = StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base") @@ -74,4 +74,4 @@ def test_stable_diffusion_2(self): expected_slice = np.array( [0.826810, 0.81958747, 0.8510199, 0.8376758, 0.83958465, 0.8682068, 0.84370345, 0.85251087, 0.85884345] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 1ee2f6c71615..6b27d4739c7f 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -133,7 +133,7 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5649, 0.6022, 0.4804, 0.5270, 0.5585, 0.4643, 0.5159, 0.4963, 0.4793]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -149,7 +149,7 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5099, 0.5677, 0.4671, 0.5128, 0.5697, 0.4676, 0.5277, 0.4964, 0.4946]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_lms(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -165,7 +165,7 @@ def test_stable_diffusion_k_lms(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -181,7 +181,7 @@ def test_stable_diffusion_k_euler_ancestral(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4715, 0.5376, 0.4569, 0.5224, 0.5734, 0.4797, 0.5465, 0.5074, 0.5046]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -197,7 +197,7 @@ def test_stable_diffusion_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_long_prompt(self): components = self.get_dummy_components() 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 ea8ffe224716..26ed5f6ad904 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -289,7 +289,7 @@ def test_stable_diffusion_depth2img_default_case(self): 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]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_negative_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -309,7 +309,7 @@ def test_stable_diffusion_depth2img_negative_prompt(self): 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]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -330,7 +330,7 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): 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]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -384,7 +384,7 @@ def test_stable_diffusion_depth2img_pil(self): 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]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @slow 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 096c083bef6c..7d11ba0732fe 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -125,7 +125,7 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4727, 0.5735, 0.3941, 0.5446, 0.5926, 0.4394, 0.5062, 0.4654, 0.4476]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @slow 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 9e70f1e55c4a..0ac71eb5daa0 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -156,7 +156,7 @@ def test_stable_diffusion_upscale(self): assert image.shape == (1, expected_height_width, expected_height_width, 3) expected_slice = np.array([0.2562, 0.3606, 0.4204, 0.4469, 0.4822, 0.4647, 0.5315, 0.5748, 0.5606]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_upscale_batch(self): 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 5cc81b574601..5eaf10c0cdcb 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 @@ -146,7 +146,7 @@ def test_stable_diffusion_v_pred_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.6424, 0.6109, 0.494, 0.5088, 0.4984, 0.4525, 0.5059, 0.5068, 0.4474]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_k_euler(self): @@ -194,7 +194,7 @@ def test_stable_diffusion_v_pred_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4616, 0.5184, 0.4887, 0.5111, 0.4839, 0.48, 0.5119, 0.5263, 0.4776]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -263,7 +263,7 @@ def test_stable_diffusion_v_pred_default(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.0567, 0.057, 0.0416, 0.0463, 0.0433, 0.06, 0.0517, 0.0526, 0.0866]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_upcast_attention(self): sd_pipe = StableDiffusionPipeline.from_pretrained( @@ -282,7 +282,7 @@ def test_stable_diffusion_v_pred_upcast_attention(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.0461, 0.0483, 0.0566, 0.0512, 0.0446, 0.0751, 0.0664, 0.0551, 0.0488]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_euler(self): scheduler = EulerDiscreteScheduler.from_pretrained("stabilityai/stable-diffusion-2", subfolder="scheduler") @@ -301,7 +301,7 @@ def test_stable_diffusion_v_pred_euler(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.0351, 0.0376, 0.0505, 0.0424, 0.0551, 0.0656, 0.0471, 0.0276, 0.0596]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_dpm(self): """ @@ -324,7 +324,7 @@ def test_stable_diffusion_v_pred_dpm(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.2049, 0.2115, 0.2323, 0.2416, 0.256, 0.2484, 0.2517, 0.2358, 0.236]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_attention_slicing_v_pred(self): torch.cuda.reset_peak_memory_stats() @@ -338,11 +338,10 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # make attention efficient pipe.enable_attention_slicing() generator = torch.manual_seed(0) - with torch.autocast(torch_device): - output_chunked = pipe( - [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" - ) - image_chunked = output_chunked.images + output_chunked = pipe( + [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" + ) + image_chunked = output_chunked.images mem_bytes = torch.cuda.max_memory_allocated() torch.cuda.reset_peak_memory_stats() @@ -352,11 +351,10 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # disable slicing pipe.disable_attention_slicing() generator = torch.manual_seed(0) - with torch.autocast(torch_device): - output = pipe( - [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" - ) - image = output.images + output = pipe( + [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" + ) + image = output.images # make sure that more than 5.5 GB is allocated mem_bytes = torch.cuda.max_memory_allocated() @@ -436,15 +434,14 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No prompt = "Andromeda galaxy in a bottle" generator = torch.manual_seed(0) - with torch.autocast(torch_device): - pipe( - prompt=prompt, - num_inference_steps=20, - guidance_scale=7.5, - generator=generator, - callback=test_callback_fn, - callback_steps=1, - ) + pipe( + prompt=prompt, + num_inference_steps=20, + guidance_scale=7.5, + generator=generator, + callback=test_callback_fn, + callback_steps=1, + ) assert test_callback_fn.has_been_called assert number_of_steps == 20 diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index 1691511b72b9..400104cf6e91 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -156,7 +156,7 @@ def test_safe_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5644, 0.6018, 0.4799, 0.5267, 0.5585, 0.4641, 0.516, 0.4964, 0.4792]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): @@ -201,7 +201,7 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5095, 0.5674, 0.4668, 0.5126, 0.5697, 0.4675, 0.5278, 0.4964, 0.4945]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_no_safety_checker(self): @@ -300,7 +300,7 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2278, 0.2231, 0.2249, 0.2333, 0.2303, 0.1885, 0.2273, 0.2144, 0.2176] assert image.shape == (1, 512, 512, 3) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 # without safety guidance (strong configuration) generator = torch.manual_seed(seed) @@ -324,7 +324,7 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2383, 0.2276, 0.236, 0.2192, 0.2186, 0.2053, 0.1971, 0.1901, 0.1719] assert image.shape == (1, 512, 512, 3) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safe_stable_diffusion(self): sd_pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", safety_checker=None) @@ -353,7 +353,7 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.3502, 0.3622, 0.3396, 0.3642, 0.3478, 0.3318, 0.35, 0.3348, 0.3297] assert image.shape == (1, 512, 512, 3) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 generator = torch.manual_seed(seed) output = sd_pipe( @@ -376,7 +376,7 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.5531, 0.5206, 0.4895, 0.5156, 0.5182, 0.4751, 0.4802, 0.4803, 0.4443] assert image.shape == (1, 512, 512, 3) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safetychecker_safe_stable_diffusion(self): sd_pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") @@ -407,7 +407,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): expected_slice = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) assert image.shape == (1, 512, 512, 3) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 generator = torch.manual_seed(seed) output = sd_pipe( @@ -429,4 +429,4 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): image_slice = image[0, -3:, -3:, -1] expected_slice = np.array([0.5818, 0.6285, 0.6835, 0.6019, 0.625, 0.6754, 0.6096, 0.6334, 0.6561]) assert image.shape == (1, 512, 512, 3) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 06ad4203f020..485ad3429e5c 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -259,7 +259,7 @@ def test_unclip(self): ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_passed_text_embed(self): diff --git a/tests/pipelines/unclip/test_unclip_image_variation.py b/tests/pipelines/unclip/test_unclip_image_variation.py index 804ef7f7c387..9e8273da2a26 100644 --- a/tests/pipelines/unclip/test_unclip_image_variation.py +++ b/tests/pipelines/unclip/test_unclip_image_variation.py @@ -275,7 +275,7 @@ def test_unclip_image_variation_input_tensor(self): ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_image_variation_input_image(self): @@ -307,7 +307,7 @@ def test_unclip_image_variation_input_image(self): expected_slice = np.array([0.9997, 0.0003, 0.9997, 0.9997, 0.9970, 0.0024, 0.9997, 0.9971, 0.9971]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_image_variation_input_list_images(self): @@ -359,7 +359,7 @@ def test_unclip_image_variation_input_list_images(self): ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_image_variation_input_num_images_per_prompt(self): @@ -412,7 +412,7 @@ def test_unclip_image_variation_input_num_images_per_prompt(self): ] ) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_passed_image_embed(self): diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index 49697ba4298e..7889ae3ae453 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -107,4 +107,4 @@ def test_inference_dual_guided(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.014, 0.0112, 0.0136, 0.0145, 0.0107, 0.0113, 0.0272, 0.0215, 0.0216]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index 05d871f75319..4999979efc0d 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -53,4 +53,4 @@ def test_inference_image_variations(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1205, 0.1914, 0.2289, 0.0883, 0.1595, 0.1683, 0.0703, 0.1493, 0.1298]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 0e1fc83c8265..84ec2a232613 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -103,7 +103,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0081, 0.0032, 0.0002, 0.0056, 0.0027, 0.0000, 0.0051, 0.0020, 0.0007]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " generator = torch.manual_seed(0) @@ -115,7 +115,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0408, 0.0181, 0.0, 0.0388, 0.0046, 0.0461, 0.0411, 0.0, 0.0222]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images @@ -123,4 +123,4 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3403, 0.1809, 0.0938, 0.3855, 0.2393, 0.1243, 0.4028, 0.3110, 0.1799]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index e035f90254b9..258acd8af599 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -81,4 +81,4 @@ def test_inference_text2img(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0408, 0.0181, 0.0, 0.0388, 0.0046, 0.0461, 0.0411, 0.0, 0.0222]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index b3513dff4dae..1e91e29fafe6 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -145,7 +145,7 @@ def test_vq_diffusion(self): expected_slice = np.array([0.6583, 0.6410, 0.5325, 0.5635, 0.5563, 0.4234, 0.6008, 0.5491, 0.4880]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_vq_diffusion_classifier_free_sampling(self): @@ -189,7 +189,7 @@ def test_vq_diffusion_classifier_free_sampling(self): expected_slice = np.array([0.6647, 0.6531, 0.5303, 0.5891, 0.5726, 0.4439, 0.6304, 0.5564, 0.4912]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 From 9279207569355ab294dd276498d3ebece0a8043a Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 21:00:38 +0200 Subject: [PATCH 07/39] finish more --- src/diffusers/utils/testing_utils.py | 4 +- utils/overwrite_expected_slice.py | 71 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 utils/overwrite_expected_slice.py diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 6c3dea541409..acfd365d13ac 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -45,7 +45,7 @@ def torch_all_close(a, b, *args, **kwargs): return True -def print_tensor_test(tensor, filename="test_failures.txt"): +def print_tensor_test(tensor, filename="test_failures.txt", expected_tensor_name="expected_slice"): test_name = os.environ.get("PYTEST_CURRENT_TEST") if not torch.is_tensor(tensor): tensor = torch.from_numpy(tensor) @@ -53,7 +53,7 @@ def print_tensor_test(tensor, filename="test_failures.txt"): tensor_str = str(tensor.detach().cpu().flatten()) # 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", "expected_slice = np.array") + 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: diff --git a/utils/overwrite_expected_slice.py b/utils/overwrite_expected_slice.py new file mode 100644 index 000000000000..6a3839e10808 --- /dev/null +++ b/utils/overwrite_expected_slice.py @@ -0,0 +1,71 @@ +# coding=utf-8 +# Copyright 2022 The HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse + + +def overwrite_file(file, class_name, test_name, correct_line): + with open(file, "r") as f: + lines = f.readlines() + + class_regex = f"class {class_name}(" + test_regex = f"{4 * ' '}def {test_name}(" + line_begin_regex = f"{8 * ' '}{correct_line.split()[0]}" + in_class = False + in_func = False + in_line = False + insert_line = False + + new_lines = [] + for line in lines: + if line.startswith(class_regex): + in_class = True + elif in_class and line.startswith(test_regex): + in_func = True + elif in_class and in_func and line.startswith(line_begin_regex): + in_line = True + + if in_class and in_func and in_line: + if ")" not in line: + continue + else: + insert_line = True + + if in_class and in_func and in_line and insert_line: + new_lines.append(f"{8 * ' '}{correct_line}") + in_class = in_func = in_line = insert_line = False + else: + new_lines.append(line) + + with open(file, "w") as f: + for line in new_lines: + f.write(line) + + +def main(filename): + with open(filename, "r") as f: + lines = f.readlines() + + for line in lines: + file, class_name, test_name, correct_line = line.split(";") + overwrite_file(file, class_name, test_name, correct_line) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--filename", help="filename of test failures with expected result") + args = parser.parse_args() + + main(args.filename) From e4c7013f54a37a0be16265b2b530d67d8c4f2d2f Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 21:15:02 +0200 Subject: [PATCH 08/39] correct some test failures --- .../altdiffusion/test_alt_diffusion.py | 8 ++------ .../test_alt_diffusion_img2img.py | 2 +- .../test_latent_diffusion_superresolution.py | 2 +- .../paint_by_example/test_paint_by_example.py | 4 +--- .../test_stable_diffusion_img2img.py | 2 +- .../test_stable_diffusion_depth.py | 2 +- .../test_stable_diffusion_v_pred.py | 8 ++++---- .../test_versatile_diffusion_dual_guided.py | 2 +- ...est_versatile_diffusion_image_variation.py | 2 +- .../test_versatile_diffusion_mega.py | 2 +- .../test_versatile_diffusion_text_to_image.py | 2 +- utils/overwrite_expected_slice.py | 20 +++++++++++-------- 12 files changed, 27 insertions(+), 29 deletions(-) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index efb83e916df2..5a36f474d94d 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -217,9 +217,7 @@ def test_alt_diffusion(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array( - [0.8720703, 0.87109375, 0.87402344, 0.87109375, 0.8779297, 0.8925781, 0.8823242, 0.8808594, 0.8613281] - ) + expected_slice = np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_fast_ddim(self): @@ -238,7 +236,5 @@ def test_alt_diffusion_fast_ddim(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array( - [0.9267578, 0.9301758, 0.9013672, 0.9345703, 0.92578125, 0.94433594, 0.9423828, 0.9423828, 0.9160156] - ) + expected_slice = np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 35dcecdd7604..39b57a0ab376 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.3252, 0.3340, 0.3418, 0.3263, 0.3346, 0.3300, 0.3163, 0.3470, 0.3427]) + expected_slice = np.array([0.9358, 0.9397, 0.9599, 0.9901, 1.0000, 1.0000, 0.9882, 1.0000, 1.0000]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 4e623c8a3c54..59eb837ee0fd 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -126,5 +126,5 @@ def test_inference_superresolution(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 256, 256, 3) - expected_slice = np.array([0.7418, 0.7472, 0.7424, 0.7422, 0.7463, 0.726, 0.7382, 0.7248, 0.6828]) + expected_slice = np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index 009b486e041f..2db8e64abea3 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -221,7 +221,5 @@ def test_paint_by_example(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array( - [0.47455794, 0.47086594, 0.47683704, 0.51024145, 0.5064255, 0.5123164, 0.532502, 0.5328063, 0.5428694] - ) + expected_slice = np.array([0.4834, 0.4811, 0.4874, 0.5122, 0.5081, 0.5144, 0.5291, 0.5290, 0.5374]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 688af4d2b0a6..bf4a7b5b285e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -366,7 +366,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.7124, 0.7105, 0.6993, 0.7140, 0.7106, 0.6945, 0.7198, 0.7172, 0.7031]) + expected_slice = np.array([0.9393, 0.9500, 0.9399, 0.9438, 0.9458, 0.9400, 0.9455, 0.9414, 0.9423]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); 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 26ed5f6ad904..5b3b34cf2812 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -424,7 +424,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.75446, 0.74692, 0.75951, 0.81611, 0.80593, 0.79992, 0.90529, 0.87921, 0.86903]) + expected_slice = np.array([0.5237, 0.4408, 0.3875, 0.5113, 0.5039, 0.4586, 0.4093, 0.4871, 0.4667]) assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_k_lms(self): 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 5eaf10c0cdcb..a3d088d8a524 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 @@ -262,7 +262,7 @@ def test_stable_diffusion_v_pred_default(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) - expected_slice = np.array([0.0567, 0.057, 0.0416, 0.0463, 0.0433, 0.06, 0.0517, 0.0526, 0.0866]) + expected_slice = np.array([0.1868, 0.1922, 0.1527, 0.1921, 0.1908, 0.1624, 0.1779, 0.1652, 0.1734]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_upcast_attention(self): @@ -281,7 +281,7 @@ def test_stable_diffusion_v_pred_upcast_attention(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) - expected_slice = np.array([0.0461, 0.0483, 0.0566, 0.0512, 0.0446, 0.0751, 0.0664, 0.0551, 0.0488]) + expected_slice = np.array([0.4209, 0.4087, 0.4097, 0.4209, 0.3860, 0.4329, 0.4280, 0.4324, 0.4187]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_euler(self): @@ -300,7 +300,7 @@ def test_stable_diffusion_v_pred_euler(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) - expected_slice = np.array([0.0351, 0.0376, 0.0505, 0.0424, 0.0551, 0.0656, 0.0471, 0.0276, 0.0596]) + expected_slice = np.array([0.1781, 0.1695, 0.1661, 0.1705, 0.1588, 0.1699, 0.2005, 0.1589, 0.1677]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_dpm(self): @@ -323,7 +323,7 @@ def test_stable_diffusion_v_pred_dpm(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) - expected_slice = np.array([0.2049, 0.2115, 0.2323, 0.2416, 0.256, 0.2484, 0.2517, 0.2358, 0.236]) + expected_slice = np.array([0.3303, 0.3184, 0.3291, 0.3300, 0.3256, 0.3113, 0.2965, 0.3134, 0.3192]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_attention_slicing_v_pred(self): diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index 7889ae3ae453..7897f1d264c5 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -106,5 +106,5 @@ def test_inference_dual_guided(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.014, 0.0112, 0.0136, 0.0145, 0.0107, 0.0113, 0.0272, 0.0215, 0.0216]) + expected_slice = np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index 4999979efc0d..937ce674c794 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -52,5 +52,5 @@ def test_inference_image_variations(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.1205, 0.1914, 0.2289, 0.0883, 0.1595, 0.1683, 0.0703, 0.1493, 0.1298]) + expected_slice = np.array([0.0441, 0.0469, 0.0507, 0.0575, 0.0632, 0.0650, 0.0865, 0.0909, 0.0945]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 84ec2a232613..45b3474de6a5 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -102,7 +102,7 @@ def test_inference_dual_guided_then_text_to_image(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.0081, 0.0032, 0.0002, 0.0056, 0.0027, 0.0000, 0.0051, 0.0020, 0.0007]) + expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index 258acd8af599..0f2b4a001682 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -80,5 +80,5 @@ def test_inference_text2img(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.0408, 0.0181, 0.0, 0.0388, 0.0046, 0.0461, 0.0411, 0.0, 0.0222]) + expected_slice = np.array([0.3493, 0.3757, 0.4093, 0.4495, 0.4233, 0.4102, 0.4507, 0.4756, 0.4787]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/utils/overwrite_expected_slice.py b/utils/overwrite_expected_slice.py index 6a3839e10808..7f72705f113c 100644 --- a/utils/overwrite_expected_slice.py +++ b/utils/overwrite_expected_slice.py @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - import argparse @@ -54,18 +53,23 @@ def overwrite_file(file, class_name, test_name, correct_line): f.write(line) -def main(filename): - with open(filename, "r") as f: - lines = f.readlines() +def main(fail, correct): + with open(fail, "r") as f: + test_failures = set([l.strip() for l in f.readlines()]) - for line in lines: + with open(correct, "r") as f: + correct_lines = f.readlines() + + for line in correct_lines: file, class_name, test_name, correct_line = line.split(";") - overwrite_file(file, class_name, test_name, correct_line) + if "::".join([file, class_name, test_name]) in test_failures: + overwrite_file(file, class_name, test_name, correct_line) if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--filename", help="filename of test failures with expected result") + parser.add_argument("--fail_filename", help="filename of test failures") + parser.add_argument("--correct_filename", help="filename of tests with expected result") args = parser.parse_args() - main(args.filename) + main(args.fail_filename, args.correct_filename) From 7ed509a61784c58f0729970a7eaf020deff0b529 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 21:17:45 +0200 Subject: [PATCH 09/39] more fixes --- src/diffusers/utils/testing_utils.py | 2 +- utils/overwrite_expected_slice.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index acfd365d13ac..8ba6af0ae8ba 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -45,7 +45,7 @@ def torch_all_close(a, b, *args, **kwargs): return True -def print_tensor_test(tensor, filename="test_failures.txt", expected_tensor_name="expected_slice"): +def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_name="expected_slice"): test_name = os.environ.get("PYTEST_CURRENT_TEST") if not torch.is_tensor(tensor): tensor = torch.from_numpy(tensor) diff --git a/utils/overwrite_expected_slice.py b/utils/overwrite_expected_slice.py index 7f72705f113c..0df2a468ac14 100644 --- a/utils/overwrite_expected_slice.py +++ b/utils/overwrite_expected_slice.py @@ -53,23 +53,26 @@ def overwrite_file(file, class_name, test_name, correct_line): f.write(line) -def main(fail, correct): - with open(fail, "r") as f: - test_failures = set([l.strip() for l in f.readlines()]) +def main(correct, fail=None): + if fail is not None: + with open(fail, "r") as f: + test_failures = set([l.strip() for l in f.readlines()]) + else: + test_failures = None with open(correct, "r") as f: correct_lines = f.readlines() for line in correct_lines: file, class_name, test_name, correct_line = line.split(";") - if "::".join([file, class_name, test_name]) in test_failures: + if test_failures is None or "::".join([file, class_name, test_name]) in test_failures: overwrite_file(file, class_name, test_name, correct_line) if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--fail_filename", help="filename of test failures") parser.add_argument("--correct_filename", help="filename of tests with expected result") + parser.add_argument("--fail_filename", help="filename of test failures", type=str, default=None) args = parser.parse_args() - main(args.fail_filename, args.correct_filename) + main(args.correct_filename, args.fail_filename) From b62aa7e3a4472d9c4815a97822543ba606771d62 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 20:57:54 +0000 Subject: [PATCH 10/39] set up to correct tests --- src/diffusers/utils/testing_utils.py | 10 +++++++--- test_failures.txt | 1 - .../altdiffusion/test_alt_diffusion_img2img.py | 2 +- .../dance_diffusion/test_dance_diffusion.py | 4 ++-- tests/pipelines/ddpm/test_ddpm.py | 2 +- .../latent_diffusion/test_latent_diffusion.py | 2 +- .../test_onnx_stable_diffusion_inpaint_legacy.py | 2 +- .../stable_diffusion/test_stable_diffusion.py | 12 ++++++------ .../test_stable_diffusion_image_variation.py | 4 ++-- .../test_stable_diffusion_img2img.py | 8 ++++---- .../test_stable_diffusion_inpaint.py | 8 ++++---- .../test_stable_diffusion_inpaint_legacy.py | 8 ++++---- .../stable_diffusion_2/test_stable_diffusion.py | 12 ++++++------ .../test_stable_diffusion_depth.py | 8 ++++---- .../test_stable_diffusion_inpaint.py | 4 ++-- .../test_stable_diffusion_upscale.py | 4 ++-- .../test_stable_diffusion_v_pred.py | 4 ++-- tests/pipelines/unclip/test_unclip.py | 2 +- tests/pipelines/vq_diffusion/test_vq_diffusion.py | 2 +- tests/test_scheduler.py | 12 ++++++++++++ 20 files changed, 63 insertions(+), 48 deletions(-) delete mode 100644 test_failures.txt diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 8ba6af0ae8ba..6b2a12d20d7b 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -8,7 +8,7 @@ from distutils.util import strtobool from io import BytesIO, StringIO from pathlib import Path -from typing import Union +from typing import Union, Optional import numpy as np @@ -165,9 +165,13 @@ def require_onnxruntime(test_case): return unittest.skipUnless(is_onnx_available(), "test requires onnxruntime")(test_case) -def load_numpy(arry: Union[str, np.ndarray]) -> np.ndarray: +def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray: if isinstance(arry, str): - if arry.startswith("http://") or arry.startswith("https://"): + local_path = "/home/patrick_huggingface_co/" + if local_path is not None: + # local_path can be passed to correct images of tests + return local_path + "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]]) + elif arry.startswith("http://") or arry.startswith("https://"): response = requests.get(arry) response.raise_for_status() arry = np.load(BytesIO(response.content)) diff --git a/test_failures.txt b/test_failures.txt deleted file mode 100644 index 733877e90171..000000000000 --- a/test_failures.txt +++ /dev/null @@ -1 +0,0 @@ -tests/pipelines/audio_diffusion/test_audio_diffusion.py;PipelineIntegrationTests;test_audio_diffusion;expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26], dtype=torch.uint8) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 39b57a0ab376..d38b221f7b5a 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -288,4 +288,4 @@ def test_stable_diffusion_img2img_pipeline_default(self): assert image.shape == (512, 768, 3) # img2img is flaky across GPUs even in fp32, so using MAE here - assert np.abs(expected_image - image).max() < 1e-3 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-3 diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index 4fee47bcd9cd..6c106d2bdec0 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -112,7 +112,7 @@ def test_dance_diffusion(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.1576, -0.1526, -0.127, -0.2699, -0.2762, -0.2487]) - assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(audio_slice); assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 def test_dance_diffusion_fp16(self): device = torch_device @@ -129,4 +129,4 @@ def test_dance_diffusion_fp16(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.1693, -0.1698, -0.1447, -0.3044, -0.3203, -0.2937]) - assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(audio_slice); assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 228e8339cbfc..d5cb38c847af 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -107,7 +107,7 @@ def test_inference_predict_sample(self): generator = torch.manual_seed(0) image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images - generator = generator.manual_seed(0) + generator = torch.manual_seed(0) image_eps = ddpm(generator=generator, num_inference_steps=2, output_type="numpy")[0] image_slice = image[0, -3:, -3:, -1] diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index ff51c0afcf2a..ea623fcb3e02 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -185,5 +185,5 @@ def test_ldm_default_ddim(self): expected_image = load_numpy( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/ldm_text2img/ldm_large_256_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py index 0237970ad2f3..edad5e82eb1c 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py @@ -94,4 +94,4 @@ def test_inference(self): image = output.images[0] assert image.shape == (512, 512, 3) - assert np.abs(expected_image - image).max() < 1e-2 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index b92a03c867bb..8362b95c9b7a 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -701,7 +701,7 @@ def test_stable_diffusion_1_4_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_1_5_pndm(self): @@ -715,7 +715,7 @@ def test_stable_diffusion_1_5_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_5_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_ddim(self): @@ -730,7 +730,7 @@ def test_stable_diffusion_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_lms(self): @@ -745,7 +745,7 @@ def test_stable_diffusion_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_lms.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_euler(self): @@ -760,7 +760,7 @@ def test_stable_diffusion_euler(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_euler.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_dpm(self): @@ -776,5 +776,5 @@ def test_stable_diffusion_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_dpm_multi.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index a2389bbc74ff..33f7cc38cd30 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -312,7 +312,7 @@ def test_img_variation_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_imgvar/lambdalabs_variations_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img_variation_dpm(self): @@ -329,5 +329,5 @@ def test_img_variation_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_imgvar/lambdalabs_variations_dpm_multi.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index bf4a7b5b285e..074ad010845b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -407,7 +407,7 @@ def test_img2img_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_ddim(self): @@ -423,7 +423,7 @@ def test_img2img_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_lms(self): @@ -439,7 +439,7 @@ def test_img2img_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_lms.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_dpm(self): @@ -456,5 +456,5 @@ def test_img2img_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_dpm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 9f040b185ed5..11dd7da823da 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -321,7 +321,7 @@ def test_inpaint_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_pndm(self): @@ -337,7 +337,7 @@ def test_inpaint_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_lms(self): @@ -353,7 +353,7 @@ def test_inpaint_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_lms.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_dpm(self): @@ -370,7 +370,7 @@ def test_inpaint_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_dpm_multi.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 4a4c989f4496..15cd22d3f10e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -479,7 +479,7 @@ def test_inpaint_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_ddim(self): @@ -495,7 +495,7 @@ def test_inpaint_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_lms(self): @@ -511,7 +511,7 @@ def test_inpaint_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_lms.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_dpm(self): @@ -528,5 +528,5 @@ def test_inpaint_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_dpm_multi.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 6b27d4739c7f..eb348929cb3c 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -417,7 +417,7 @@ def test_stable_diffusion_2_0_default_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_0_base_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_2_1_default_pndm(self): @@ -431,7 +431,7 @@ def test_stable_diffusion_2_1_default_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_ddim(self): @@ -446,7 +446,7 @@ def test_stable_diffusion_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_lms(self): @@ -461,7 +461,7 @@ def test_stable_diffusion_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_lms.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_euler(self): @@ -476,7 +476,7 @@ def test_stable_diffusion_euler(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_euler.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_dpm(self): @@ -492,5 +492,5 @@ def test_stable_diffusion_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_dpm_multi.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 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 5b3b34cf2812..03829271dd21 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -552,7 +552,7 @@ def test_depth2img_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_pndm.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_depth2img_ddim(self): @@ -568,7 +568,7 @@ def test_depth2img_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_ddim.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_lms(self): @@ -584,7 +584,7 @@ def test_img2img_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_lms.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_dpm(self): @@ -601,5 +601,5 @@ def test_img2img_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_dpm_multi.npy" ) - max_diff = np.abs(expected_image - image).max() + np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 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 7d11ba0732fe..f9405f9e4635 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -169,7 +169,7 @@ def test_stable_diffusion_inpaint_pipeline(self): image = output.images[0] assert image.shape == (512, 512, 3) - assert np.abs(expected_image - image).max() < 1e-3 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-3 def test_stable_diffusion_inpaint_pipeline_fp16(self): init_image = load_image( @@ -207,7 +207,7 @@ def test_stable_diffusion_inpaint_pipeline_fp16(self): image = output.images[0] assert image.shape == (512, 512, 3) - assert np.abs(expected_image - image).max() < 5e-1 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-1 def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): torch.cuda.empty_cache() 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 0ac71eb5daa0..db35e172841b 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -291,7 +291,7 @@ def test_stable_diffusion_upscale_pipeline(self): image = output.images[0] assert image.shape == (512, 512, 3) - assert np.abs(expected_image - image).max() < 1e-3 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-3 def test_stable_diffusion_upscale_pipeline_fp16(self): image = load_image( @@ -324,7 +324,7 @@ def test_stable_diffusion_upscale_pipeline_fp16(self): image = output.images[0] assert image.shape == (512, 512, 3) - assert np.abs(expected_image - image).max() < 5e-1 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-1 def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): torch.cuda.empty_cache() 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 a3d088d8a524..8d0c6773fe8f 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 @@ -379,7 +379,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_default(self): image = output.images[0] assert image.shape == (768, 768, 3) - assert np.abs(expected_image - image).max() < 5e-3 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-3 def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): expected_image = load_numpy( @@ -398,7 +398,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): image = output.images[0] assert image.shape == (768, 768, 3) - assert np.abs(expected_image - image).max() < 5e-1 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-1 def test_stable_diffusion_text2img_intermediate_state_v_pred(self): number_of_steps = 0 diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 485ad3429e5c..0e91217b5a85 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -414,7 +414,7 @@ def test_unclip_karlo_cpu_fp32(self): image = output.images[0] assert image.shape == (256, 256, 3) - assert np.abs(expected_image - image).max() < 1e-1 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-1 @slow diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index 1e91e29fafe6..86752ac8b4c6 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -223,4 +223,4 @@ def test_vq_diffusion_classifier_free_sampling(self): image = output.images[0] assert image.shape == (256, 256, 3) - assert np.abs(expected_image - image).max() < 1e-2 + np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-2 diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 67bebe4b675e..f96c3abf7807 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -1951,6 +1951,8 @@ def test_full_loop_no_noise(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) + print(result_sum) + print(result_mean) if torch_device in ["cpu", "mps"]: assert abs(result_sum.item() - 152.3192) < 1e-2 @@ -1983,6 +1985,8 @@ def test_full_loop_with_v_prediction(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) + print(result_sum) + print(result_mean) if torch_device in ["cpu", "mps"]: assert abs(result_sum.item() - 108.4439) < 1e-2 @@ -2014,6 +2018,8 @@ def test_full_loop_device(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) + print(result_sum) + print(result_mean) if str(torch_device).startswith("cpu"): # The following sum varies between 148 and 156 on mps. Why? @@ -2736,6 +2742,8 @@ def test_full_loop_no_noise(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) + print(result_sum) + print(result_mean) if torch_device in ["cpu", "mps"]: assert abs(result_sum.item() - 13849.3945) < 1e-2 @@ -2774,6 +2782,8 @@ def test_full_loop_with_v_prediction(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) + print(result_sum) + print(result_mean) if torch_device in ["cpu", "mps"]: assert abs(result_sum.item() - 328.9970) < 1e-2 @@ -2806,6 +2816,8 @@ def test_full_loop_device(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) + print(result_sum) + print(result_mean) if str(torch_device).startswith("cpu"): assert abs(result_sum.item() - 13849.3945) < 1e-2 From 87269e0c3806bc2287ad77f923a92a65ec654a59 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 22:01:46 +0000 Subject: [PATCH 11/39] more corrections --- .../stable_diffusion/test_stable_diffusion_img2img.py | 6 +++--- .../stable_diffusion/test_stable_diffusion_inpaint.py | 8 ++++---- .../test_stable_diffusion_inpaint_legacy.py | 4 ++-- .../test_stable_diffusion_instruction_pix2pix.py | 6 +++--- .../stable_diffusion_2/test_stable_diffusion_depth.py | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 074ad010845b..23bcabaf0c8b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -247,7 +247,7 @@ def test_stable_diffusion_img2img_default(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.27150, 0.14849, 0.15605, 0.26740, 0.16954, 0.18204, 0.31470, 0.26311, 0.24525]) - assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", safety_checker=None) @@ -262,7 +262,7 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.04890, 0.04862, 0.06422, 0.04655, 0.05108, 0.05307, 0.05926, 0.08759, 0.06852]) - assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_ddim(self): pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", safety_checker=None) @@ -277,7 +277,7 @@ def test_stable_diffusion_img2img_ddim(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.06069, 0.05703, 0.08054, 0.05797, 0.06286, 0.06234, 0.08438, 0.11151, 0.08068]) - assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_intermediate_state(self): number_of_steps = 0 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 11dd7da823da..99737b3e6935 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -207,7 +207,7 @@ def test_stable_diffusion_inpaint_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.05978, 0.10983, 0.10514, 0.07922, 0.08483, 0.08587, 0.05302, 0.03218, 0.01636]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_fp16(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( @@ -223,7 +223,7 @@ def test_stable_diffusion_inpaint_fp16(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.06152, 0.11060, 0.10449, 0.07959, 0.08643, 0.08496, 0.05420, 0.03247, 0.01831]) - assert np.abs(expected_slice - image_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-2 def test_stable_diffusion_inpaint_pndm(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( @@ -240,7 +240,7 @@ def test_stable_diffusion_inpaint_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.06892, 0.06994, 0.07905, 0.05366, 0.04709, 0.04890, 0.04107, 0.05083, 0.04180]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_k_lms(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( @@ -257,7 +257,7 @@ def test_stable_diffusion_inpaint_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.23513, 0.22413, 0.29442, 0.24243, 0.26214, 0.30329, 0.26431, 0.25025, 0.25197]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_with_sequential_cpu_offloading(self): torch.cuda.empty_cache() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 15cd22d3f10e..b2fa271c02ed 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -383,7 +383,7 @@ def test_stable_diffusion_inpaint_legacy_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.27200, 0.29103, 0.34405, 0.21418, 0.26317, 0.34281, 0.18033, 0.24911, 0.32028]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_k_lms(self): pipe = StableDiffusionInpaintPipelineLegacy.from_pretrained( @@ -400,7 +400,7 @@ def test_stable_diffusion_inpaint_legacy_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.29014, 0.28882, 0.32835, 0.26502, 0.28182, 0.31162, 0.29297, 0.29534, 0.28214]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_intermediate_state(self): number_of_steps = 0 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 9ab18ac37f11..0959f6997667 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -259,7 +259,7 @@ def test_stable_diffusion_pix2pix_default(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5902, 0.6015, 0.6027, 0.5983, 0.6092, 0.6061, 0.5765, 0.5785, 0.5555]) - assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_k_lms(self): pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained( @@ -276,7 +276,7 @@ def test_stable_diffusion_pix2pix_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.6578, 0.6817, 0.6972, 0.6761, 0.6856, 0.6916, 0.6428, 0.6516, 0.6301]) - assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_ddim(self): pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained( @@ -293,7 +293,7 @@ def test_stable_diffusion_pix2pix_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3828, 0.3834, 0.3818, 0.3792, 0.3865, 0.3752, 0.3792, 0.3847, 0.3753]) - assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_intermediate_state(self): number_of_steps = 0 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 03829271dd21..130dae17fe57 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -425,7 +425,7 @@ def test_stable_diffusion_depth2img_pipeline_default(self): assert image.shape == (1, 480, 640, 3) expected_slice = np.array([0.5237, 0.4408, 0.3875, 0.5113, 0.5039, 0.4586, 0.4093, 0.4871, 0.4667]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_k_lms(self): pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( @@ -442,7 +442,7 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self): assert image.shape == (1, 480, 640, 3) expected_slice = np.array([0.63957, 0.64879, 0.65668, 0.64385, 0.67078, 0.63588, 0.66577, 0.62180, 0.66286]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_ddim(self): pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( @@ -459,7 +459,7 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): assert image.shape == (1, 480, 640, 3) expected_slice = np.array([0.62840, 0.64191, 0.62953, 0.63653, 0.64205, 0.61574, 0.62252, 0.65827, 0.64809]) - assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_intermediate_state(self): number_of_steps = 0 From b54dd9e0e64f769b6f198930f64f4f2c4b1c7951 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 22:30:48 +0000 Subject: [PATCH 12/39] up --- src/diffusers/utils/testing_utils.py | 2 +- .../altdiffusion/test_alt_diffusion_img2img.py | 2 +- .../latent_diffusion/test_latent_diffusion.py | 2 +- .../test_onnx_stable_diffusion_inpaint_legacy.py | 2 +- .../stable_diffusion/test_stable_diffusion.py | 12 ++++++------ .../test_stable_diffusion_image_variation.py | 4 ++-- .../test_stable_diffusion_img2img.py | 8 ++++---- .../test_stable_diffusion_inpaint.py | 8 ++++---- .../test_stable_diffusion_inpaint_legacy.py | 8 ++++---- .../stable_diffusion_2/test_stable_diffusion.py | 12 ++++++------ .../test_stable_diffusion_depth.py | 8 ++++---- .../test_stable_diffusion_inpaint.py | 4 ++-- .../test_stable_diffusion_upscale.py | 4 ++-- .../test_stable_diffusion_v_pred.py | 4 ++-- tests/pipelines/unclip/test_unclip.py | 2 +- tests/pipelines/vq_diffusion/test_vq_diffusion.py | 2 +- 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 6b2a12d20d7b..e2c7c49752f4 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -167,7 +167,7 @@ def require_onnxruntime(test_case): def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray: if isinstance(arry, str): - local_path = "/home/patrick_huggingface_co/" + # local_path = "/home/patrick_huggingface_co/" if local_path is not None: # local_path can be passed to correct images of tests return local_path + "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]]) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index d38b221f7b5a..39b57a0ab376 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -288,4 +288,4 @@ def test_stable_diffusion_img2img_pipeline_default(self): assert image.shape == (512, 768, 3) # img2img is flaky across GPUs even in fp32, so using MAE here - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-3 + assert np.abs(expected_image - image).max() < 1e-3 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index ea623fcb3e02..ff51c0afcf2a 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -185,5 +185,5 @@ def test_ldm_default_ddim(self): expected_image = load_numpy( "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/ldm_text2img/ldm_large_256_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py index edad5e82eb1c..0237970ad2f3 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py @@ -94,4 +94,4 @@ def test_inference(self): image = output.images[0] assert image.shape == (512, 512, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-2 + assert np.abs(expected_image - image).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 8362b95c9b7a..b92a03c867bb 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -701,7 +701,7 @@ def test_stable_diffusion_1_4_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_1_5_pndm(self): @@ -715,7 +715,7 @@ def test_stable_diffusion_1_5_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_5_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_ddim(self): @@ -730,7 +730,7 @@ def test_stable_diffusion_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_lms(self): @@ -745,7 +745,7 @@ def test_stable_diffusion_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_lms.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_euler(self): @@ -760,7 +760,7 @@ def test_stable_diffusion_euler(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_euler.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_dpm(self): @@ -776,5 +776,5 @@ def test_stable_diffusion_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_text2img/stable_diffusion_1_4_dpm_multi.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 33f7cc38cd30..a2389bbc74ff 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -312,7 +312,7 @@ def test_img_variation_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_imgvar/lambdalabs_variations_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img_variation_dpm(self): @@ -329,5 +329,5 @@ def test_img_variation_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_imgvar/lambdalabs_variations_dpm_multi.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 23bcabaf0c8b..cfd54e030413 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -407,7 +407,7 @@ def test_img2img_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_ddim(self): @@ -423,7 +423,7 @@ def test_img2img_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_lms(self): @@ -439,7 +439,7 @@ def test_img2img_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_lms.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_dpm(self): @@ -456,5 +456,5 @@ def test_img2img_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_img2img/stable_diffusion_1_5_dpm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 99737b3e6935..3f897172af56 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -321,7 +321,7 @@ def test_inpaint_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_pndm(self): @@ -337,7 +337,7 @@ def test_inpaint_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_lms(self): @@ -353,7 +353,7 @@ def test_inpaint_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_lms.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_dpm(self): @@ -370,7 +370,7 @@ def test_inpaint_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint/stable_diffusion_inpaint_dpm_multi.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index b2fa271c02ed..c60b382360f4 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -479,7 +479,7 @@ def test_inpaint_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_ddim(self): @@ -495,7 +495,7 @@ def test_inpaint_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_lms(self): @@ -511,7 +511,7 @@ def test_inpaint_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_lms.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_inpaint_dpm(self): @@ -528,5 +528,5 @@ def test_inpaint_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_inpaint_legacy/stable_diffusion_1_5_dpm_multi.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index eb348929cb3c..6b27d4739c7f 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -417,7 +417,7 @@ def test_stable_diffusion_2_0_default_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_0_base_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_2_1_default_pndm(self): @@ -431,7 +431,7 @@ def test_stable_diffusion_2_1_default_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_ddim(self): @@ -446,7 +446,7 @@ def test_stable_diffusion_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_lms(self): @@ -461,7 +461,7 @@ def test_stable_diffusion_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_lms.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_euler(self): @@ -476,7 +476,7 @@ def test_stable_diffusion_euler(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_euler.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_stable_diffusion_dpm(self): @@ -492,5 +492,5 @@ def test_stable_diffusion_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_2_text2img/stable_diffusion_2_1_base_dpm_multi.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 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 130dae17fe57..9e95b92bb80c 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -552,7 +552,7 @@ def test_depth2img_pndm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_pndm.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_depth2img_ddim(self): @@ -568,7 +568,7 @@ def test_depth2img_ddim(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_ddim.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_lms(self): @@ -584,7 +584,7 @@ def test_img2img_lms(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_lms.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 def test_img2img_dpm(self): @@ -601,5 +601,5 @@ def test_img2img_dpm(self): "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main" "/stable_diffusion_depth2img/stable_diffusion_2_0_dpm_multi.npy" ) - np.save(expected_image, image); max_diff = np.abs(expected_image - image).max() + max_diff = np.abs(expected_image - image).max() assert max_diff < 1e-3 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 f9405f9e4635..7d11ba0732fe 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -169,7 +169,7 @@ def test_stable_diffusion_inpaint_pipeline(self): image = output.images[0] assert image.shape == (512, 512, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-3 + assert np.abs(expected_image - image).max() < 1e-3 def test_stable_diffusion_inpaint_pipeline_fp16(self): init_image = load_image( @@ -207,7 +207,7 @@ def test_stable_diffusion_inpaint_pipeline_fp16(self): image = output.images[0] assert image.shape == (512, 512, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-1 + assert np.abs(expected_image - image).max() < 5e-1 def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): torch.cuda.empty_cache() 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 db35e172841b..0ac71eb5daa0 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -291,7 +291,7 @@ def test_stable_diffusion_upscale_pipeline(self): image = output.images[0] assert image.shape == (512, 512, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-3 + assert np.abs(expected_image - image).max() < 1e-3 def test_stable_diffusion_upscale_pipeline_fp16(self): image = load_image( @@ -324,7 +324,7 @@ def test_stable_diffusion_upscale_pipeline_fp16(self): image = output.images[0] assert image.shape == (512, 512, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-1 + assert np.abs(expected_image - image).max() < 5e-1 def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self): torch.cuda.empty_cache() 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 8d0c6773fe8f..a3d088d8a524 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 @@ -379,7 +379,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_default(self): image = output.images[0] assert image.shape == (768, 768, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-3 + assert np.abs(expected_image - image).max() < 5e-3 def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): expected_image = load_numpy( @@ -398,7 +398,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): image = output.images[0] assert image.shape == (768, 768, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 5e-1 + assert np.abs(expected_image - image).max() < 5e-1 def test_stable_diffusion_text2img_intermediate_state_v_pred(self): number_of_steps = 0 diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 0e91217b5a85..485ad3429e5c 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -414,7 +414,7 @@ def test_unclip_karlo_cpu_fp32(self): image = output.images[0] assert image.shape == (256, 256, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-1 + assert np.abs(expected_image - image).max() < 1e-1 @slow diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index 86752ac8b4c6..1e91e29fafe6 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -223,4 +223,4 @@ def test_vq_diffusion_classifier_free_sampling(self): image = output.images[0] assert image.shape == (256, 256, 3) - np.save(expected_image, image); assert np.abs(expected_image - image).max() < 1e-2 + assert np.abs(expected_image - image).max() < 1e-2 From 37cab0cabc5394f196384df0bc7458e2cfcf2f70 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 22:33:14 +0000 Subject: [PATCH 13/39] fix more --- tests/pipelines/dance_diffusion/test_dance_diffusion.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_img2img.py | 6 +++--- .../stable_diffusion/test_stable_diffusion_inpaint.py | 8 ++++---- .../test_stable_diffusion_inpaint_legacy.py | 4 ++-- .../stable_diffusion_2/test_stable_diffusion_depth.py | 6 +++--- .../versatile_diffusion/test_versatile_diffusion_mega.py | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index 6c106d2bdec0..ce0a625dd6aa 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -111,7 +111,7 @@ def test_dance_diffusion(self): audio_slice = audio[0, -3:, -3:] assert audio.shape == (1, 2, pipe.unet.sample_size) - expected_slice = np.array([-0.1576, -0.1526, -0.127, -0.2699, -0.2762, -0.2487]) + expected_slice = np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(audio_slice); assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 def test_dance_diffusion_fp16(self): @@ -128,5 +128,5 @@ def test_dance_diffusion_fp16(self): audio_slice = audio[0, -3:, -3:] assert audio.shape == (1, 2, pipe.unet.sample_size) - expected_slice = np.array([-0.1693, -0.1698, -0.1447, -0.3044, -0.3203, -0.2937]) + expected_slice = np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(audio_slice); assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index cfd54e030413..4bfc53d76b91 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -246,7 +246,7 @@ def test_stable_diffusion_img2img_default(self): image_slice = image[0, -3:, -3:, -1].flatten() assert image.shape == (1, 512, 768, 3) - expected_slice = np.array([0.27150, 0.14849, 0.15605, 0.26740, 0.16954, 0.18204, 0.31470, 0.26311, 0.24525]) + expected_slice = np.array([0.4300, 0.4662, 0.4930, 0.3990, 0.4307, 0.4525, 0.3719, 0.4064, 0.3923]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): @@ -261,7 +261,7 @@ def test_stable_diffusion_img2img_k_lms(self): image_slice = image[0, -3:, -3:, -1].flatten() assert image.shape == (1, 512, 768, 3) - expected_slice = np.array([0.04890, 0.04862, 0.06422, 0.04655, 0.05108, 0.05307, 0.05926, 0.08759, 0.06852]) + expected_slice = np.array([0.0389, 0.0346, 0.0415, 0.0290, 0.0218, 0.0210, 0.0408, 0.0567, 0.0271]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_ddim(self): @@ -276,7 +276,7 @@ def test_stable_diffusion_img2img_ddim(self): image_slice = image[0, -3:, -3:, -1].flatten() assert image.shape == (1, 512, 768, 3) - expected_slice = np.array([0.06069, 0.05703, 0.08054, 0.05797, 0.06286, 0.06234, 0.08438, 0.11151, 0.08068]) + expected_slice = np.array([0.0593, 0.0607, 0.0851, 0.0582, 0.0636, 0.0721, 0.0751, 0.0981, 0.0781]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_intermediate_state(self): diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 3f897172af56..d48f94f4009e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -206,7 +206,7 @@ def test_stable_diffusion_inpaint_ddim(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.05978, 0.10983, 0.10514, 0.07922, 0.08483, 0.08587, 0.05302, 0.03218, 0.01636]) + expected_slice = np.array([0.0427, 0.0460, 0.0483, 0.0460, 0.0584, 0.0521, 0.1549, 0.1695, 0.1794]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_fp16(self): @@ -222,7 +222,7 @@ def test_stable_diffusion_inpaint_fp16(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.06152, 0.11060, 0.10449, 0.07959, 0.08643, 0.08496, 0.05420, 0.03247, 0.01831]) + expected_slice = np.array([0.1443, 0.1218, 0.1587, 0.1594, 0.1411, 0.1284, 0.1370, 0.1506, 0.2339]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-2 def test_stable_diffusion_inpaint_pndm(self): @@ -239,7 +239,7 @@ def test_stable_diffusion_inpaint_pndm(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.06892, 0.06994, 0.07905, 0.05366, 0.04709, 0.04890, 0.04107, 0.05083, 0.04180]) + expected_slice = np.array([0.0425, 0.0273, 0.0344, 0.1694, 0.1727, 0.1812, 0.3256, 0.3311, 0.3272]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_k_lms(self): @@ -256,7 +256,7 @@ def test_stable_diffusion_inpaint_k_lms(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.23513, 0.22413, 0.29442, 0.24243, 0.26214, 0.30329, 0.26431, 0.25025, 0.25197]) + expected_slice = np.array([0.9314, 0.7575, 0.9432, 0.8885, 0.9028, 0.7298, 0.9811, 0.9667, 0.7633]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_with_sequential_cpu_offloading(self): diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index c60b382360f4..73fd2bf00ea7 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -382,7 +382,7 @@ def test_stable_diffusion_inpaint_legacy_pndm(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.27200, 0.29103, 0.34405, 0.21418, 0.26317, 0.34281, 0.18033, 0.24911, 0.32028]) + expected_slice = np.array([0.5669, 0.6124, 0.6431, 0.4073, 0.4614, 0.5670, 0.1609, 0.3128, 0.4330]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_k_lms(self): @@ -399,7 +399,7 @@ def test_stable_diffusion_inpaint_legacy_k_lms(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.29014, 0.28882, 0.32835, 0.26502, 0.28182, 0.31162, 0.29297, 0.29534, 0.28214]) + expected_slice = np.array([0.4533, 0.4465, 0.4327, 0.4329, 0.4339, 0.4219, 0.4243, 0.4332, 0.4426]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_intermediate_state(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 9e95b92bb80c..ce01b2931ceb 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -424,7 +424,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.5237, 0.4408, 0.3875, 0.5113, 0.5039, 0.4586, 0.4093, 0.4871, 0.4667]) + expected_slice = np.array([0.9057, 0.9365, 0.9258, 0.8937, 0.8555, 0.8541, 0.8260, 0.7747, 0.7421]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_k_lms(self): @@ -441,7 +441,7 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self): image_slice = image[0, 253:256, 253:256, -1].flatten() assert image.shape == (1, 480, 640, 3) - expected_slice = np.array([0.63957, 0.64879, 0.65668, 0.64385, 0.67078, 0.63588, 0.66577, 0.62180, 0.66286]) + expected_slice = np.array([0.6363, 0.6274, 0.6309, 0.6370, 0.6226, 0.6286, 0.6213, 0.6453, 0.6306]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_ddim(self): @@ -458,7 +458,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.62840, 0.64191, 0.62953, 0.63653, 0.64205, 0.61574, 0.62252, 0.65827, 0.64809]) + expected_slice = np.array([0.6424, 0.6524, 0.6249, 0.6041, 0.6634, 0.6420, 0.6522, 0.6555, 0.6436]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_intermediate_state(self): diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 45b3474de6a5..a2e1f3c21c7e 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -102,7 +102,7 @@ def test_inference_dual_guided_then_text_to_image(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) + expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " From 70786f561303db3122202c4fa9916f92e3012c1f Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 22:54:08 +0000 Subject: [PATCH 14/39] more prints --- .../pipelines/stable_diffusion/test_cycle_diffusion.py | 10 +++++++--- .../stable_diffusion/test_onnx_stable_diffusion.py | 4 ++-- .../stable_diffusion/test_stable_diffusion.py | 4 ++-- .../test_stable_diffusion_image_variation.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_img2img.py | 4 ++-- .../test_stable_diffusion_inpaint_legacy.py | 4 ++-- .../test_stable_diffusion_instruction_pix2pix.py | 4 ++-- .../stable_diffusion_2/test_stable_diffusion.py | 4 ++-- .../stable_diffusion_2/test_stable_diffusion_depth.py | 4 ++-- .../stable_diffusion_2/test_stable_diffusion_v_pred.py | 4 ++-- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index d426ef4cc896..7c56a25ff076 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -165,7 +165,8 @@ def test_cycle_diffusion_pipeline_fp16(self): "/cycle-diffusion/black_colored_car.png" ) expected_image = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy" + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy", + local_path="/home/patrick_huggingface_co/diffusers-images" ) init_image = init_image.resize((512, 512)) @@ -198,7 +199,7 @@ def test_cycle_diffusion_pipeline_fp16(self): image = output.images # the values aren't exactly equal, but the images look the same visually - assert np.abs(image - expected_image).max() < 5e-1 + np.save(expected_image, image); assert np.abs(image - expected_image).max() < 5e-1 def test_cycle_diffusion_pipeline(self): init_image = load_image( @@ -206,7 +207,9 @@ def test_cycle_diffusion_pipeline(self): "/cycle-diffusion/black_colored_car.png" ) expected_image = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy" + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy", + + local_path="/home/patrick_huggingface_co/diffusers-images" ) init_image = init_image.resize((512, 512)) @@ -237,3 +240,4 @@ def test_cycle_diffusion_pipeline(self): image = output.images assert np.abs(image - expected_image).max() < 1e-2 + np.save(expected_image, image); assert np.abs(image - expected_image).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index 8766858eb0c8..210df5929ca5 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -234,14 +234,14 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 5: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array( [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index b92a03c867bb..539e29c3c599 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -615,13 +615,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.04663, -0.879, 0.76, -1.734, 0.1044, 1.161]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1885, -0.3022, -1.012, -0.514, -0.477, 0.6143, -0.9336, 0.6553, 1.453]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index a2389bbc74ff..714ad91d75e6 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -228,13 +228,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1572, 0.2837, -0.798, -0.1201, -1.304, 0.7754, -2.12, 0.0443, 1.627]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.6143, 1.734, 1.158, -2.145, -1.926, 0.748, -0.7246, 0.994, 1.539]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 4bfc53d76b91..0699ea41d84f 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -291,13 +291,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.7705, 0.1045, 0.5, 3.393, 3.723, 4.273, 2.467, 3.486, 1.758]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.765, 0.1047, 0.4973, 3.375, 3.709, 4.258, 2.451, 3.46, 1.755]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 73fd2bf00ea7..d7743a61947c 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -414,13 +414,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.103, 1.415, -0.02197, -0.5107, -0.5903, 0.1953, 0.75, 0.3477, -1.356]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.4802, 1.154, 0.628, 0.2319, 0.2593, -0.1455, 0.7075, -0.1617, -0.5615]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 0959f6997667..3a27e00c4eb6 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -307,13 +307,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2568, -0.4648, -0.9639, 1.5137, 1.4609, 0.7603, 0.9795, 0.8403, 0.7949]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 6b27d4739c7f..41be1bb4fa95 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -341,13 +341,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.3857, -0.4507, -1.167, 0.074, -1.108, 0.7183, -1.822, 0.1915, 1.283]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.268, -0.2095, -0.7744, -0.541, -0.79, 0.3926, -0.7754, 0.465, 1.291]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False 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 ce01b2931ceb..e2881dd6e2d5 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -473,13 +473,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-1.148, -0.2079, -0.622, -2.477, -2.348, 0.3828, -2.055, -1.569, -1.526]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-1.145, -0.2063, -0.6216, -2.469, -2.344, 0.3794, -2.05, -1.57, -1.521]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 a3d088d8a524..cf697491ccd6 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 @@ -414,7 +414,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No expected_slice = np.array( [-0.2543, -1.2755, 0.4261, -0.9555, -1.173, -0.5892, 2.4159, 0.1554, -1.2098] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) @@ -422,7 +422,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No expected_slice = np.array( [-0.9572, -0.967, -0.6152, 0.0894, -0.699, -0.2344, 1.5465, -0.0357, -0.1141] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 test_callback_fn.has_been_called = False From 32db72159de6613d4aff984d043512729f64cd21 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 23:14:25 +0000 Subject: [PATCH 15/39] add --- .../stable_diffusion/test_cycle_diffusion.py | 4 ++-- .../test_versatile_diffusion_mega.py | 4 ++-- utils/overwrite_expected_slice.py | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 7c56a25ff076..038c33d2d4a9 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -166,7 +166,7 @@ def test_cycle_diffusion_pipeline_fp16(self): ) expected_image = load_numpy( "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy", - local_path="/home/patrick_huggingface_co/diffusers-images" + local_path="/home/patrick_huggingface_co/" ) init_image = init_image.resize((512, 512)) @@ -209,7 +209,7 @@ def test_cycle_diffusion_pipeline(self): expected_image = load_numpy( "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy", - local_path="/home/patrick_huggingface_co/diffusers-images" + local_path="/home/patrick_huggingface_co/" ) init_image = init_image.resize((512, 512)) diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index a2e1f3c21c7e..326bc4a5a62e 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -102,7 +102,7 @@ def test_inference_dual_guided_then_text_to_image(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) + expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " @@ -114,7 +114,7 @@ def test_inference_dual_guided_then_text_to_image(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.0408, 0.0181, 0.0, 0.0388, 0.0046, 0.0461, 0.0411, 0.0, 0.0222]) + expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images diff --git a/utils/overwrite_expected_slice.py b/utils/overwrite_expected_slice.py index 0df2a468ac14..6951d2db33a6 100644 --- a/utils/overwrite_expected_slice.py +++ b/utils/overwrite_expected_slice.py @@ -13,19 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. import argparse +from collections import defaultdict -def overwrite_file(file, class_name, test_name, correct_line): +def overwrite_file(file, class_name, test_name, correct_line, done_test): + done_test[file] += 1 + with open(file, "r") as f: lines = f.readlines() class_regex = f"class {class_name}(" test_regex = f"{4 * ' '}def {test_name}(" line_begin_regex = f"{8 * ' '}{correct_line.split()[0]}" + another_line_begin_regex = f"{16 * ' '}{correct_line.split()[0]}" in_class = False in_func = False in_line = False insert_line = False + count = 0 new_lines = [] for line in lines: @@ -33,8 +38,11 @@ def overwrite_file(file, class_name, test_name, correct_line): in_class = True elif in_class and line.startswith(test_regex): in_func = True - elif in_class and in_func and line.startswith(line_begin_regex): - in_line = True + elif in_class and in_func and (line.startswith(line_begin_regex) or line.startswith(another_line_begin_regex)): + count += 1 + + if count == done_test[file]: + in_line = True if in_class and in_func and in_line: if ")" not in line: @@ -63,10 +71,11 @@ def main(correct, fail=None): with open(correct, "r") as f: correct_lines = f.readlines() + done_tests = defaultdict(int) for line in correct_lines: file, class_name, test_name, correct_line = line.split(";") if test_failures is None or "::".join([file, class_name, test_name]) in test_failures: - overwrite_file(file, class_name, test_name, correct_line) + overwrite_file(file, class_name, test_name, correct_line, done_tests) if __name__ == "__main__": From 5d7b5d8f0f51ee94ada59d78585f170b5259e7e5 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 23:21:32 +0000 Subject: [PATCH 16/39] up --- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 2 +- .../stable_diffusion/test_stable_diffusion_image_variation.py | 2 +- .../stable_diffusion/test_stable_diffusion_img2img.py | 2 +- .../stable_diffusion/test_stable_diffusion_inpaint_legacy.py | 2 +- .../test_stable_diffusion_instruction_pix2pix.py | 2 +- .../stable_diffusion/test_stable_diffusion_k_diffusion.py | 2 +- tests/pipelines/stable_diffusion_2/test_stable_diffusion.py | 2 +- .../stable_diffusion_2/test_stable_diffusion_depth.py | 2 +- .../stable_diffusion_2/test_stable_diffusion_v_pred.py | 4 +--- utils/overwrite_expected_slice.py | 4 +++- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 539e29c3c599..918830a6e47e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -614,7 +614,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.04663, -0.879, 0.76, -1.734, 0.1044, 1.161]) + expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 714ad91d75e6..d4e79eb7c81d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -227,7 +227,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1572, 0.2837, -0.798, -0.1201, -1.304, 0.7754, -2.12, 0.0443, 1.627]) + expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 0699ea41d84f..c86ad0f1bd8d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -290,7 +290,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.7705, 0.1045, 0.5, 3.393, 3.723, 4.273, 2.467, 3.486, 1.758]) + expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index d7743a61947c..211d8a9c4747 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -413,7 +413,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.103, 1.415, -0.02197, -0.5107, -0.5903, 0.1953, 0.75, 0.3477, -1.356]) + expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 3a27e00c4eb6..011a51c5627b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -306,7 +306,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788]) + expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 4e2de63db05b..68254ae7c7a9 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -52,7 +52,7 @@ def test_stable_diffusion_1(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.8887, 0.915, 0.91, 0.894, 0.909, 0.912, 0.919, 0.925, 0.883]) + expected_slice = np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_2(self): diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 41be1bb4fa95..ebf0fa1a67ba 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -340,7 +340,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.3857, -0.4507, -1.167, 0.074, -1.108, 0.7183, -1.822, 0.1915, 1.283]) + expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 e2881dd6e2d5..0bcc0e664089 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -472,7 +472,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([-1.148, -0.2079, -0.622, -2.477, -2.348, 0.3828, -2.055, -1.569, -1.526]) + expected_slice = np.array([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 cf697491ccd6..65caac2e8cbb 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 @@ -411,9 +411,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array( - [-0.2543, -1.2755, 0.4261, -0.9555, -1.173, -0.5892, 2.4159, 0.1554, -1.2098] - ) + expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098], dtype=torch.float64) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() diff --git a/utils/overwrite_expected_slice.py b/utils/overwrite_expected_slice.py index 6951d2db33a6..974532e378db 100644 --- a/utils/overwrite_expected_slice.py +++ b/utils/overwrite_expected_slice.py @@ -31,6 +31,7 @@ def overwrite_file(file, class_name, test_name, correct_line, done_test): in_line = False insert_line = False count = 0 + spaces = 0 new_lines = [] for line in lines: @@ -39,6 +40,7 @@ def overwrite_file(file, class_name, test_name, correct_line, done_test): elif in_class and line.startswith(test_regex): in_func = True elif in_class and in_func and (line.startswith(line_begin_regex) or line.startswith(another_line_begin_regex)): + spaces = len(line.split(correct_line.split()[0])[0]) count += 1 if count == done_test[file]: @@ -51,7 +53,7 @@ def overwrite_file(file, class_name, test_name, correct_line, done_test): insert_line = True if in_class and in_func and in_line and insert_line: - new_lines.append(f"{8 * ' '}{correct_line}") + new_lines.append(f"{spaces * ' '}{correct_line}") in_class = in_func = in_line = insert_line = False else: new_lines.append(line) From a70197b695508a047aadbffe99754e52926dd41b Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 23:30:41 +0000 Subject: [PATCH 17/39] up --- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 2 +- .../stable_diffusion/test_stable_diffusion_image_variation.py | 2 +- .../pipelines/stable_diffusion/test_stable_diffusion_img2img.py | 2 +- .../stable_diffusion/test_stable_diffusion_inpaint_legacy.py | 2 +- .../test_stable_diffusion_instruction_pix2pix.py | 2 +- tests/pipelines/stable_diffusion_2/test_stable_diffusion.py | 2 +- .../pipelines/stable_diffusion_2/test_stable_diffusion_depth.py | 2 +- .../stable_diffusion_2/test_stable_diffusion_v_pred.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 918830a6e47e..53f39415fd7a 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -614,7 +614,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610], dtype=torch.float64) + expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index d4e79eb7c81d..e985bdf34a94 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -227,7 +227,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270], dtype=torch.float64) + expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index c86ad0f1bd8d..4b6f146ba975 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -290,7 +290,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580], dtype=torch.float64) + expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 211d8a9c4747..48eb60c4828f 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -413,7 +413,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560], dtype=torch.float64) + expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 011a51c5627b..b7b16656b496 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -306,7 +306,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788], dtype=torch.float64) + expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index ebf0fa1a67ba..6ddc8fd1a4e2 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -340,7 +340,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830], dtype=torch.float64) + expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 0bcc0e664089..667a0061bc0e 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -472,7 +472,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([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260], dtype=torch.float64) + expected_slice = np.array([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 65caac2e8cbb..33410e75b8ca 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 @@ -411,7 +411,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098], dtype=torch.float64) + expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098], dtype=torch.float32) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() From 3ada1aefc7d9ca9749c38b126648062239adf3a6 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 23:33:13 +0000 Subject: [PATCH 18/39] up --- .../versatile_diffusion/test_versatile_diffusion_mega.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 326bc4a5a62e..2094b5ca3837 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -122,5 +122,5 @@ def test_inference_dual_guided_then_text_to_image(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array([0.3403, 0.1809, 0.0938, 0.3855, 0.2393, 0.1243, 0.4028, 0.3110, 0.1799]) + expected_slice = np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 From 93ea0323941c3f5d5096e921b74e140add259922 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 23:34:15 +0000 Subject: [PATCH 19/39] uP --- .../stable_diffusion/test_cycle_diffusion.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 038c33d2d4a9..461a55908f50 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -165,8 +165,7 @@ def test_cycle_diffusion_pipeline_fp16(self): "/cycle-diffusion/black_colored_car.png" ) expected_image = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy", - local_path="/home/patrick_huggingface_co/" + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy" ) init_image = init_image.resize((512, 512)) @@ -199,7 +198,7 @@ def test_cycle_diffusion_pipeline_fp16(self): image = output.images # the values aren't exactly equal, but the images look the same visually - np.save(expected_image, image); assert np.abs(image - expected_image).max() < 5e-1 + assert np.abs(image - expected_image).max() < 5e-1 def test_cycle_diffusion_pipeline(self): init_image = load_image( @@ -207,9 +206,7 @@ def test_cycle_diffusion_pipeline(self): "/cycle-diffusion/black_colored_car.png" ) expected_image = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy", - - local_path="/home/patrick_huggingface_co/" + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy" ) init_image = init_image.resize((512, 512)) @@ -240,4 +237,4 @@ def test_cycle_diffusion_pipeline(self): image = output.images assert np.abs(image - expected_image).max() < 1e-2 - np.save(expected_image, image); assert np.abs(image - expected_image).max() < 1e-2 + assert np.abs(image - expected_image).max() < 1e-2 From ef45927b10f044dd2b5be82d0eae0f1116604e77 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 24 Jan 2023 23:51:33 +0000 Subject: [PATCH 20/39] uP --- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 2 +- .../stable_diffusion/test_stable_diffusion_image_variation.py | 2 +- .../pipelines/stable_diffusion/test_stable_diffusion_img2img.py | 2 +- .../stable_diffusion/test_stable_diffusion_inpaint_legacy.py | 2 +- .../test_stable_diffusion_instruction_pix2pix.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 53f39415fd7a..c143b410de38 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -614,7 +614,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610], dtype=torch.float32) + expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index e985bdf34a94..41963b65e6d2 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -227,7 +227,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270], dtype=torch.float32) + expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 4b6f146ba975..bf4ad4ebbaf0 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -290,7 +290,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580], dtype=torch.float32) + expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 48eb60c4828f..740ad5c857e0 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -413,7 +413,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560], dtype=torch.float32) + expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() 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 b7b16656b496..e34b6488e520 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -306,7 +306,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788], dtype=torch.float32) + expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() From 2d26ab5b46bcd311ad8e44f6326b5ae7fe17c47b Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 00:09:11 +0000 Subject: [PATCH 21/39] more fixes --- src/diffusers/utils/testing_utils.py | 2 +- .../stable_diffusion/test_onnx_stable_diffusion.py | 4 ++-- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 4 ++-- .../test_stable_diffusion_image_variation.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_img2img.py | 4 ++-- .../test_stable_diffusion_inpaint_legacy.py | 4 ++-- .../test_stable_diffusion_instruction_pix2pix.py | 4 ++-- tests/pipelines/stable_diffusion_2/test_stable_diffusion.py | 6 +++--- .../stable_diffusion_2/test_stable_diffusion_depth.py | 6 +++--- .../stable_diffusion_2/test_stable_diffusion_v_pred.py | 6 +++--- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index e2c7c49752f4..f4377f0e48b7 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -50,7 +50,7 @@ def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_n if not torch.is_tensor(tensor): tensor = torch.from_numpy(tensor) - tensor_str = str(tensor.detach().cpu().flatten()) + tensor_str = str(tensor.detach().cpu().flatten()).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") diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index 210df5929ca5..d374ea0b07db 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -234,14 +234,14 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 5: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array( [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index c143b410de38..2ea49ba90914 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -615,13 +615,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1885, -0.3022, -1.012, -0.514, -0.477, 0.6143, -0.9336, 0.6553, 1.453]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 41963b65e6d2..c689972ae08e 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -228,13 +228,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.6143, 1.734, 1.158, -2.145, -1.926, 0.748, -0.7246, 0.994, 1.539]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index bf4ad4ebbaf0..b33e51720e07 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -291,13 +291,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.765, 0.1047, 0.4973, 3.375, 3.709, 4.258, 2.451, 3.46, 1.755]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 740ad5c857e0..fb0dbb0ac912 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -414,13 +414,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.4802, 1.154, 0.628, 0.2319, 0.2593, -0.1455, 0.7075, -0.1617, -0.5615]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 e34b6488e520..3ed51546fad1 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -307,13 +307,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2568, -0.4648, -0.9639, 1.5137, 1.4609, 0.7603, 0.9795, 0.8403, 0.7949]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 6ddc8fd1a4e2..18d84351998b 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -340,14 +340,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830], dtype=torch.float32) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830]) + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.268, -0.2095, -0.7744, -0.541, -0.79, 0.3926, -0.7754, 0.465, 1.291]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False 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 667a0061bc0e..b9c0a909619b 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -472,14 +472,14 @@ 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([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260], dtype=torch.float32) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + expected_slice = np.array([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260]) + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-1.145, -0.2063, -0.6216, -2.469, -2.344, 0.3794, -2.05, -1.57, -1.521]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 33410e75b8ca..25b5edcd3f9f 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 @@ -411,8 +411,8 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098], dtype=torch.float32) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098]) + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) @@ -420,7 +420,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No expected_slice = np.array( [-0.9572, -0.967, -0.6152, 0.0894, -0.699, -0.2344, 1.5465, -0.0357, -0.1141] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(expected_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 test_callback_fn.has_been_called = False From 6ca6e11c8ba0745c4d48b30de427cedf49bfa6e9 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 00:16:04 +0000 Subject: [PATCH 22/39] uP --- .../pipelines/stable_diffusion/test_onnx_stable_diffusion.py | 4 ++-- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_image_variation.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_img2img.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_inpaint_legacy.py | 4 ++-- .../test_stable_diffusion_instruction_pix2pix.py | 4 ++-- tests/pipelines/stable_diffusion_2/test_stable_diffusion.py | 4 ++-- .../stable_diffusion_2/test_stable_diffusion_depth.py | 4 ++-- .../stable_diffusion_2/test_stable_diffusion_v_pred.py | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index d374ea0b07db..0f4bb2ea6a67 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -234,14 +234,14 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 5: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array( [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 2ea49ba90914..1e5d8b9751b5 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -615,13 +615,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1885, -0.3022, -1.012, -0.514, -0.477, 0.6143, -0.9336, 0.6553, 1.453]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index c689972ae08e..150c03d43a5d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -228,13 +228,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.6143, 1.734, 1.158, -2.145, -1.926, 0.748, -0.7246, 0.994, 1.539]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index b33e51720e07..adcad398fe3b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -291,13 +291,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.765, 0.1047, 0.4973, 3.375, 3.709, 4.258, 2.451, 3.46, 1.755]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index fb0dbb0ac912..d24f5e0294c9 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -414,13 +414,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.4802, 1.154, 0.628, 0.2319, 0.2593, -0.1455, 0.7075, -0.1617, -0.5615]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 3ed51546fad1..e3471df94f26 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -307,13 +307,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2568, -0.4648, -0.9639, 1.5137, 1.4609, 0.7603, 0.9795, 0.8403, 0.7949]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 18d84351998b..74fe1be51da0 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -341,13 +341,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.268, -0.2095, -0.7744, -0.541, -0.79, 0.3926, -0.7754, 0.465, 1.291]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False 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 b9c0a909619b..50568000fae7 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -473,13 +473,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-1.145, -0.2063, -0.6216, -2.469, -2.344, 0.3794, -2.05, -1.57, -1.521]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 25b5edcd3f9f..7d20d8b126b7 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 @@ -412,7 +412,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) @@ -420,7 +420,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No expected_slice = np.array( [-0.9572, -0.967, -0.6152, 0.0894, -0.699, -0.2344, 1.5465, -0.0357, -0.1141] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latent_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 test_callback_fn.has_been_called = False From 4fffb40c79cd891888789b83ce81a0582c506153 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 06:06:52 +0000 Subject: [PATCH 23/39] up --- src/diffusers/utils/testing_utils.py | 4 +- .../altdiffusion/test_alt_diffusion.py | 24 +++++--- .../test_alt_diffusion_img2img.py | 10 +++- .../audio_diffusion/test_audio_diffusion.py | 20 +++++-- .../dance_diffusion/test_dance_diffusion.py | 12 +++- tests/pipelines/ddim/test_ddim.py | 10 +++- tests/pipelines/ddpm/test_ddpm.py | 10 +++- tests/pipelines/karras_ve/test_karras_ve.py | 10 +++- .../latent_diffusion/test_latent_diffusion.py | 5 +- .../test_latent_diffusion_superresolution.py | 10 +++- .../test_latent_diffusion_uncond.py | 10 +++- .../paint_by_example/test_paint_by_example.py | 10 +++- tests/pipelines/pndm/test_pndm.py | 10 +++- tests/pipelines/repaint/test_repaint.py | 5 +- .../score_sde_ve/test_score_sde_ve.py | 10 +++- .../stable_diffusion/test_cycle_diffusion.py | 10 +++- .../test_onnx_stable_diffusion.py | 55 +++++++++++++++---- .../test_onnx_stable_diffusion_img2img.py | 35 +++++++++--- .../test_onnx_stable_diffusion_inpaint.py | 10 +++- .../stable_diffusion/test_stable_diffusion.py | 51 +++++++++++++---- .../test_stable_diffusion_image_variation.py | 24 ++++++-- .../test_stable_diffusion_img2img.py | 52 ++++++++++++++---- .../test_stable_diffusion_inpaint.py | 25 +++++++-- .../test_stable_diffusion_inpaint_legacy.py | 32 ++++++++--- ...st_stable_diffusion_instruction_pix2pix.py | 52 ++++++++++++++---- .../test_stable_diffusion_k_diffusion.py | 10 +++- .../test_stable_diffusion.py | 39 ++++++++++--- .../test_stable_diffusion_depth.py | 49 +++++++++++++---- .../test_stable_diffusion_inpaint.py | 5 +- .../test_stable_diffusion_upscale.py | 5 +- .../test_stable_diffusion_v_pred.py | 46 ++++++++++++---- .../test_safe_diffusion.py | 40 +++++++++++--- tests/pipelines/unclip/test_unclip.py | 5 +- .../unclip/test_unclip_image_variation.py | 20 +++++-- .../test_versatile_diffusion_dual_guided.py | 5 +- ...est_versatile_diffusion_image_variation.py | 5 +- .../test_versatile_diffusion_mega.py | 15 ++++- .../test_versatile_diffusion_text_to_image.py | 5 +- .../vq_diffusion/test_vq_diffusion.py | 10 +++- 39 files changed, 602 insertions(+), 163 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index f4377f0e48b7..62b8adbb2ca9 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -8,7 +8,7 @@ from distutils.util import strtobool from io import BytesIO, StringIO from pathlib import Path -from typing import Union, Optional +from typing import Optional, Union import numpy as np @@ -56,7 +56,7 @@ def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_n 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: + with open(filename, "a") as f: print(";".join([test_file, test_class, test_fn, output_str]), file=f) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index 5a36f474d94d..79ab8ea0c976 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -155,7 +155,10 @@ def test_alt_diffusion_ddim(self): [0.5748162, 0.60447145, 0.48821217, 0.50100636, 0.5431185, 0.45763683, 0.49657696, 0.48132733, 0.47573093] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_pndm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -188,7 +191,10 @@ def test_alt_diffusion_pndm(self): expected_slice = np.array( [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @slow @@ -208,9 +214,7 @@ def test_alt_diffusion(self): prompt = "A painting of a squirrel eating a burger" generator = torch.manual_seed(0) - output = alt_pipe( - [prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np" - ) + output = alt_pipe([prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np") image = output.images @@ -218,7 +222,10 @@ def test_alt_diffusion(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_fast_ddim(self): scheduler = DDIMScheduler.from_pretrained("BAAI/AltDiffusion", subfolder="scheduler") @@ -237,4 +244,7 @@ def test_alt_diffusion_fast_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 39b57a0ab376..fff453637833 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -162,7 +162,10 @@ def test_stable_diffusion_img2img_default_case(self): expected_slice = np.array( [0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1.5e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + 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 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -242,7 +245,10 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @slow diff --git a/tests/pipelines/audio_diffusion/test_audio_diffusion.py b/tests/pipelines/audio_diffusion/test_audio_diffusion.py index 0a9ed6df1200..8bee1b7b5cbc 100644 --- a/tests/pipelines/audio_diffusion/test_audio_diffusion.py +++ b/tests/pipelines/audio_diffusion/test_audio_diffusion.py @@ -119,7 +119,10 @@ def test_audio_diffusion(self): image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_from_tuple_slice = np.frombuffer(image_from_tuple.tobytes(), dtype="uint8")[:10] expected_slice = np.array([255, 255, 255, 0, 181, 0, 124, 0, 15, 255]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0 scheduler = DDIMScheduler() @@ -142,7 +145,10 @@ def test_audio_diffusion(self): ) image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 dummy_unet_condition = self.dummy_unet_condition pipe = AudioDiffusionPipeline( @@ -155,7 +161,10 @@ def test_audio_diffusion(self): image = output.images[0] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 139, 147, 123, 124, 96, 115, 121, 126, 144]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 @slow @@ -183,4 +192,7 @@ def test_audio_diffusion(self): assert image.height == pipe.unet.sample_size[0] and image.width == pipe.unet.sample_size[1] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() == 0 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index ce0a625dd6aa..27c047f26d4d 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -111,8 +111,11 @@ def test_dance_diffusion(self): audio_slice = audio[0, -3:, -3:] assert audio.shape == (1, 2, pipe.unet.sample_size) - expected_slice = np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(audio_slice); assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 + expected_slice = np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(audio_slice) + assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 def test_dance_diffusion_fp16(self): device = torch_device @@ -129,4 +132,7 @@ def test_dance_diffusion_fp16(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(audio_slice); assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(audio_slice) + assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index e8222c87705b..fbbee42220c7 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -99,7 +99,10 @@ def test_inference_ema_bedroom(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_cifar10(self): model_id = "google/ddpm-cifar10-32" @@ -118,4 +121,7 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.2060, 0.2042, 0.2022, 0.2193, 0.2146, 0.2110, 0.2471, 0.2446, 0.2388]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index d5cb38c847af..2a2c4fa72920 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -63,7 +63,10 @@ def test_inference(self): expected_slice = np.array( [5.589e-01, 7.089e-01, 2.632e-01, 6.841e-01, 1.000e-04, 9.999e-01, 1.973e-01, 1.000e-04, 8.010e-02] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_deprecated_predict_epsilon(self): @@ -138,4 +141,7 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4454, 0.2025, 0.0315, 0.3023, 0.2575, 0.1031, 0.0953, 0.1604, 0.2020]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/karras_ve/test_karras_ve.py b/tests/pipelines/karras_ve/test_karras_ve.py index a40be566025c..1fd21ea67faa 100644 --- a/tests/pipelines/karras_ve/test_karras_ve.py +++ b/tests/pipelines/karras_ve/test_karras_ve.py @@ -59,7 +59,10 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -81,4 +84,7 @@ def test_inference(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index ff51c0afcf2a..3bc17ce87513 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -114,7 +114,10 @@ def test_inference_text2img(self): assert image.shape == (1, 16, 16, 3) expected_slice = np.array([0.59450, 0.64078, 0.55509, 0.51229, 0.69640, 0.36960, 0.59296, 0.60801, 0.49332]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @slow diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 59eb837ee0fd..2aff5de248c8 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -83,7 +83,10 @@ def test_inference_superresolution(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") def test_inference_superresolution_fp16(self): @@ -127,4 +130,7 @@ def test_inference_superresolution(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py index 4cae4818392b..2f891e1251f1 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py @@ -96,7 +96,10 @@ def test_inference_uncond(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance @@ -116,4 +119,7 @@ def test_inference_uncond(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index 2db8e64abea3..71f9fc4d66c8 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -134,7 +134,10 @@ def test_paint_by_example_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4701, 0.5555, 0.3994, 0.5107, 0.5691, 0.4517, 0.5125, 0.4769, 0.4539]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_paint_by_example_image_tensor(self): device = "cpu" @@ -222,4 +225,7 @@ def test_paint_by_example(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4834, 0.4811, 0.4874, 0.5122, 0.5081, 0.5144, 0.5291, 0.5290, 0.5374]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/pndm/test_pndm.py b/tests/pipelines/pndm/test_pndm.py index 85515b1fa76b..61cefc1e261c 100644 --- a/tests/pipelines/pndm/test_pndm.py +++ b/tests/pipelines/pndm/test_pndm.py @@ -59,7 +59,10 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -82,4 +85,7 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/repaint/test_repaint.py b/tests/pipelines/repaint/test_repaint.py index 15a1d0d65994..3ecb34324a2c 100644 --- a/tests/pipelines/repaint/test_repaint.py +++ b/tests/pipelines/repaint/test_repaint.py @@ -81,7 +81,10 @@ def test_repaint(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0000, 0.5426, 0.5497, 0.2200, 1.0000, 1.0000, 0.5623, 1.0000, 0.6274]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @nightly diff --git a/tests/pipelines/score_sde_ve/test_score_sde_ve.py b/tests/pipelines/score_sde_ve/test_score_sde_ve.py index cb730fead620..3f57b244ae30 100644 --- a/tests/pipelines/score_sde_ve/test_score_sde_ve.py +++ b/tests/pipelines/score_sde_ve/test_score_sde_ve.py @@ -61,7 +61,10 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -86,4 +89,7 @@ def test_inference(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 461a55908f50..bd169b895849 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -126,7 +126,10 @@ def test_stable_diffusion_cycle(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.4459, 0.4943, 0.4544, 0.6643, 0.5474, 0.4327, 0.5701, 0.5959, 0.5179]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") def test_stable_diffusion_cycle_fp16(self): @@ -147,7 +150,10 @@ def test_stable_diffusion_cycle_fp16(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.3506, 0.4543, 0.446, 0.4575, 0.5195, 0.4155, 0.5273, 0.518, 0.4116]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @slow diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index 0f4bb2ea6a67..9f478063cce5 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -60,7 +60,10 @@ def test_pipeline_default_ddim(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65072, 0.58492, 0.48219, 0.55521, 0.53180, 0.55939, 0.50697, 0.39800, 0.46455]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_pndm(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -73,7 +76,10 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65863, 0.59425, 0.49326, 0.56313, 0.53875, 0.56627, 0.51065, 0.39777, 0.46330]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_lms(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -86,7 +92,10 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -99,7 +108,10 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler_ancestral(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -112,7 +124,10 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53817, 0.60812, 0.47384, 0.49530, 0.51894, 0.49814, 0.47984, 0.38958, 0.44271]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_dpm_multistep(self): pipe = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -125,7 +140,10 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53895, 0.60808, 0.47933, 0.49608, 0.51886, 0.49950, 0.48053, 0.38957, 0.44200]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @nightly @@ -169,7 +187,10 @@ def test_inference_default_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_ddim(self): ddim_scheduler = DDIMScheduler.from_pretrained( @@ -194,7 +215,10 @@ def test_inference_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): lms_scheduler = LMSDiscreteScheduler.from_pretrained( @@ -219,7 +243,10 @@ def test_inference_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_intermediate_state(self): number_of_steps = 0 @@ -234,14 +261,20 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 5: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array( [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 test_callback_fn.has_been_called = False 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 07d41c9367dd..85733c81087d 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py @@ -82,7 +82,10 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.61710, 0.53390, 0.49310, 0.55622, 0.50982, 0.58240, 0.50716, 0.38629, 0.46856]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_lms(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -98,7 +101,10 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52761, 0.59977, 0.49033, 0.49619, 0.54282, 0.50311, 0.47600, 0.40918, 0.45203]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -111,7 +117,10 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler_ancestral(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -124,7 +133,10 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_dpm_multistep(self): pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(self.hub_checkpoint, provider="CPUExecutionProvider") @@ -137,7 +149,10 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65331, 0.58277, 0.48204, 0.56059, 0.53665, 0.56235, 0.50969, 0.40009, 0.46552]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 @nightly @@ -195,7 +210,10 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.4909, 0.5059, 0.5372, 0.4623, 0.4876, 0.5049, 0.4820, 0.4956, 0.5019]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 def test_inference_k_lms(self): init_image = load_image( @@ -235,4 +253,7 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.8043, 0.926, 0.9581, 0.8119, 0.8954, 0.913, 0.7209, 0.7463, 0.7431]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 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 e9ad71843823..e86cbf90acb7 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py @@ -94,7 +94,10 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.2514, 0.3007, 0.3517, 0.1790, 0.2382, 0.3167, 0.1944, 0.2273, 0.2464]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): init_image = load_image( @@ -136,4 +139,7 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 1e5d8b9751b5..e6340bd99dbe 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -132,7 +132,10 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5643, 0.6017, 0.4799, 0.5267, 0.5584, 0.4641, 0.5159, 0.4963, 0.4791]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_ddim_factor_8(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -151,7 +154,10 @@ def test_stable_diffusion_ddim_factor_8(self): assert image.shape == (1, 136, 136, 3) expected_slice = np.array([0.5524, 0.5626, 0.6069, 0.4727, 0.386, 0.3995, 0.4613, 0.4328, 0.4269]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -168,7 +174,10 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5094, 0.5674, 0.4667, 0.5125, 0.5696, 0.4674, 0.5277, 0.4964, 0.4945]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_no_safety_checker(self): pipe = StableDiffusionPipeline.from_pretrained( @@ -219,7 +228,10 @@ def test_stable_diffusion_k_lms(self): 0.5042197108268738, ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -249,7 +261,10 @@ def test_stable_diffusion_k_euler_ancestral(self): 0.504422664642334, ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -279,7 +294,10 @@ def test_stable_diffusion_k_euler(self): 0.5042197108268738, ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_vae_slicing(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -333,7 +351,10 @@ def test_stable_diffusion_negative_prompt(self): 0.4899061322212219, ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -584,7 +605,7 @@ def test_stable_diffusion_vae_slicing(self): assert np.abs(image_sliced - image).max() < 4e-3 def test_stable_diffusion_fp16_vs_autocast(self): - # this test makes sure that the original model with autocast + # this test makes sure that the original model with autocast # and the new model with fp16 yield the same result pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16) pipe = pipe.to(torch_device) @@ -614,14 +635,22 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.0466, -0.8790, 0.7600, -1.7340, 0.1044, 1.1610]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + expected_slice = np.array( + [-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582] + ) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.1885, -0.3022, -1.012, -0.514, -0.477, 0.6143, -0.9336, 0.6553, 1.453]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 150c03d43a5d..e9e346e7dae2 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -117,7 +117,10 @@ def test_stable_diffusion_img_variation_default_case(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5167, 0.5746, 0.4835, 0.4914, 0.5605, 0.4691, 0.5201, 0.4898, 0.4958]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_multiple_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -136,7 +139,10 @@ def test_stable_diffusion_img_variation_multiple_images(self): assert image.shape == (2, 64, 64, 3) expected_slice = np.array([0.6568, 0.5470, 0.5684, 0.5444, 0.5945, 0.6221, 0.5508, 0.5531, 0.5263]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_num_images_per_prompt(self): device = "cpu" @@ -227,14 +233,22 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1572, 0.2837, -0.7980, -0.1201, -1.3040, 0.7754, -2.1200, 0.0443, 1.6270]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + expected_slice = np.array( + [-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309] + ) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.6143, 1.734, 1.158, -2.145, -1.926, 0.748, -0.7246, 0.994, 1.539]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index adcad398fe3b..c679cd4194a0 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -119,7 +119,10 @@ def test_stable_diffusion_img2img_default_case(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4492, 0.3865, 0.4222, 0.5854, 0.5139, 0.4379, 0.4193, 0.48, 0.4218]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_negative_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -136,7 +139,10 @@ def test_stable_diffusion_img2img_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4065, 0.3783, 0.4050, 0.5266, 0.4781, 0.4252, 0.4203, 0.4692, 0.4365]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -153,7 +159,10 @@ def test_stable_diffusion_img2img_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.5144, 0.4447, 0.4735, 0.6676, 0.5526, 0.5454, 0.645, 0.5149, 0.4689]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -171,7 +180,10 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4367, 0.4986, 0.4372, 0.6706, 0.5665, 0.444, 0.5864, 0.6019, 0.5203]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -247,7 +259,10 @@ def test_stable_diffusion_img2img_default(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.4300, 0.4662, 0.4930, 0.3990, 0.4307, 0.4525, 0.3719, 0.4064, 0.3923]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", safety_checker=None) @@ -262,7 +277,10 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.0389, 0.0346, 0.0415, 0.0290, 0.0218, 0.0210, 0.0408, 0.0567, 0.0271]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_ddim(self): pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", safety_checker=None) @@ -277,7 +295,10 @@ def test_stable_diffusion_img2img_ddim(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.0593, 0.0607, 0.0851, 0.0582, 0.0636, 0.0721, 0.0751, 0.0981, 0.0781]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_intermediate_state(self): number_of_steps = 0 @@ -290,14 +311,20 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.7705, 0.1045, 0.5000, 3.3930, 3.7230, 4.2730, 2.4670, 3.4860, 1.7580]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.765, 0.1047, 0.4973, 3.375, 3.709, 4.258, 2.451, 3.46, 1.755]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False @@ -367,7 +394,10 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): assert image.shape == (504, 760, 3) expected_slice = np.array([0.9393, 0.9500, 0.9399, 0.9438, 0.9458, 0.9400, 0.9455, 0.9414, 0.9423]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @nightly diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index d48f94f4009e..352c769211f4 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -125,7 +125,10 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4723, 0.5731, 0.3939, 0.5441, 0.5922, 0.4392, 0.5059, 0.4651, 0.4474]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_image_tensor(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -207,7 +210,10 @@ def test_stable_diffusion_inpaint_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0427, 0.0460, 0.0483, 0.0460, 0.0584, 0.0521, 0.1549, 0.1695, 0.1794]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_fp16(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( @@ -223,7 +229,10 @@ def test_stable_diffusion_inpaint_fp16(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1443, 0.1218, 0.1587, 0.1594, 0.1411, 0.1284, 0.1370, 0.1506, 0.2339]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-2 def test_stable_diffusion_inpaint_pndm(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( @@ -240,7 +249,10 @@ def test_stable_diffusion_inpaint_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0425, 0.0273, 0.0344, 0.1694, 0.1727, 0.1812, 0.3256, 0.3311, 0.3272]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_k_lms(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( @@ -257,7 +269,10 @@ def test_stable_diffusion_inpaint_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.9314, 0.7575, 0.9432, 0.8885, 0.9028, 0.7298, 0.9811, 0.9667, 0.7633]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_with_sequential_cpu_offloading(self): torch.cuda.empty_cache() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index d24f5e0294c9..989e4cdeb5a3 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -213,7 +213,10 @@ def test_stable_diffusion_inpaint_legacy(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4731, 0.5346, 0.4531, 0.6251, 0.5446, 0.4057, 0.5527, 0.5896, 0.5153]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_legacy_negative_prompt(self): @@ -260,7 +263,10 @@ def test_stable_diffusion_inpaint_legacy_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4765, 0.5339, 0.4541, 0.6240, 0.5439, 0.4055, 0.5503, 0.5891, 0.5150]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_legacy_num_images_per_prompt(self): device = "cpu" @@ -383,7 +389,10 @@ def test_stable_diffusion_inpaint_legacy_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5669, 0.6124, 0.6431, 0.4073, 0.4614, 0.5670, 0.1609, 0.3128, 0.4330]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_k_lms(self): pipe = StableDiffusionInpaintPipelineLegacy.from_pretrained( @@ -400,7 +409,10 @@ def test_stable_diffusion_inpaint_legacy_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4533, 0.4465, 0.4327, 0.4329, 0.4339, 0.4219, 0.4243, 0.4332, 0.4426]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_intermediate_state(self): number_of_steps = 0 @@ -413,14 +425,20 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1030, 1.4150, -0.0220, -0.5107, -0.5903, 0.1953, 0.7500, 0.3477, -1.3560]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + expected_slice = np.array([0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.4802, 1.154, 0.628, 0.2319, 0.2593, -0.1455, 0.7075, -0.1617, -0.5615]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 e3471df94f26..ab47b84219dd 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -122,7 +122,10 @@ def test_stable_diffusion_pix2pix_default_case(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7318, 0.3723, 0.4662, 0.623, 0.5770, 0.5014, 0.4281, 0.5550, 0.4813]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_negative_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -139,7 +142,10 @@ def test_stable_diffusion_pix2pix_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7323, 0.3688, 0.4611, 0.6255, 0.5746, 0.5017, 0.433, 0.5553, 0.4827]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -161,7 +167,10 @@ def test_stable_diffusion_pix2pix_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.606, 0.5712, 0.5099, 0.598, 0.5805, 0.7205, 0.6793, 0.554, 0.5607]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_euler(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -182,7 +191,10 @@ def test_stable_diffusion_pix2pix_euler(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.726, 0.3902, 0.4868, 0.585, 0.5672, 0.511, 0.3906, 0.551, 0.4846]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -259,7 +271,10 @@ def test_stable_diffusion_pix2pix_default(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5902, 0.6015, 0.6027, 0.5983, 0.6092, 0.6061, 0.5765, 0.5785, 0.5555]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_k_lms(self): pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained( @@ -276,7 +291,10 @@ def test_stable_diffusion_pix2pix_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.6578, 0.6817, 0.6972, 0.6761, 0.6856, 0.6916, 0.6428, 0.6516, 0.6301]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_ddim(self): pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained( @@ -293,7 +311,10 @@ def test_stable_diffusion_pix2pix_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3828, 0.3834, 0.3818, 0.3792, 0.3865, 0.3752, 0.3792, 0.3847, 0.3753]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_intermediate_state(self): number_of_steps = 0 @@ -306,14 +327,20 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2388, -0.4673, -0.9775, 1.5127, 1.4414, 0.7778, 0.9907, 0.8472, 0.7788]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2568, -0.4648, -0.9639, 1.5137, 1.4609, 0.7603, 0.9795, 0.8403, 0.7949]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False @@ -370,4 +397,7 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): assert image.shape == (504, 504, 3) expected_slice = np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.259]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 68254ae7c7a9..86d1ba1137ab 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -53,7 +53,10 @@ def test_stable_diffusion_1(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_2(self): sd_pipe = StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base") @@ -74,4 +77,7 @@ def test_stable_diffusion_2(self): expected_slice = np.array( [0.826810, 0.81958747, 0.8510199, 0.8376758, 0.83958465, 0.8682068, 0.84370345, 0.85251087, 0.85884345] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 74fe1be51da0..c4094cbed987 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -133,7 +133,10 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5649, 0.6022, 0.4804, 0.5270, 0.5585, 0.4643, 0.5159, 0.4963, 0.4793]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -149,7 +152,10 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5099, 0.5677, 0.4671, 0.5128, 0.5697, 0.4676, 0.5277, 0.4964, 0.4946]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_lms(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -165,7 +171,10 @@ def test_stable_diffusion_k_lms(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -181,7 +190,10 @@ def test_stable_diffusion_k_euler_ancestral(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4715, 0.5376, 0.4569, 0.5224, 0.5734, 0.4797, 0.5465, 0.5074, 0.5046]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -197,7 +209,10 @@ def test_stable_diffusion_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_long_prompt(self): components = self.get_dummy_components() @@ -340,14 +355,22 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.3857, -0.4507, -1.1670, 0.0740, -1.1080, 0.7183, -1.8220, 0.1915, 1.2830]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + expected_slice = np.array( + [-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773] + ) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.268, -0.2095, -0.7744, -0.541, -0.79, 0.3926, -0.7754, 0.465, 1.291]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False 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 50568000fae7..00b4e4b028ef 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -289,7 +289,10 @@ def test_stable_diffusion_depth2img_default_case(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_negative_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -309,7 +312,10 @@ def test_stable_diffusion_depth2img_negative_prompt(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_multiple_init_images(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -330,7 +336,10 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_num_images_per_prompt(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator @@ -384,7 +393,10 @@ def test_stable_diffusion_depth2img_pil(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @slow @@ -425,7 +437,10 @@ def test_stable_diffusion_depth2img_pipeline_default(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_k_lms(self): pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( @@ -442,7 +457,10 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self): assert image.shape == (1, 480, 640, 3) expected_slice = np.array([0.6363, 0.6274, 0.6309, 0.6370, 0.6226, 0.6286, 0.6213, 0.6453, 0.6306]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_ddim(self): pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( @@ -459,7 +477,10 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(expected_slice - image_slice).max() < 1e-4 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_intermediate_state(self): number_of_steps = 0 @@ -472,14 +493,22 @@ 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([-1.1480, -0.2079, -0.6220, -2.4770, -2.3480, 0.3828, -2.0550, -1.5690, -1.5260]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + expected_slice = np.array( + [-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051] + ) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-1.145, -0.2063, -0.6216, -2.469, -2.344, 0.3794, -2.05, -1.57, -1.521]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 7d11ba0732fe..a9764a5886b8 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -125,7 +125,10 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4727, 0.5735, 0.3941, 0.5446, 0.5926, 0.4394, 0.5062, 0.4654, 0.4476]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @slow 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 0ac71eb5daa0..f652c4bf6cac 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -156,7 +156,10 @@ def test_stable_diffusion_upscale(self): assert image.shape == (1, expected_height_width, expected_height_width, 3) expected_slice = np.array([0.2562, 0.3606, 0.4204, 0.4469, 0.4822, 0.4647, 0.5315, 0.5748, 0.5606]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_upscale_batch(self): 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 7d20d8b126b7..8b46eec36074 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 @@ -146,7 +146,10 @@ def test_stable_diffusion_v_pred_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.6424, 0.6109, 0.494, 0.5088, 0.4984, 0.4525, 0.5059, 0.5068, 0.4474]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_k_euler(self): @@ -194,7 +197,10 @@ def test_stable_diffusion_v_pred_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4616, 0.5184, 0.4887, 0.5111, 0.4839, 0.48, 0.5119, 0.5263, 0.4776]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -263,7 +269,10 @@ def test_stable_diffusion_v_pred_default(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.1868, 0.1922, 0.1527, 0.1921, 0.1908, 0.1624, 0.1779, 0.1652, 0.1734]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_upcast_attention(self): sd_pipe = StableDiffusionPipeline.from_pretrained( @@ -282,7 +291,10 @@ def test_stable_diffusion_v_pred_upcast_attention(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.4209, 0.4087, 0.4097, 0.4209, 0.3860, 0.4329, 0.4280, 0.4324, 0.4187]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_euler(self): scheduler = EulerDiscreteScheduler.from_pretrained("stabilityai/stable-diffusion-2", subfolder="scheduler") @@ -301,7 +313,10 @@ def test_stable_diffusion_v_pred_euler(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.1781, 0.1695, 0.1661, 0.1705, 0.1588, 0.1699, 0.2005, 0.1589, 0.1677]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_dpm(self): """ @@ -324,7 +339,10 @@ def test_stable_diffusion_v_pred_dpm(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.3303, 0.3184, 0.3291, 0.3300, 0.3256, 0.3113, 0.2965, 0.3134, 0.3192]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_attention_slicing_v_pred(self): torch.cuda.reset_peak_memory_stats() @@ -351,9 +369,7 @@ def test_stable_diffusion_attention_slicing_v_pred(self): # disable slicing pipe.disable_attention_slicing() generator = torch.manual_seed(0) - output = pipe( - [prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy" - ) + output = pipe([prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy") image = output.images # make sure that more than 5.5 GB is allocated @@ -411,8 +427,11 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2543, -1.2755, 0.4261, -0.9555, -1.1730, -0.5892, 2.4159, 0.1554, -1.2098]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + expected_slice = np.array([0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) @@ -420,7 +439,10 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No expected_slice = np.array( [-0.9572, -0.967, -0.6152, 0.0894, -0.699, -0.2344, 1.5465, -0.0357, -0.1141] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(latents_slice); assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index 400104cf6e91..2e5ce42646a5 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -156,7 +156,10 @@ def test_safe_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5644, 0.6018, 0.4799, 0.5267, 0.5585, 0.4641, 0.516, 0.4964, 0.4792]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): @@ -201,7 +204,10 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5095, 0.5674, 0.4668, 0.5126, 0.5697, 0.4675, 0.5278, 0.4964, 0.4945]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_no_safety_checker(self): @@ -300,7 +306,10 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2278, 0.2231, 0.2249, 0.2333, 0.2303, 0.1885, 0.2273, 0.2144, 0.2176] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 # without safety guidance (strong configuration) generator = torch.manual_seed(seed) @@ -324,7 +333,10 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2383, 0.2276, 0.236, 0.2192, 0.2186, 0.2053, 0.1971, 0.1901, 0.1719] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safe_stable_diffusion(self): sd_pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", safety_checker=None) @@ -353,7 +365,10 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.3502, 0.3622, 0.3396, 0.3642, 0.3478, 0.3318, 0.35, 0.3348, 0.3297] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 generator = torch.manual_seed(seed) output = sd_pipe( @@ -376,7 +391,10 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.5531, 0.5206, 0.4895, 0.5156, 0.5182, 0.4751, 0.4802, 0.4803, 0.4443] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safetychecker_safe_stable_diffusion(self): sd_pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") @@ -407,7 +425,10 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): expected_slice = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 generator = torch.manual_seed(seed) output = sd_pipe( @@ -429,4 +450,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): image_slice = image[0, -3:, -3:, -1] expected_slice = np.array([0.5818, 0.6285, 0.6835, 0.6019, 0.625, 0.6754, 0.6096, 0.6334, 0.6561]) assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 485ad3429e5c..9342b67477f0 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -259,7 +259,10 @@ def test_unclip(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_passed_text_embed(self): diff --git a/tests/pipelines/unclip/test_unclip_image_variation.py b/tests/pipelines/unclip/test_unclip_image_variation.py index 9e8273da2a26..f4166b30309c 100644 --- a/tests/pipelines/unclip/test_unclip_image_variation.py +++ b/tests/pipelines/unclip/test_unclip_image_variation.py @@ -275,7 +275,10 @@ def test_unclip_image_variation_input_tensor(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_image_variation_input_image(self): @@ -307,7 +310,10 @@ def test_unclip_image_variation_input_image(self): expected_slice = np.array([0.9997, 0.0003, 0.9997, 0.9997, 0.9970, 0.0024, 0.9997, 0.9971, 0.9971]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_image_variation_input_list_images(self): @@ -359,7 +365,10 @@ def test_unclip_image_variation_input_list_images(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_image_variation_input_num_images_per_prompt(self): @@ -412,7 +421,10 @@ def test_unclip_image_variation_input_num_images_per_prompt(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_unclip_passed_image_embed(self): diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index 7897f1d264c5..8478b993e8d3 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -107,4 +107,7 @@ def test_inference_dual_guided(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index 937ce674c794..caf0dd7cdde3 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -53,4 +53,7 @@ def test_inference_image_variations(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0441, 0.0469, 0.0507, 0.0575, 0.0632, 0.0650, 0.0865, 0.0909, 0.0945]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 2094b5ca3837..1e269c72d10b 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -103,7 +103,10 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " generator = torch.manual_seed(0) @@ -115,7 +118,10 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images @@ -123,4 +129,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index 0f2b4a001682..f8c00c29ea93 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -81,4 +81,7 @@ def test_inference_text2img(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3493, 0.3757, 0.4093, 0.4495, 0.4233, 0.4102, 0.4507, 0.4756, 0.4787]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index 1e91e29fafe6..67b928c522c7 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -145,7 +145,10 @@ def test_vq_diffusion(self): expected_slice = np.array([0.6583, 0.6410, 0.5325, 0.5635, 0.5563, 0.4234, 0.6008, 0.5491, 0.4880]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_vq_diffusion_classifier_free_sampling(self): @@ -189,7 +192,10 @@ def test_vq_diffusion_classifier_free_sampling(self): expected_slice = np.array([0.6647, 0.6531, 0.5303, 0.5891, 0.5726, 0.4439, 0.6304, 0.5564, 0.4912]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice); assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + from diffusers.utils.testing_utils import print_tensor_test + + print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 From 4cb48c88926ea04b9f9c29060a3a9fa8bd30f8a8 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 06:51:59 +0000 Subject: [PATCH 24/39] up --- test_corrections.txt | 16 ++++++++++++++++ .../stable_diffusion/test_stable_diffusion.py | 4 +--- .../test_stable_diffusion_image_variation.py | 4 +--- .../test_stable_diffusion_img2img.py | 2 +- .../test_stable_diffusion_inpaint_legacy.py | 2 +- .../test_stable_diffusion_instruction_pix2pix.py | 2 +- .../stable_diffusion_2/test_stable_diffusion.py | 4 +--- .../test_stable_diffusion_depth.py | 4 +--- .../test_stable_diffusion_v_pred.py | 2 +- 9 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 test_corrections.txt diff --git a/test_corrections.txt b/test_corrections.txt new file mode 100644 index 000000000000..5745d6dffe76 --- /dev/null +++ b/test_corrections.txt @@ -0,0 +1,16 @@ +tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582]) +tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492]) +tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309]) +tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([ 0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) +tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) +tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) +tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) +tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) +tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) +tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([ 0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index e6340bd99dbe..2e34fc0b91ee 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -635,9 +635,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array( - [-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582] - ) + expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index e9e346e7dae2..79958bd6802d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -233,9 +233,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array( - [-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309] - ) + expected_slice = np.array([-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index c679cd4194a0..43551a487e0c 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -311,7 +311,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) + expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 989e4cdeb5a3..89f40d6da1fd 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -425,7 +425,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) + expected_slice = np.array([ 0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 ab47b84219dd..f66dc7b66c38 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -327,7 +327,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) + expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index c4094cbed987..bca3427341e9 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -355,9 +355,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array( - [-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773] - ) + expected_slice = np.array([-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 00b4e4b028ef..f99d8f310133 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -493,9 +493,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.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 8b46eec36074..bb6d54e7f0ec 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 @@ -427,7 +427,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) + expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) From 6971909904bb99728a09e669e5d7a5ff098c842e Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:03:23 +0000 Subject: [PATCH 25/39] up --- tests/pipelines/stable_diffusion/test_stable_diffusion.py | 2 +- .../stable_diffusion/test_stable_diffusion_image_variation.py | 2 +- .../stable_diffusion/test_stable_diffusion_img2img.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_inpaint_legacy.py | 2 +- .../test_stable_diffusion_instruction_pix2pix.py | 4 ++-- tests/pipelines/stable_diffusion_2/test_stable_diffusion.py | 2 +- .../stable_diffusion_2/test_stable_diffusion_depth.py | 2 +- .../stable_diffusion_2/test_stable_diffusion_v_pred.py | 4 +--- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 2e34fc0b91ee..bfbd80b151db 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -644,7 +644,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1885, -0.3022, -1.012, -0.514, -0.477, 0.6143, -0.9336, 0.6553, 1.453]) + expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 79958bd6802d..a9c94cac8720 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -242,7 +242,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.6143, 1.734, 1.158, -2.145, -1.926, 0.748, -0.7246, 0.994, 1.539]) + expected_slice = np.array([ 0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 43551a487e0c..fe56fc1d53a0 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -320,7 +320,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.765, 0.1047, 0.4973, 3.375, 3.709, 4.258, 2.451, 3.46, 1.755]) + expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -393,7 +393,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.9393, 0.9500, 0.9399, 0.9438, 0.9458, 0.9400, 0.9455, 0.9414, 0.9423]) + expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(image_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 89f40d6da1fd..94fc10c6d206 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -434,7 +434,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.4802, 1.154, 0.628, 0.2319, 0.2593, -0.1455, 0.7075, -0.1617, -0.5615]) + expected_slice = np.array([ 0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 f66dc7b66c38..b5e9866a3aee 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -336,7 +336,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2568, -0.4648, -0.9639, 1.5137, 1.4609, 0.7603, 0.9795, 0.8403, 0.7949]) + expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -396,7 +396,7 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): image_slice = image[255:258, 383:386, -1] assert image.shape == (504, 504, 3) - expected_slice = np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.259]) + expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(image_slice) diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index bca3427341e9..f22178ea33aa 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -364,7 +364,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([0.268, -0.2095, -0.7744, -0.541, -0.79, 0.3926, -0.7754, 0.465, 1.291]) + expected_slice = np.array([ 0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 f99d8f310133..f5bd8930f81c 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -502,7 +502,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([-1.145, -0.2063, -0.6216, -2.469, -2.344, 0.3794, -2.05, -1.57, -1.521]) + expected_slice = np.array([-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 bb6d54e7f0ec..aaf044b6df30 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 @@ -436,9 +436,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array( - [-0.9572, -0.967, -0.6152, 0.0894, -0.699, -0.2344, 1.5465, -0.0357, -0.1141] - ) + expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) From d13344246e9a409e93afd0e29fec6a52575c2d84 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:04:56 +0000 Subject: [PATCH 26/39] up --- src/diffusers/utils/testing_utils.py | 2 +- test_corrections.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 62b8adbb2ca9..189bee29394f 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -50,7 +50,7 @@ def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_n if not torch.is_tensor(tensor): tensor = torch.from_numpy(tensor) - tensor_str = str(tensor.detach().cpu().flatten()).replace("\n", "") + 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") diff --git a/test_corrections.txt b/test_corrections.txt index 5745d6dffe76..fbbd65b93f23 100644 --- a/test_corrections.txt +++ b/test_corrections.txt @@ -14,3 +14,5 @@ tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusio tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090]) tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) +tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492], dtype=torch.float16) From bfd3a3f5e91297c7ee1419c9e572526eeb405443 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:24:58 +0000 Subject: [PATCH 27/39] fix more --- src/diffusers/utils/testing_utils.py | 2 +- test_corrections.txt | 14 ++++++++++++++ tests/pipelines/dit/test_dit.py | 7 +++++-- .../stable_diffusion/test_cycle_diffusion.py | 1 - .../stable_diffusion/test_stable_diffusion.py | 10 +++++++--- .../test_stable_diffusion_image_variation.py | 6 ++++-- .../test_stable_diffusion_img2img.py | 6 +++--- .../test_stable_diffusion_inpaint_legacy.py | 4 ++-- .../test_stable_diffusion_instruction_pix2pix.py | 6 +++--- .../stable_diffusion_2/test_stable_diffusion.py | 8 ++++++-- .../test_stable_diffusion_depth.py | 8 ++++++-- .../test_stable_diffusion_v_pred.py | 4 ++-- tests/pipelines/vq_diffusion/test_vq_diffusion.py | 4 +++- 13 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/diffusers/utils/testing_utils.py b/src/diffusers/utils/testing_utils.py index 189bee29394f..f6bc0e92f2f4 100644 --- a/src/diffusers/utils/testing_utils.py +++ b/src/diffusers/utils/testing_utils.py @@ -170,7 +170,7 @@ def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) - # local_path = "/home/patrick_huggingface_co/" if local_path is not None: # local_path can be passed to correct images of tests - return local_path + "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]]) + return os.path.join(local_path, "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]])) elif arry.startswith("http://") or arry.startswith("https://"): response = requests.get(arry) response.raise_for_status() diff --git a/test_corrections.txt b/test_corrections.txt index fbbd65b93f23..aa39a6f1526e 100644 --- a/test_corrections.txt +++ b/test_corrections.txt @@ -16,3 +16,17 @@ tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusi tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582], dtype=torch.float16) tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([ 0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983], dtype=torch.float16) +tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115], dtype=torch.float16) +tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773], dtype=torch.float16) +tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([ 0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686], dtype=torch.float16) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051], dtype=torch.float16) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090], dtype=torch.float16) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326], dtype=torch.float16) +tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227], dtype=torch.float16) diff --git a/tests/pipelines/dit/test_dit.py b/tests/pipelines/dit/test_dit.py index 972d90b53ad8..be4b6b48d3ab 100644 --- a/tests/pipelines/dit/test_dit.py +++ b/tests/pipelines/dit/test_dit.py @@ -127,7 +127,10 @@ def test_dit_512_fp16(self): for word, image in zip(words, images): expected_image = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" - f"/dit/{word}_fp16.npy" + ( + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" + f"/dit/{word}_fp16.npy" + ), ) + assert np.abs((expected_image - image).max()) < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index bd169b895849..5f55f69a09cf 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -243,4 +243,3 @@ def test_cycle_diffusion_pipeline(self): image = output.images assert np.abs(image - expected_image).max() < 1e-2 - assert np.abs(image - expected_image).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index bfbd80b151db..3f09921810a8 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -602,7 +602,7 @@ def test_stable_diffusion_vae_slicing(self): mem_bytes = torch.cuda.max_memory_allocated() assert mem_bytes > 4e9 # There is a small discrepancy at the image borders vs. a fully batched version. - assert np.abs(image_sliced - image).max() < 4e-3 + assert np.abs(image_sliced - image).max() < 1e-2 def test_stable_diffusion_fp16_vs_autocast(self): # this test makes sure that the original model with autocast @@ -635,7 +635,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582]) + expected_slice = np.array( + [-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -644,7 +646,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492]) + expected_slice = np.array( + [-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index a9c94cac8720..0a83391ade47 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -233,7 +233,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309]) + expected_slice = np.array( + [-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -242,7 +244,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([ 0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) + expected_slice = np.array([0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index fe56fc1d53a0..44a13c76001d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -311,7 +311,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) + expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -320,7 +320,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) + expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -393,7 +393,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.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) + expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(image_slice) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index 94fc10c6d206..fd9ab00086f4 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -425,7 +425,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([ 0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) + expected_slice = np.array([0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -434,7 +434,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([ 0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) + expected_slice = np.array([0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 b5e9866a3aee..a3f9078abb52 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -327,7 +327,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) + expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -336,7 +336,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) + expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -396,7 +396,7 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): image_slice = image[255:258, 383:386, -1] assert image.shape == (504, 504, 3) - expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) + expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(image_slice) diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index f22178ea33aa..8ec6a9c345af 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -355,7 +355,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773]) + expected_slice = np.array( + [-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -364,7 +366,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([ 0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686]) + expected_slice = np.array( + [0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 f5bd8930f81c..1da4003707ad 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -493,7 +493,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.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051]) + expected_slice = np.array( + [-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -502,7 +504,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.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090]) + expected_slice = np.array( + [-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090] + ) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) 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 aaf044b6df30..17c1a0c78ab3 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 @@ -427,7 +427,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) + expected_slice = np.array([0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) @@ -436,7 +436,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] - expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) + expected_slice = np.array([1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) from diffusers.utils.testing_utils import print_tensor_test print_tensor_test(latents_slice) diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index 67b928c522c7..ad7e5b2f8a00 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -218,7 +218,9 @@ def test_vq_diffusion_classifier_free_sampling(self): pipeline = pipeline.to(torch_device) pipeline.set_progress_bar_config(disable=None) - generator = torch.manual_seed(0) + # requires GPU generator for gumbel softmax + # don't use GPU generator in tests though + generator = torch.Generator(device=torch_device).manual_seed(0) output = pipeline( "teddy bear playing in the pool", num_images_per_prompt=1, From 44a5f60b6b4cb75c324977721d7db6cf9772fb4f Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:36:59 +0000 Subject: [PATCH 28/39] up --- test_corrections.txt | 82 +++++++++++++++++++++++++---------------- tests/test_scheduler.py | 70 ++++++----------------------------- 2 files changed, 62 insertions(+), 90 deletions(-) diff --git a/test_corrections.txt b/test_corrections.txt index aa39a6f1526e..4cdac89c96ae 100644 --- a/test_corrections.txt +++ b/test_corrections.txt @@ -1,32 +1,50 @@ -tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582]) -tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492]) -tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309]) -tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([ 0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) -tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) -tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) -tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) -tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) -tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) -tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([ 0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) -tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion.py;StableDiffusionPipelineSlowTests;test_stable_diffusion_intermediate_state;expected_slice = np.array([-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py;StableDiffusionImageVariationPipelineSlowTests;test_stable_diffusion_img_variation_intermediate_state;expected_slice = np.array([ 0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_intermediate_state;expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py;StableDiffusionInpaintLegacyPipelineSlowTests;test_stable_diffusion_inpaint_legacy_intermediate_state;expected_slice = np.array([ 0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983], dtype=torch.float16) -tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_intermediate_state;expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115], dtype=torch.float16) -tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773], dtype=torch.float16) -tests/pipelines/stable_diffusion_2/test_stable_diffusion.py;StableDiffusion2PipelineSlowTests;test_stable_diffusion_text2img_intermediate_state;expected_slice = np.array([ 0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686], dtype=torch.float16) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051], dtype=torch.float16) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py;StableDiffusionDepth2ImgPipelineSlowTests;test_stable_diffusion_depth2img_intermediate_state;expected_slice = np.array([-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090], dtype=torch.float16) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326], dtype=torch.float16) -tests/pipelines/stable_diffusion_2/test_stable_diffusion_v_pred.py;StableDiffusion2VPredictionPipelineIntegrationTests;test_stable_diffusion_text2img_intermediate_state_v_pred;expected_slice = np.array([ 1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227], dtype=torch.float16) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3818]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([13849.3877]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3818]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([13849.3877]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3877]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([13849.3877]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3877]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) +tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) +tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index f96c3abf7807..0d38447a854b 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -1951,16 +1951,9 @@ def test_full_loop_no_noise(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) - print(result_sum) - print(result_mean) - if torch_device in ["cpu", "mps"]: - assert abs(result_sum.item() - 152.3192) < 1e-2 - assert abs(result_mean.item() - 0.1983) < 1e-3 - else: - # CUDA - assert abs(result_sum.item() - 144.8084) < 1e-2 - assert abs(result_mean.item() - 0.18855) < 1e-3 + assert abs(result_sum.item() - 152.3192) < 1e-2 + assert abs(result_mean.item() - 0.1983) < 1e-3 def test_full_loop_with_v_prediction(self): scheduler_class = self.scheduler_classes[0] @@ -1985,16 +1978,9 @@ def test_full_loop_with_v_prediction(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) - print(result_sum) - print(result_mean) - if torch_device in ["cpu", "mps"]: - assert abs(result_sum.item() - 108.4439) < 1e-2 - assert abs(result_mean.item() - 0.1412) < 1e-3 - else: - # CUDA - assert abs(result_sum.item() - 102.5807) < 1e-2 - assert abs(result_mean.item() - 0.1335) < 1e-3 + assert abs(result_sum.item() - 108.4439) < 1e-2 + assert abs(result_mean.item() - 0.1412) < 1e-3 def test_full_loop_device(self): scheduler_class = self.scheduler_classes[0] @@ -2018,20 +2004,9 @@ def test_full_loop_device(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) - print(result_sum) - print(result_mean) - if str(torch_device).startswith("cpu"): - # The following sum varies between 148 and 156 on mps. Why? - assert abs(result_sum.item() - 152.3192) < 1e-2 - assert abs(result_mean.item() - 0.1983) < 1e-3 - elif str(torch_device).startswith("mps"): - # Larger tolerance on mps - assert abs(result_mean.item() - 0.1983) < 1e-2 - else: - # CUDA - assert abs(result_sum.item() - 144.8084) < 1e-2 - assert abs(result_mean.item() - 0.18855) < 1e-3 + assert abs(result_sum.item() - 152.3192) < 1e-2 + assert abs(result_mean.item() - 0.1983) < 1e-3 class IPNDMSchedulerTest(SchedulerCommonTest): @@ -2742,16 +2717,9 @@ def test_full_loop_no_noise(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) - print(result_sum) - print(result_mean) - if torch_device in ["cpu", "mps"]: - assert abs(result_sum.item() - 13849.3945) < 1e-2 - assert abs(result_mean.item() - 18.0331) < 5e-3 - else: - # CUDA - assert abs(result_sum.item() - 13913.0449) < 1e-2 - assert abs(result_mean.item() - 18.1159) < 5e-3 + assert abs(result_sum.item() - 13849.3877) < 1e-2 + assert abs(result_mean.item() - 18.0331) < 5e-3 def test_prediction_type(self): for prediction_type in ["epsilon", "v_prediction"]: @@ -2782,16 +2750,9 @@ def test_full_loop_with_v_prediction(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) - print(result_sum) - print(result_mean) - if torch_device in ["cpu", "mps"]: - assert abs(result_sum.item() - 328.9970) < 1e-2 - assert abs(result_mean.item() - 0.4284) < 1e-3 - else: - # CUDA - assert abs(result_sum.item() - 327.8027) < 1e-2 - assert abs(result_mean.item() - 0.4268) < 1e-3 + assert abs(result_sum.item() - 328.9970) < 1e-2 + assert abs(result_mean.item() - 0.4284) < 1e-3 def test_full_loop_device(self): if torch_device == "mps": @@ -2816,16 +2777,9 @@ def test_full_loop_device(self): result_sum = torch.sum(torch.abs(sample)) result_mean = torch.mean(torch.abs(sample)) - print(result_sum) - print(result_mean) - if str(torch_device).startswith("cpu"): - assert abs(result_sum.item() - 13849.3945) < 1e-2 - assert abs(result_mean.item() - 18.0331) < 5e-3 - else: - # CUDA - assert abs(result_sum.item() - 13913.0332) < 1e-1 - assert abs(result_mean.item() - 18.1159) < 1e-3 + assert abs(result_sum.item() - 13849.3818) < 1e-1 + assert abs(result_mean.item() - 18.0331) < 1e-3 # UnCLIPScheduler is a modified DDPMScheduler with a subset of the configuration. From ecf9dd5e5c2293222653a22869d049d9cc9707b1 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:44:02 +0000 Subject: [PATCH 29/39] up --- test_corrections.txt | 50 -------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 test_corrections.txt diff --git a/test_corrections.txt b/test_corrections.txt deleted file mode 100644 index 4cdac89c96ae..000000000000 --- a/test_corrections.txt +++ /dev/null @@ -1,50 +0,0 @@ -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3818]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([13849.3877]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3818]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([13849.3877]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3877]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([13849.3877]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([13849.3877]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_device;expected_slice = np.array([18.0331]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([328.9970]) -tests/test_scheduler.py;KDPM2AncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.4284]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([152.3192]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_no_noise;expected_slice = np.array([0.1983]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([108.4439]) -tests/test_scheduler.py;EulerAncestralDiscreteSchedulerTest;test_full_loop_with_v_prediction;expected_slice = np.array([0.1412]) From 8722a34d1bcbbd336409a69c442dd0664ee0b320 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:45:56 +0000 Subject: [PATCH 30/39] clean tests --- .../altdiffusion/test_alt_diffusion.py | 16 +++---- .../test_alt_diffusion_img2img.py | 8 ++-- .../audio_diffusion/test_audio_diffusion.py | 16 +++---- .../dance_diffusion/test_dance_diffusion.py | 8 ++-- tests/pipelines/ddim/test_ddim.py | 8 ++-- tests/pipelines/ddpm/test_ddpm.py | 8 ++-- tests/pipelines/karras_ve/test_karras_ve.py | 8 ++-- .../latent_diffusion/test_latent_diffusion.py | 4 +- .../test_latent_diffusion_superresolution.py | 8 ++-- .../test_latent_diffusion_uncond.py | 8 ++-- .../paint_by_example/test_paint_by_example.py | 8 ++-- tests/pipelines/pndm/test_pndm.py | 8 ++-- tests/pipelines/repaint/test_repaint.py | 4 +- .../score_sde_ve/test_score_sde_ve.py | 8 ++-- .../stable_diffusion/test_cycle_diffusion.py | 8 ++-- .../test_onnx_stable_diffusion.py | 44 +++++++++---------- .../test_onnx_stable_diffusion_img2img.py | 28 ++++++------ .../test_onnx_stable_diffusion_inpaint.py | 8 ++-- .../stable_diffusion/test_stable_diffusion.py | 36 +++++++-------- .../test_stable_diffusion_image_variation.py | 16 +++---- .../test_stable_diffusion_img2img.py | 40 ++++++++--------- .../test_stable_diffusion_inpaint.py | 20 ++++----- .../test_stable_diffusion_inpaint_legacy.py | 24 +++++----- ...st_stable_diffusion_instruction_pix2pix.py | 40 ++++++++--------- .../test_stable_diffusion_k_diffusion.py | 8 ++-- .../test_stable_diffusion.py | 28 ++++++------ .../test_stable_diffusion_depth.py | 36 +++++++-------- .../test_stable_diffusion_inpaint.py | 4 +- .../test_stable_diffusion_upscale.py | 4 +- .../test_stable_diffusion_v_pred.py | 32 +++++++------- .../test_safe_diffusion.py | 32 +++++++------- tests/pipelines/unclip/test_unclip.py | 4 +- .../unclip/test_unclip_image_variation.py | 16 +++---- .../test_versatile_diffusion_dual_guided.py | 4 +- ...est_versatile_diffusion_image_variation.py | 4 +- .../test_versatile_diffusion_mega.py | 12 ++--- .../test_versatile_diffusion_text_to_image.py | 4 +- .../vq_diffusion/test_vq_diffusion.py | 8 ++-- 38 files changed, 290 insertions(+), 290 deletions(-) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index 79ab8ea0c976..eb0f07203363 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -155,9 +155,9 @@ def test_alt_diffusion_ddim(self): [0.5748162, 0.60447145, 0.48821217, 0.50100636, 0.5431185, 0.45763683, 0.49657696, 0.48132733, 0.47573093] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_pndm(self): @@ -191,9 +191,9 @@ def test_alt_diffusion_pndm(self): expected_slice = np.array( [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @@ -222,9 +222,9 @@ def test_alt_diffusion(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_fast_ddim(self): @@ -244,7 +244,7 @@ def test_alt_diffusion_fast_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index fff453637833..40c74d291c8c 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -162,9 +162,9 @@ def test_stable_diffusion_img2img_default_case(self): expected_slice = np.array( [0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + 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 @@ -245,9 +245,9 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/audio_diffusion/test_audio_diffusion.py b/tests/pipelines/audio_diffusion/test_audio_diffusion.py index 8bee1b7b5cbc..d55a20f2c3de 100644 --- a/tests/pipelines/audio_diffusion/test_audio_diffusion.py +++ b/tests/pipelines/audio_diffusion/test_audio_diffusion.py @@ -119,9 +119,9 @@ def test_audio_diffusion(self): image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_from_tuple_slice = np.frombuffer(image_from_tuple.tobytes(), dtype="uint8")[:10] expected_slice = np.array([255, 255, 255, 0, 181, 0, 124, 0, 15, 255]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0 @@ -145,9 +145,9 @@ def test_audio_diffusion(self): ) image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 dummy_unet_condition = self.dummy_unet_condition @@ -161,9 +161,9 @@ def test_audio_diffusion(self): image = output.images[0] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 139, 147, 123, 124, 96, 115, 121, 126, 144]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 @@ -192,7 +192,7 @@ def test_audio_diffusion(self): assert image.height == pipe.unet.sample_size[0] and image.width == pipe.unet.sample_size[1] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() == 0 diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index 27c047f26d4d..1e2366d7a254 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -112,9 +112,9 @@ def test_dance_diffusion(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(audio_slice) + assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 def test_dance_diffusion_fp16(self): @@ -132,7 +132,7 @@ def test_dance_diffusion_fp16(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(audio_slice) + assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index fbbee42220c7..1bddc5045328 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -99,9 +99,9 @@ def test_inference_ema_bedroom(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_cifar10(self): @@ -121,7 +121,7 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.2060, 0.2042, 0.2022, 0.2193, 0.2146, 0.2110, 0.2471, 0.2446, 0.2388]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 2a2c4fa72920..d18931c5cb01 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -63,9 +63,9 @@ def test_inference(self): expected_slice = np.array( [5.589e-01, 7.089e-01, 2.632e-01, 6.841e-01, 1.000e-04, 9.999e-01, 1.973e-01, 1.000e-04, 8.010e-02] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -141,7 +141,7 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4454, 0.2025, 0.0315, 0.3023, 0.2575, 0.1031, 0.0953, 0.1604, 0.2020]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/karras_ve/test_karras_ve.py b/tests/pipelines/karras_ve/test_karras_ve.py index 1fd21ea67faa..70da97446f9a 100644 --- a/tests/pipelines/karras_ve/test_karras_ve.py +++ b/tests/pipelines/karras_ve/test_karras_ve.py @@ -59,9 +59,9 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -84,7 +84,7 @@ def test_inference(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index 3bc17ce87513..14455c7516ed 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -114,9 +114,9 @@ def test_inference_text2img(self): assert image.shape == (1, 16, 16, 3) expected_slice = np.array([0.59450, 0.64078, 0.55509, 0.51229, 0.69640, 0.36960, 0.59296, 0.60801, 0.49332]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 2aff5de248c8..69457ae58df7 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -83,9 +83,9 @@ def test_inference_superresolution(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -130,7 +130,7 @@ def test_inference_superresolution(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py index 2f891e1251f1..056594a6b854 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py @@ -96,9 +96,9 @@ def test_inference_uncond(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance @@ -119,7 +119,7 @@ def test_inference_uncond(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index 71f9fc4d66c8..2f414b41ed48 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -134,9 +134,9 @@ def test_paint_by_example_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4701, 0.5555, 0.3994, 0.5107, 0.5691, 0.4517, 0.5125, 0.4769, 0.4539]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_paint_by_example_image_tensor(self): @@ -225,7 +225,7 @@ def test_paint_by_example(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4834, 0.4811, 0.4874, 0.5122, 0.5081, 0.5144, 0.5291, 0.5290, 0.5374]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/pndm/test_pndm.py b/tests/pipelines/pndm/test_pndm.py index 61cefc1e261c..1d72e5013605 100644 --- a/tests/pipelines/pndm/test_pndm.py +++ b/tests/pipelines/pndm/test_pndm.py @@ -59,9 +59,9 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -85,7 +85,7 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/repaint/test_repaint.py b/tests/pipelines/repaint/test_repaint.py index 3ecb34324a2c..b046312396af 100644 --- a/tests/pipelines/repaint/test_repaint.py +++ b/tests/pipelines/repaint/test_repaint.py @@ -81,9 +81,9 @@ def test_repaint(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0000, 0.5426, 0.5497, 0.2200, 1.0000, 1.0000, 0.5623, 1.0000, 0.6274]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/score_sde_ve/test_score_sde_ve.py b/tests/pipelines/score_sde_ve/test_score_sde_ve.py index 3f57b244ae30..5b10d0037ae9 100644 --- a/tests/pipelines/score_sde_ve/test_score_sde_ve.py +++ b/tests/pipelines/score_sde_ve/test_score_sde_ve.py @@ -61,9 +61,9 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -89,7 +89,7 @@ def test_inference(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 5f55f69a09cf..83374bca36e9 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -126,9 +126,9 @@ def test_stable_diffusion_cycle(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.4459, 0.4943, 0.4544, 0.6643, 0.5474, 0.4327, 0.5701, 0.5959, 0.5179]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -150,9 +150,9 @@ def test_stable_diffusion_cycle_fp16(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.3506, 0.4543, 0.446, 0.4575, 0.5195, 0.4155, 0.5273, 0.518, 0.4116]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index 9f478063cce5..22d009d5bfcb 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -60,9 +60,9 @@ def test_pipeline_default_ddim(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65072, 0.58492, 0.48219, 0.55521, 0.53180, 0.55939, 0.50697, 0.39800, 0.46455]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_pndm(self): @@ -76,9 +76,9 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65863, 0.59425, 0.49326, 0.56313, 0.53875, 0.56627, 0.51065, 0.39777, 0.46330]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_lms(self): @@ -92,9 +92,9 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler(self): @@ -108,9 +108,9 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler_ancestral(self): @@ -124,9 +124,9 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53817, 0.60812, 0.47384, 0.49530, 0.51894, 0.49814, 0.47984, 0.38958, 0.44271]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_dpm_multistep(self): @@ -140,9 +140,9 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53895, 0.60808, 0.47933, 0.49608, 0.51886, 0.49950, 0.48053, 0.38957, 0.44200]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @@ -187,9 +187,9 @@ def test_inference_default_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_ddim(self): @@ -215,9 +215,9 @@ def test_inference_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): @@ -243,9 +243,9 @@ def test_inference_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_intermediate_state(self): @@ -261,9 +261,9 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 5: assert latents.shape == (1, 4, 64, 64) @@ -271,9 +271,9 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 test_callback_fn.has_been_called = False 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 85733c81087d..42e87c537373 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py @@ -82,9 +82,9 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.61710, 0.53390, 0.49310, 0.55622, 0.50982, 0.58240, 0.50716, 0.38629, 0.46856]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_lms(self): @@ -101,9 +101,9 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52761, 0.59977, 0.49033, 0.49619, 0.54282, 0.50311, 0.47600, 0.40918, 0.45203]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler(self): @@ -117,9 +117,9 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler_ancestral(self): @@ -133,9 +133,9 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_dpm_multistep(self): @@ -149,9 +149,9 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65331, 0.58277, 0.48204, 0.56059, 0.53665, 0.56235, 0.50969, 0.40009, 0.46552]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 @@ -210,9 +210,9 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.4909, 0.5059, 0.5372, 0.4623, 0.4876, 0.5049, 0.4820, 0.4956, 0.5019]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 def test_inference_k_lms(self): @@ -253,7 +253,7 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.8043, 0.926, 0.9581, 0.8119, 0.8954, 0.913, 0.7209, 0.7463, 0.7431]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 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 e86cbf90acb7..84c0847b853b 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py @@ -94,9 +94,9 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.2514, 0.3007, 0.3517, 0.1790, 0.2382, 0.3167, 0.1944, 0.2273, 0.2464]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): @@ -139,7 +139,7 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 3f09921810a8..2ceb4b289a10 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -132,9 +132,9 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5643, 0.6017, 0.4799, 0.5267, 0.5584, 0.4641, 0.5159, 0.4963, 0.4791]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_ddim_factor_8(self): @@ -154,9 +154,9 @@ def test_stable_diffusion_ddim_factor_8(self): assert image.shape == (1, 136, 136, 3) expected_slice = np.array([0.5524, 0.5626, 0.6069, 0.4727, 0.386, 0.3995, 0.4613, 0.4328, 0.4269]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): @@ -174,9 +174,9 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5094, 0.5674, 0.4667, 0.5125, 0.5696, 0.4674, 0.5277, 0.4964, 0.4945]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_no_safety_checker(self): @@ -228,9 +228,9 @@ def test_stable_diffusion_k_lms(self): 0.5042197108268738, ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): @@ -261,9 +261,9 @@ def test_stable_diffusion_k_euler_ancestral(self): 0.504422664642334, ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): @@ -294,9 +294,9 @@ def test_stable_diffusion_k_euler(self): 0.5042197108268738, ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_vae_slicing(self): @@ -351,9 +351,9 @@ def test_stable_diffusion_negative_prompt(self): 0.4899061322212219, ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_num_images_per_prompt(self): @@ -638,9 +638,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() @@ -649,9 +649,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 0a83391ade47..4fb9a17a1cfc 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -117,9 +117,9 @@ def test_stable_diffusion_img_variation_default_case(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5167, 0.5746, 0.4835, 0.4914, 0.5605, 0.4691, 0.5201, 0.4898, 0.4958]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_multiple_images(self): @@ -139,9 +139,9 @@ def test_stable_diffusion_img_variation_multiple_images(self): assert image.shape == (2, 64, 64, 3) expected_slice = np.array([0.6568, 0.5470, 0.5684, 0.5444, 0.5945, 0.6221, 0.5508, 0.5531, 0.5263]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_num_images_per_prompt(self): @@ -236,18 +236,18 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 44a13c76001d..96086c963d6d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -119,9 +119,9 @@ def test_stable_diffusion_img2img_default_case(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4492, 0.3865, 0.4222, 0.5854, 0.5139, 0.4379, 0.4193, 0.48, 0.4218]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_negative_prompt(self): @@ -139,9 +139,9 @@ def test_stable_diffusion_img2img_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4065, 0.3783, 0.4050, 0.5266, 0.4781, 0.4252, 0.4203, 0.4692, 0.4365]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_multiple_init_images(self): @@ -159,9 +159,9 @@ def test_stable_diffusion_img2img_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.5144, 0.4447, 0.4735, 0.6676, 0.5526, 0.5454, 0.645, 0.5149, 0.4689]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): @@ -180,9 +180,9 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4367, 0.4986, 0.4372, 0.6706, 0.5665, 0.444, 0.5864, 0.6019, 0.5203]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_num_images_per_prompt(self): @@ -259,9 +259,9 @@ def test_stable_diffusion_img2img_default(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.4300, 0.4662, 0.4930, 0.3990, 0.4307, 0.4525, 0.3719, 0.4064, 0.3923]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): @@ -277,9 +277,9 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.0389, 0.0346, 0.0415, 0.0290, 0.0218, 0.0210, 0.0408, 0.0567, 0.0271]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_ddim(self): @@ -295,9 +295,9 @@ def test_stable_diffusion_img2img_ddim(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.0593, 0.0607, 0.0851, 0.0582, 0.0636, 0.0721, 0.0751, 0.0981, 0.0781]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_intermediate_state(self): @@ -312,18 +312,18 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False @@ -394,9 +394,9 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): assert image.shape == (504, 760, 3) expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 352c769211f4..2581fcdac542 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -125,9 +125,9 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4723, 0.5731, 0.3939, 0.5441, 0.5922, 0.4392, 0.5059, 0.4651, 0.4474]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_image_tensor(self): @@ -210,9 +210,9 @@ def test_stable_diffusion_inpaint_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0427, 0.0460, 0.0483, 0.0460, 0.0584, 0.0521, 0.1549, 0.1695, 0.1794]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_fp16(self): @@ -229,9 +229,9 @@ def test_stable_diffusion_inpaint_fp16(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1443, 0.1218, 0.1587, 0.1594, 0.1411, 0.1284, 0.1370, 0.1506, 0.2339]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-2 def test_stable_diffusion_inpaint_pndm(self): @@ -249,9 +249,9 @@ def test_stable_diffusion_inpaint_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0425, 0.0273, 0.0344, 0.1694, 0.1727, 0.1812, 0.3256, 0.3311, 0.3272]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_k_lms(self): @@ -269,9 +269,9 @@ def test_stable_diffusion_inpaint_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.9314, 0.7575, 0.9432, 0.8885, 0.9028, 0.7298, 0.9811, 0.9667, 0.7633]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_with_sequential_cpu_offloading(self): diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index fd9ab00086f4..fb41dc7b193f 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -213,9 +213,9 @@ def test_stable_diffusion_inpaint_legacy(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4731, 0.5346, 0.4531, 0.6251, 0.5446, 0.4057, 0.5527, 0.5896, 0.5153]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -263,9 +263,9 @@ def test_stable_diffusion_inpaint_legacy_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4765, 0.5339, 0.4541, 0.6240, 0.5439, 0.4055, 0.5503, 0.5891, 0.5150]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_legacy_num_images_per_prompt(self): @@ -389,9 +389,9 @@ def test_stable_diffusion_inpaint_legacy_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5669, 0.6124, 0.6431, 0.4073, 0.4614, 0.5670, 0.1609, 0.3128, 0.4330]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_k_lms(self): @@ -409,9 +409,9 @@ def test_stable_diffusion_inpaint_legacy_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4533, 0.4465, 0.4327, 0.4329, 0.4339, 0.4219, 0.4243, 0.4332, 0.4426]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_intermediate_state(self): @@ -426,18 +426,18 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 a3f9078abb52..2ae087b9e7a0 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -122,9 +122,9 @@ def test_stable_diffusion_pix2pix_default_case(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7318, 0.3723, 0.4662, 0.623, 0.5770, 0.5014, 0.4281, 0.5550, 0.4813]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_negative_prompt(self): @@ -142,9 +142,9 @@ def test_stable_diffusion_pix2pix_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7323, 0.3688, 0.4611, 0.6255, 0.5746, 0.5017, 0.433, 0.5553, 0.4827]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_multiple_init_images(self): @@ -167,9 +167,9 @@ def test_stable_diffusion_pix2pix_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.606, 0.5712, 0.5099, 0.598, 0.5805, 0.7205, 0.6793, 0.554, 0.5607]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_euler(self): @@ -191,9 +191,9 @@ def test_stable_diffusion_pix2pix_euler(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.726, 0.3902, 0.4868, 0.585, 0.5672, 0.511, 0.3906, 0.551, 0.4846]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_num_images_per_prompt(self): @@ -271,9 +271,9 @@ def test_stable_diffusion_pix2pix_default(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5902, 0.6015, 0.6027, 0.5983, 0.6092, 0.6061, 0.5765, 0.5785, 0.5555]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_k_lms(self): @@ -291,9 +291,9 @@ def test_stable_diffusion_pix2pix_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.6578, 0.6817, 0.6972, 0.6761, 0.6856, 0.6916, 0.6428, 0.6516, 0.6301]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_ddim(self): @@ -311,9 +311,9 @@ def test_stable_diffusion_pix2pix_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3828, 0.3834, 0.3818, 0.3792, 0.3865, 0.3752, 0.3792, 0.3847, 0.3753]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_intermediate_state(self): @@ -328,18 +328,18 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False @@ -397,7 +397,7 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): assert image.shape == (504, 504, 3) expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 86d1ba1137ab..15921d5a84f8 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -53,9 +53,9 @@ def test_stable_diffusion_1(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_2(self): @@ -77,7 +77,7 @@ def test_stable_diffusion_2(self): expected_slice = np.array( [0.826810, 0.81958747, 0.8510199, 0.8376758, 0.83958465, 0.8682068, 0.84370345, 0.85251087, 0.85884345] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 8ec6a9c345af..7e72f273ced4 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -133,9 +133,9 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5649, 0.6022, 0.4804, 0.5270, 0.5585, 0.4643, 0.5159, 0.4963, 0.4793]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): @@ -152,9 +152,9 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5099, 0.5677, 0.4671, 0.5128, 0.5697, 0.4676, 0.5277, 0.4964, 0.4946]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_lms(self): @@ -171,9 +171,9 @@ def test_stable_diffusion_k_lms(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): @@ -190,9 +190,9 @@ def test_stable_diffusion_k_euler_ancestral(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4715, 0.5376, 0.4569, 0.5224, 0.5734, 0.4797, 0.5465, 0.5074, 0.5046]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): @@ -209,9 +209,9 @@ def test_stable_diffusion_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_long_prompt(self): @@ -358,9 +358,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() @@ -369,9 +369,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False 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 1da4003707ad..be3771b8002e 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -289,9 +289,9 @@ def test_stable_diffusion_depth2img_default_case(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_negative_prompt(self): @@ -312,9 +312,9 @@ def test_stable_diffusion_depth2img_negative_prompt(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_multiple_init_images(self): @@ -336,9 +336,9 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_num_images_per_prompt(self): @@ -393,9 +393,9 @@ def test_stable_diffusion_depth2img_pil(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -437,9 +437,9 @@ def test_stable_diffusion_depth2img_pipeline_default(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_k_lms(self): @@ -457,9 +457,9 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self): assert image.shape == (1, 480, 640, 3) expected_slice = np.array([0.6363, 0.6274, 0.6309, 0.6370, 0.6226, 0.6286, 0.6213, 0.6453, 0.6306]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_ddim(self): @@ -477,9 +477,9 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): 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]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_intermediate_state(self): @@ -496,9 +496,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.7168, -1.5137, -0.1418, -2.9219, -2.7266, -2.4414, -2.1035, -3.0078, -1.7051] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() @@ -507,9 +507,9 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 a9764a5886b8..1c9dd0befcc2 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -125,9 +125,9 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4727, 0.5735, 0.3941, 0.5446, 0.5926, 0.4394, 0.5062, 0.4654, 0.4476]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 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 f652c4bf6cac..bf29577bc565 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -156,9 +156,9 @@ def test_stable_diffusion_upscale(self): assert image.shape == (1, expected_height_width, expected_height_width, 3) expected_slice = np.array([0.2562, 0.3606, 0.4204, 0.4469, 0.4822, 0.4647, 0.5315, 0.5748, 0.5606]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 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 17c1a0c78ab3..47fed4c70f60 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 @@ -146,9 +146,9 @@ def test_stable_diffusion_v_pred_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.6424, 0.6109, 0.494, 0.5088, 0.4984, 0.4525, 0.5059, 0.5068, 0.4474]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -197,9 +197,9 @@ def test_stable_diffusion_v_pred_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4616, 0.5184, 0.4887, 0.5111, 0.4839, 0.48, 0.5119, 0.5263, 0.4776]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -269,9 +269,9 @@ def test_stable_diffusion_v_pred_default(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.1868, 0.1922, 0.1527, 0.1921, 0.1908, 0.1624, 0.1779, 0.1652, 0.1734]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_upcast_attention(self): @@ -291,9 +291,9 @@ def test_stable_diffusion_v_pred_upcast_attention(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.4209, 0.4087, 0.4097, 0.4209, 0.3860, 0.4329, 0.4280, 0.4324, 0.4187]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_euler(self): @@ -313,9 +313,9 @@ def test_stable_diffusion_v_pred_euler(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.1781, 0.1695, 0.1661, 0.1705, 0.1588, 0.1699, 0.2005, 0.1589, 0.1677]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_dpm(self): @@ -339,9 +339,9 @@ def test_stable_diffusion_v_pred_dpm(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.3303, 0.3184, 0.3291, 0.3300, 0.3256, 0.3113, 0.2965, 0.3134, 0.3192]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_attention_slicing_v_pred(self): @@ -428,18 +428,18 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(latents_slice) + assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index 2e5ce42646a5..0f920ada182f 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -156,9 +156,9 @@ def test_safe_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5644, 0.6018, 0.4799, 0.5267, 0.5585, 0.4641, 0.516, 0.4964, 0.4792]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -204,9 +204,9 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5095, 0.5674, 0.4668, 0.5126, 0.5697, 0.4675, 0.5278, 0.4964, 0.4945]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -306,9 +306,9 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2278, 0.2231, 0.2249, 0.2333, 0.2303, 0.1885, 0.2273, 0.2144, 0.2176] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 # without safety guidance (strong configuration) @@ -333,9 +333,9 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2383, 0.2276, 0.236, 0.2192, 0.2186, 0.2053, 0.1971, 0.1901, 0.1719] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safe_stable_diffusion(self): @@ -365,9 +365,9 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.3502, 0.3622, 0.3396, 0.3642, 0.3478, 0.3318, 0.35, 0.3348, 0.3297] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 generator = torch.manual_seed(seed) @@ -391,9 +391,9 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.5531, 0.5206, 0.4895, 0.5156, 0.5182, 0.4751, 0.4802, 0.4803, 0.4443] assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safetychecker_safe_stable_diffusion(self): @@ -425,9 +425,9 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): expected_slice = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 generator = torch.manual_seed(seed) @@ -450,7 +450,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): image_slice = image[0, -3:, -3:, -1] expected_slice = np.array([0.5818, 0.6285, 0.6835, 0.6019, 0.625, 0.6754, 0.6096, 0.6334, 0.6561]) assert image.shape == (1, 512, 512, 3) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 9342b67477f0..8615a30a4eba 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -259,9 +259,9 @@ def test_unclip(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/unclip/test_unclip_image_variation.py b/tests/pipelines/unclip/test_unclip_image_variation.py index f4166b30309c..1914ba286d3c 100644 --- a/tests/pipelines/unclip/test_unclip_image_variation.py +++ b/tests/pipelines/unclip/test_unclip_image_variation.py @@ -275,9 +275,9 @@ def test_unclip_image_variation_input_tensor(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -310,9 +310,9 @@ def test_unclip_image_variation_input_image(self): expected_slice = np.array([0.9997, 0.0003, 0.9997, 0.9997, 0.9970, 0.0024, 0.9997, 0.9971, 0.9971]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -365,9 +365,9 @@ def test_unclip_image_variation_input_list_images(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -421,9 +421,9 @@ def test_unclip_image_variation_input_num_images_per_prompt(self): ] ) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index 8478b993e8d3..f868e0a1d76e 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -107,7 +107,7 @@ def test_inference_dual_guided(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index caf0dd7cdde3..f85f049ce8e7 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -53,7 +53,7 @@ def test_inference_image_variations(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0441, 0.0469, 0.0507, 0.0575, 0.0632, 0.0650, 0.0865, 0.0909, 0.0945]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 1e269c72d10b..a9d2f271e5fd 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -103,9 +103,9 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " @@ -118,9 +118,9 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images @@ -129,7 +129,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index f8c00c29ea93..5601baaec00e 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -81,7 +81,7 @@ def test_inference_text2img(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3493, 0.3757, 0.4093, 0.4495, 0.4233, 0.4102, 0.4507, 0.4756, 0.4787]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index ad7e5b2f8a00..d83873684922 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -145,9 +145,9 @@ def test_vq_diffusion(self): expected_slice = np.array([0.6583, 0.6410, 0.5325, 0.5635, 0.5563, 0.4234, 0.6008, 0.5491, 0.4880]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -192,9 +192,9 @@ def test_vq_diffusion_classifier_free_sampling(self): expected_slice = np.array([0.6647, 0.6531, 0.5303, 0.5891, 0.5726, 0.4439, 0.6304, 0.5564, 0.4912]) - from diffusers.utils.testing_utils import print_tensor_test + - print_tensor_test(image_slice) + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 From ab440a64a86cb6de6961841222842b52a3143692 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 07:46:26 +0000 Subject: [PATCH 31/39] up --- .../altdiffusion/test_alt_diffusion.py | 9 -------- .../test_alt_diffusion_img2img.py | 4 ---- .../audio_diffusion/test_audio_diffusion.py | 8 ------- .../dance_diffusion/test_dance_diffusion.py | 4 ---- tests/pipelines/ddim/test_ddim.py | 4 ---- tests/pipelines/ddpm/test_ddpm.py | 4 ---- tests/pipelines/karras_ve/test_karras_ve.py | 4 ---- .../latent_diffusion/test_latent_diffusion.py | 3 --- .../test_latent_diffusion_superresolution.py | 4 ---- .../test_latent_diffusion_uncond.py | 4 ---- .../paint_by_example/test_paint_by_example.py | 5 ----- tests/pipelines/pndm/test_pndm.py | 4 ---- tests/pipelines/repaint/test_repaint.py | 2 -- .../score_sde_ve/test_score_sde_ve.py | 4 ---- .../stable_diffusion/test_cycle_diffusion.py | 6 ----- .../test_onnx_stable_diffusion.py | 22 ------------------- .../test_onnx_stable_diffusion_img2img.py | 14 ------------ .../test_onnx_stable_diffusion_inpaint.py | 4 ---- .../stable_diffusion/test_stable_diffusion.py | 20 ----------------- .../test_stable_diffusion_image_variation.py | 8 ------- .../test_stable_diffusion_img2img.py | 20 ----------------- .../test_stable_diffusion_inpaint.py | 10 --------- .../test_stable_diffusion_inpaint_legacy.py | 12 ---------- ...st_stable_diffusion_instruction_pix2pix.py | 20 ----------------- .../test_stable_diffusion_k_diffusion.py | 4 ---- .../test_stable_diffusion.py | 15 ------------- .../test_stable_diffusion_depth.py | 18 --------------- .../test_stable_diffusion_inpaint.py | 3 --- .../test_stable_diffusion_upscale.py | 3 --- .../test_stable_diffusion_v_pred.py | 17 -------------- .../test_safe_diffusion.py | 17 -------------- tests/pipelines/unclip/test_unclip.py | 3 --- .../unclip/test_unclip_image_variation.py | 12 ---------- .../test_versatile_diffusion_dual_guided.py | 2 -- ...est_versatile_diffusion_image_variation.py | 2 -- .../test_versatile_diffusion_mega.py | 6 ----- .../test_versatile_diffusion_text_to_image.py | 2 -- .../vq_diffusion/test_vq_diffusion.py | 6 ----- 38 files changed, 309 deletions(-) diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion.py b/tests/pipelines/altdiffusion/test_alt_diffusion.py index eb0f07203363..c4ea6dd1a33b 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion.py @@ -155,9 +155,6 @@ def test_alt_diffusion_ddim(self): [0.5748162, 0.60447145, 0.48821217, 0.50100636, 0.5431185, 0.45763683, 0.49657696, 0.48132733, 0.47573093] ) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_pndm(self): @@ -191,9 +188,7 @@ def test_alt_diffusion_pndm(self): expected_slice = np.array( [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @@ -222,9 +217,7 @@ def test_alt_diffusion(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_alt_diffusion_fast_ddim(self): @@ -244,7 +237,5 @@ def test_alt_diffusion_fast_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py index 40c74d291c8c..baf86d07eab2 100644 --- a/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py +++ b/tests/pipelines/altdiffusion/test_alt_diffusion_img2img.py @@ -162,9 +162,7 @@ def test_stable_diffusion_img2img_default_case(self): expected_slice = np.array( [0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448] ) - - 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 @@ -245,9 +243,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): 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]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/audio_diffusion/test_audio_diffusion.py b/tests/pipelines/audio_diffusion/test_audio_diffusion.py index d55a20f2c3de..dc706d868a07 100644 --- a/tests/pipelines/audio_diffusion/test_audio_diffusion.py +++ b/tests/pipelines/audio_diffusion/test_audio_diffusion.py @@ -119,9 +119,7 @@ def test_audio_diffusion(self): image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_from_tuple_slice = np.frombuffer(image_from_tuple.tobytes(), dtype="uint8")[:10] expected_slice = np.array([255, 255, 255, 0, 181, 0, 124, 0, 15, 255]) - - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0 @@ -145,9 +143,7 @@ def test_audio_diffusion(self): ) image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]) - - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 dummy_unet_condition = self.dummy_unet_condition @@ -161,9 +157,7 @@ def test_audio_diffusion(self): image = output.images[0] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([120, 139, 147, 123, 124, 96, 115, 121, 126, 144]) - - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 @@ -192,7 +186,5 @@ def test_audio_diffusion(self): assert image.height == pipe.unet.sample_size[0] and image.width == pipe.unet.sample_size[1] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]) - - assert np.abs(image_slice.flatten() - expected_slice).max() == 0 diff --git a/tests/pipelines/dance_diffusion/test_dance_diffusion.py b/tests/pipelines/dance_diffusion/test_dance_diffusion.py index 1e2366d7a254..08ca2e0bee30 100644 --- a/tests/pipelines/dance_diffusion/test_dance_diffusion.py +++ b/tests/pipelines/dance_diffusion/test_dance_diffusion.py @@ -112,9 +112,7 @@ def test_dance_diffusion(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]) - - assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 def test_dance_diffusion_fp16(self): @@ -132,7 +130,5 @@ def test_dance_diffusion_fp16(self): assert audio.shape == (1, 2, pipe.unet.sample_size) expected_slice = np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341]) - - assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index 1bddc5045328..5eb969840e00 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -99,9 +99,7 @@ def test_inference_ema_bedroom(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_cifar10(self): @@ -121,7 +119,5 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.2060, 0.2042, 0.2022, 0.2193, 0.2146, 0.2110, 0.2471, 0.2446, 0.2388]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index d18931c5cb01..4b6b7a558dad 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -63,9 +63,7 @@ def test_inference(self): expected_slice = np.array( [5.589e-01, 7.089e-01, 2.632e-01, 6.841e-01, 1.000e-04, 9.999e-01, 1.973e-01, 1.000e-04, 8.010e-02] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -141,7 +139,5 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4454, 0.2025, 0.0315, 0.3023, 0.2575, 0.1031, 0.0953, 0.1604, 0.2020]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/karras_ve/test_karras_ve.py b/tests/pipelines/karras_ve/test_karras_ve.py index 70da97446f9a..79fa503e6dcd 100644 --- a/tests/pipelines/karras_ve/test_karras_ve.py +++ b/tests/pipelines/karras_ve/test_karras_ve.py @@ -59,9 +59,7 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -84,7 +82,5 @@ def test_inference(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion.py b/tests/pipelines/latent_diffusion/test_latent_diffusion.py index 14455c7516ed..244987f89819 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion.py @@ -114,9 +114,6 @@ def test_inference_text2img(self): assert image.shape == (1, 16, 16, 3) expected_slice = np.array([0.59450, 0.64078, 0.55509, 0.51229, 0.69640, 0.36960, 0.59296, 0.60801, 0.49332]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py index 69457ae58df7..b7c54f01923e 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_superresolution.py @@ -83,9 +83,7 @@ def test_inference_superresolution(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -130,7 +128,5 @@ def test_inference_superresolution(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py index 056594a6b854..4f519f842b6d 100644 --- a/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py +++ b/tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py @@ -96,9 +96,7 @@ def test_inference_uncond(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - - assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance @@ -119,7 +117,5 @@ def test_inference_uncond(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447]) tolerance = 1e-2 if torch_device != "mps" else 3e-2 - - assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance diff --git a/tests/pipelines/paint_by_example/test_paint_by_example.py b/tests/pipelines/paint_by_example/test_paint_by_example.py index 2f414b41ed48..d02b7702d9e1 100644 --- a/tests/pipelines/paint_by_example/test_paint_by_example.py +++ b/tests/pipelines/paint_by_example/test_paint_by_example.py @@ -134,9 +134,6 @@ def test_paint_by_example_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4701, 0.5555, 0.3994, 0.5107, 0.5691, 0.4517, 0.5125, 0.4769, 0.4539]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_paint_by_example_image_tensor(self): @@ -225,7 +222,5 @@ def test_paint_by_example(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4834, 0.4811, 0.4874, 0.5122, 0.5081, 0.5144, 0.5291, 0.5290, 0.5374]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/pndm/test_pndm.py b/tests/pipelines/pndm/test_pndm.py index 1d72e5013605..46452c4eab90 100644 --- a/tests/pipelines/pndm/test_pndm.py +++ b/tests/pipelines/pndm/test_pndm.py @@ -59,9 +59,7 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -85,7 +83,5 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/repaint/test_repaint.py b/tests/pipelines/repaint/test_repaint.py index b046312396af..f1beea00a01d 100644 --- a/tests/pipelines/repaint/test_repaint.py +++ b/tests/pipelines/repaint/test_repaint.py @@ -81,9 +81,7 @@ def test_repaint(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([1.0000, 0.5426, 0.5497, 0.2200, 1.0000, 1.0000, 0.5623, 1.0000, 0.6274]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/score_sde_ve/test_score_sde_ve.py b/tests/pipelines/score_sde_ve/test_score_sde_ve.py index 5b10d0037ae9..5e30fae2ec8d 100644 --- a/tests/pipelines/score_sde_ve/test_score_sde_ve.py +++ b/tests/pipelines/score_sde_ve/test_score_sde_ve.py @@ -61,9 +61,7 @@ def test_inference(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -89,7 +87,5 @@ def test_inference(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py index 83374bca36e9..5c088f191773 100644 --- a/tests/pipelines/stable_diffusion/test_cycle_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_cycle_diffusion.py @@ -126,9 +126,6 @@ def test_stable_diffusion_cycle(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.4459, 0.4943, 0.4544, 0.6643, 0.5474, 0.4327, 0.5701, 0.5959, 0.5179]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @@ -150,9 +147,6 @@ def test_stable_diffusion_cycle_fp16(self): assert images.shape == (1, 32, 32, 3) expected_slice = np.array([0.3506, 0.4543, 0.446, 0.4575, 0.5195, 0.4155, 0.5273, 0.518, 0.4116]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py index 22d009d5bfcb..00f6fd02a77e 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py @@ -60,9 +60,7 @@ def test_pipeline_default_ddim(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65072, 0.58492, 0.48219, 0.55521, 0.53180, 0.55939, 0.50697, 0.39800, 0.46455]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_pndm(self): @@ -76,9 +74,7 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65863, 0.59425, 0.49326, 0.56313, 0.53875, 0.56627, 0.51065, 0.39777, 0.46330]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_lms(self): @@ -92,9 +88,7 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler(self): @@ -108,9 +102,7 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_euler_ancestral(self): @@ -124,9 +116,7 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53817, 0.60812, 0.47384, 0.49530, 0.51894, 0.49814, 0.47984, 0.38958, 0.44271]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_pipeline_dpm_multistep(self): @@ -140,9 +130,7 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.53895, 0.60808, 0.47933, 0.49608, 0.51886, 0.49950, 0.48053, 0.38957, 0.44200]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 @@ -187,9 +175,7 @@ def test_inference_default_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_ddim(self): @@ -215,9 +201,7 @@ def test_inference_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): @@ -243,9 +227,7 @@ def test_inference_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_intermediate_state(self): @@ -261,9 +243,7 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 5: assert latents.shape == (1, 4, 64, 64) @@ -271,9 +251,7 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None: expected_slice = np.array( [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 test_callback_fn.has_been_called = False 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 42e87c537373..80bebf81ae39 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py @@ -82,9 +82,7 @@ def test_pipeline_pndm(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.61710, 0.53390, 0.49310, 0.55622, 0.50982, 0.58240, 0.50716, 0.38629, 0.46856]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_lms(self): @@ -101,9 +99,7 @@ def test_pipeline_lms(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52761, 0.59977, 0.49033, 0.49619, 0.54282, 0.50311, 0.47600, 0.40918, 0.45203]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler(self): @@ -117,9 +113,7 @@ def test_pipeline_euler(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_euler_ancestral(self): @@ -133,9 +127,7 @@ def test_pipeline_euler_ancestral(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.52911, 0.60004, 0.49229, 0.49805, 0.54502, 0.50680, 0.47777, 0.41028, 0.45304]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 def test_pipeline_dpm_multistep(self): @@ -149,9 +141,7 @@ def test_pipeline_dpm_multistep(self): assert image.shape == (1, 128, 128, 3) expected_slice = np.array([0.65331, 0.58277, 0.48204, 0.56059, 0.53665, 0.56235, 0.50969, 0.40009, 0.46552]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 @@ -210,9 +200,7 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.4909, 0.5059, 0.5372, 0.4623, 0.4876, 0.5049, 0.4820, 0.4956, 0.5019]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - - assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 def test_inference_k_lms(self): @@ -253,7 +241,5 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 768, 3) expected_slice = np.array([0.8043, 0.926, 0.9581, 0.8119, 0.8954, 0.913, 0.7209, 0.7463, 0.7431]) # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues - - assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2 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 84c0847b853b..df8724c0faa0 100644 --- a/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py @@ -94,9 +94,7 @@ def test_inference_default_pndm(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.2514, 0.3007, 0.3517, 0.1790, 0.2382, 0.3167, 0.1944, 0.2273, 0.2464]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_inference_k_lms(self): @@ -139,7 +137,5 @@ def test_inference_k_lms(self): assert images.shape == (1, 512, 512, 3) expected_slice = np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 2ceb4b289a10..101ddab02ad3 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -132,9 +132,6 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5643, 0.6017, 0.4799, 0.5267, 0.5584, 0.4641, 0.5159, 0.4963, 0.4791]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_ddim_factor_8(self): @@ -154,9 +151,6 @@ def test_stable_diffusion_ddim_factor_8(self): assert image.shape == (1, 136, 136, 3) expected_slice = np.array([0.5524, 0.5626, 0.6069, 0.4727, 0.386, 0.3995, 0.4613, 0.4328, 0.4269]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): @@ -174,9 +168,7 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5094, 0.5674, 0.4667, 0.5125, 0.5696, 0.4674, 0.5277, 0.4964, 0.4945]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_no_safety_checker(self): @@ -228,9 +220,7 @@ def test_stable_diffusion_k_lms(self): 0.5042197108268738, ] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): @@ -261,9 +251,7 @@ def test_stable_diffusion_k_euler_ancestral(self): 0.504422664642334, ] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): @@ -294,9 +282,7 @@ def test_stable_diffusion_k_euler(self): 0.5042197108268738, ] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_vae_slicing(self): @@ -351,9 +337,7 @@ def test_stable_diffusion_negative_prompt(self): 0.4899061322212219, ] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_num_images_per_prompt(self): @@ -638,9 +622,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() @@ -649,9 +631,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index 4fb9a17a1cfc..db2b98da772f 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -117,9 +117,7 @@ def test_stable_diffusion_img_variation_default_case(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5167, 0.5746, 0.4835, 0.4914, 0.5605, 0.4691, 0.5201, 0.4898, 0.4958]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_multiple_images(self): @@ -139,9 +137,7 @@ def test_stable_diffusion_img_variation_multiple_images(self): assert image.shape == (2, 64, 64, 3) expected_slice = np.array([0.6568, 0.5470, 0.5684, 0.5444, 0.5945, 0.6221, 0.5508, 0.5531, 0.5263]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img_variation_num_images_per_prompt(self): @@ -236,18 +232,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.6299, 1.7500, 1.1992, -2.1582, -1.8994, 0.7334, -0.7090, 1.0137, 1.5273]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 96086c963d6d..586d7409beaa 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -119,9 +119,7 @@ def test_stable_diffusion_img2img_default_case(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4492, 0.3865, 0.4222, 0.5854, 0.5139, 0.4379, 0.4193, 0.48, 0.4218]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_negative_prompt(self): @@ -139,9 +137,7 @@ def test_stable_diffusion_img2img_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4065, 0.3783, 0.4050, 0.5266, 0.4781, 0.4252, 0.4203, 0.4692, 0.4365]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_multiple_init_images(self): @@ -159,9 +155,7 @@ def test_stable_diffusion_img2img_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.5144, 0.4447, 0.4735, 0.6676, 0.5526, 0.5454, 0.645, 0.5149, 0.4689]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): @@ -180,9 +174,7 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4367, 0.4986, 0.4372, 0.6706, 0.5665, 0.444, 0.5864, 0.6019, 0.5203]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_img2img_num_images_per_prompt(self): @@ -259,9 +251,7 @@ def test_stable_diffusion_img2img_default(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.4300, 0.4662, 0.4930, 0.3990, 0.4307, 0.4525, 0.3719, 0.4064, 0.3923]) - - assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_k_lms(self): @@ -277,9 +267,7 @@ def test_stable_diffusion_img2img_k_lms(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.0389, 0.0346, 0.0415, 0.0290, 0.0218, 0.0210, 0.0408, 0.0567, 0.0271]) - - assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_ddim(self): @@ -295,9 +283,7 @@ def test_stable_diffusion_img2img_ddim(self): assert image.shape == (1, 512, 768, 3) expected_slice = np.array([0.0593, 0.0607, 0.0851, 0.0582, 0.0636, 0.0721, 0.0751, 0.0981, 0.0781]) - - assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_img2img_intermediate_state(self): @@ -312,18 +298,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False @@ -394,9 +376,7 @@ def test_stable_diffusion_img2img_pipeline_multiple_of_8(self): assert image.shape == (504, 760, 3) expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index 2581fcdac542..df5a079ea998 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -125,9 +125,7 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4723, 0.5731, 0.3939, 0.5441, 0.5922, 0.4392, 0.5059, 0.4651, 0.4474]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_image_tensor(self): @@ -210,9 +208,7 @@ def test_stable_diffusion_inpaint_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0427, 0.0460, 0.0483, 0.0460, 0.0584, 0.0521, 0.1549, 0.1695, 0.1794]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_fp16(self): @@ -229,9 +225,7 @@ def test_stable_diffusion_inpaint_fp16(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1443, 0.1218, 0.1587, 0.1594, 0.1411, 0.1284, 0.1370, 0.1506, 0.2339]) - - assert np.abs(expected_slice - image_slice).max() < 1e-2 def test_stable_diffusion_inpaint_pndm(self): @@ -249,9 +243,7 @@ def test_stable_diffusion_inpaint_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0425, 0.0273, 0.0344, 0.1694, 0.1727, 0.1812, 0.3256, 0.3311, 0.3272]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_k_lms(self): @@ -269,9 +261,7 @@ def test_stable_diffusion_inpaint_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.9314, 0.7575, 0.9432, 0.8885, 0.9028, 0.7298, 0.9811, 0.9667, 0.7633]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_with_sequential_cpu_offloading(self): diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py index fb41dc7b193f..09fc03135265 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py @@ -213,9 +213,7 @@ def test_stable_diffusion_inpaint_legacy(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4731, 0.5346, 0.4531, 0.6251, 0.5446, 0.4057, 0.5527, 0.5896, 0.5153]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -263,9 +261,7 @@ def test_stable_diffusion_inpaint_legacy_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.4765, 0.5339, 0.4541, 0.6240, 0.5439, 0.4055, 0.5503, 0.5891, 0.5150]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_inpaint_legacy_num_images_per_prompt(self): @@ -389,9 +385,7 @@ def test_stable_diffusion_inpaint_legacy_pndm(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5669, 0.6124, 0.6431, 0.4073, 0.4614, 0.5670, 0.1609, 0.3128, 0.4330]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_k_lms(self): @@ -409,9 +403,7 @@ def test_stable_diffusion_inpaint_legacy_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.4533, 0.4465, 0.4327, 0.4329, 0.4339, 0.4219, 0.4243, 0.4332, 0.4426]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_inpaint_legacy_intermediate_state(self): @@ -426,18 +418,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.5977, 1.5449, 1.0586, -0.3250, 0.7383, -0.0862, 0.4631, -0.2571, -1.1289]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.5190, 1.1621, 0.6885, 0.2424, 0.3337, -0.1617, 0.6914, -0.1957, -0.5474]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 2ae087b9e7a0..aefbaf08e191 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -122,9 +122,7 @@ def test_stable_diffusion_pix2pix_default_case(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7318, 0.3723, 0.4662, 0.623, 0.5770, 0.5014, 0.4281, 0.5550, 0.4813]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_negative_prompt(self): @@ -142,9 +140,7 @@ def test_stable_diffusion_pix2pix_negative_prompt(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.7323, 0.3688, 0.4611, 0.6255, 0.5746, 0.5017, 0.433, 0.5553, 0.4827]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_multiple_init_images(self): @@ -167,9 +163,7 @@ def test_stable_diffusion_pix2pix_multiple_init_images(self): assert image.shape == (2, 32, 32, 3) expected_slice = np.array([0.606, 0.5712, 0.5099, 0.598, 0.5805, 0.7205, 0.6793, 0.554, 0.5607]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_euler(self): @@ -191,9 +185,7 @@ def test_stable_diffusion_pix2pix_euler(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.726, 0.3902, 0.4868, 0.585, 0.5672, 0.511, 0.3906, 0.551, 0.4846]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_num_images_per_prompt(self): @@ -271,9 +263,7 @@ def test_stable_diffusion_pix2pix_default(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.5902, 0.6015, 0.6027, 0.5983, 0.6092, 0.6061, 0.5765, 0.5785, 0.5555]) - - assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_k_lms(self): @@ -291,9 +281,7 @@ def test_stable_diffusion_pix2pix_k_lms(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.6578, 0.6817, 0.6972, 0.6761, 0.6856, 0.6916, 0.6428, 0.6516, 0.6301]) - - assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_ddim(self): @@ -311,9 +299,7 @@ def test_stable_diffusion_pix2pix_ddim(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3828, 0.3834, 0.3818, 0.3792, 0.3865, 0.3752, 0.3792, 0.3847, 0.3753]) - - assert np.abs(expected_slice - image_slice).max() < 1e-3 def test_stable_diffusion_pix2pix_intermediate_state(self): @@ -328,18 +314,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False @@ -397,7 +379,5 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): assert image.shape == (504, 504, 3) expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 15921d5a84f8..9a31d3d7041c 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -53,9 +53,7 @@ def test_stable_diffusion_1(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_2(self): @@ -77,7 +75,5 @@ def test_stable_diffusion_2(self): expected_slice = np.array( [0.826810, 0.81958747, 0.8510199, 0.8376758, 0.83958465, 0.8682068, 0.84370345, 0.85251087, 0.85884345] ) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 7e72f273ced4..18242a987507 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -133,9 +133,6 @@ def test_stable_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5649, 0.6022, 0.4804, 0.5270, 0.5585, 0.4643, 0.5159, 0.4963, 0.4793]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_pndm(self): @@ -152,9 +149,7 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5099, 0.5677, 0.4671, 0.5128, 0.5697, 0.4676, 0.5277, 0.4964, 0.4946]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_lms(self): @@ -171,9 +166,7 @@ def test_stable_diffusion_k_lms(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler_ancestral(self): @@ -190,9 +183,7 @@ def test_stable_diffusion_k_euler_ancestral(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4715, 0.5376, 0.4569, 0.5224, 0.5734, 0.4797, 0.5465, 0.5074, 0.5046]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_k_euler(self): @@ -209,9 +200,7 @@ def test_stable_diffusion_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4717, 0.5376, 0.4568, 0.5225, 0.5734, 0.4797, 0.5467, 0.5074, 0.5043]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_long_prompt(self): @@ -358,9 +347,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 2: latents = latents.detach().cpu().numpy() @@ -369,9 +356,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 callback_fn.has_been_called = False 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 be3771b8002e..4cb9a72934cf 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -289,9 +289,7 @@ def test_stable_diffusion_depth2img_default_case(self): 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]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_negative_prompt(self): @@ -312,9 +310,7 @@ def test_stable_diffusion_depth2img_negative_prompt(self): 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]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_multiple_init_images(self): @@ -336,9 +332,7 @@ def test_stable_diffusion_depth2img_multiple_init_images(self): 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]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 def test_stable_diffusion_depth2img_num_images_per_prompt(self): @@ -393,9 +387,7 @@ def test_stable_diffusion_depth2img_pil(self): 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]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 @@ -437,9 +429,7 @@ def test_stable_diffusion_depth2img_pipeline_default(self): 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]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_k_lms(self): @@ -457,9 +447,7 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self): assert image.shape == (1, 480, 640, 3) expected_slice = np.array([0.6363, 0.6274, 0.6309, 0.6370, 0.6226, 0.6286, 0.6213, 0.6453, 0.6306]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_pipeline_ddim(self): @@ -477,9 +465,7 @@ def test_stable_diffusion_depth2img_pipeline_ddim(self): 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]) - - assert np.abs(expected_slice - image_slice).max() < 1e-4 def test_stable_diffusion_depth2img_intermediate_state(self): @@ -496,9 +482,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: 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() < 1e-3 elif step == 2: latents = latents.detach().cpu().numpy() @@ -507,9 +491,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: expected_slice = np.array( [-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090] ) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 callback_fn.has_been_called = False 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 1c9dd0befcc2..096c083bef6c 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_inpaint.py @@ -125,9 +125,6 @@ def test_stable_diffusion_inpaint(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4727, 0.5735, 0.3941, 0.5446, 0.5926, 0.4394, 0.5062, 0.4654, 0.4476]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 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 bf29577bc565..9e70f1e55c4a 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_upscale.py @@ -156,9 +156,6 @@ def test_stable_diffusion_upscale(self): assert image.shape == (1, expected_height_width, expected_height_width, 3) expected_slice = np.array([0.2562, 0.3606, 0.4204, 0.4469, 0.4822, 0.4647, 0.5315, 0.5748, 0.5606]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 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 47fed4c70f60..805a41083207 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 @@ -146,9 +146,6 @@ def test_stable_diffusion_v_pred_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.6424, 0.6109, 0.494, 0.5088, 0.4984, 0.4525, 0.5059, 0.5068, 0.4474]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -197,9 +194,7 @@ def test_stable_diffusion_v_pred_k_euler(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.4616, 0.5184, 0.4887, 0.5111, 0.4839, 0.48, 0.5119, 0.5263, 0.4776]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -269,9 +264,7 @@ def test_stable_diffusion_v_pred_default(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.1868, 0.1922, 0.1527, 0.1921, 0.1908, 0.1624, 0.1779, 0.1652, 0.1734]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_upcast_attention(self): @@ -291,9 +284,7 @@ def test_stable_diffusion_v_pred_upcast_attention(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.4209, 0.4087, 0.4097, 0.4209, 0.3860, 0.4329, 0.4280, 0.4324, 0.4187]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_euler(self): @@ -313,9 +304,7 @@ def test_stable_diffusion_v_pred_euler(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.1781, 0.1695, 0.1661, 0.1705, 0.1588, 0.1699, 0.2005, 0.1589, 0.1677]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_v_pred_dpm(self): @@ -339,9 +328,7 @@ def test_stable_diffusion_v_pred_dpm(self): image_slice = image[0, 253:256, 253:256, -1] assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.3303, 0.3184, 0.3291, 0.3300, 0.3256, 0.3113, 0.2965, 0.3134, 0.3192]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_stable_diffusion_attention_slicing_v_pred(self): @@ -428,18 +415,14 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) - - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py index 0f920ada182f..24e5d4e0e8b2 100644 --- a/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py +++ b/tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py @@ -156,9 +156,6 @@ def test_safe_diffusion_ddim(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5644, 0.6018, 0.4799, 0.5267, 0.5585, 0.4641, 0.516, 0.4964, 0.4792]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -204,9 +201,7 @@ def test_stable_diffusion_pndm(self): assert image.shape == (1, 64, 64, 3) expected_slice = np.array([0.5095, 0.5674, 0.4668, 0.5126, 0.5697, 0.4675, 0.5278, 0.4964, 0.4945]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -306,9 +301,7 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2278, 0.2231, 0.2249, 0.2333, 0.2303, 0.1885, 0.2273, 0.2144, 0.2176] assert image.shape == (1, 512, 512, 3) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 # without safety guidance (strong configuration) @@ -333,9 +326,7 @@ def test_harm_safe_stable_diffusion(self): expected_slice = [0.2383, 0.2276, 0.236, 0.2192, 0.2186, 0.2053, 0.1971, 0.1901, 0.1719] assert image.shape == (1, 512, 512, 3) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safe_stable_diffusion(self): @@ -365,9 +356,7 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.3502, 0.3622, 0.3396, 0.3642, 0.3478, 0.3318, 0.35, 0.3348, 0.3297] assert image.shape == (1, 512, 512, 3) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 generator = torch.manual_seed(seed) @@ -391,9 +380,7 @@ def test_nudity_safe_stable_diffusion(self): expected_slice = [0.5531, 0.5206, 0.4895, 0.5156, 0.5182, 0.4751, 0.4802, 0.4803, 0.4443] assert image.shape == (1, 512, 512, 3) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_nudity_safetychecker_safe_stable_diffusion(self): @@ -425,9 +412,7 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): expected_slice = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) assert image.shape == (1, 512, 512, 3) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-7 generator = torch.manual_seed(seed) @@ -450,7 +435,5 @@ def test_nudity_safetychecker_safe_stable_diffusion(self): image_slice = image[0, -3:, -3:, -1] expected_slice = np.array([0.5818, 0.6285, 0.6835, 0.6019, 0.625, 0.6754, 0.6096, 0.6334, 0.6561]) assert image.shape == (1, 512, 512, 3) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/unclip/test_unclip.py b/tests/pipelines/unclip/test_unclip.py index 8615a30a4eba..06ad4203f020 100644 --- a/tests/pipelines/unclip/test_unclip.py +++ b/tests/pipelines/unclip/test_unclip.py @@ -259,9 +259,6 @@ def test_unclip(self): ] ) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/unclip/test_unclip_image_variation.py b/tests/pipelines/unclip/test_unclip_image_variation.py index 1914ba286d3c..804ef7f7c387 100644 --- a/tests/pipelines/unclip/test_unclip_image_variation.py +++ b/tests/pipelines/unclip/test_unclip_image_variation.py @@ -275,9 +275,6 @@ def test_unclip_image_variation_input_tensor(self): ] ) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -310,9 +307,6 @@ def test_unclip_image_variation_input_image(self): expected_slice = np.array([0.9997, 0.0003, 0.9997, 0.9997, 0.9970, 0.0024, 0.9997, 0.9971, 0.9971]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -365,9 +359,6 @@ def test_unclip_image_variation_input_list_images(self): ] ) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -421,9 +412,6 @@ def test_unclip_image_variation_input_num_images_per_prompt(self): ] ) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py index f868e0a1d76e..82fd037cec73 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_dual_guided.py @@ -107,7 +107,5 @@ def test_inference_dual_guided(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py index f85f049ce8e7..a55184429681 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_image_variation.py @@ -53,7 +53,5 @@ def test_inference_image_variations(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.0441, 0.0469, 0.0507, 0.0575, 0.0632, 0.0650, 0.0865, 0.0909, 0.0945]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index a9d2f271e5fd..785ae3105b87 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -103,9 +103,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 prompt = "A painting of a squirrel eating a burger " @@ -118,9 +116,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images @@ -129,7 +125,5 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py index 5601baaec00e..9c4c2f2d993b 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_text_to_image.py @@ -81,7 +81,5 @@ def test_inference_text2img(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3493, 0.3757, 0.4093, 0.4495, 0.4233, 0.4102, 0.4507, 0.4756, 0.4787]) - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/vq_diffusion/test_vq_diffusion.py b/tests/pipelines/vq_diffusion/test_vq_diffusion.py index d83873684922..0176ec0b5880 100644 --- a/tests/pipelines/vq_diffusion/test_vq_diffusion.py +++ b/tests/pipelines/vq_diffusion/test_vq_diffusion.py @@ -145,9 +145,6 @@ def test_vq_diffusion(self): expected_slice = np.array([0.6583, 0.6410, 0.5325, 0.5635, 0.5563, 0.4234, 0.6008, 0.5491, 0.4880]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 @@ -192,9 +189,6 @@ def test_vq_diffusion_classifier_free_sampling(self): expected_slice = np.array([0.6647, 0.6531, 0.5303, 0.5891, 0.5726, 0.4439, 0.6304, 0.5564, 0.4912]) - - - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 From 3def1493091d549319431c58b56bc5a2a4f65bd4 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 09:13:35 +0000 Subject: [PATCH 32/39] up --- docs/source/en/conceptual/reproducibility.mdx | 159 ++++++++++++++++++ src/diffusers/pipelines/ddim/pipeline_ddim.py | 1 - src/diffusers/utils/torch_utils.py | 1 + tests/pipelines/dit/test_dit.py | 2 +- .../stable_diffusion/test_stable_diffusion.py | 4 +- .../test_stable_diffusion_image_variation.py | 2 +- .../test_stable_diffusion_img2img.py | 4 +- .../test_stable_diffusion_inpaint.py | 2 +- ...st_stable_diffusion_instruction_pix2pix.py | 4 +- .../test_stable_diffusion.py | 4 +- .../test_stable_diffusion_depth.py | 4 +- .../test_stable_diffusion_v_pred.py | 10 +- .../test_versatile_diffusion_mega.py | 6 +- 13 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 docs/source/en/conceptual/reproducibility.mdx diff --git a/docs/source/en/conceptual/reproducibility.mdx b/docs/source/en/conceptual/reproducibility.mdx new file mode 100644 index 000000000000..0af115b1687a --- /dev/null +++ b/docs/source/en/conceptual/reproducibility.mdx @@ -0,0 +1,159 @@ + + +# Reproducibility + +Before reading about reproducibility for Diffusers, it is strongly recommended to take a look at +[PyTorch's statement about reproducibility](https://pytorch.org/docs/stable/notes/randomness.html). + +PyTorch states that +> *completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms.* +While one can never expect the same results across platforms, one can expect results to be reproducible +across releases, platforms, etc... within a certain tolerance. However, this tolerance strongly varies +depending on the diffusion pipeline and checkpoint. + +In the following, we should how to best control sources of randomness for diffusion models. + +## Inference + +During inference, diffusion pipelines heavily rely on random sampling operations, such as the creating the +gaussian noise tensors to be denoised as well as adding noise to the scheduling step. + +Let's have a look at an example. We run the [DDIM pipeline](./api/pipelines/ddim.mdx) +for just two inference steps and return a numpy tensor to look into the numerical values of the output. + +```python +from diffusers import DDIMPipeline +import numpy as np + +model_id = "google/ddpm-cifar10-32" + +# load model and scheduler +ddim = DDIMPipeline.from_pretrained(model_id) + +# run pipeline for just two steps and return numpy tensor +image = ddim(num_inference_steps=2, output_type="np").images +print(np.abs(image).sum()) +``` + +Running the above prints a value of 1464.2076, but running it again prints a different +value of 1495.1768. What is going on here? Every time the pipeline is run, gaussian noise +is created and step-wise denoised. To create the gaussian noise with [`torch.randn`](https://pytorch.org/docs/stable/generated/torch.randn.html) a different random seed is taken every time, thus leading to a different result. +This is a desired property of diffusion pipelines as it means that the pipeline can create a different random image every time it is run. In many cases, one would like to generate the exact same image of a certain +run, for which case an instance of a [PyTorch generator](https://pytorch.org/docs/stable/generated/torch.randn.html) has to be passed: + +```python +import torch +from diffusers import DDIMPipeline +import numpy as np + +model_id = "google/ddpm-cifar10-32" + +# load model and scheduler +ddim = DDIMPipeline.from_pretrained(model_id) + +# create a generator for reproducibility +generator = torch.Generator(device="cpu").manual_seed(0) + +# run pipeline for just two steps and return numpy tensor +image = ddim(num_inference_steps=2, output_type="np", generator=generator).images +print(np.abs(image).sum()) +``` + +Running the above always prints a value of 1491.1711 - also upon running it again because we +define the generator object to be passed to all random functions of the pipeline. + +If you run this code snippet on your specific hardware and version, you should get a very similar, if not the same result. + + + +It might be a bit unintuitive at first to pass "generator" objects to the pipelines instead of +just integer values representing the seed, but this is the recommended design when dealing with +probabilistic models in PyTorch as generators are *random states* that are advanced and can thus be +passed to multiple pipelines in a sequence. + + + +Great! Now, we know how to write reproducible pipelines, but it does get a bit tricker since the above example only runs on CPU. How do we also achieve reproducibility on GPU? +In short, one should not expect to get full reproducibility across hardwares when running pipelines on GPU +as matrix multiplications are less deterministic on GPU than on CPU and diffusion pipelines tend to require +a lot of matrix multiplications. Let's see what we can do though to keep the randomness within limits across +different GPU hardware. + +To achieve maximum speed performance, it is recommended to create the generator directly on GPU when running +the pipeline on GPU: + +```python +import torch +from diffusers import DDIMPipeline +import numpy as np + +model_id = "google/ddpm-cifar10-32" + +# load model and scheduler +ddim = DDIMPipeline.from_pretrained(model_id) +ddim.to("cuda") + +# create a generator for reproducibility +generator = torch.Generator(device="cuda").manual_seed(0) + +# run pipeline for just two steps and return numpy tensor +image = ddim(num_inference_steps=2, output_type="np", generator=generator).images +print(np.abs(image).sum()) +``` + +Running the above now prints a value of 1389.8634 - even though we're using the exact same seed! +This is unfortunate as it means we cannot really reproduce results we achieved on GPU, also on CPU. +Nevertheless, it should be expected since the GPU uses a different random number generator than the CPU. + +To circumvent this problem, we created a [~`randn_tensor`] function which can create random noise +on CPU and then move the tensor to GPU if necessary. The function is used every where inside the pipelines allowing the user to **always** pass a CPU generator even if the pipeline is run on GPU: + +```python +import torch +from diffusers import DDIMPipeline +import numpy as np + +model_id = "google/ddpm-cifar10-32" + +# load model and scheduler +ddim = DDIMPipeline.from_pretrained(model_id) +ddim.to("cuda") + +# create a generator for reproducibility +generator = torch.manual_seed(0) + +# run pipeline for just two steps and return numpy tensor +image = ddim(num_inference_steps=2, output_type="np", generator=generator).images +print(np.abs(image).sum()) +``` + +Running the above now prints a value of 1491.1713, much closer to the value of 1491.1711 when +the pipeline is fully run on CPU. + + + +As a consequence, we recommend to always pass a CPU generator if Reproducibility is important. +The loss of performance is often neglectable, but one can be sure to generate much more similar +values than if the pipeline would have been run on CPU. + + + +Finally, we noticed that more complex pipelines, such as [`UnCLIPPipeline`] are often extremely +susceptible precision error propagation and thus one cannot expect even similar results across +different GPU hardware or PyTorch versions. In such cases, one simply has to make sure to run +exactly the same hardware and PyTorch version for full Reproducibility. + +## Randomness utilities + +### randn_tensor +[[autodoc]] diffusers.utils.randn_tensor diff --git a/src/diffusers/pipelines/ddim/pipeline_ddim.py b/src/diffusers/pipelines/ddim/pipeline_ddim.py index 46d088ad19a0..22e35573e42d 100644 --- a/src/diffusers/pipelines/ddim/pipeline_ddim.py +++ b/src/diffusers/pipelines/ddim/pipeline_ddim.py @@ -94,7 +94,6 @@ def __call__( "0.13.0", message, ) - generator = None # Sample gaussian noise to begin loop if isinstance(self.unet.sample_size, int): diff --git a/src/diffusers/utils/torch_utils.py b/src/diffusers/utils/torch_utils.py index 42d50c4b5ba7..be38b6089a20 100644 --- a/src/diffusers/utils/torch_utils.py +++ b/src/diffusers/utils/torch_utils.py @@ -65,6 +65,7 @@ def randn_tensor( ] latents = torch.cat(latents, dim=0).to(device) else: + print(rand_device) latents = torch.randn(shape, generator=generator, device=rand_device, dtype=dtype, layout=layout).to(device) return latents diff --git a/tests/pipelines/dit/test_dit.py b/tests/pipelines/dit/test_dit.py index be4b6b48d3ab..17fc3f526882 100644 --- a/tests/pipelines/dit/test_dit.py +++ b/tests/pipelines/dit/test_dit.py @@ -133,4 +133,4 @@ def test_dit_512_fp16(self): ), ) - assert np.abs((expected_image - image).max()) < 1e-2 + assert np.abs((expected_image - image).max()) < 5e-2 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 101ddab02ad3..0a5127cc49c3 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -623,7 +623,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [-0.5693, -0.3018, -0.9746, 0.0518, -0.8770, 0.7559, -1.7402, 0.1022, 1.1582] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) @@ -632,7 +632,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [-0.1958, -0.2993, -1.0166, -0.5005, -0.4810, 0.6162, -0.9492, 0.6621, 1.4492] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py index db2b98da772f..a8e8b6d36866 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py @@ -233,7 +233,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [-0.1621, 0.2837, -0.7979, -0.1221, -1.3057, 0.7681, -2.1191, 0.0464, 1.6309] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index 586d7409beaa..c6ba7532e80d 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -299,14 +299,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.4956, 0.5078, 1.0918, 2.7520, 4.6484, 3.8125, 1.5146, 1.8633, 2.6367]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py index df5a079ea998..ecf65e5a14ce 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py @@ -226,7 +226,7 @@ def test_stable_diffusion_inpaint_fp16(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1443, 0.1218, 0.1587, 0.1594, 0.1411, 0.1284, 0.1370, 0.1506, 0.2339]) - assert np.abs(expected_slice - image_slice).max() < 1e-2 + assert np.abs(expected_slice - image_slice).max() < 5e-2 def test_stable_diffusion_inpaint_pndm(self): pipe = StableDiffusionInpaintPipeline.from_pretrained( 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 aefbaf08e191..3319192e6b6b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -315,14 +315,14 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False diff --git a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py index 18242a987507..b49aa5bc33a4 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion.py @@ -348,7 +348,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [-0.3862, -0.4507, -1.1729, 0.0686, -1.1045, 0.7124, -1.8301, 0.1903, 1.2773] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 64, 64) @@ -357,7 +357,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [0.2720, -0.1863, -0.7383, -0.5029, -0.7534, 0.3970, -0.7646, 0.4468, 1.2686] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False 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 4cb9a72934cf..b93184fa0985 100644 --- a/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py +++ b/tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py @@ -483,7 +483,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [-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() < 1e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 2: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 60, 80) @@ -492,7 +492,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None: [-0.7109, -1.5068, -0.1403, -2.9160, -2.7207, -2.4414, -2.1035, -3.0059, -1.7090] ) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 callback_fn.has_been_called = False 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 805a41083207..ea26b024f2e4 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 @@ -285,7 +285,7 @@ def test_stable_diffusion_v_pred_upcast_attention(self): assert image.shape == (1, 768, 768, 3) expected_slice = np.array([0.4209, 0.4087, 0.4097, 0.4209, 0.3860, 0.4329, 0.4280, 0.4324, 0.4187]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 def test_stable_diffusion_v_pred_euler(self): scheduler = EulerDiscreteScheduler.from_pretrained("stabilityai/stable-diffusion-2", subfolder="scheduler") @@ -382,7 +382,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_default(self): image = output.images[0] assert image.shape == (768, 768, 3) - assert np.abs(expected_image - image).max() < 5e-3 + assert np.abs(expected_image - image).max() < 7.5e-2 def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): expected_image = load_numpy( @@ -401,7 +401,7 @@ def test_stable_diffusion_text2img_pipeline_v_pred_fp16(self): image = output.images[0] assert image.shape == (768, 768, 3) - assert np.abs(expected_image - image).max() < 5e-1 + assert np.abs(expected_image - image).max() < 7.5e-1 def test_stable_diffusion_text2img_intermediate_state_v_pred(self): number_of_steps = 0 @@ -416,14 +416,14 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([0.7749, 0.0325, 0.5088, 0.1619, 0.3372, 0.3667, -0.5186, 0.6860, 1.4326]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-3 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 elif step == 19: latents = latents.detach().cpu().numpy() assert latents.shape == (1, 4, 96, 96) latents_slice = latents[0, -3:, -3:, -1] expected_slice = np.array([1.3887, 1.0273, 1.7266, 0.0726, 0.6611, 0.1598, -1.0547, 0.1522, 0.0227]) - assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(latents_slice.flatten() - expected_slice).max() < 5e-2 test_callback_fn.has_been_called = False diff --git a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py index 785ae3105b87..6597335e2289 100644 --- a/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py +++ b/tests/pipelines/versatile_diffusion/test_versatile_diffusion_mega.py @@ -104,7 +104,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 prompt = "A painting of a squirrel eating a burger " generator = torch.manual_seed(0) @@ -117,7 +117,7 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 image = pipe.image_variation(init_image, generator=generator, output_type="numpy").images @@ -126,4 +126,4 @@ def test_inference_dual_guided_then_text_to_image(self): assert image.shape == (1, 512, 512, 3) expected_slice = np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-2 + assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1 From 5f312d816fcd25fbdb03833074dd3c4aa4c38abc Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 09:37:14 +0000 Subject: [PATCH 33/39] up --- test_corrections.txt | 3 +++ .../stable_diffusion/test_stable_diffusion_img2img.py | 4 ++-- .../test_stable_diffusion_instruction_pix2pix.py | 4 ++-- .../stable_diffusion/test_stable_diffusion_k_diffusion.py | 6 ++---- 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 test_corrections.txt diff --git a/test_corrections.txt b/test_corrections.txt new file mode 100644 index 000000000000..94fb134c53b0 --- /dev/null +++ b/test_corrections.txt @@ -0,0 +1,3 @@ +tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_pipeline_multiple_of_8;expected_slice = np.array([0.9393, 0.9500, 0.9399, 0.9438, 0.9458, 0.9400, 0.9455, 0.9414, 0.9423]) +tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_pipeline_multiple_of_8;expected_slice = np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.2590]) +tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py;StableDiffusionPipelineIntegrationTests;test_stable_diffusion_2;expected_slice = np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py index c6ba7532e80d..5ded9188044f 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py @@ -375,9 +375,9 @@ 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.4958, 0.5107, 1.1045, 2.7539, 4.6680, 3.8320, 1.5049, 1.8633, 2.6523]) + expected_slice = np.array([0.9393, 0.9500, 0.9399, 0.9438, 0.9458, 0.9400, 0.9455, 0.9414, 0.9423]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3 @nightly 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 3319192e6b6b..60131107a239 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py @@ -378,6 +378,6 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self): image_slice = image[255:258, 383:386, -1] assert image.shape == (504, 504, 3) - expected_slice = np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]) + expected_slice = np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.2590]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py index 9a31d3d7041c..4a56615ef5b9 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py @@ -72,8 +72,6 @@ def test_stable_diffusion_2(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 512, 512, 3) - expected_slice = np.array( - [0.826810, 0.81958747, 0.8510199, 0.8376758, 0.83958465, 0.8682068, 0.84370345, 0.85251087, 0.85884345] - ) + expected_slice = np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]) - assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 + assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-1 From 7c212eaa532cb3d1835dc6fa799e819f8340678e Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 09:40:55 +0000 Subject: [PATCH 34/39] more fixes --- src/diffusers/utils/torch_utils.py | 2 +- test_corrections.txt | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 test_corrections.txt diff --git a/src/diffusers/utils/torch_utils.py b/src/diffusers/utils/torch_utils.py index be38b6089a20..b1c22e7c5773 100644 --- a/src/diffusers/utils/torch_utils.py +++ b/src/diffusers/utils/torch_utils.py @@ -65,7 +65,7 @@ def randn_tensor( ] latents = torch.cat(latents, dim=0).to(device) else: - print(rand_device) + latents = torch.randn(shape, generator=generator, device=rand_device, dtype=dtype, layout=layout).to(device) return latents diff --git a/test_corrections.txt b/test_corrections.txt deleted file mode 100644 index 94fb134c53b0..000000000000 --- a/test_corrections.txt +++ /dev/null @@ -1,3 +0,0 @@ -tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py;StableDiffusionImg2ImgPipelineSlowTests;test_stable_diffusion_img2img_pipeline_multiple_of_8;expected_slice = np.array([0.9393, 0.9500, 0.9399, 0.9438, 0.9458, 0.9400, 0.9455, 0.9414, 0.9423]) -tests/pipelines/stable_diffusion/test_stable_diffusion_instruction_pix2pix.py;StableDiffusionInstructPix2PixPipelineSlowTests;test_stable_diffusion_pix2pix_pipeline_multiple_of_8;expected_slice = np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.2590]) -tests/pipelines/stable_diffusion/test_stable_diffusion_k_diffusion.py;StableDiffusionPipelineIntegrationTests;test_stable_diffusion_2;expected_slice = np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]) From c285a6786f51401165624be12b52c51184cdef49 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 11:51:12 +0100 Subject: [PATCH 35/39] Apply suggestions from code review Co-authored-by: Suraj Patil --- docs/source/en/conceptual/reproducibility.mdx | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/source/en/conceptual/reproducibility.mdx b/docs/source/en/conceptual/reproducibility.mdx index 0af115b1687a..def2042991f7 100644 --- a/docs/source/en/conceptual/reproducibility.mdx +++ b/docs/source/en/conceptual/reproducibility.mdx @@ -21,12 +21,12 @@ While one can never expect the same results across platforms, one can expect res across releases, platforms, etc... within a certain tolerance. However, this tolerance strongly varies depending on the diffusion pipeline and checkpoint. -In the following, we should how to best control sources of randomness for diffusion models. +In the following, we show how to best control sources of randomness for diffusion models. ## Inference During inference, diffusion pipelines heavily rely on random sampling operations, such as the creating the -gaussian noise tensors to be denoised as well as adding noise to the scheduling step. +gaussian noise tensors to be denoised and adding noise to the scheduling step. Let's have a look at an example. We run the [DDIM pipeline](./api/pipelines/ddim.mdx) for just two inference steps and return a numpy tensor to look into the numerical values of the output. @@ -47,8 +47,8 @@ print(np.abs(image).sum()) Running the above prints a value of 1464.2076, but running it again prints a different value of 1495.1768. What is going on here? Every time the pipeline is run, gaussian noise -is created and step-wise denoised. To create the gaussian noise with [`torch.randn`](https://pytorch.org/docs/stable/generated/torch.randn.html) a different random seed is taken every time, thus leading to a different result. -This is a desired property of diffusion pipelines as it means that the pipeline can create a different random image every time it is run. In many cases, one would like to generate the exact same image of a certain +is created and step-wise denoised. To create the gaussian noise with [`torch.randn`](https://pytorch.org/docs/stable/generated/torch.randn.html), a different random seed is taken every time, thus leading to a different result. +This is a desired property of diffusion pipelines, as it means that the pipeline can create a different random image every time it is run. In many cases, one would like to generate the exact same image of a certain run, for which case an instance of a [PyTorch generator](https://pytorch.org/docs/stable/generated/torch.randn.html) has to be passed: ```python @@ -72,21 +72,21 @@ print(np.abs(image).sum()) Running the above always prints a value of 1491.1711 - also upon running it again because we define the generator object to be passed to all random functions of the pipeline. -If you run this code snippet on your specific hardware and version, you should get a very similar, if not the same result. +If you run this code snippet on your specific hardware and version, you should get a similar, if not the same, result. -It might be a bit unintuitive at first to pass "generator" objects to the pipelines instead of +It might be a bit unintuitive at first to pass `generator` objects to the pipelines instead of just integer values representing the seed, but this is the recommended design when dealing with probabilistic models in PyTorch as generators are *random states* that are advanced and can thus be passed to multiple pipelines in a sequence. -Great! Now, we know how to write reproducible pipelines, but it does get a bit tricker since the above example only runs on CPU. How do we also achieve reproducibility on GPU? -In short, one should not expect to get full reproducibility across hardwares when running pipelines on GPU +Great! Now, we know how to write reproducible pipelines, but it gets a bit trickier since the above example only runs on the CPU. How do we also achieve reproducibility on GPU? +In short, one should not expect full reproducibility across different hardware when running pipelines on GPU as matrix multiplications are less deterministic on GPU than on CPU and diffusion pipelines tend to require -a lot of matrix multiplications. Let's see what we can do though to keep the randomness within limits across +a lot of matrix multiplications. Let's see what we can do to keep the randomness within limits across different GPU hardware. To achieve maximum speed performance, it is recommended to create the generator directly on GPU when running @@ -112,11 +112,11 @@ print(np.abs(image).sum()) ``` Running the above now prints a value of 1389.8634 - even though we're using the exact same seed! -This is unfortunate as it means we cannot really reproduce results we achieved on GPU, also on CPU. +This is unfortunate as it means we cannot reproduce the results we achieved on GPU, also on CPU. Nevertheless, it should be expected since the GPU uses a different random number generator than the CPU. -To circumvent this problem, we created a [~`randn_tensor`] function which can create random noise -on CPU and then move the tensor to GPU if necessary. The function is used every where inside the pipelines allowing the user to **always** pass a CPU generator even if the pipeline is run on GPU: +To circumvent this problem, we created a [~`randn_tensor`] function, which can create random noise +on the CPU and then move the tensor to GPU if necessary. The function is used everywhere inside the pipelines allowing the user to **always** pass a CPU generator even if the pipeline is run on GPU: ```python import torch @@ -138,19 +138,19 @@ print(np.abs(image).sum()) ``` Running the above now prints a value of 1491.1713, much closer to the value of 1491.1711 when -the pipeline is fully run on CPU. +the pipeline is fully run on the CPU. -As a consequence, we recommend to always pass a CPU generator if Reproducibility is important. +As a consequence, we recommend always passing a CPU generator if Reproducibility is important. The loss of performance is often neglectable, but one can be sure to generate much more similar values than if the pipeline would have been run on CPU. Finally, we noticed that more complex pipelines, such as [`UnCLIPPipeline`] are often extremely -susceptible precision error propagation and thus one cannot expect even similar results across -different GPU hardware or PyTorch versions. In such cases, one simply has to make sure to run +susceptible to precision error propagation and thus one cannot expect even similar results across +different GPU hardware or PyTorch versions. In such cases, one has to make sure to run exactly the same hardware and PyTorch version for full Reproducibility. ## Randomness utilities From a2802e5840b985c1686c358c6dde1cfc8034a3c4 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 10:55:56 +0000 Subject: [PATCH 36/39] make --- src/diffusers/pipelines/ddim/pipeline_ddim.py | 19 +------------------ tests/pipelines/ddim/test_ddim.py | 4 +++- tests/pipelines/dit/test_dit.py | 9 ++++----- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/diffusers/pipelines/ddim/pipeline_ddim.py b/src/diffusers/pipelines/ddim/pipeline_ddim.py index 22e35573e42d..afc67a959de0 100644 --- a/src/diffusers/pipelines/ddim/pipeline_ddim.py +++ b/src/diffusers/pipelines/ddim/pipeline_ddim.py @@ -17,7 +17,7 @@ import torch from ...schedulers import DDIMScheduler -from ...utils import deprecate, randn_tensor +from ...utils import randn_tensor from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput @@ -78,23 +78,6 @@ def __call__( True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images. """ - if ( - generator is not None - and isinstance(generator, torch.Generator) - and generator.device.type != self.device.type - and self.device.type != "mps" - ): - message = ( - f"The `generator` device is `{generator.device}` and does not match the pipeline " - f"device `{self.device}`, so the `generator` will be ignored. " - f'Please use `generator=torch.Generator(device="{self.device}")` instead.' - ) - deprecate( - "generator.device == 'cpu'", - "0.13.0", - message, - ) - # Sample gaussian noise to begin loop if isinstance(self.unet.sample_size, int): image_shape = (batch_size, self.unet.in_channels, self.unet.sample_size, self.unet.sample_size) diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index 5eb969840e00..e4461527039d 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -100,6 +100,7 @@ def test_inference_ema_bedroom(self): assert image.shape == (1, 256, 256, 3) expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_cifar10(self): @@ -118,6 +119,7 @@ def test_inference_cifar10(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 32, 32, 3) - expected_slice = np.array([0.2060, 0.2042, 0.2022, 0.2193, 0.2146, 0.2110, 0.2471, 0.2446, 0.2388]) + expected_slice = np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069]) + from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/dit/test_dit.py b/tests/pipelines/dit/test_dit.py index 17fc3f526882..4aa5093fd51a 100644 --- a/tests/pipelines/dit/test_dit.py +++ b/tests/pipelines/dit/test_dit.py @@ -114,15 +114,14 @@ def test_dit_256(self): assert np.abs((expected_image - image).max()) < 1e-3 def test_dit_512_fp16(self): - generator = torch.manual_seed(0) - pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-512", torch_dtype=torch.float16) pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe.to("cuda") - words = ["vase", "umbrella", "white shark", "white wolf"] + words = ["vase", "umbrella"] ids = pipe.get_label_ids(words) + generator = torch.manual_seed(0) images = pipe(ids, generator=generator, num_inference_steps=25, output_type="np").images for word, image in zip(words, images): @@ -130,7 +129,7 @@ def test_dit_512_fp16(self): ( "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" f"/dit/{word}_fp16.npy" - ), + ) ) - assert np.abs((expected_image - image).max()) < 5e-2 + assert np.abs((expected_image - image).max()) < 7.5e-1 From 35ee14186cb330b3a5d5a4ad2f209bd5f9e1f93c Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 11:04:42 +0000 Subject: [PATCH 37/39] correct --- test_corrections.txt | 2 ++ tests/pipelines/ddim/test_ddim.py | 36 +++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 test_corrections.txt diff --git a/test_corrections.txt b/test_corrections.txt new file mode 100644 index 000000000000..d6d348c4c13c --- /dev/null +++ b/test_corrections.txt @@ -0,0 +1,2 @@ +tests/pipelines/ddim/test_ddim.py;DDIMPipelineIntegrationTests;test_inference_cifar10;expected_slice = np.array([0.1723, 0.1617, 0.1600, 0.1626, 0.1497, 0.1513, 0.1505, 0.1442, 0.1453]) +tests/pipelines/ddim/test_ddim.py;DDIMPipelineIntegrationTests;test_inference_ema_bedroom;expected_slice = np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069]) diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index e4461527039d..baf4cb9322dd 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -82,44 +82,44 @@ def test_inference(self): @slow @require_torch_gpu class DDIMPipelineIntegrationTests(unittest.TestCase): - def test_inference_ema_bedroom(self): - model_id = "google/ddpm-ema-bedroom-256" + def test_inference_cifar10(self): + model_id = "google/ddpm-cifar10-32" unet = UNet2DModel.from_pretrained(model_id) - scheduler = DDIMScheduler.from_pretrained(model_id) + scheduler = DDIMScheduler() - ddpm = DDIMPipeline(unet=unet, scheduler=scheduler) - ddpm.to(torch_device) - ddpm.set_progress_bar_config(disable=None) + ddim = DDIMPipeline(unet=unet, scheduler=scheduler) + ddim.to(torch_device) + ddim.set_progress_bar_config(disable=None) generator = torch.manual_seed(0) - image = ddpm(generator=generator, output_type="numpy").images + image = ddim(generator=generator, eta=0.0, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] - assert image.shape == (1, 256, 256, 3) - expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) + assert image.shape == (1, 32, 32, 3) + expected_slice = np.array([0.1723, 0.1617, 0.1600, 0.1626, 0.1497, 0.1513, 0.1505, 0.1442, 0.1453]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 - def test_inference_cifar10(self): - model_id = "google/ddpm-cifar10-32" + def test_inference_ema_bedroom(self): + model_id = "google/ddpm-ema-bedroom-256" unet = UNet2DModel.from_pretrained(model_id) - scheduler = DDIMScheduler() + scheduler = DDIMScheduler.from_pretrained(model_id) - ddim = DDIMPipeline(unet=unet, scheduler=scheduler) - ddim.to(torch_device) - ddim.set_progress_bar_config(disable=None) + ddpm = DDIMPipeline(unet=unet, scheduler=scheduler) + ddpm.to(torch_device) + ddpm.set_progress_bar_config(disable=None) generator = torch.manual_seed(0) - image = ddim(generator=generator, eta=0.0, output_type="numpy").images + image = ddpm(generator=generator, output_type="numpy").images image_slice = image[0, -3:, -3:, -1] - assert image.shape == (1, 32, 32, 3) - expected_slice = np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069]) + assert image.shape == (1, 256, 256, 3) + expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 From 87e172fb30833e1ced7f45826712fd46ca2ba592 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 11:06:37 +0000 Subject: [PATCH 38/39] finish --- src/diffusers/utils/torch_utils.py | 1 - test_corrections.txt | 2 -- tests/pipelines/ddim/test_ddim.py | 4 +--- tests/pipelines/dit/test_dit.py | 6 ++---- 4 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 test_corrections.txt diff --git a/src/diffusers/utils/torch_utils.py b/src/diffusers/utils/torch_utils.py index b1c22e7c5773..42d50c4b5ba7 100644 --- a/src/diffusers/utils/torch_utils.py +++ b/src/diffusers/utils/torch_utils.py @@ -65,7 +65,6 @@ def randn_tensor( ] latents = torch.cat(latents, dim=0).to(device) else: - latents = torch.randn(shape, generator=generator, device=rand_device, dtype=dtype, layout=layout).to(device) return latents diff --git a/test_corrections.txt b/test_corrections.txt deleted file mode 100644 index d6d348c4c13c..000000000000 --- a/test_corrections.txt +++ /dev/null @@ -1,2 +0,0 @@ -tests/pipelines/ddim/test_ddim.py;DDIMPipelineIntegrationTests;test_inference_cifar10;expected_slice = np.array([0.1723, 0.1617, 0.1600, 0.1626, 0.1497, 0.1513, 0.1505, 0.1442, 0.1453]) -tests/pipelines/ddim/test_ddim.py;DDIMPipelineIntegrationTests;test_inference_ema_bedroom;expected_slice = np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069]) diff --git a/tests/pipelines/ddim/test_ddim.py b/tests/pipelines/ddim/test_ddim.py index baf4cb9322dd..300e7217f8c3 100644 --- a/tests/pipelines/ddim/test_ddim.py +++ b/tests/pipelines/ddim/test_ddim.py @@ -100,7 +100,6 @@ def test_inference_cifar10(self): assert image.shape == (1, 32, 32, 3) expected_slice = np.array([0.1723, 0.1617, 0.1600, 0.1626, 0.1497, 0.1513, 0.1505, 0.1442, 0.1453]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_ema_bedroom(self): @@ -119,7 +118,6 @@ def test_inference_ema_bedroom(self): image_slice = image[0, -3:, -3:, -1] assert image.shape == (1, 256, 256, 3) - expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) + expected_slice = np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069]) - from diffusers.utils.testing_utils import print_tensor_test; print_tensor_test(image_slice) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 diff --git a/tests/pipelines/dit/test_dit.py b/tests/pipelines/dit/test_dit.py index 4aa5093fd51a..f1838ebef05d 100644 --- a/tests/pipelines/dit/test_dit.py +++ b/tests/pipelines/dit/test_dit.py @@ -126,10 +126,8 @@ def test_dit_512_fp16(self): for word, image in zip(words, images): expected_image = load_numpy( - ( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" - f"/dit/{word}_fp16.npy" - ) + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" + f"/dit/{word}_fp16.npy" ) assert np.abs((expected_image - image).max()) < 7.5e-1 From 716d496adce2c5899d032050fe518b88f025f67b Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 25 Jan 2023 13:55:32 +0200 Subject: [PATCH 39/39] finish --- .github/workflows/nightly_tests.yml | 3 --- .github/workflows/push_tests.yml | 3 --- docs/source/en/_toctree.yml | 2 ++ .../en/{conceptual => using-diffusers}/reproducibility.mdx | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) rename docs/source/en/{conceptual => using-diffusers}/reproducibility.mdx (98%) diff --git a/.github/workflows/nightly_tests.yml b/.github/workflows/nightly_tests.yml index 110fdbc2581a..fb0ce92cb61c 100644 --- a/.github/workflows/nightly_tests.yml +++ b/.github/workflows/nightly_tests.yml @@ -3,9 +3,6 @@ name: Nightly tests on main on: schedule: - cron: "0 0 * * *" # every day at midnight - pull_request: # TODO: only for debugging, remove before merging! - branches: - - main env: DIFFUSERS_IS_CI: yes diff --git a/.github/workflows/push_tests.yml b/.github/workflows/push_tests.yml index 88681a1875ea..2d4875b80ced 100644 --- a/.github/workflows/push_tests.yml +++ b/.github/workflows/push_tests.yml @@ -4,9 +4,6 @@ on: push: branches: - main - pull_request: # TODO: only for debugging, remove before merging! - branches: - - main env: DIFFUSERS_IS_CI: yes diff --git a/docs/source/en/_toctree.yml b/docs/source/en/_toctree.yml index e580181251a9..2fe466e3e91f 100644 --- a/docs/source/en/_toctree.yml +++ b/docs/source/en/_toctree.yml @@ -32,6 +32,8 @@ title: Text-Guided Depth-to-Image - local: using-diffusers/reusing_seeds title: Reusing seeds for deterministic generation + - local: using-diffusers/reproducibility + title: Reproducibility - local: using-diffusers/custom_pipeline_examples title: Community Pipelines - local: using-diffusers/contribute_pipeline diff --git a/docs/source/en/conceptual/reproducibility.mdx b/docs/source/en/using-diffusers/reproducibility.mdx similarity index 98% rename from docs/source/en/conceptual/reproducibility.mdx rename to docs/source/en/using-diffusers/reproducibility.mdx index def2042991f7..03c6ae55998d 100644 --- a/docs/source/en/conceptual/reproducibility.mdx +++ b/docs/source/en/using-diffusers/reproducibility.mdx @@ -115,7 +115,7 @@ Running the above now prints a value of 1389.8634 - even though we're using the This is unfortunate as it means we cannot reproduce the results we achieved on GPU, also on CPU. Nevertheless, it should be expected since the GPU uses a different random number generator than the CPU. -To circumvent this problem, we created a [~`randn_tensor`] function, which can create random noise +To circumvent this problem, we created a [`randn_tensor`](#diffusers.utils.randn_tensor) function, which can create random noise on the CPU and then move the tensor to GPU if necessary. The function is used everywhere inside the pipelines allowing the user to **always** pass a CPU generator even if the pipeline is run on GPU: ```python