From 7513162b8b3ab4108dfe58de2a4ae896f888e883 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Mon, 3 Mar 2025 16:55:01 +0530 Subject: [PATCH] [Tests] Remove more encode prompts tests (#10942) * fix-copies went uncaught it seems. * remove more unneeded encode_prompt() tests * Revert "fix-copies went uncaught it seems." This reverts commit eefb302791172a4fb8ef008e400f94878de2c6c9. * empty --- .../test_controlnet_flux_img2img.py | 24 ----- tests/pipelines/flux/test_pipeline_flux.py | 24 ----- .../flux/test_pipeline_flux_control.py | 24 ----- .../test_pipeline_flux_control_img2img.py | 24 ----- .../test_pipeline_flux_control_inpaint.py | 40 -------- .../pipelines/flux/test_pipeline_flux_fill.py | 24 ----- .../flux/test_pipeline_flux_img2img.py | 24 ----- .../flux/test_pipeline_flux_inpaint.py | 24 ----- .../pipelines/hunyuandit/test_hunyuan_dit.py | 96 +----------------- tests/pipelines/latte/test_latte.py | 71 +------------- tests/pipelines/lumina/test_lumina_nextdit.py | 29 ------ tests/pipelines/pag/test_pag_hunyuan_dit.py | 97 +------------------ tests/pipelines/pag/test_pag_pixart_sigma.py | 76 --------------- tests/pipelines/pag/test_pag_sd3.py | 33 ------- tests/pipelines/pixart_alpha/test_pixart.py | 76 +-------------- tests/pipelines/pixart_sigma/test_pixart.py | 76 +-------------- .../test_stable_cascade_combined.py | 37 ------- .../test_stable_cascade_decoder.py | 39 -------- .../test_stable_cascade_prior.py | 35 ------- 19 files changed, 8 insertions(+), 865 deletions(-) diff --git a/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py b/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py index 02270d7fbd..59ccb92378 100644 --- a/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py +++ b/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py @@ -158,30 +158,6 @@ class FluxControlNetImg2ImgPipelineFastTests(unittest.TestCase, PipelineTesterMi assert max_diff > 1e-6 - def test_flux_controlnet_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_fused_qkv_projections(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/flux/test_pipeline_flux.py b/tests/pipelines/flux/test_pipeline_flux.py index 2382f453bb..2df39e7347 100644 --- a/tests/pipelines/flux/test_pipeline_flux.py +++ b/tests/pipelines/flux/test_pipeline_flux.py @@ -136,30 +136,6 @@ class FluxPipelineFastTests( # For some reasons, they don't show large differences assert max_diff > 1e-6 - def test_flux_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_fused_qkv_projections(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/flux/test_pipeline_flux_control.py b/tests/pipelines/flux/test_pipeline_flux_control.py index 5bb7cdec03..d8293952ad 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control.py +++ b/tests/pipelines/flux/test_pipeline_flux_control.py @@ -126,30 +126,6 @@ class FluxControlPipelineFastTests(unittest.TestCase, PipelineTesterMixin): # For some reasons, they don't show large differences assert max_diff > 1e-6 - def test_flux_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_fused_qkv_projections(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/flux/test_pipeline_flux_control_img2img.py b/tests/pipelines/flux/test_pipeline_flux_control_img2img.py index 807013270e..966543f63a 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control_img2img.py +++ b/tests/pipelines/flux/test_pipeline_flux_control_img2img.py @@ -129,30 +129,6 @@ class FluxControlImg2ImgPipelineFastTests(unittest.TestCase, PipelineTesterMixin # For some reasons, they don't show large differences assert max_diff > 1e-6 - def test_flux_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_flux_image_output_shape(self): pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) inputs = self.get_dummy_inputs(torch_device) diff --git a/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py b/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py index c5ff02a525..44ce2a4ded 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py +++ b/tests/pipelines/flux/test_pipeline_flux_control_inpaint.py @@ -120,46 +120,6 @@ class FluxControlInpaintPipelineFastTests(unittest.TestCase, PipelineTesterMixin } return inputs - # def test_flux_different_prompts(self): - # pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - - # inputs = self.get_dummy_inputs(torch_device) - # output_same_prompt = pipe(**inputs).images[0] - - # inputs = self.get_dummy_inputs(torch_device) - # inputs["prompt_2"] = "a different prompt" - # output_different_prompts = pipe(**inputs).images[0] - - # max_diff = np.abs(output_same_prompt - output_different_prompts).max() - - # # Outputs should be different here - # # For some reasons, they don't show large differences - # assert max_diff > 1e-6 - - def test_flux_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_fused_qkv_projections(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/flux/test_pipeline_flux_fill.py b/tests/pipelines/flux/test_pipeline_flux_fill.py index 1d488db71c..04d4c68db8 100644 --- a/tests/pipelines/flux/test_pipeline_flux_fill.py +++ b/tests/pipelines/flux/test_pipeline_flux_fill.py @@ -128,30 +128,6 @@ class FluxFillPipelineFastTests(unittest.TestCase, PipelineTesterMixin): # For some reasons, they don't show large differences assert max_diff > 1e-6 - def test_flux_fill_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_flux_image_output_shape(self): pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) inputs = self.get_dummy_inputs(torch_device) diff --git a/tests/pipelines/flux/test_pipeline_flux_img2img.py b/tests/pipelines/flux/test_pipeline_flux_img2img.py index f6e9d205af..6d33ca721b 100644 --- a/tests/pipelines/flux/test_pipeline_flux_img2img.py +++ b/tests/pipelines/flux/test_pipeline_flux_img2img.py @@ -126,30 +126,6 @@ class FluxImg2ImgPipelineFastTests(unittest.TestCase, PipelineTesterMixin, FluxI # For some reasons, they don't show large differences assert max_diff > 1e-6 - def test_flux_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_flux_image_output_shape(self): pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) inputs = self.get_dummy_inputs(torch_device) diff --git a/tests/pipelines/flux/test_pipeline_flux_inpaint.py b/tests/pipelines/flux/test_pipeline_flux_inpaint.py index 4a05ec46c6..161348455c 100644 --- a/tests/pipelines/flux/test_pipeline_flux_inpaint.py +++ b/tests/pipelines/flux/test_pipeline_flux_inpaint.py @@ -128,30 +128,6 @@ class FluxInpaintPipelineFastTests(unittest.TestCase, PipelineTesterMixin, FluxI # For some reasons, they don't show large differences assert max_diff > 1e-6 - def test_flux_inpaint_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - (prompt_embeds, pooled_prompt_embeds, text_ids) = pipe.encode_prompt( - prompt, - prompt_2=None, - device=torch_device, - max_sequence_length=inputs["max_sequence_length"], - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_flux_image_output_shape(self): pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) inputs = self.get_dummy_inputs(torch_device) diff --git a/tests/pipelines/hunyuandit/test_hunyuan_dit.py b/tests/pipelines/hunyuandit/test_hunyuan_dit.py index 18c41c1ae8..5bf71b3518 100644 --- a/tests/pipelines/hunyuandit/test_hunyuan_dit.py +++ b/tests/pipelines/hunyuandit/test_hunyuan_dit.py @@ -14,7 +14,6 @@ # limitations under the License. import gc -import tempfile import unittest import numpy as np @@ -128,10 +127,12 @@ class HunyuanDiTPipelineFastTests(PipelineTesterMixin, unittest.TestCase): max_diff = np.abs(image_slice.flatten() - expected_slice).max() self.assertLessEqual(max_diff, 1e-3) + @unittest.skip("Not supported.") def test_sequential_cpu_offload_forward_pass(self): # TODO(YiYi) need to fix later pass + @unittest.skip("Not supported.") def test_sequential_offload_forward_pass_twice(self): # TODO(YiYi) need to fix later pass @@ -141,99 +142,6 @@ class HunyuanDiTPipelineFastTests(PipelineTesterMixin, unittest.TestCase): expected_max_diff=1e-3, ) - def test_save_load_optional_components(self): - components = self.get_dummy_components() - pipe = self.pipeline_class(**components) - pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(torch_device) - - prompt = inputs["prompt"] - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - ( - prompt_embeds, - negative_prompt_embeds, - prompt_attention_mask, - negative_prompt_attention_mask, - ) = pipe.encode_prompt(prompt, device=torch_device, dtype=torch.float32, text_encoder_index=0) - - ( - prompt_embeds_2, - negative_prompt_embeds_2, - prompt_attention_mask_2, - negative_prompt_attention_mask_2, - ) = pipe.encode_prompt( - prompt, - device=torch_device, - dtype=torch.float32, - text_encoder_index=1, - ) - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "prompt_embeds_2": prompt_embeds_2, - "prompt_attention_mask_2": prompt_attention_mask_2, - "negative_prompt_embeds_2": negative_prompt_embeds_2, - "negative_prompt_attention_mask_2": negative_prompt_attention_mask_2, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - # set all optional components to None - for optional_component in pipe._optional_components: - setattr(pipe, optional_component, None) - - output = pipe(**inputs)[0] - - with tempfile.TemporaryDirectory() as tmpdir: - pipe.save_pretrained(tmpdir) - pipe_loaded = self.pipeline_class.from_pretrained(tmpdir) - pipe_loaded.to(torch_device) - pipe_loaded.set_progress_bar_config(disable=None) - - for optional_component in pipe._optional_components: - self.assertTrue( - getattr(pipe_loaded, optional_component) is None, - f"`{optional_component}` did not stay set to None after loading.", - ) - - inputs = self.get_dummy_inputs(torch_device) - - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "prompt_embeds_2": prompt_embeds_2, - "prompt_attention_mask_2": prompt_attention_mask_2, - "negative_prompt_embeds_2": negative_prompt_embeds_2, - "negative_prompt_attention_mask_2": negative_prompt_attention_mask_2, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - output_loaded = pipe_loaded(**inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_loaded)).max() - self.assertLess(max_diff, 1e-4) - def test_feed_forward_chunking(self): device = "cpu" diff --git a/tests/pipelines/latte/test_latte.py b/tests/pipelines/latte/test_latte.py index fb74bce284..d6001cfed0 100644 --- a/tests/pipelines/latte/test_latte.py +++ b/tests/pipelines/latte/test_latte.py @@ -15,7 +15,6 @@ import gc import inspect -import tempfile import unittest import numpy as np @@ -39,7 +38,7 @@ from diffusers.utils.testing_utils import ( ) from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS -from ..test_pipelines_common import PipelineTesterMixin, PyramidAttentionBroadcastTesterMixin, to_np +from ..test_pipelines_common import PipelineTesterMixin, PyramidAttentionBroadcastTesterMixin enable_full_determinism() @@ -202,76 +201,10 @@ class LattePipelineFastTests(PipelineTesterMixin, PyramidAttentionBroadcastTeste def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(batch_size=3, expected_max_diff=1e-3) + @unittest.skip("Not supported.") def test_attention_slicing_forward_pass(self): pass - def test_save_load_optional_components(self): - if not hasattr(self.pipeline_class, "_optional_components"): - return - - components = self.get_dummy_components() - pipe = self.pipeline_class(**components) - - for component in pipe.components.values(): - if hasattr(component, "set_default_attn_processor"): - component.set_default_attn_processor() - pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(torch_device) - - prompt = inputs["prompt"] - generator = inputs["generator"] - - ( - prompt_embeds, - negative_prompt_embeds, - ) = pipe.encode_prompt(prompt) - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "generator": generator, - "num_inference_steps": 2, - "guidance_scale": 5.0, - "height": 8, - "width": 8, - "video_length": 1, - "mask_feature": False, - "output_type": "pt", - "clean_caption": False, - } - - # set all optional components to None - for optional_component in pipe._optional_components: - setattr(pipe, optional_component, None) - - output = pipe(**inputs)[0] - - with tempfile.TemporaryDirectory() as tmpdir: - pipe.save_pretrained(tmpdir, safe_serialization=False) - pipe_loaded = self.pipeline_class.from_pretrained(tmpdir) - pipe_loaded.to(torch_device) - - for component in pipe_loaded.components.values(): - if hasattr(component, "set_default_attn_processor"): - component.set_default_attn_processor() - - pipe_loaded.set_progress_bar_config(disable=None) - - for optional_component in pipe._optional_components: - self.assertTrue( - getattr(pipe_loaded, optional_component) is None, - f"`{optional_component}` did not stay set to None after loading.", - ) - - output_loaded = pipe_loaded(**inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_loaded)).max() - self.assertLess(max_diff, 1.0) - @unittest.skipIf( torch_device != "cuda" or not is_xformers_available(), reason="XFormers attention is only available with CUDA and `xformers` installed", diff --git a/tests/pipelines/lumina/test_lumina_nextdit.py b/tests/pipelines/lumina/test_lumina_nextdit.py index 18dcdef98d..e3a364f38e 100644 --- a/tests/pipelines/lumina/test_lumina_nextdit.py +++ b/tests/pipelines/lumina/test_lumina_nextdit.py @@ -94,35 +94,6 @@ class LuminaText2ImgPipelinePipelineFastTests(unittest.TestCase, PipelineTesterM } return inputs - def test_lumina_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - do_classifier_free_guidance = inputs["guidance_scale"] > 1 - ( - prompt_embeds, - prompt_attention_mask, - negative_prompt_embeds, - negative_prompt_attention_mask, - ) = pipe.encode_prompt( - prompt, - do_classifier_free_guidance=do_classifier_free_guidance, - device=torch_device, - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - prompt_attention_mask=prompt_attention_mask, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - @unittest.skip("xformers attention processor does not exist for Lumina") def test_xformers_attention_forwardGenerator_pass(self): pass diff --git a/tests/pipelines/pag/test_pag_hunyuan_dit.py b/tests/pipelines/pag/test_pag_hunyuan_dit.py index 3bc4240de9..59516959a9 100644 --- a/tests/pipelines/pag/test_pag_hunyuan_dit.py +++ b/tests/pipelines/pag/test_pag_hunyuan_dit.py @@ -14,7 +14,6 @@ # limitations under the License. import inspect -import tempfile import unittest import numpy as np @@ -30,7 +29,6 @@ from diffusers import ( ) from diffusers.utils.testing_utils import ( enable_full_determinism, - torch_device, ) from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS @@ -121,10 +119,12 @@ class HunyuanDiTPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): max_diff = np.abs(image_slice.flatten() - expected_slice).max() self.assertLessEqual(max_diff, 1e-3) + @unittest.skip("Not supported.") def test_sequential_cpu_offload_forward_pass(self): # TODO(YiYi) need to fix later pass + @unittest.skip("Not supported.") def test_sequential_offload_forward_pass_twice(self): # TODO(YiYi) need to fix later pass @@ -134,99 +134,6 @@ class HunyuanDiTPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): expected_max_diff=1e-3, ) - def test_save_load_optional_components(self): - components = self.get_dummy_components() - pipe = self.pipeline_class(**components) - pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(torch_device) - - prompt = inputs["prompt"] - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - ( - prompt_embeds, - negative_prompt_embeds, - prompt_attention_mask, - negative_prompt_attention_mask, - ) = pipe.encode_prompt(prompt, device=torch_device, dtype=torch.float32, text_encoder_index=0) - - ( - prompt_embeds_2, - negative_prompt_embeds_2, - prompt_attention_mask_2, - negative_prompt_attention_mask_2, - ) = pipe.encode_prompt( - prompt, - device=torch_device, - dtype=torch.float32, - text_encoder_index=1, - ) - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "prompt_embeds_2": prompt_embeds_2, - "prompt_attention_mask_2": prompt_attention_mask_2, - "negative_prompt_embeds_2": negative_prompt_embeds_2, - "negative_prompt_attention_mask_2": negative_prompt_attention_mask_2, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - # set all optional components to None - for optional_component in pipe._optional_components: - setattr(pipe, optional_component, None) - - output = pipe(**inputs)[0] - - with tempfile.TemporaryDirectory() as tmpdir: - pipe.save_pretrained(tmpdir) - pipe_loaded = self.pipeline_class.from_pretrained(tmpdir) - pipe_loaded.to(torch_device) - pipe_loaded.set_progress_bar_config(disable=None) - - for optional_component in pipe._optional_components: - self.assertTrue( - getattr(pipe_loaded, optional_component) is None, - f"`{optional_component}` did not stay set to None after loading.", - ) - - inputs = self.get_dummy_inputs(torch_device) - - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "prompt_embeds_2": prompt_embeds_2, - "prompt_attention_mask_2": prompt_attention_mask_2, - "negative_prompt_embeds_2": negative_prompt_embeds_2, - "negative_prompt_attention_mask_2": negative_prompt_attention_mask_2, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - output_loaded = pipe_loaded(**inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_loaded)).max() - self.assertLess(max_diff, 1e-4) - def test_feed_forward_chunking(self): device = "cpu" diff --git a/tests/pipelines/pag/test_pag_pixart_sigma.py b/tests/pipelines/pag/test_pag_pixart_sigma.py index 7de19e0f00..b6d6bdd70a 100644 --- a/tests/pipelines/pag/test_pag_pixart_sigma.py +++ b/tests/pipelines/pag/test_pag_pixart_sigma.py @@ -184,82 +184,6 @@ class PixArtSigmaPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): max_diff = np.abs(image_slice.flatten() - expected_slice).max() self.assertLessEqual(max_diff, 1e-3) - # Copied from tests.pipelines.pixart_sigma.test_pixart.PixArtSigmaPipelineFastTests.test_save_load_optional_components - def test_save_load_optional_components(self): - components = self.get_dummy_components() - pipe = self.pipeline_class(**components) - pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(torch_device) - - prompt = inputs["prompt"] - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - ( - prompt_embeds, - prompt_attention_mask, - negative_prompt_embeds, - negative_prompt_attention_mask, - ) = pipe.encode_prompt(prompt) - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - # set all optional components to None - for optional_component in pipe._optional_components: - setattr(pipe, optional_component, None) - - output = pipe(**inputs)[0] - - with tempfile.TemporaryDirectory() as tmpdir: - pipe.save_pretrained(tmpdir) - pipe_loaded = self.pipeline_class.from_pretrained(tmpdir, pag_applied_layers=["blocks.1"]) - pipe_loaded.to(torch_device) - pipe_loaded.set_progress_bar_config(disable=None) - - for optional_component in pipe._optional_components: - self.assertTrue( - getattr(pipe_loaded, optional_component) is None, - f"`{optional_component}` did not stay set to None after loading.", - ) - - inputs = self.get_dummy_inputs(torch_device) - - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - output_loaded = pipe_loaded(**inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_loaded)).max() - self.assertLess(max_diff, 1e-4) - # Because the PAG PixArt Sigma has `pag_applied_layers`. # Also, we shouldn't be doing `set_default_attn_processor()` after loading # the pipeline with `pag_applied_layers`. diff --git a/tests/pipelines/pag/test_pag_sd3.py b/tests/pipelines/pag/test_pag_sd3.py index 627d613ee2..41ff0c3c09 100644 --- a/tests/pipelines/pag/test_pag_sd3.py +++ b/tests/pipelines/pag/test_pag_sd3.py @@ -156,39 +156,6 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi # Outputs should be different here assert max_diff > 1e-2 - def test_stable_diffusion_3_prompt_embeds(self): - pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) - inputs = self.get_dummy_inputs(torch_device) - - output_with_prompt = pipe(**inputs).images[0] - - inputs = self.get_dummy_inputs(torch_device) - prompt = inputs.pop("prompt") - - do_classifier_free_guidance = inputs["guidance_scale"] > 1 - ( - prompt_embeds, - negative_prompt_embeds, - pooled_prompt_embeds, - negative_pooled_prompt_embeds, - ) = pipe.encode_prompt( - prompt, - prompt_2=None, - prompt_3=None, - do_classifier_free_guidance=do_classifier_free_guidance, - device=torch_device, - ) - output_with_embeds = pipe( - prompt_embeds=prompt_embeds, - negative_prompt_embeds=negative_prompt_embeds, - pooled_prompt_embeds=pooled_prompt_embeds, - negative_pooled_prompt_embeds=negative_pooled_prompt_embeds, - **inputs, - ).images[0] - - max_diff = np.abs(output_with_prompt - output_with_embeds).max() - assert max_diff < 1e-4 - def test_fused_qkv_projections(self): device = "cpu" # ensure determinism for the device-dependent torch.Generator components = self.get_dummy_components() diff --git a/tests/pipelines/pixart_alpha/test_pixart.py b/tests/pipelines/pixart_alpha/test_pixart.py index ae0f9b50f7..6b71f8bb81 100644 --- a/tests/pipelines/pixart_alpha/test_pixart.py +++ b/tests/pipelines/pixart_alpha/test_pixart.py @@ -104,85 +104,11 @@ class PixArtAlphaPipelineFastTests(PipelineTesterMixin, unittest.TestCase): } return inputs + @unittest.skip("Not supported.") def test_sequential_cpu_offload_forward_pass(self): # TODO(PVP, Sayak) need to fix later return - def test_save_load_optional_components(self): - components = self.get_dummy_components() - pipe = self.pipeline_class(**components) - pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(torch_device) - - prompt = inputs["prompt"] - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - ( - prompt_embeds, - prompt_attention_mask, - negative_prompt_embeds, - negative_prompt_attention_mask, - ) = pipe.encode_prompt(prompt) - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - # set all optional components to None - for optional_component in pipe._optional_components: - setattr(pipe, optional_component, None) - - output = pipe(**inputs)[0] - - with tempfile.TemporaryDirectory() as tmpdir: - pipe.save_pretrained(tmpdir) - pipe_loaded = self.pipeline_class.from_pretrained(tmpdir) - pipe_loaded.to(torch_device) - pipe_loaded.set_progress_bar_config(disable=None) - - for optional_component in pipe._optional_components: - self.assertTrue( - getattr(pipe_loaded, optional_component) is None, - f"`{optional_component}` did not stay set to None after loading.", - ) - - inputs = self.get_dummy_inputs(torch_device) - - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - output_loaded = pipe_loaded(**inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_loaded)).max() - self.assertLess(max_diff, 1e-4) - def test_inference(self): device = "cpu" diff --git a/tests/pipelines/pixart_sigma/test_pixart.py b/tests/pipelines/pixart_sigma/test_pixart.py index 9bfeb691d7..ca2d1cbb84 100644 --- a/tests/pipelines/pixart_sigma/test_pixart.py +++ b/tests/pipelines/pixart_sigma/test_pixart.py @@ -109,85 +109,11 @@ class PixArtSigmaPipelineFastTests(PipelineTesterMixin, unittest.TestCase): } return inputs + @unittest.skip("Not supported.") def test_sequential_cpu_offload_forward_pass(self): # TODO(PVP, Sayak) need to fix later return - def test_save_load_optional_components(self): - components = self.get_dummy_components() - pipe = self.pipeline_class(**components) - pipe.to(torch_device) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(torch_device) - - prompt = inputs["prompt"] - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - ( - prompt_embeds, - prompt_attention_mask, - negative_prompt_embeds, - negative_prompt_attention_mask, - ) = pipe.encode_prompt(prompt) - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - # set all optional components to None - for optional_component in pipe._optional_components: - setattr(pipe, optional_component, None) - - output = pipe(**inputs)[0] - - with tempfile.TemporaryDirectory() as tmpdir: - pipe.save_pretrained(tmpdir) - pipe_loaded = self.pipeline_class.from_pretrained(tmpdir) - pipe_loaded.to(torch_device) - pipe_loaded.set_progress_bar_config(disable=None) - - for optional_component in pipe._optional_components: - self.assertTrue( - getattr(pipe_loaded, optional_component) is None, - f"`{optional_component}` did not stay set to None after loading.", - ) - - inputs = self.get_dummy_inputs(torch_device) - - generator = inputs["generator"] - num_inference_steps = inputs["num_inference_steps"] - output_type = inputs["output_type"] - - # inputs with prompt converted to embeddings - inputs = { - "prompt_embeds": prompt_embeds, - "prompt_attention_mask": prompt_attention_mask, - "negative_prompt": None, - "negative_prompt_embeds": negative_prompt_embeds, - "negative_prompt_attention_mask": negative_prompt_attention_mask, - "generator": generator, - "num_inference_steps": num_inference_steps, - "output_type": output_type, - "use_resolution_binning": False, - } - - output_loaded = pipe_loaded(**inputs)[0] - - max_diff = np.abs(to_np(output) - to_np(output_loaded)).max() - self.assertLess(max_diff, 1e-4) - def test_inference(self): device = "cpu" diff --git a/tests/pipelines/stable_cascade/test_stable_cascade_combined.py b/tests/pipelines/stable_cascade/test_stable_cascade_combined.py index d256deed37..e220e441a3 100644 --- a/tests/pipelines/stable_cascade/test_stable_cascade_combined.py +++ b/tests/pipelines/stable_cascade/test_stable_cascade_combined.py @@ -242,40 +242,3 @@ class StableCascadeCombinedPipelineFastTests(PipelineTesterMixin, unittest.TestC @unittest.skip(reason="no callback test for combined pipeline") def test_callback_inputs(self): super().test_callback_inputs() - - def test_stable_cascade_combined_prompt_embeds(self): - device = "cpu" - components = self.get_dummy_components() - - pipe = StableCascadeCombinedPipeline(**components) - pipe.set_progress_bar_config(disable=None) - - prompt = "A photograph of a shiba inu, wearing a hat" - ( - prompt_embeds, - prompt_embeds_pooled, - negative_prompt_embeds, - negative_prompt_embeds_pooled, - ) = pipe.prior_pipe.encode_prompt(device, 1, 1, False, prompt=prompt) - generator = torch.Generator(device=device) - - output_prompt = pipe( - prompt=prompt, - num_inference_steps=1, - prior_num_inference_steps=1, - output_type="np", - generator=generator.manual_seed(0), - ) - output_prompt_embeds = pipe( - prompt=None, - prompt_embeds=prompt_embeds, - prompt_embeds_pooled=prompt_embeds_pooled, - negative_prompt_embeds=negative_prompt_embeds, - negative_prompt_embeds_pooled=negative_prompt_embeds_pooled, - num_inference_steps=1, - prior_num_inference_steps=1, - output_type="np", - generator=generator.manual_seed(0), - ) - - assert np.abs(output_prompt.images - output_prompt_embeds.images).max() < 1e-5 diff --git a/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py b/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py index 1d8f4a4f6c..87c1a76cb2 100644 --- a/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py +++ b/tests/pipelines/stable_cascade/test_stable_cascade_decoder.py @@ -208,45 +208,6 @@ class StableCascadeDecoderPipelineFastTests(PipelineTesterMixin, unittest.TestCa def test_float16_inference(self): super().test_float16_inference() - def test_stable_cascade_decoder_prompt_embeds(self): - device = "cpu" - components = self.get_dummy_components() - - pipe = StableCascadeDecoderPipeline(**components) - pipe.set_progress_bar_config(disable=None) - - inputs = self.get_dummy_inputs(device) - image_embeddings = inputs["image_embeddings"] - prompt = "A photograph of a shiba inu, wearing a hat" - ( - prompt_embeds, - prompt_embeds_pooled, - negative_prompt_embeds, - negative_prompt_embeds_pooled, - ) = pipe.encode_prompt(device, 1, 1, False, prompt=prompt) - generator = torch.Generator(device=device) - - decoder_output_prompt = pipe( - image_embeddings=image_embeddings, - prompt=prompt, - num_inference_steps=1, - output_type="np", - generator=generator.manual_seed(0), - ) - decoder_output_prompt_embeds = pipe( - image_embeddings=image_embeddings, - prompt=None, - prompt_embeds=prompt_embeds, - prompt_embeds_pooled=prompt_embeds_pooled, - negative_prompt_embeds=negative_prompt_embeds, - negative_prompt_embeds_pooled=negative_prompt_embeds_pooled, - num_inference_steps=1, - output_type="np", - generator=generator.manual_seed(0), - ) - - assert np.abs(decoder_output_prompt.images - decoder_output_prompt_embeds.images).max() < 1e-5 - def test_stable_cascade_decoder_single_prompt_multiple_image_embeddings(self): device = "cpu" components = self.get_dummy_components() diff --git a/tests/pipelines/stable_cascade/test_stable_cascade_prior.py b/tests/pipelines/stable_cascade/test_stable_cascade_prior.py index db1c7703a5..fb879eb5a2 100644 --- a/tests/pipelines/stable_cascade/test_stable_cascade_prior.py +++ b/tests/pipelines/stable_cascade/test_stable_cascade_prior.py @@ -240,41 +240,6 @@ class StableCascadePriorPipelineFastTests(PipelineTesterMixin, unittest.TestCase self.assertTrue(image_embed.shape == lora_image_embed.shape) - def test_stable_cascade_decoder_prompt_embeds(self): - device = "cpu" - components = self.get_dummy_components() - - pipe = self.pipeline_class(**components) - pipe.set_progress_bar_config(disable=None) - - prompt = "A photograph of a shiba inu, wearing a hat" - ( - prompt_embeds, - prompt_embeds_pooled, - negative_prompt_embeds, - negative_prompt_embeds_pooled, - ) = pipe.encode_prompt(device, 1, 1, False, prompt=prompt) - generator = torch.Generator(device=device) - - output_prompt = pipe( - prompt=prompt, - num_inference_steps=1, - output_type="np", - generator=generator.manual_seed(0), - ) - output_prompt_embeds = pipe( - prompt=None, - prompt_embeds=prompt_embeds, - prompt_embeds_pooled=prompt_embeds_pooled, - negative_prompt_embeds=negative_prompt_embeds, - negative_prompt_embeds_pooled=negative_prompt_embeds_pooled, - num_inference_steps=1, - output_type="np", - generator=generator.manual_seed(0), - ) - - assert np.abs(output_prompt.image_embeddings - output_prompt_embeds.image_embeddings).max() < 1e-5 - @unittest.skip("Test not supported because dtype determination relies on text encoder.") def test_encode_prompt_works_in_isolation(self): pass