Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sayakpaul committed Feb 13, 2025
1 parent b148bab commit 8c004ea
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 8 deletions.
8 changes: 8 additions & 0 deletions tests/pipelines/animatediff/test_animatediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,14 @@ def test_xformers_attention_forwardGenerator_pass(self):
def test_vae_slicing(self):
return super().test_vae_slicing(image_count=2)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"num_images_per_prompt": 1,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@slow
@require_torch_accelerator
Expand Down
8 changes: 8 additions & 0 deletions tests/pipelines/animatediff/test_animatediff_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,11 @@ def test_vae_slicing(self, video_count=2):
output_2 = pipe(**inputs)

assert np.abs(output_2[0].flatten() - output_1[0].flatten()).max() < 1e-2

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"num_images_per_prompt": 1,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
4 changes: 4 additions & 0 deletions tests/pipelines/animatediff/test_animatediff_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,7 @@ def test_xformers_attention_forwardGenerator_pass(self):

max_diff = np.abs(to_np(output_with_offload) - to_np(output_without_offload)).max()
self.assertLess(max_diff, 1e-4, "XFormers attention should not affect the inference results")

@unittest.skip("Test currently not supported.")
def test_encode_prompt_works_in_isolation(self):
pass
8 changes: 8 additions & 0 deletions tests/pipelines/animatediff/test_animatediff_sparsectrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,11 @@ def test_free_init_with_schedulers(self):

def test_vae_slicing(self):
return super().test_vae_slicing(image_count=2)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"num_images_per_prompt": 1,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
8 changes: 8 additions & 0 deletions tests/pipelines/animatediff/test_animatediff_video2video.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,11 @@ def test_free_noise_multi_prompt(self):
inputs["strength"] = 0.5
inputs["prompt"] = {0: "Caterpillar on a leaf", 10: "Butterfly on a leaf", 42: "Error on a leaf"}
pipe(**inputs).frames[0]

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"num_images_per_prompt": 1,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,11 @@ def test_free_noise_multi_prompt(self):
inputs["strength"] = 0.5
inputs["prompt"] = {0: "Caterpillar on a leaf", 10: "Butterfly on a leaf", 42: "Error on a leaf"}
pipe(**inputs).frames[0]

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"num_images_per_prompt": 1,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
4 changes: 4 additions & 0 deletions tests/pipelines/blipdiffusion/test_blipdiffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,7 @@ def test_blipdiffusion(self):
assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
), f" expected_slice {image_slice.flatten()}, but got {image_slice.flatten()}"

@unittest.skip("Test not supported because of complexities in deriving query_embeds.")
def test_encode_prompt_works_in_isolation(self):
pass
21 changes: 21 additions & 0 deletions tests/pipelines/controlnet/test_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ def test_controlnet_lcm_custom_timesteps(self):

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


class StableDiffusionMultiControlNetPipelineFastTests(
IPAdapterTesterMixin, PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
Expand Down Expand Up @@ -521,6 +528,13 @@ def test_inference_multiple_prompt_input(self):

assert image.shape == (4, 64, 64, 3)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


class StableDiffusionMultiControlNetOneModelPipelineFastTests(
IPAdapterTesterMixin, PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
Expand Down Expand Up @@ -706,6 +720,13 @@ def test_save_pretrained_raise_not_implemented_exception(self):
except NotImplementedError:
pass

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@slow
@require_torch_accelerator
Expand Down
4 changes: 4 additions & 0 deletions tests/pipelines/controlnet/test_controlnet_blip_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@ def test_blipdiffusion_controlnet(self):
assert (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}"

@unittest.skip("Test not supported because of complexities in deriving query_embeds.")
def test_encode_prompt_works_in_isolation(self):
pass
14 changes: 14 additions & 0 deletions tests/pipelines/controlnet/test_controlnet_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ def test_xformers_attention_forwardGenerator_pass(self):
def test_inference_batch_single_identical(self):
self._test_inference_batch_single_identical(expected_max_diff=2e-3)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


class StableDiffusionMultiControlNetPipelineFastTests(
IPAdapterTesterMixin, PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
Expand Down Expand Up @@ -391,6 +398,13 @@ def test_save_pretrained_raise_not_implemented_exception(self):
except NotImplementedError:
pass

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@slow
@require_torch_accelerator
Expand Down
7 changes: 7 additions & 0 deletions tests/pipelines/controlnet/test_controlnet_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ def test_save_pretrained_raise_not_implemented_exception(self):
except NotImplementedError:
pass

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@slow
@require_torch_accelerator
Expand Down
8 changes: 8 additions & 0 deletions tests/pipelines/pag/test_pag_animatediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,11 @@ def test_pag_applied_layers(self):
pag_layers = ["motion_modules.42"]
with self.assertRaises(ValueError):
pipe._set_pag_attn_processor(pag_applied_layers=pag_layers, do_classifier_free_guidance=False)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"num_images_per_prompt": 1,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
11 changes: 8 additions & 3 deletions tests/pipelines/pag/test_pag_controlnet_sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
StableDiffusionControlNetPipeline,
UNet2DConditionModel,
)
from diffusers.utils.testing_utils import (
enable_full_determinism,
)
from diffusers.utils.testing_utils import enable_full_determinism, torch_device
from diffusers.utils.torch_utils import randn_tensor

from ..pipeline_params import (
Expand Down Expand Up @@ -246,3 +244,10 @@ def test_pag_uncond(self):

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
12 changes: 8 additions & 4 deletions tests/pipelines/pag/test_pag_controlnet_sd_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
StableDiffusionControlNetPAGInpaintPipeline,
UNet2DConditionModel,
)
from diffusers.utils.testing_utils import (
enable_full_determinism,
floats_tensor,
)
from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, torch_device
from diffusers.utils.torch_utils import randn_tensor

from ..pipeline_params import (
Expand Down Expand Up @@ -243,3 +240,10 @@ def test_pag_uncond(self):

max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
7 changes: 7 additions & 0 deletions tests/pipelines/pag/test_pag_hunyuan_dit.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,10 @@ def test_pag_applied_layers(self):
pag_layers = ["blocks.0", r"blocks\.1"]
pipe._set_pag_attn_processor(pag_applied_layers=pag_layers, do_classifier_free_guidance=False)
assert len(pipe.pag_attn_processors) == 2

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)
3 changes: 3 additions & 0 deletions tests/pipelines/pag/test_pag_kolors.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,6 @@ def test_pag_inference(self):

def test_inference_batch_single_identical(self):
self._test_inference_batch_single_identical(expected_max_diff=3e-3)

def test_encode_prompt_works_in_isolation(self):
return super().test_encode_prompt_works_in_isolation(atol=1e-3, rtol=1e-3)
7 changes: 7 additions & 0 deletions tests/pipelines/pag/test_pag_sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ def test_pag_inference(self):
max_diff = np.abs(image_slice.flatten() - expected_slice).max()
self.assertLessEqual(max_diff, 1e-3)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@slow
@require_torch_gpu
Expand Down
7 changes: 7 additions & 0 deletions tests/pipelines/pag/test_pag_sd_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ def test_pag_inference(self):
max_diff = np.abs(image_slice.flatten() - expected_slice).max()
self.assertLessEqual(max_diff, 1e-3)

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@slow
@require_torch_gpu
Expand Down
7 changes: 7 additions & 0 deletions tests/pipelines/pag/test_pag_sd_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ def test_pag_inference(self):
max_diff = np.abs(image_slice.flatten() - expected_slice).max()
assert max_diff < 1e-3, f"output is different from expected, {image_slice.flatten()}"

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict, atol=1e-3, rtol=1e-3)


@slow
@require_torch_gpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ def test_adapter_lcm_custom_timesteps(self):

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


class StableDiffusionFullAdapterPipelineFastTests(
AdapterTests, PipelineTesterMixin, PipelineFromPipeTesterMixin, unittest.TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ def test_attention_slicing_forward_pass(self):

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(batch_size=3, expected_max_diff=3e-3)

@unittest.skip("Test not supported as tokenizer is used for parsing bounding boxes.")
def test_encode_prompt_works_in_isolation(self):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ def test_stable_diffusion_panorama_pndm(self):

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2

def test_encode_prompt_works_in_isolation(self):
extra_required_param_value_dict = {
"device": torch.device(torch_device).type,
"do_classifier_free_guidance": self.get_dummy_inputs(device=torch_device).get("guidance_scale", 1.0) > 1.0,
}
return super().test_encode_prompt_works_in_isolation(extra_required_param_value_dict)


@nightly
@require_torch_gpu
Expand Down
7 changes: 6 additions & 1 deletion tests/pipelines/test_pipelines_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2080,13 +2080,18 @@ def test_encode_prompt_works_in_isolation(self, extra_required_param_value_dict=
and pipe_call_parameters.get("prompt_embeds").default is None
):
pipe_without_tes_inputs.update({"prompt": None})

pipe_out = pipe_without_text_encoders(**pipe_without_tes_inputs)[0]

# Compare against regular pipeline outputs.
full_pipe = self.pipeline_class(**components).to(torch_device)
inputs = self.get_dummy_inputs(torch_device)
pipe_out_2 = full_pipe(**inputs)[0]
self.assertTrue(np.allclose(pipe_out, pipe_out_2, atol=atol, rtol=rtol))

if isinstance(pipe_out, np.ndarray) and isinstance(pipe_out_2, np.ndarray):
self.assertTrue(np.allclose(pipe_out, pipe_out_2, atol=atol, rtol=rtol))
elif isinstance(pipe_out, torch.Tensor) and isinstance(pipe_out_2, torch.Tensor):
self.assertTrue(torch.allclose(pipe_out, pipe_out_2, atol=atol, rtol=rtol))

def test_StableDiffusionMixin_component(self):
"""Any pipeline that have LDMFuncMixin should have vae and unet components."""
Expand Down

0 comments on commit 8c004ea

Please sign in to comment.