From a67ff3230129de5f7d4c714731d6907c90d2840d Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Wed, 9 Aug 2023 12:38:15 +0200 Subject: [PATCH] Move slow tests to nightly (#4526) * move slow pix2pixzero tests to nightly * move slow panorama tests to nightly * move txt2video full test to nightly * clean up * remove nightly test from text to video pipeline --- .../test_stable_diffusion_panorama.py | 6 +-- .../test_stable_diffusion_pix2pix_zero.py | 51 ++----------------- .../text_to_video/test_text_to_video.py | 23 ++------- 3 files changed, 11 insertions(+), 69 deletions(-) diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_panorama.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_panorama.py index c221ac5fb8..294a867828 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_panorama.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_panorama.py @@ -29,7 +29,7 @@ from diffusers import ( StableDiffusionPanoramaPipeline, UNet2DConditionModel, ) -from diffusers.utils import slow, torch_device +from diffusers.utils import nightly, torch_device from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS @@ -245,9 +245,9 @@ class StableDiffusionPanoramaPipelineFastTests(PipelineLatentTesterMixin, Pipeli assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 -@slow +@nightly @require_torch_gpu -class StableDiffusionPanoramaSlowTests(unittest.TestCase): +class StableDiffusionPanoramaNightlyTests(unittest.TestCase): def tearDown(self): super().tearDown() gc.collect() diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion_pix2pix_zero.py b/tests/pipelines/stable_diffusion/test_stable_diffusion_pix2pix_zero.py index 7d94b9f230..c513fb1c0b 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion_pix2pix_zero.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion_pix2pix_zero.py @@ -33,7 +33,7 @@ from diffusers import ( UNet2DConditionModel, ) from diffusers.image_processor import VaeImageProcessor -from diffusers.utils import floats_tensor, load_numpy, slow, torch_device +from diffusers.utils import floats_tensor, load_numpy, nightly, torch_device from diffusers.utils.testing_utils import enable_full_determinism, load_image, load_pt, require_torch_gpu, skip_mps from ..pipeline_params import ( @@ -349,9 +349,9 @@ class StableDiffusionPix2PixZeroPipelineFastTests(PipelineLatentTesterMixin, Pip return super().test_inference_batch_single_identical() -@slow +@nightly @require_torch_gpu -class StableDiffusionPix2PixZeroPipelineSlowTests(unittest.TestCase): +class StableDiffusionPix2PixZeroPipelineNightlyTests(unittest.TestCase): def tearDown(self): super().tearDown() gc.collect() @@ -477,9 +477,9 @@ class StableDiffusionPix2PixZeroPipelineSlowTests(unittest.TestCase): assert mem_bytes < 8.2 * 10**9 -@slow +@nightly @require_torch_gpu -class InversionPipelineSlowTests(unittest.TestCase): +class InversionPipelineNightlyTests(unittest.TestCase): def tearDown(self): super().tearDown() gc.collect() @@ -539,47 +539,6 @@ class InversionPipelineSlowTests(unittest.TestCase): assert np.abs(expected_slice - image_slice.cpu().numpy()).max() < 5e-2 - def test_stable_diffusion_pix2pix_full(self): - # numpy array of https://huggingface.co/datasets/hf-internal-testing/diffusers-images/blob/main/pix2pix/dog.png - expected_image = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/dog.npy" - ) - - pipe = StableDiffusionPix2PixZeroPipeline.from_pretrained( - "CompVis/stable-diffusion-v1-4", safety_checker=None, torch_dtype=torch.float16 - ) - pipe.inverse_scheduler = DDIMInverseScheduler.from_config(pipe.scheduler.config) - - caption = "a photography of a cat with flowers" - pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) - pipe.enable_model_cpu_offload() - pipe.set_progress_bar_config(disable=None) - - generator = torch.manual_seed(0) - output = pipe.invert(caption, image=self.raw_image, generator=generator) - inv_latents = output[0] - - source_prompts = 4 * ["a cat sitting on the street", "a cat playing in the field", "a face of a cat"] - target_prompts = 4 * ["a dog sitting on the street", "a dog playing in the field", "a face of a dog"] - - source_embeds = pipe.get_embeds(source_prompts) - target_embeds = pipe.get_embeds(target_prompts) - - image = pipe( - caption, - source_embeds=source_embeds, - target_embeds=target_embeds, - num_inference_steps=50, - cross_attention_guidance_amount=0.15, - generator=generator, - latents=inv_latents, - negative_prompt=caption, - output_type="np", - ).images - - max_diff = np.abs(expected_image - image).mean() - assert max_diff < 0.05 - def test_stable_diffusion_2_pix2pix_full(self): # numpy array of https://huggingface.co/datasets/hf-internal-testing/diffusers-images/blob/main/pix2pix/dog_2.png expected_image = load_numpy( diff --git a/tests/pipelines/text_to_video/test_text_to_video.py b/tests/pipelines/text_to_video/test_text_to_video.py index f391568d10..801af7f6b4 100644 --- a/tests/pipelines/text_to_video/test_text_to_video.py +++ b/tests/pipelines/text_to_video/test_text_to_video.py @@ -22,11 +22,10 @@ from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer from diffusers import ( AutoencoderKL, DDIMScheduler, - DPMSolverMultistepScheduler, TextToVideoSDPipeline, UNet3DConditionModel, ) -from diffusers.utils import is_xformers_available, load_numpy, skip_mps, slow, torch_device +from diffusers.utils import is_xformers_available, load_numpy, require_torch_gpu, skip_mps, slow, torch_device from diffusers.utils.testing_utils import enable_full_determinism from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS @@ -170,31 +169,15 @@ class TextToVideoSDPipelineFastTests(PipelineTesterMixin, unittest.TestCase): @slow @skip_mps +@require_torch_gpu class TextToVideoSDPipelineSlowTests(unittest.TestCase): - def test_full_model(self): - expected_video = load_numpy( - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video.npy" - ) - - pipe = TextToVideoSDPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b") - pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) - pipe = pipe.to("cuda") - - prompt = "Spiderman is surfing" - generator = torch.Generator(device="cpu").manual_seed(0) - - video_frames = pipe(prompt, generator=generator, num_inference_steps=25, output_type="pt").frames - video = video_frames.cpu().numpy() - - assert np.abs(expected_video - video).mean() < 5e-2 - def test_two_step_model(self): expected_video = load_numpy( "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video_2step.npy" ) pipe = TextToVideoSDPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b") - pipe = pipe.to("cuda") + pipe = pipe.to(torch_device) prompt = "Spiderman is surfing" generator = torch.Generator(device="cpu").manual_seed(0)