28
28
from diffusers .utils import load_image
29
29
from diffusers .utils .testing_utils import floats_tensor
30
30
from openvino .runtime .ie_api import CompiledModel
31
- from packaging .version import Version , parse
32
31
from parameterized import parameterized
33
32
from utils_tests import MODEL_NAMES , SEED
34
33
46
45
OVModelVaeDecoder ,
47
46
OVModelVaeEncoder ,
48
47
)
49
- from optimum .onnxruntime import (
50
- ORTStableDiffusionImg2ImgPipeline ,
51
- ORTStableDiffusionInpaintPipeline ,
52
- ORTStableDiffusionXLImg2ImgPipeline ,
53
- ORTStableDiffusionXLPipeline ,
54
- )
55
- from optimum .utils .import_utils import _diffusers_version
48
+ from optimum .intel .utils .import_utils import is_diffusers_version
49
+ from optimum .utils .import_utils import is_onnxruntime_available
56
50
57
51
58
52
F32_CONFIG = {"INFERENCE_PRECISION_HINT" : "f32" }
@@ -167,7 +161,6 @@ def generate_inputs(self, height=128, width=128, batch_size=1):
167
161
class OVStableDiffusionImg2ImgPipelineTest (OVStableDiffusionPipelineBaseTest ):
168
162
SUPPORTED_ARCHITECTURES = ("stable-diffusion" ,)
169
163
MODEL_CLASS = OVStableDiffusionImg2ImgPipeline
170
- ORT_MODEL_CLASS = ORTStableDiffusionImg2ImgPipeline
171
164
TASK = "image-to-image"
172
165
173
166
@parameterized .expand (SUPPORTED_ARCHITECTURES )
@@ -298,11 +291,13 @@ def test_height_width_properties(self, model_arch: str):
298
291
class OVStableDiffusionInpaintPipelineTest (OVStableDiffusionPipelineBaseTest ):
299
292
SUPPORTED_ARCHITECTURES = ("stable-diffusion" ,)
300
293
MODEL_CLASS = OVStableDiffusionInpaintPipeline
301
- ORT_MODEL_CLASS = ORTStableDiffusionInpaintPipeline
302
294
TASK = "inpaint"
303
295
304
296
@parameterized .expand (SUPPORTED_ARCHITECTURES )
297
+ @unittest .skipIf (not is_onnxruntime_available (), "this test requires onnxruntime" )
305
298
def test_compare_diffusers_pipeline (self , model_arch : str ):
299
+ from optimum .onnxruntime import ORTStableDiffusionInpaintPipeline
300
+
306
301
model_id = MODEL_NAMES [model_arch ]
307
302
pipeline = self .MODEL_CLASS .from_pretrained (model_id , export = True , ov_config = F32_CONFIG )
308
303
batch_size , num_images , height , width = 1 , 1 , 64 , 64
@@ -329,7 +324,7 @@ def test_compare_diffusers_pipeline(self, model_arch: str):
329
324
outputs = pipeline (** inputs , latents = latents ).images
330
325
self .assertEqual (outputs .shape , (batch_size * num_images , height , width , 3 ))
331
326
332
- ort_pipeline = self . ORT_MODEL_CLASS .from_pretrained (model_id , export = True )
327
+ ort_pipeline = ORTStableDiffusionInpaintPipeline .from_pretrained (model_id , export = True )
333
328
ort_outputs = ort_pipeline (** inputs , latents = latents ).images
334
329
self .assertTrue (np .allclose (outputs , ort_outputs , atol = 1e-1 ))
335
330
@@ -358,7 +353,6 @@ def generate_inputs(self, height=128, width=128, batch_size=1):
358
353
class OVtableDiffusionXLPipelineTest (unittest .TestCase ):
359
354
SUPPORTED_ARCHITECTURES = ("stable-diffusion-xl" ,)
360
355
MODEL_CLASS = OVStableDiffusionXLPipeline
361
- ORT_MODEL_CLASS = ORTStableDiffusionXLPipeline
362
356
PT_MODEL_CLASS = StableDiffusionXLPipeline
363
357
TASK = "text-to-image"
364
358
@@ -444,7 +438,6 @@ def test_num_images_per_prompt_static_model(self, model_arch: str):
444
438
class OVStableDiffusionXLImg2ImgPipelineTest (unittest .TestCase ):
445
439
SUPPORTED_ARCHITECTURES = ("stable-diffusion-xl" , "stable-diffusion-xl-refiner" )
446
440
MODEL_CLASS = OVStableDiffusionXLImg2ImgPipeline
447
- ORT_MODEL_CLASS = ORTStableDiffusionXLImg2ImgPipeline
448
441
PT_MODEL_CLASS = StableDiffusionXLImg2ImgPipeline
449
442
TASK = "image-to-image"
450
443
@@ -489,7 +482,7 @@ class OVLatentConsistencyModelPipelineTest(unittest.TestCase):
489
482
TASK = "text-to-image"
490
483
491
484
@parameterized .expand (SUPPORTED_ARCHITECTURES )
492
- @unittest .skipIf (parse ( _diffusers_version ) <= Version ( "0.21.4" ), "not supported with this diffusers version" )
485
+ @unittest .skipIf (is_diffusers_version ( "<=" , "0.21.4" ), "not supported with this diffusers version" )
493
486
def test_compare_to_diffusers (self , model_arch : str ):
494
487
ov_pipeline = self .MODEL_CLASS .from_pretrained (MODEL_NAMES [model_arch ], export = True , ov_config = F32_CONFIG )
495
488
self .assertIsInstance (ov_pipeline .text_encoder , OVModelTextEncoder )
@@ -532,7 +525,7 @@ def test_compare_to_diffusers(self, model_arch: str):
532
525
self .assertEqual (pipeline .device .type , ov_pipeline .device )
533
526
534
527
@parameterized .expand (SUPPORTED_ARCHITECTURES )
535
- @unittest .skipIf (parse ( _diffusers_version ) <= Version ( "0.21.4" ), "not supported with this diffusers version" )
528
+ @unittest .skipIf (is_diffusers_version ( "<=" , "0.21.4" ), "not supported with this diffusers version" )
536
529
def test_num_images_per_prompt_static_model (self , model_arch : str ):
537
530
model_id = MODEL_NAMES [model_arch ]
538
531
pipeline = self .MODEL_CLASS .from_pretrained (model_id , export = True , compile = False , dynamic_shapes = False )
0 commit comments