Skip to content

Commit 3cdeb6e

Browse files
added tests
1 parent e7c9daf commit 3cdeb6e

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

optimum/intel/openvino/loaders.py

-6
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ def load_textual_inversion(
180180
force_download (`bool`, *optional*, defaults to `False`):
181181
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
182182
cached versions if they exist.
183-
resume_download (`bool`, *optional*, defaults to `False`):
184-
Whether or not to resume downloading the model weights and configuration files. If set to `False`, any
185-
incompletely downloaded files are deleted.
186183
proxies (`Dict[str, str]`, *optional*):
187184
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
188185
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
@@ -257,7 +254,6 @@ def load_textual_inversion(
257254

258255
cache_dir = kwargs.pop("cache_dir", DIFFUSERS_CACHE)
259256
force_download = kwargs.pop("force_download", False)
260-
resume_download = kwargs.pop("resume_download", False)
261257
proxies = kwargs.pop("proxies", None)
262258
local_files_only = kwargs.pop("local_files_only", HF_HUB_OFFLINE)
263259
use_auth_token = kwargs.pop("use_auth_token", None)
@@ -329,7 +325,6 @@ def load_textual_inversion(
329325
weights_name=weight_name or TEXTUAL_INVERSION_NAME_SAFE,
330326
cache_dir=cache_dir,
331327
force_download=force_download,
332-
resume_download=resume_download,
333328
proxies=proxies,
334329
local_files_only=local_files_only,
335330
use_auth_token=token, # still uses use_auth_token
@@ -350,7 +345,6 @@ def load_textual_inversion(
350345
weights_name=weight_name or TEXTUAL_INVERSION_NAME,
351346
cache_dir=cache_dir,
352347
force_download=force_download,
353-
resume_download=resume_download,
354348
proxies=proxies,
355349
local_files_only=local_files_only,
356350
use_auth_token=token, # still uses use_auth_token

optimum/intel/openvino/modeling_diffusion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464

6565
from ...exporters.openvino import main_export
6666
from .configuration import OVConfig, OVQuantizationMethod, OVWeightQuantizationConfig
67-
from .modeling_base import OVBaseModel
6867
from .loaders import OVTextualInversionLoaderMixin
68+
from .modeling_base import OVBaseModel
6969
from .utils import (
7070
ONNX_WEIGHTS_NAME,
7171
OV_TO_PT_TYPE,

tests/openvino/test_diffusion.py

+70
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
2626
from diffusers.utils import load_image
2727
from parameterized import parameterized
28+
from transformers.testing_utils import slow
2829
from utils_tests import MODEL_NAMES, SEED
2930

3031
from optimum.intel.openvino import (
@@ -295,6 +296,29 @@ def test_height_width_properties(self, model_arch: str):
295296
self.assertEqual(ov_pipeline.height, height)
296297
self.assertEqual(ov_pipeline.width, width)
297298

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+
298322

299323
class OVPipelineForImage2ImageTest(unittest.TestCase):
300324
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency"]
@@ -484,6 +508,29 @@ def test_height_width_properties(self, model_arch: str):
484508
self.assertEqual(ov_pipeline.height, height)
485509
self.assertEqual(ov_pipeline.width, width)
486510

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+
487534

488535
class OVPipelineForInpaintingTest(unittest.TestCase):
489536
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl"]
@@ -677,3 +724,26 @@ def test_height_width_properties(self, model_arch: str):
677724
)
678725
self.assertEqual(ov_pipeline.height, height)
679726
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

Comments
 (0)