-
Notifications
You must be signed in to change notification settings - Fork 572
Add support for optimizing clip models #1263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm having trouble getting the tests to run, but it's not obvious what tests I would need to add? From what I can tell, there's nothing currently testing the |
disable_packed_qkv: bool = False | ||
disable_bias_add: bool = False | ||
# As of onnxruntime 1.15.1, NHWC is not an implemented op, so disable: | ||
# https://github.com/microsoft/onnxruntime/blob/v1.15.1/onnxruntime/python/tools/transformers/onnx_model_clip.py#L23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new arguments are for UNet, and not CLIP. Note that those operators only works in GPU and not CPU right now.
NhwcConv exists in ORT since 1.14. It is used to speed up convolution for GPU inference (new GPUs with tensor cores).
CLIP does not have convolution. These arguments have no impact on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, gotcha! I was getting errors without this, but I can test again without that. Are you saying this line should be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I try to optimize a model without disabling NhwcConv, I get this error:
AttributeError Traceback (most recent call last)
Cell In[3], line 30
---> 30 optimizer.optimize(
31 save_dir=output_dir, optimization_config=optimization_config, file_suffix=""
32 )
File /path/to/optimum/optimum/onnxruntime/optimization.py:166, in ORTOptimizer.optimize(self, optimization_config, save_dir, file_suffix, use_external_data_format, one_external_file)
163 maybe_save_preprocessors(self.onnx_model_path[0].parent, save_dir)
165 model_type = ORTConfigManager.get_model_ort_type(self.config.model_type)
--> 166 optimization_options = optimization_config.create_fusion_options(model_type)
168 logger.info("Optimizing model...")
170 # TODO: this is quite inefficient as we load in memory if models are <2GB without external data
File /path/to/optimum/optimum/onnxruntime/configuration.py:825, in OptimizationConfig.create_fusion_options(self, model_type)
822 continue
823 setattr(args, attr, value)
--> 825 return FusionOptions.parse(args)
File /path/to/onnxruntime/transformers/fusion_options.py:105, in FusionOptions.parse(args)
102 options.disable_attention_mask()
104 if args.model_type in ["unet", "vae", "clip"]:
--> 105 if args.disable_nhwc_conv:
106 options.enable_nhwc_conv = False
107 if args.disable_group_norm:
AttributeError: 'Box' object has no attribute 'disable_nhwc_conv'
This is using onnxruntime
version 1.15.1, for what it's worth.
This PR has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs. |
What does this PR do?
This allows optimization of
clip
andclip_text_model
onnx models.Before submitting