|
25 | 25 | from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
|
26 | 26 | from diffusers.utils import load_image
|
27 | 27 | from parameterized import parameterized
|
| 28 | +from transformers.testing_utils import slow |
28 | 29 | from utils_tests import MODEL_NAMES, SEED
|
29 | 30 |
|
30 | 31 | from optimum.intel.openvino import (
|
@@ -295,6 +296,29 @@ def test_height_width_properties(self, model_arch: str):
|
295 | 296 | self.assertEqual(ov_pipeline.height, height)
|
296 | 297 | self.assertEqual(ov_pipeline.width, width)
|
297 | 298 |
|
| 299 | + @slow |
| 300 | + @require_diffusers |
| 301 | + def test_textual_inversion(self): |
| 302 | + # for now we only test for stable-diffusion |
| 303 | + # this is very slow and costly to run right now |
| 304 | + |
| 305 | + model_id = "runwayml/stable-diffusion-v1-5" |
| 306 | + |
| 307 | + diffusers_pipeline = self.AUTOMODEL_CLASS.from_pretrained(model_id, safety_checker=None) |
| 308 | + diffusers_pipeline.load_textual_inversion("sd-concepts-library/cat-toy") |
| 309 | + |
| 310 | + ov_pipeline = self.OVMODEL_CLASS.from_pretrained(model_id, safety_checker=None) |
| 311 | + ov_pipeline.load_textual_inversion("sd-concepts-library/cat-toy") |
| 312 | + |
| 313 | + inputs = self.generate_inputs() |
| 314 | + inputs["prompt"] = "A <cat-toy> backpack" |
| 315 | + |
| 316 | + diffusers_output = diffusers_pipeline(**inputs, generator=get_generator("pt", SEED)).images |
| 317 | + ov_output = ov_pipeline(**inputs, generator=get_generator("pt", SEED)).images |
| 318 | + |
| 319 | + # TODO: investigate why it works but not numerically consistent with diffusers |
| 320 | + np.testing.assert_allclose(ov_output, diffusers_output, atol=1e-4, rtol=1e-2) |
| 321 | + |
298 | 322 |
|
299 | 323 | class OVPipelineForImage2ImageTest(unittest.TestCase):
|
300 | 324 | SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency"]
|
@@ -484,6 +508,29 @@ def test_height_width_properties(self, model_arch: str):
|
484 | 508 | self.assertEqual(ov_pipeline.height, height)
|
485 | 509 | self.assertEqual(ov_pipeline.width, width)
|
486 | 510 |
|
| 511 | + @slow |
| 512 | + @require_diffusers |
| 513 | + def test_textual_inversion(self): |
| 514 | + # for now we only test for stable-diffusion |
| 515 | + # this is very slow and costly to run right now |
| 516 | + |
| 517 | + model_id = "runwayml/stable-diffusion-v1-5" |
| 518 | + |
| 519 | + diffusers_pipeline = self.AUTOMODEL_CLASS.from_pretrained(model_id, safety_checker=None) |
| 520 | + diffusers_pipeline.load_textual_inversion("sd-concepts-library/cat-toy") |
| 521 | + |
| 522 | + ov_pipeline = self.OVMODEL_CLASS.from_pretrained(model_id, safety_checker=None) |
| 523 | + ov_pipeline.load_textual_inversion("sd-concepts-library/cat-toy") |
| 524 | + |
| 525 | + inputs = self.generate_inputs() |
| 526 | + inputs["prompt"] = "A <cat-toy> backpack" |
| 527 | + |
| 528 | + diffusers_output = diffusers_pipeline(**inputs, generator=get_generator("pt", SEED)).images |
| 529 | + ov_output = ov_pipeline(**inputs, generator=get_generator("pt", SEED)).images |
| 530 | + |
| 531 | + # TODO: investigate why it works but not numerically consistent with diffusers |
| 532 | + np.testing.assert_allclose(ov_output, diffusers_output, atol=1e-4, rtol=1e-2) |
| 533 | + |
487 | 534 |
|
488 | 535 | class OVPipelineForInpaintingTest(unittest.TestCase):
|
489 | 536 | SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl"]
|
@@ -677,3 +724,26 @@ def test_height_width_properties(self, model_arch: str):
|
677 | 724 | )
|
678 | 725 | self.assertEqual(ov_pipeline.height, height)
|
679 | 726 | self.assertEqual(ov_pipeline.width, width)
|
| 727 | + |
| 728 | + @slow |
| 729 | + @require_diffusers |
| 730 | + def test_textual_inversion(self): |
| 731 | + # for now we only test for stable-diffusion |
| 732 | + # this is very slow and costly to run right now |
| 733 | + |
| 734 | + model_id = "runwayml/stable-diffusion-v1-5" |
| 735 | + |
| 736 | + diffusers_pipeline = self.AUTOMODEL_CLASS.from_pretrained(model_id, safety_checker=None) |
| 737 | + diffusers_pipeline.load_textual_inversion("sd-concepts-library/cat-toy") |
| 738 | + |
| 739 | + ov_pipeline = self.OVMODEL_CLASS.from_pretrained(model_id, safety_checker=None) |
| 740 | + ov_pipeline.load_textual_inversion("sd-concepts-library/cat-toy") |
| 741 | + |
| 742 | + inputs = self.generate_inputs() |
| 743 | + inputs["prompt"] = "A <cat-toy> backpack" |
| 744 | + |
| 745 | + diffusers_output = diffusers_pipeline(**inputs, generator=get_generator("pt", SEED)).images |
| 746 | + ov_output = ov_pipeline(**inputs, generator=get_generator("pt", SEED)).images |
| 747 | + |
| 748 | + # TODO: investigate why it works but not numerically consistent with diffusers |
| 749 | + np.testing.assert_allclose(ov_output, diffusers_output, atol=1e-4, rtol=1e-2) |
0 commit comments