@@ -101,12 +101,9 @@ def _set_runtime_options(
101
101
):
102
102
for model_name in models_and_export_configs .keys ():
103
103
_ , sub_export_config = models_and_export_configs [model_name ]
104
- sub_export_config .runtime_options = {}
105
- if (
106
- "diffusers" in library_name
107
- or "text-generation" in task
108
- or ("image-text-to-text" in task and model_name == "language_model" )
109
- ):
104
+ if not hasattr (sub_export_config , "runtime_options" ):
105
+ sub_export_config .runtime_options = {}
106
+ if "text-generation" in task or ("image-text-to-text" in task and model_name == "language_model" ):
110
107
sub_export_config .runtime_options ["ACTIVATIONS_SCALE_FACTOR" ] = "8.0"
111
108
if not quantized_model and (
112
109
"text-generation" in task or ("image-text-to-text" in task and model_name == "language_model" )
@@ -999,41 +996,22 @@ def _get_submodels_and_export_configs(
999
996
def get_diffusion_models_for_export_ext (
1000
997
pipeline : "DiffusionPipeline" , int_dtype : str = "int64" , float_dtype : str = "fp32" , exporter : str = "openvino"
1001
998
):
1002
- if is_diffusers_version (">=" , "0.29.0" ):
1003
- from diffusers import StableDiffusion3Img2ImgPipeline , StableDiffusion3Pipeline
1004
-
1005
- sd3_pipes = [StableDiffusion3Pipeline , StableDiffusion3Img2ImgPipeline ]
1006
- if is_diffusers_version (">=" , "0.30.0" ):
1007
- from diffusers import StableDiffusion3InpaintPipeline
1008
-
1009
- sd3_pipes .append (StableDiffusion3InpaintPipeline )
1010
-
1011
- is_sd3 = isinstance (pipeline , tuple (sd3_pipes ))
1012
- else :
1013
- is_sd3 = False
1014
-
1015
- if is_diffusers_version (">=" , "0.30.0" ):
1016
- from diffusers import FluxPipeline
999
+ is_sdxl = pipeline .__class__ .__name__ .startswith ("StableDiffusionXL" )
1000
+ is_sd3 = pipeline .__class__ .__name__ .startswith ("StableDiffusion3" )
1001
+ is_flux = pipeline .__class__ .__name__ .startswith ("Flux" )
1002
+ is_sd = pipeline .__class__ .__name__ .startswith ("StableDiffusion" ) and not is_sd3
1017
1003
1018
- flux_pipes = [FluxPipeline ]
1019
-
1020
- if is_diffusers_version (">=" , "0.31.0" ):
1021
- from diffusers import FluxImg2ImgPipeline , FluxInpaintPipeline
1022
-
1023
- flux_pipes .extend ([FluxPipeline , FluxImg2ImgPipeline , FluxInpaintPipeline ])
1024
-
1025
- if is_diffusers_version (">=" , "0.32.0" ):
1026
- from diffusers import FluxFillPipeline
1027
-
1028
- flux_pipes .append (FluxFillPipeline )
1004
+ if not is_sd3 and not is_flux :
1005
+ models_for_export = get_diffusion_models_for_export (pipeline , int_dtype , float_dtype , exporter )
1006
+ if is_sdxl and pipeline .vae .config .force_upcast :
1007
+ models_for_export ["vae_encoder" ][1 ].runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "128.0" }
1008
+ models_for_export ["vae_decoder" ][1 ].runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "128.0" }
1029
1009
1030
- is_flux = isinstance ( pipeline , tuple ( flux_pipes ))
1031
- else :
1032
- is_flux = False
1010
+ if is_sd and pipeline . scheduler . config . prediction_type == "v_prediction" :
1011
+ models_for_export [ "vae_encoder" ][ 1 ]. runtime_options = { "ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1012
+ models_for_export [ "vae_decoder" ][ 1 ]. runtime_options = { "ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1033
1013
1034
- if not is_sd3 and not is_flux :
1035
- return None , get_diffusion_models_for_export (pipeline , int_dtype , float_dtype , exporter )
1036
- if is_sd3 :
1014
+ elif is_sd3 :
1037
1015
models_for_export = get_sd3_models_for_export (pipeline , exporter , int_dtype , float_dtype )
1038
1016
else :
1039
1017
models_for_export = get_flux_models_for_export (pipeline , exporter , int_dtype , float_dtype )
@@ -1135,6 +1113,7 @@ def get_sd3_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1135
1113
int_dtype = int_dtype ,
1136
1114
float_dtype = float_dtype ,
1137
1115
)
1116
+ export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1138
1117
models_for_export ["text_encoder_3" ] = (text_encoder_3 , export_config )
1139
1118
1140
1119
return models_for_export
@@ -1172,6 +1151,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1172
1151
transformer_export_config = export_config_constructor (
1173
1152
pipeline .transformer .config , int_dtype = int_dtype , float_dtype = float_dtype
1174
1153
)
1154
+ transformer_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1175
1155
models_for_export ["transformer" ] = (transformer , transformer_export_config )
1176
1156
1177
1157
# VAE Encoder https://github.com/huggingface/diffusers/blob/v0.11.1/src/diffusers/models/vae.py#L565
@@ -1187,6 +1167,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1187
1167
vae_encoder_export_config = vae_config_constructor (
1188
1168
vae_encoder .config , int_dtype = int_dtype , float_dtype = float_dtype
1189
1169
)
1170
+ vae_encoder_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1190
1171
models_for_export ["vae_encoder" ] = (vae_encoder , vae_encoder_export_config )
1191
1172
1192
1173
# VAE Decoder https://github.com/huggingface/diffusers/blob/v0.11.1/src/diffusers/models/vae.py#L600
@@ -1202,6 +1183,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1202
1183
vae_decoder_export_config = vae_config_constructor (
1203
1184
vae_decoder .config , int_dtype = int_dtype , float_dtype = float_dtype
1204
1185
)
1186
+ vae_decoder_export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1205
1187
models_for_export ["vae_decoder" ] = (vae_decoder , vae_decoder_export_config )
1206
1188
1207
1189
text_encoder_2 = getattr (pipeline , "text_encoder_2" , None )
@@ -1218,6 +1200,7 @@ def get_flux_models_for_export(pipeline, exporter, int_dtype, float_dtype):
1218
1200
int_dtype = int_dtype ,
1219
1201
float_dtype = float_dtype ,
1220
1202
)
1203
+ export_config .runtime_options = {"ACTIVATIONS_SCALE_FACTOR" : "8.0" }
1221
1204
models_for_export ["text_encoder_2" ] = (text_encoder_2 , export_config )
1222
1205
1223
1206
return models_for_export
0 commit comments