46
46
_torch_version ,
47
47
_transformers_version ,
48
48
compare_versions ,
49
- is_diffusers_version ,
50
49
is_openvino_tokenizers_version ,
51
50
is_openvino_version ,
52
51
is_tokenizers_version ,
@@ -104,10 +103,10 @@ def _set_runtime_options(
104
103
):
105
104
for model_name in models_and_export_configs .keys ():
106
105
_ , 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 = {}
108
108
if (
109
- "diffusers" in library_name
110
- or "text-generation" in task
109
+ "text-generation" in task
111
110
or ("image-text-to-text" in task and model_name == "language_model" )
112
111
or getattr (sub_export_config , "stateful" , False )
113
112
):
@@ -1014,45 +1013,29 @@ def _get_submodels_and_export_configs(
1014
1013
def get_diffusion_models_for_export_ext (
1015
1014
pipeline : "DiffusionPipeline" , int_dtype : str = "int64" , float_dtype : str = "fp32" , exporter : str = "openvino"
1016
1015
):
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 :
1052
1034
models_for_export = get_sd3_models_for_export (pipeline , exporter , int_dtype , float_dtype )
1053
- else :
1035
+ elif is_flux :
1054
1036
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" )
1056
1039
return None , models_for_export
1057
1040
1058
1041
@@ -1150,6 +1133,7 @@ def get_sd3_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1150
1133
int_dtype = int_dtype ,
1151
1134
float_dtype = float_dtype ,
1152
1135
)
1136
+ export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1153
1137
models_for_export ["text_encoder_3" ] = (text_encoder_3 , export_config )
1154
1138
1155
1139
return models_for_export
@@ -1187,6 +1171,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1187
1171
transformer_export_config = export_config_constructor (
1188
1172
pipeline .transformer .config , int_dtype = int_dtype , float_dtype = float_dtype
1189
1173
)
1174
+ transformer_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1190
1175
models_for_export ["transformer" ] = (transformer , transformer_export_config )
1191
1176
1192
1177
# 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):
1202
1187
vae_encoder_export_config = vae_config_constructor (
1203
1188
vae_encoder .config , int_dtype = int_dtype , float_dtype = float_dtype
1204
1189
)
1190
+ vae_encoder_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1205
1191
models_for_export ["vae_encoder" ] = (vae_encoder , vae_encoder_export_config )
1206
1192
1207
1193
# 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):
1217
1203
vae_decoder_export_config = vae_config_constructor (
1218
1204
vae_decoder .config , int_dtype = int_dtype , float_dtype = float_dtype
1219
1205
)
1206
+ vae_decoder_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1220
1207
models_for_export ["vae_decoder" ] = (vae_decoder , vae_decoder_export_config )
1221
1208
1222
1209
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):
1233
1220
int_dtype = int_dtype ,
1234
1221
float_dtype = float_dtype ,
1235
1222
)
1223
+ export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1236
1224
models_for_export ["text_encoder_2" ] = (text_encoder_2 , export_config )
1237
1225
1238
1226
return models_for_export
0 commit comments