Compile API: disable optimizations by default#25474
Merged
adrianlizarraga merged 7 commits intomainfrom Sep 3, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR disables graph optimizations by default in the explicit compiling API, preferring to let execution providers handle optimizations instead. It adds a new method to allow users to manually enable optimizations when needed.
- Changes the default graph optimization level to
TransformerLevel::Default(minimum optimizations) instead of the previous behavior - Adds
ModelCompilationOptions_SetGraphOptimizationLevelAPI to allow users to explicitly set optimization levels - Updates test expectations to account for different EPContext node input counts based on optimization settings
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/core/session/model_compilation_options.h | Declares new SetGraphOptimizationLevel method |
| onnxruntime/core/session/model_compilation_options.cc | Implements optimization level setting and sets default to L0 |
| onnxruntime/core/session/compile_api.h | Declares C API wrapper for graph optimization level setting |
| onnxruntime/core/session/compile_api.cc | Implements C API wrapper function |
| include/onnxruntime/core/session/onnxruntime_c_api.h | Adds C API function declaration and documentation |
| include/onnxruntime/core/session/onnxruntime_cxx_api.h | Adds C++ wrapper method declaration |
| include/onnxruntime/core/session/onnxruntime_cxx_inline.h | Implements C++ wrapper method |
| onnxruntime/test/providers/qnn/qnn_ep_context_test.cc | Updates tests to handle different optimization behaviors and add explicit optimization setting |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
yuslepukhin
requested changes
Aug 29, 2025
adrianlizarraga
commented
Sep 2, 2025
yuslepukhin
approved these changes
Sep 2, 2025
tianleiwu
pushed a commit
that referenced
this pull request
Sep 4, 2025
### Description - Disables graph optimizations by default when using the explicit compiling API. - Adds `ModelCompilationOptions_SetGraphOptimizationLevel` to allow the user to set an optimization level. - Adds C++, Python, and C# bindings for the new API function. - Updates `ModelCompilationOptions_SetFlags` to take in a `uint32_t flags` parameter instead of `size_t flags` to ensure the same size across platforms. This API is not yet in a public ORT release, so safe to modify. ### Motivation and Context When compiling, prefer allowing the EP to do the optimizations instead of ORT.
jywu-msft
pushed a commit
that referenced
this pull request
Sep 5, 2025
### Description Cherry-pick the following PRs: #25943 #25937 #25917 #25909 #25898 #25897 #25888 #25881 #25830 #25619 #25575 #25572 #25558 #25530 #25474 #25455 #25110 Also two dependent PRs for qMoE cpu: #25877 #25822 --------- Co-authored-by: xiaomsft <136376084+xiaomsft@users.noreply.github.com> Co-authored-by: Xiaoyan Hu <xiaoh@microsoft.com> Co-authored-by: Akshay Sonawane <111780983+apsonawane@users.noreply.github.com> Co-authored-by: Kunal Vaishnavi <kvaishnavi@microsoft.com> Co-authored-by: Pradeep Sakhamoori <psakhamoori@microsoft.com> Co-authored-by: mingyue <131847423+mingyueliuh@users.noreply.github.com> Co-authored-by: Maximilian Müller <44298237+gedoensmax@users.noreply.github.com> Co-authored-by: Adrian Lizarraga <adlizarraga@microsoft.com> Co-authored-by: Dmitri Smirnov <yuslepukhin@users.noreply.github.com> Co-authored-by: Emmanuel <91394589+kobby-kobbs@users.noreply.github.com> Co-authored-by: Emmanuel Assumang <eassumang@microsoft.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: praneshgo <pranesh.iitp@gmail.com> Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com> Co-authored-by: Jing Fang <fajin@microsoft.com> Co-authored-by: Ishwar Raut <iraut@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ModelCompilationOptions_SetGraphOptimizationLevelto allow the user to set an optimization level.ModelCompilationOptions_SetFlagsto take in auint32_t flagsparameter instead ofsize_t flagsto ensure the same size across platforms. This API is not yet in a public ORT release, so safe to modify.Motivation and Context
When compiling, prefer allowing the EP to do the optimizations instead of ORT.