Skip to content

Commit 6f4355f

Browse files
authored
Cleanup pass for flaky Slow Tests for Stable diffusion (huggingface#4415)
* update expected slice so img2img compile tests pass * use default attn processor * use default attn processor and update expected slice value to pass test * use default attn processor * set default attn processor and update expected slice * set default attn processor and change precision for check * set unet to use default attn processor
1 parent 05a1cb9 commit 6f4355f

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ def _test_img2img_compile(in_queue, out_queue, timeout):
6363

6464
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", safety_checker=None)
6565
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
66+
pipe.unet.set_default_attn_processor()
6667
pipe.to(torch_device)
6768
pipe.set_progress_bar_config(disable=None)
68-
6969
pipe.unet.to(memory_format=torch.channels_last)
7070
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
7171

7272
image = pipe(**inputs).images
7373
image_slice = image[0, -3:, -3:, -1].flatten()
7474

7575
assert image.shape == (1, 512, 768, 3)
76-
expected_slice = np.array([0.0593, 0.0607, 0.0851, 0.0582, 0.0636, 0.0721, 0.0751, 0.0981, 0.0781])
76+
expected_slice = np.array([0.0606, 0.0570, 0.0805, 0.0579, 0.0628, 0.0623, 0.0843, 0.1115, 0.0806])
7777

7878
assert np.abs(expected_slice - image_slice).max() < 1e-3
7979
except Exception:

tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def _test_inpaint_compile(in_queue, out_queue, timeout):
6464
pipe = StableDiffusionInpaintPipeline.from_pretrained(
6565
"runwayml/stable-diffusion-inpainting", safety_checker=None
6666
)
67+
pipe.unet.set_default_attn_processor()
6768
pipe.scheduler = PNDMScheduler.from_config(pipe.scheduler.config)
6869
pipe.to(torch_device)
6970
pipe.set_progress_bar_config(disable=None)
@@ -75,8 +76,7 @@ def _test_inpaint_compile(in_queue, out_queue, timeout):
7576
image_slice = image[0, 253:256, 253:256, -1].flatten()
7677

7778
assert image.shape == (1, 512, 512, 3)
78-
expected_slice = np.array([0.0425, 0.0273, 0.0344, 0.1694, 0.1727, 0.1812, 0.3256, 0.3311, 0.3272])
79-
79+
expected_slice = np.array([0.0689, 0.0699, 0.0790, 0.0536, 0.0470, 0.0488, 0.041, 0.0508, 0.04179])
8080
assert np.abs(expected_slice - image_slice).max() < 3e-3
8181
except Exception:
8282
error = f"{traceback.format_exc()}"
@@ -382,6 +382,7 @@ def test_stable_diffusion_inpaint_fp16(self):
382382
pipe = StableDiffusionInpaintPipeline.from_pretrained(
383383
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, safety_checker=None
384384
)
385+
pipe.unet.set_default_attn_processor()
385386
pipe.to(torch_device)
386387
pipe.set_progress_bar_config(disable=None)
387388
pipe.enable_attention_slicing()
@@ -391,8 +392,7 @@ def test_stable_diffusion_inpaint_fp16(self):
391392
image_slice = image[0, 253:256, 253:256, -1].flatten()
392393

393394
assert image.shape == (1, 512, 512, 3)
394-
expected_slice = np.array([0.1350, 0.1123, 0.1350, 0.1641, 0.1328, 0.1230, 0.1289, 0.1531, 0.1687])
395-
395+
expected_slice = np.array([0.1509, 0.1245, 0.1672, 0.1655, 0.1519, 0.1226, 0.1462, 0.1567, 0.2451])
396396
assert np.abs(expected_slice - image_slice).max() < 5e-2
397397

398398
def test_stable_diffusion_inpaint_pndm(self):
@@ -485,6 +485,7 @@ def test_stable_diffusion_inpaint_strength_test(self):
485485
"runwayml/stable-diffusion-inpainting", safety_checker=None
486486
)
487487
pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
488+
pipe.unet.set_default_attn_processor()
488489
pipe.to(torch_device)
489490
pipe.set_progress_bar_config(disable=None)
490491
pipe.enable_attention_slicing()
@@ -497,11 +498,12 @@ def test_stable_diffusion_inpaint_strength_test(self):
497498
assert image.shape == (1, 512, 512, 3)
498499

499500
image_slice = image[0, 253:256, 253:256, -1].flatten()
500-
expected_slice = np.array([0.0021, 0.2350, 0.3712, 0.0575, 0.2485, 0.3451, 0.1857, 0.3156, 0.3943])
501-
assert np.abs(expected_slice - image_slice).max() < 3e-3
501+
expected_slice = np.array([0.2728, 0.2803, 0.2665, 0.2511, 0.2774, 0.2586, 0.2391, 0.2392, 0.2582])
502+
assert np.abs(expected_slice - image_slice).max() < 1e-3
502503

503504
def test_stable_diffusion_simple_inpaint_ddim(self):
504505
pipe = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", safety_checker=None)
506+
pipe.unet.set_default_attn_processor()
505507
pipe.to(torch_device)
506508
pipe.set_progress_bar_config(disable=None)
507509
pipe.enable_attention_slicing()
@@ -512,9 +514,8 @@ def test_stable_diffusion_simple_inpaint_ddim(self):
512514
image_slice = image[0, 253:256, 253:256, -1].flatten()
513515

514516
assert image.shape == (1, 512, 512, 3)
515-
expected_slice = np.array([0.5157, 0.6858, 0.6873, 0.4619, 0.6416, 0.6898, 0.3702, 0.5960, 0.6935])
516-
517-
assert np.abs(expected_slice - image_slice).max() < 6e-4
517+
expected_slice = np.array([0.3757, 0.3875, 0.4445, 0.4353, 0.3780, 0.4513, 0.3965, 0.3984, 0.4362])
518+
assert np.abs(expected_slice - image_slice).max() < 1e-3
518519

519520
def test_download_local(self):
520521
filename = hf_hub_download("runwayml/stable-diffusion-inpainting", filename="sd-v1-5-inpainting.ckpt")

tests/pipelines/stable_diffusion/test_stable_diffusion_panorama.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,14 @@ def test_stable_diffusion_panorama_k_lms(self):
299299
"stabilityai/stable-diffusion-2-base", safety_checker=None
300300
)
301301
pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
302+
pipe.unet.set_default_attn_processor()
302303
pipe.to(torch_device)
303304
pipe.set_progress_bar_config(disable=None)
304305
pipe.enable_attention_slicing()
305306

306307
inputs = self.get_inputs()
307308
image = pipe(**inputs).images
308309
image_slice = image[0, -3:, -3:, -1].flatten()
309-
310310
assert image.shape == (1, 512, 2048, 3)
311311

312312
expected_slice = np.array(
@@ -325,7 +325,7 @@ def test_stable_diffusion_panorama_k_lms(self):
325325
]
326326
)
327327

328-
assert np.abs(expected_slice - image_slice).max() < 1e-3
328+
assert np.abs(expected_slice - image_slice).max() < 1e-2
329329

330330
def test_stable_diffusion_panorama_intermediate_state(self):
331331
number_of_steps = 0

tests/pipelines/stable_diffusion_2/test_stable_diffusion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ def test_stable_diffusion_attention_slicing(self):
344344
pipe = StableDiffusionPipeline.from_pretrained(
345345
"stabilityai/stable-diffusion-2-base", torch_dtype=torch.float16
346346
)
347+
pipe.unet.set_default_attn_processor()
347348
pipe = pipe.to(torch_device)
348349
pipe.set_progress_bar_config(disable=None)
349350

@@ -359,6 +360,7 @@ def test_stable_diffusion_attention_slicing(self):
359360

360361
# disable slicing
361362
pipe.disable_attention_slicing()
363+
pipe.unet.set_default_attn_processor()
362364
inputs = self.get_inputs(torch_device, dtype=torch.float16)
363365
image = pipe(**inputs).images
364366

tests/pipelines/stable_diffusion_2/test_stable_diffusion_depth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def test_stable_diffusion_depth2img_pipeline_k_lms(self):
417417
pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
418418
"stabilityai/stable-diffusion-2-depth", safety_checker=None
419419
)
420+
pipe.unet.set_default_attn_processor()
420421
pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
421422
pipe.to(torch_device)
422423
pipe.set_progress_bar_config(disable=None)

0 commit comments

Comments
 (0)