Model Package Support (Phase 2)#28271
Merged
Merged
Conversation
chilo-ms
marked this pull request as ready for review
May 6, 2026 17:24
Contributor
Author
|
Please note that in variant selection, we need the new EP API |
jambayk
previously approved these changes
Jun 1, 2026
The submodule update in #28577 caused webgl-operators.md to be out-of-date, failing the JS CI doc check. Revert to the prior pointer until the doc is regenerated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jambayk
previously approved these changes
Jun 1, 2026
…nxruntime into chi/model_package_2
…nxruntime into chi/model_package_2
jambayk
previously approved these changes
Jun 1, 2026
jambayk
approved these changes
Jun 3, 2026
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.
Summary
This PR implements the model package feature for ONNX Runtime — a structured packaging format that bundles multiple model variants (targeting different EPs) with metadata for automatic variant selection at runtime. It builds on the foundational model package support introduced in #27786 by extracting the parsing logic into a standalone reusable library, simplifying the public API surface, adding new query/traversal APIs, and hardening security and correctness.
Key Components
Standalone
model_package/library — A self-contained C library at the repo root that parses model packages (manifest.json, metadata.json, variant.json). No dependency on ONNX Runtime. Designed to be consumed independently by ORT, GenAI, and FL.ORT integration — ORT links the standalone library as a static lib and uses its internal C++ types directly (not the public C API) to avoid double-wrapping overhead. The public C API exists for external consumers.
OrtModelPackageApiC API — A new vtable-based API surface (similar toOrtApi) exposing package parsing, variant enumeration, variant selection, and session creation.C++ wrappers and Python bindings — RAII C++ wrappers (
ModelPackageContext,ModelPackageComponentContext,ModelPackageOptions) and full Python bindings.API Surface — Standalone Library (
model_package/include/model_package_api.h)A dependency-free C API for parsing and inspecting model packages without linking ONNX Runtime.
ModelPackage_ReleaseStatusModelPackage_GetErrorMessageModelPackage_CreateContextModelPackage_ReleaseContextModelPackage_GetSchemaVersionModelPackage_GetComponentCountModelPackage_GetComponentNameModelPackage_GetVariantCountModelPackage_GetVariantNameModelPackage_GetVariantFolderPathModelPackage_GetVariantEpNameAPI Surface — ORT (
OrtModelPackageApiinonnxruntime_c_api.h)Accessed via
OrtApi::GetModelPackageApi(). Extends the standalone surface with EP-aware variant selection and session creation.CreateModelPackageOptionsFromSessionOptionsReleaseModelPackageOptionsCreateModelPackageContextReleaseModelPackageContextModelPackage_GetSchemaVersionModelPackage_GetComponentCountModelPackage_GetComponentNamesModelPackage_GetVariantCountModelPackage_GetVariantNamesModelPackage_GetVariantEpNameSelectComponentReleaseModelPackageComponentContextModelPackageComponent_GetSelectedVariantNameModelPackageComponent_GetSelectedVariantFolderPathCreateSessionSecurity & Correctness
ValidatePathSegment,ValidatePathConfinement)ModelPackageComponentContextowns all stateSession Creation
OrtSessionOptionsAddSessionConfigEntryFiles Added
model_package/— Standalone library (header, parser, C API, CMakeLists, README)onnxruntime/core/session/model_package_api.{h,cc}— ORT C API implementation + vtableonnxruntime/core/session/model_package/model_package_options.{h,cc}— Options/EP resolutiononnxruntime/core/session/model_package/model_package_variant_selector.{h,cc}— Variant selectorFiles Removed
onnxruntime/core/session/model_package/model_package_descriptor_parser.{h,cc}— Replaced by standalone libTesting
test_model_package.ccwith tests for all API functions, variant selection, tie-break determinism, session option dispatch, and error cases