Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
a-r-r-o-w committed Feb 15, 2024
1 parent 08d6b15 commit 6744cac
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tests/pipelines/controlnet/test_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_controlnet_lcm_custom_timesteps(self):


class StableDiffusionMultiControlNetPipelineFastTests(
PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
IPAdapterTesterMixin, PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
):
pipeline_class = StableDiffusionControlNetPipeline
params = TEXT_TO_IMAGE_PARAMS
Expand Down Expand Up @@ -495,7 +495,7 @@ def test_inference_multiple_prompt_input(self):


class StableDiffusionMultiControlNetOneModelPipelineFastTests(
PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
IPAdapterTesterMixin, PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
):
pipeline_class = StableDiffusionControlNetPipeline
params = TEXT_TO_IMAGE_PARAMS
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/controlnet/test_controlnet_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_inference_batch_single_identical(self):


class StableDiffusionMultiControlNetPipelineFastTests(
PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
IPAdapterTesterMixin, PipelineTesterMixin, PipelineKarrasSchedulerTesterMixin, unittest.TestCase
):
pipeline_class = StableDiffusionControlNetImg2ImgPipeline
params = TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"height", "width"}
Expand Down
13 changes: 2 additions & 11 deletions tests/pipelines/controlnet/test_controlnet_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,14 @@
TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
TEXT_TO_IMAGE_IMAGE_PARAMS,
)
from ..test_pipelines_common import (
IPAdapterTesterMixin,
PipelineKarrasSchedulerTesterMixin,
PipelineLatentTesterMixin,
PipelineTesterMixin,
)
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()


class ControlNetInpaintPipelineFastTests(
IPAdapterTesterMixin,
PipelineLatentTesterMixin,
PipelineKarrasSchedulerTesterMixin,
PipelineTesterMixin,
unittest.TestCase,
PipelineLatentTesterMixin, PipelineKarrasSchedulerTesterMixin, PipelineTesterMixin, unittest.TestCase
):
pipeline_class = StableDiffusionControlNetInpaintPipeline
params = TEXT_GUIDED_IMAGE_INPAINTING_PARAMS
Expand Down
8 changes: 5 additions & 3 deletions tests/pipelines/test_pipelines_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ def test_pipeline_signature(self):
)

def _get_dummy_image_embeds(self, cross_attention_dim: int = 32):
return torch.zeros((2, 1, cross_attention_dim), device=torch_device)
return torch.randn((2, 1, cross_attention_dim), device=torch_device)

def _modify_inputs_for_ip_adapter_test(self, inputs: Dict[str, Any]):
inputs["output_type"] = "np"
inputs["return_dict"] = False
if "image" in inputs.keys():
inputs["num_inference_steps"] = 4
return inputs

def test_ip_adapter(self, expected_max_diff: float = 1e-4):
Expand All @@ -114,7 +116,7 @@ def test_ip_adapter(self, expected_max_diff: float = 1e-4):
# forward pass with single ip adapter, but with scale of adapter weights
inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device))
inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)]
pipe.set_ip_adapter_scale(1.0)
pipe.set_ip_adapter_scale(42.0)
output_with_adapter_scale = pipe(**inputs)[0]

pipe.unet._load_ip_adapter_weights([adapter_state_dict_1, adapter_state_dict_2])
Expand All @@ -128,7 +130,7 @@ def test_ip_adapter(self, expected_max_diff: float = 1e-4):
# forward pass with multi ip adapter, but with scale of adapter weights
inputs = self._modify_inputs_for_ip_adapter_test(self.get_dummy_inputs(torch_device))
inputs["ip_adapter_image_embeds"] = [self._get_dummy_image_embeds(cross_attention_dim)] * 2
pipe.set_ip_adapter_scale([0.5, 0.5])
pipe.set_ip_adapter_scale([42.0, 42.0])
output_with_multi_adapter_scale = pipe(**inputs)[0]

max_diff_without_adapter_scale = np.abs(output_without_adapter_scale - output_without_adapter).max()
Expand Down

0 comments on commit 6744cac

Please sign in to comment.