Skip to content
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

Add optimization to dynamo-based exporter #1541

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

titaiwangms
Copy link
Contributor

Describe your changes

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
  • Is this PR including examples changes? If yes, please remember to update example documentation in a follow-up PR.

(Optional) Issue link

@justinchuby justinchuby requested a review from jambayk January 8, 2025 06:14
@justinchuby
Copy link
Contributor

LGTM, cc @jambayk for review

@@ -106,6 +106,14 @@ def _default_config(cls, accelerator_spec: AcceleratorSpec) -> Dict[str, PassCon
"dynamic": PassConfigParam(
type_=bool, default_value=True, description=("Whether to export the model with dynamic axes/shapes.")
),
"optimization": PassConfigParam(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization includes onnxruntime contrib ops as well or just standard onnx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably will need to support both? Should we have two flags? Or make this an enumeration instead of bool, so we can decide whether to apply ORT specific optimizations too? Depends on what the intended use of this Olive pass is ... is it intended only for ORT users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current design in PyTorch let users to decide whether to optimize or not. This flag simply follows the idea. I personally think adding another optimization flag for ORT is confusing and complicated. If we really want ORT optimization to be an option, I suggest we can change PyTorch exporter to default applying regular optimization, and optimize() method refers to applying ORT specific optimization.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having optimize to target ort in pytorch is not the most ideal. We could expose a target option in the optimize API. However depending on what Olive wants to provide to its users, I think a similar string option is reasonable. It could default to ORT, similar to what model builder does right now. Although there are pushes for MB to be more generic.

Copy link

@gramalingam gramalingam Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that [responding to Titai's message above] is reasonable: specifically, let's forget pytorch here, and focus on olive users. The olive pass can internally always do generic optimization, no need to expose it to user as an option at all. We could expose ort-optimization as an option ... but even that is necessary only if we expect users to use olive for ORT and non-ORT. Unclear if we need that. That's why I am asking about users of this olive pass ... can we assume it is going to be only for ORT users? (We can't make that assumption for pytorch exporter.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even for ORT users, contrib operators are not supported for all target use cases. For instance, NPU targets which require QDQ models might not support any contrib operators.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you use as user input to make the decisions? Some combination of (EP, dtype)? As long as we have the necessary information to select the appropriate fusion optimizations, we should be fine

Copy link
Contributor

@jambayk jambayk Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In passes like OrtTransformersOptimization, we make some decisions on what optimizations to enable/disable based on the accelerator spec which includes the target device (cpu, gpu, npu) and EP. dtype is already a config option for this conversion pass so that info is also available if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants