diff --git a/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py b/tests/pipelines/controlnet_flux/test_controlnet_flux_img2img.py index 02270d7fbd00..59ccb9237819 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 @@ def test_flux_controlnet_different_prompts(self): 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 2382f453bb39..2df39e73476d 100644 --- a/tests/pipelines/flux/test_pipeline_flux.py +++ b/tests/pipelines/flux/test_pipeline_flux.py @@ -136,30 +136,6 @@ def test_flux_different_prompts(self): # 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 5bb7cdec034c..d8293952adcb 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control.py +++ b/tests/pipelines/flux/test_pipeline_flux_control.py @@ -126,30 +126,6 @@ def test_flux_different_prompts(self): # 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 807013270eda..966543f63aeb 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 @@ def test_flux_different_prompts(self): # 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 c5ff02a525f2..44ce2a4dedfc 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 @@ def get_dummy_inputs(self, device, seed=0): } 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 1d488db71ced..04d4c68db8f3 100644 --- a/tests/pipelines/flux/test_pipeline_flux_fill.py +++ b/tests/pipelines/flux/test_pipeline_flux_fill.py @@ -128,30 +128,6 @@ def test_flux_fill_different_prompts(self): # 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 f6e9d205af56..6d33ca721b6c 100644 --- a/tests/pipelines/flux/test_pipeline_flux_img2img.py +++ b/tests/pipelines/flux/test_pipeline_flux_img2img.py @@ -126,30 +126,6 @@ def test_flux_different_prompts(self): # 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 4a05ec46c683..161348455ca4 100644 --- a/tests/pipelines/flux/test_pipeline_flux_inpaint.py +++ b/tests/pipelines/flux/test_pipeline_flux_inpaint.py @@ -128,30 +128,6 @@ def test_flux_inpaint_different_prompts(self): # 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 18c41c1ae881..5bf71b3518d3 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 @@ def test_inference(self): 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 @@ def test_inference_batch_single_identical(self): 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 fb74bce284bb..d6001cfed0f5 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 ..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 @@ def callback_inputs_change_tensor(pipe, i, t, callback_kwargs): 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 18dcdef98d7d..e3a364f38e0a 100644 --- a/tests/pipelines/lumina/test_lumina_nextdit.py +++ b/tests/pipelines/lumina/test_lumina_nextdit.py @@ -94,35 +94,6 @@ def get_dummy_inputs(self, device, seed=0): } 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 3bc4240de90e..59516959a996 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.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 @@ def test_inference(self): 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 @@ def test_inference_batch_single_identical(self): 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 7de19e0f00fc..b6d6bdd70a71 100644 --- a/tests/pipelines/pag/test_pag_pixart_sigma.py +++ b/tests/pipelines/pag/test_pag_pixart_sigma.py @@ -184,82 +184,6 @@ def test_pag_inference(self): 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 627d613ee20d..41ff0c3c09f4 100644 --- a/tests/pipelines/pag/test_pag_sd3.py +++ b/tests/pipelines/pag/test_pag_sd3.py @@ -156,39 +156,6 @@ def test_stable_diffusion_3_different_negative_prompts(self): # 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 ae0f9b50f74e..6b71f8bb8197 100644 --- a/tests/pipelines/pixart_alpha/test_pixart.py +++ b/tests/pipelines/pixart_alpha/test_pixart.py @@ -104,85 +104,11 @@ def get_dummy_inputs(self, device, seed=0): } 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 9bfeb691d770..ca2d1cbb8474 100644 --- a/tests/pipelines/pixart_sigma/test_pixart.py +++ b/tests/pipelines/pixart_sigma/test_pixart.py @@ -109,85 +109,11 @@ def get_dummy_inputs(self, device, seed=0): } 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 d256deed376c..e220e441a350 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 @@ def test_float16_inference(self): @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 1d8f4a4f6c78..87c1a76cb277 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 @@ def test_attention_slicing_forward_pass(self): 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 db1c7703a5fa..fb879eb5a29b 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 @@ def test_inference_with_prior_lora(self): 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