Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7916966

Browse files
committedOct 21, 2024
use fp32 timesteps
1 parent 8b61c52 commit 7916966

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed
 

‎optimum/exporters/openvino/model_configs.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
DummyInputGenerator,
4545
DummyPastKeyValuesGenerator,
4646
DummyTextInputGenerator,
47+
DummyTimestepInputGenerator,
4748
DummyVisionInputGenerator,
4849
FalconDummyPastKeyValuesGenerator,
4950
MistralDummyPastKeyValuesGenerator,
@@ -1527,7 +1528,7 @@ def patch_model_for_export(
15271528

15281529

15291530
class PooledProjectionsDummyInputGenerator(DummyInputGenerator):
1530-
SUPPORTED_INPUT_NAMES = "pooled_projection"
1531+
SUPPORTED_INPUT_NAMES = "pooled_projections"
15311532

15321533
def __init__(
15331534
self,
@@ -1550,10 +1551,20 @@ def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int
15501551
return self.random_float_tensor(shape, framework=framework, dtype=float_dtype)
15511552

15521553

1554+
class DummyTransformerTimestpsInputGenerator(DummyTimestepInputGenerator):
1555+
def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int64", float_dtype: str = "fp32"):
1556+
if input_name == "timestep":
1557+
shape = [self.batch_size]
1558+
return self.random_float_tensor(shape, max_value=self.vocab_size, framework=framework, dtype=float_dtype)
1559+
return super().generate(input_name, framework, int_dtype, float_dtype)
1560+
1561+
15531562
@register_in_tasks_manager("sd3-transformer", *["semantic-segmentation"], library_name="diffusers")
1554-
class TransformerOpenVINOConfig(UNetOnnxConfig):
1555-
DUMMY_INPUT_GENERATOR_CLASSES = UNetOnnxConfig.DUMMY_INPUT_GENERATOR_CLASSES + (
1556-
PooledProjectionsDummyInputGenerator,
1563+
class SD3TransformerOpenVINOConfig(UNetOnnxConfig):
1564+
DUMMY_INPUT_GENERATOR_CLASSES = (
1565+
(DummyTransformerTimestpsInputGenerator,)
1566+
+ UNetOnnxConfig.DUMMY_INPUT_GENERATOR_CLASSES
1567+
+ (PooledProjectionsDummyInputGenerator,)
15571568
)
15581569
NORMALIZED_CONFIG_CLASS = NormalizedConfig.with_args(
15591570
image_size="sample_size",

‎tests/openvino/test_diffusion.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
OVPipelineForInpainting,
3636
OVPipelineForText2Image,
3737
)
38+
from optimum.intel.utils.import_utils import is_transformers_version
3839
from optimum.utils.testing_utils import require_diffusers
3940

4041

@@ -72,7 +73,10 @@ def _generate_images(height=128, width=128, batch_size=1, channel=3, input_type=
7273

7374

7475
class OVPipelineForText2ImageTest(unittest.TestCase):
75-
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency", "stable-diffusion-3"]
76+
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency"]
77+
if is_transformers_version(">=", "4.40.0"):
78+
SUPPORTED_ARCHITECTURES.append("stable-diffusion-3")
79+
CALLBACK_SUPPORT_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency"]
7680

7781
OVMODEL_CLASS = OVPipelineForText2Image
7882
AUTOMODEL_CLASS = AutoPipelineForText2Image
@@ -138,7 +142,7 @@ def test_compare_to_diffusers_pipeline(self, model_arch: str):
138142

139143
np.testing.assert_allclose(ov_output, diffusers_output, atol=6e-3, rtol=1e-2)
140144

141-
@parameterized.expand(["stable-diffusion", "stable-diffusion-xl", "latent-consistency"])
145+
@parameterized.expand(CALLBACK_SUPPORT_ARCHITECTURES)
142146
@require_diffusers
143147
def test_callback(self, model_arch: str):
144148
height, width, batch_size = 64, 128, 1
@@ -353,7 +357,9 @@ def test_textual_inversion(self):
353357

354358

355359
class OVPipelineForImage2ImageTest(unittest.TestCase):
356-
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency", "stable-diffusion-3"]
360+
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "latent-consistency"]
361+
if is_transformers_version(">=", "4.40.0"):
362+
SUPPORTED_ARCHITECTURES.append("stable-diffusion-3")
357363

358364
AUTOMODEL_CLASS = AutoPipelineForImage2Image
359365
OVMODEL_CLASS = OVPipelineForImage2Image
@@ -576,7 +582,10 @@ def test_textual_inversion(self):
576582

577583

578584
class OVPipelineForInpaintingTest(unittest.TestCase):
579-
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl", "stable-diffusion-3"]
585+
SUPPORTED_ARCHITECTURES = ["stable-diffusion", "stable-diffusion-xl"]
586+
587+
if is_transformers_version(">=", "4.40.0"):
588+
SUPPORTED_ARCHITECTURES.append("stable-diffusion-3")
580589

581590
AUTOMODEL_CLASS = AutoPipelineForInpainting
582591
OVMODEL_CLASS = OVPipelineForInpainting

‎tests/openvino/test_exporters_cli.py

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class OVCLIExportTestCase(unittest.TestCase):
9494
("stable-diffusion", 72, 195),
9595
("stable-diffusion-xl", 84, 331),
9696
("latent-consistency", 50, 135),
97+
("stable-diffusion-3", 84, 331),
9798
)
9899

99100
TEST_4BIT_CONFIGURATONS = [

‎tests/openvino/utils_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
"stable-diffusion-xl": (366, 34, 42, 66),
172172
"stable-diffusion-xl-refiner": (366, 34, 42, 66),
173173
"open-clip": (20, 28),
174+
"stable-diffusion-3": (366, 34, 42, 66),
174175
}
175176

176177

0 commit comments

Comments
 (0)
Please sign in to comment.