Fix/ort runtime optimization trust - #32077
Merged
Akshay Sonawane (apsonawane) merged 2 commits intoAug 16, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 14, 2026 00:55
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 14, 2026 00:55
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new session config option to control whether saved runtime optimizations embedded in ORT-format models are replayed, changing the default behavior to disabled unless explicitly enabled for trusted models. This tightens security around applying graph-rewrite instructions that come from model files.
Changes:
- Added
session.enable_saved_runtime_optimizations(kOrtSessionOptionsConfigEnableSavedRuntimeOptimizations) and wired it into ORT-model loading so replay is opt-in. - Changed
OrtFormatLoadOptionsdefault to ignore saved runtime optimizations unless explicitly enabled. - Updated unit tests and conversion/docs messaging to reflect the new opt-in behavior.
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 |
|---|---|
| tools/python/util/convert_onnx_models_to_ort.py | Updates CLI help and adds a runtime-style warning explaining the new opt-in session option. |
| onnxruntime/test/testdata/squeezenet/model_opset11.with_runtime_opt.readme.txt | Documents that loading this ORT model with replay now requires the new session option. |
| onnxruntime/test/optimizer/runtime_optimization/graph_runtime_optimization_test.cc | Enables replay explicitly where needed and adds a test asserting replay is disabled by default. |
| onnxruntime/test/internal_testing_ep/internal_testing_tests.cc | Updates the NHWC/static-kernel test helper to explicitly enable replay when required. |
| onnxruntime/test/framework/ort_model_only_test.cc | Extends update test helper to optionally enable replay; adds coverage around models with saved runtime optimizations. |
| onnxruntime/core/session/inference_session.cc | Gates replay of saved runtime optimizations on the new session config option (default off). |
| onnxruntime/core/graph/ort_format_load_options.h | Changes default to ignore saved runtime optimizations by default; updates comment. |
| include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h | Adds the new public session option key constant with documentation. |
Suppressed comments (1)
onnxruntime/test/framework/ort_model_only_test.cc:634
- This
TestOrtModelUpdateinvocation is currently formatted as a single very long line, unlike the surrounding calls in this file. This is likely to violate the repo's C++ formatting/line-length conventions and makes the lambda harder to read. Please reformat the call similarly to the earlierTestOrtModelUpdateusage above.
TestOrtModelUpdate(onnx_file, ort_file_v4, ort_file_v5, [&](NameMLValMap& inputs, std::vector<std::string>& output_names) {
constexpr int n = 3; // number of QDQ convs
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 14, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/ort-runtime-optimization-trust
branch
August 16, 2026 22:04
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.
This pull request introduces a new session option to control the replay of saved runtime optimizations from ORT format models, enhancing security and configurability. By default, replaying saved runtime optimizations is now disabled and must be explicitly enabled for trusted models. The changes also update tests and documentation to reflect this new behavior.
Session Option for Saved Runtime Optimizations
session.enable_saved_runtime_optimizations(constantkOrtSessionOptionsConfigEnableSavedRuntimeOptimizations) to control whether saved runtime optimizations are replayed. The default is "0" (disabled), and it must be set to "1" to enable replay for trusted models.OrtFormatLoadOptionsstruct so that saved runtime optimizations are ignored by default unless explicitly enabled.InferenceSession::LoadOrtModelWithLoaderto check the new session option and setignore_saved_runtime_optimizationsaccordingly. [1] [2]Test and Documentation Updates