Skip to content

Select model package variants in EP priority order - #33508

Open
maxim-davgalev wants to merge 2 commits into
microsoft:mainfrom
maxim-davgalev:model-package-ranked-ep-selection
Open

maxim-davgalev wants to merge 2 commits into
microsoft:mainfrom
maxim-davgalev:model-package-ranked-ep-selection

Conversation

@maxim-davgalev

@maxim-davgalev maxim-davgalev commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Model package variant selection previously considered only the first EP captured from the session options.
A package without a variant for that EP failed with "No suitable model variant found", even when a later EP had
a matching variant. For example, with a CPU plugin EP registered, PREFER_CPU can select [plugin EP, ORT CPU EP]. A package containing only an ORT CPU EP variant was therefore rejected.

This PR considers EPs in priority order: the order determined by a policy or the order in which EPs were added to
the session options. For the first EP with matching variants, it selects the variant with the highest compatibility score. Compatibility scores are used only to choose between variants for the same EP and do not override EP priority: once an EP with a matching variant is found, variants for later EPs are not considered, even if they have higher scores. If several matching variants for that EP have the highest score, the first one listed in the manifest is selected.

The public C API documentation and model package README describe these rules.

Tests

  • Selecting variants for later EPs, including the ORT CPU EP, through both CreateSession paths.
  • Preserving EP priority over compatibility scores.
  • Creating sessions with the selected EP and passing options to its factory.
  • Reporting missing device information and compatibility callback errors.
  • Selecting a CoreML GPU variant and creating its session on supported Apple systems.
  • Creating the selected EP only for devices matching the variant's device type.

Capture EPs in priority order instead of considering only the first.
For the first EP with matching variants, select the variant with the
highest compatibility score.
Compatibility scores are used only to choose between variants for
the same EP and do not override EP priority: once an EP with a
matching variant is found, variants for later EPs are not considered,
even if they have higher scores.

This allows packages without a variant for the first EP to use a
matching variant for a later EP, including the ORT CPU EP, instead
of failing variant selection.
Copilot AI balanced review requested due to automatic review settings October 21, 2026 07:59
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Cross-platform provider reconstruction needs human validation, and mixed-device factory replacement lacks regression coverage.

1 open issue
What changed in this PR

Updates ONNX Runtime model packages to select variants by execution provider (EP) priority, then compatibility score within the first matching EP.

Changes:

  • Captures ordered EPs and recreates the selected provider for sessions.
  • Adds selection, fallback, and error-path tests.
  • Documents selection and session-creation rules.
File Description
onnxruntime/​test/​autoep/​test_model_package.cc Adds selection and session regressions.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep_factory.cc Enables simulated compatibility errors.
onnxruntime/​core/​session/​utils.h Updates EP capture interface.
onnxruntime/​core/​session/​utils.cc Captures all providers and checks selected EP registration.
onnxruntime/​core/​session/​provider_policy_context.h Exposes per-provider selections and policy telemetry.
onnxruntime/​core/​session/​provider_policy_context.cc Preserves selected devices per provider.
onnxruntime/​core/​session/​model_package/​README.md Documents priority and session behavior.
onnxruntime/​core/​session/​model_package/​model_package_variant_selector.h Updates selection contract.
onnxruntime/​core/​session/​model_package/​model_package_variant_selector.cc Implements priority-ordered selection.
onnxruntime/​core/​session/​model_package/​model_package_options.h Stores selection policy.
onnxruntime/​core/​session/​model_package/​model_package_options.cc Captures ordered factories and devices.
onnxruntime/​core/​session/​model_package/​model_package_context.h Tracks the selected EP.
onnxruntime/​core/​session/​model_package/​model_package_context.cc Filters devices and configures selected providers.
onnxruntime/​core/​session/​model_package_api.cc Applies selected-provider options and telemetry.
include/​onnxruntime/​core/​session/​onnxruntime_c_api.h Clarifies API documentation without changing signatures.

Review effort: Balanced

Comment thread onnxruntime/core/session/model_package/model_package_context.cc
Add a test with one CPU device and two GPU devices to verify that
CreateSession creates the selected EP only for devices matching the
variant's device type.

The test covers both the default CreateSession path and the path where
the caller provides session options without EP factories.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved actionable findings remain, and regression coverage addresses the selection and session-creation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@maxim-davgalev

Copy link
Copy Markdown
Contributor Author

Hi Tianlei Wu (@tianleiwu), would you be the right person to review this PR, or could you suggest an appropriate reviewer?

This branch has not been deployed

No deployments
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.

2 participants