4646 _torch_version ,
4747 _transformers_version ,
4848 compare_versions ,
49- is_diffusers_version ,
5049 is_openvino_tokenizers_version ,
5150 is_openvino_version ,
5251 is_tokenizers_version ,
@@ -104,10 +103,10 @@ def _set_runtime_options(
104103):
105104 for model_name in models_and_export_configs .keys ():
106105 _ , sub_export_config = models_and_export_configs [model_name ]
107- sub_export_config .runtime_options = {}
106+ if not hasattr (sub_export_config , "runtime_options" ):
107+ sub_export_config .runtime_options = {}
108108 if (
109- "diffusers" in library_name
110- or "text-generation" in task
109+ "text-generation" in task
111110 or ("image-text-to-text" in task and model_name == "language_model" )
112111 or getattr (sub_export_config , "stateful" , False )
113112 ):
@@ -1014,45 +1013,29 @@ def _get_submodels_and_export_configs(
10141013def get_diffusion_models_for_export_ext (
10151014 pipeline : "DiffusionPipeline" , int_dtype : str = "int64" , float_dtype : str = "fp32" , exporter : str = "openvino"
10161015):
1017- if is_diffusers_version (">=" , "0.29.0" ):
1018- from diffusers import StableDiffusion3Img2ImgPipeline , StableDiffusion3Pipeline
1019-
1020- sd3_pipes = [StableDiffusion3Pipeline , StableDiffusion3Img2ImgPipeline ]
1021- if is_diffusers_version (">=" , "0.30.0" ):
1022- from diffusers import StableDiffusion3InpaintPipeline
1023-
1024- sd3_pipes .append (StableDiffusion3InpaintPipeline )
1025-
1026- is_sd3 = isinstance (pipeline , tuple (sd3_pipes ))
1027- else :
1028- is_sd3 = False
1029-
1030- if is_diffusers_version (">=" , "0.30.0" ):
1031- from diffusers import FluxPipeline
1032-
1033- flux_pipes = [FluxPipeline ]
1034-
1035- if is_diffusers_version (">=" , "0.31.0" ):
1036- from diffusers import FluxImg2ImgPipeline , FluxInpaintPipeline
1037-
1038- flux_pipes .extend ([FluxPipeline , FluxImg2ImgPipeline , FluxInpaintPipeline ])
1039-
1040- if is_diffusers_version (">=" , "0.32.0" ):
1041- from diffusers import FluxFillPipeline
1042-
1043- flux_pipes .append (FluxFillPipeline )
1044-
1045- is_flux = isinstance (pipeline , tuple (flux_pipes ))
1046- else :
1047- is_flux = False
1048-
1049- if not is_sd3 and not is_flux :
1050- return None , get_diffusion_models_for_export (pipeline , int_dtype , float_dtype , exporter )
1051- if is_sd3 :
1016+ is_sdxl = pipeline .__class__ .__name__ .startswith ("StableDiffusionXL" )
1017+ is_sd3 = pipeline .__class__ .__name__ .startswith ("StableDiffusion3" )
1018+ is_flux = pipeline .__class__ .__name__ .startswith ("Flux" )
1019+ is_sd = pipeline .__class__ .__name__ .startswith ("StableDiffusion" ) and not is_sd3
1020+ is_lcm = pipeline .__class__ .__name__ .startswith ("LatentConsistencyModel" )
1021+
1022+ if is_sd or is_sdxl or is_lcm :
1023+ models_for_export = get_diffusion_models_for_export (pipeline , int_dtype , float_dtype , exporter )
1024+ if is_sdxl and pipeline .vae .config .force_upcast :
1025+ models_for_export ["vae_encoder" ][1 ].runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "128.0" }
1026+ models_for_export ["vae_decoder" ][1 ].runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "128.0" }
1027+
1028+ # only SD 2.1 has overflow issue, it uses different prediction_type than other models
1029+ if is_sd and pipeline .scheduler .config .prediction_type == "v_prediction" :
1030+ models_for_export ["vae_encoder" ][1 ].runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1031+ models_for_export ["vae_decoder" ][1 ].runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1032+
1033+ elif is_sd3 :
10521034 models_for_export = get_sd3_models_for_export (pipeline , exporter , int_dtype , float_dtype )
1053- else :
1035+ elif is_flux :
10541036 models_for_export = get_flux_models_for_export (pipeline , exporter , int_dtype , float_dtype )
1055-
1037+ else :
1038+ raise ValueError (f"Unsupported pipeline type `{ pipeline .__class__ .__name__ } ` provided" )
10561039 return None , models_for_export
10571040
10581041
@@ -1150,6 +1133,7 @@ def get_sd3_models_for_export(pipeline, exporter, int_dtype, float_dtype):
11501133 int_dtype = int_dtype ,
11511134 float_dtype = float_dtype ,
11521135 )
1136+ export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
11531137 models_for_export ["text_encoder_3" ] = (text_encoder_3 , export_config )
11541138
11551139 return models_for_export
@@ -1187,6 +1171,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
11871171 transformer_export_config = export_config_constructor (
11881172 pipeline .transformer .config , int_dtype = int_dtype , float_dtype = float_dtype
11891173 )
1174+ transformer_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
11901175 models_for_export ["transformer" ] = (transformer , transformer_export_config )
11911176
11921177 # VAE Encoder https://github.com/huggingface/diffusers/blob/v0.11.1/src/diffusers/models/vae.py#L565
@@ -1202,6 +1187,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
12021187 vae_encoder_export_config = vae_config_constructor (
12031188 vae_encoder .config , int_dtype = int_dtype , float_dtype = float_dtype
12041189 )
1190+ vae_encoder_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
12051191 models_for_export ["vae_encoder" ] = (vae_encoder , vae_encoder_export_config )
12061192
12071193 # VAE Decoder https://github.com/huggingface/diffusers/blob/v0.11.1/src/diffusers/models/vae.py#L600
@@ -1217,6 +1203,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
12171203 vae_decoder_export_config = vae_config_constructor (
12181204 vae_decoder .config , int_dtype = int_dtype , float_dtype = float_dtype
12191205 )
1206+ vae_decoder_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
12201207 models_for_export ["vae_decoder" ] = (vae_decoder , vae_decoder_export_config )
12211208
12221209 text_encoder_2 = getattr (pipeline , "text_encoder_2" , None )
@@ -1233,6 +1220,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
12331220 int_dtype = int_dtype ,
12341221 float_dtype = float_dtype ,
12351222 )
1223+ export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
12361224 models_for_export ["text_encoder_2" ] = (text_encoder_2 , export_config )
12371225
12381226 return models_for_export
0 commit comments