Model package: fold external_data into session options and remove legacy directory load path - #29501
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR simplifies the model package loading flow by (1) eliminating the dedicated external_data manifest field in favor of resolving path-valued session_options entries at variant-parse time, and (2) removing the legacy OrtCreateSession(package_dir) directory-based model package load path in favor of the experimental OrtModelPackageApi pipeline.
Changes:
- Resolve allowlisted path-valued session options (e.g.,
session.model_external_initializers_file_folder_path,ep.context_file_path) against the package during variant parsing, and carry over those options on the “advanced” session-options path when unset by the caller. - Remove the legacy directory-based model package load path from
CreateSessionAndLoadModelImpl. - Migrate existing end-to-end tests to create sessions via the experimental
OrtModelPackageApi, and add a new test covering external-initializers folder resolution via variant session options.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/test/autoep/test_model_package.cc | Adds a helper to create sessions via OrtModelPackageApi, migrates directory-path tests, and adds a new test for resolved external initializers folder session option. |
| onnxruntime/core/session/utils.cc | Removes directory-based model package loading from the standard session creation path. |
| onnxruntime/core/session/model_package/README.md | Updates manifest docs to move external_data behavior into session_options and documents path-valued option resolution and carryover semantics. |
| onnxruntime/core/session/model_package/model_package_context.h | Removes legacy external-data fields and introduces IsModelPackagePathSessionOption. |
| onnxruntime/core/session/model_package/model_package_context.cc | Implements the allowlist and resolves path-valued session options during variant parsing. |
| onnxruntime/core/session/model_package_api.cc | On advanced path, carries over only variant path-valued session options that the caller didn’t set. |
…ution Resolve path-valued session options (an allowlist: the external initializers folder and ep.context_file_path) against the model package at variant-parse time, so variants reference shared assets by sha256: URI or relative path directly in session_options. Remove the dedicated external_data variant field and its special injection; the model is now always loaded from the selected variant path. On the advanced path, carry over path-valued session options from the variant for keys the caller did not set. Builds on the file-path external initializers folder support so the model package flow no longer needs to mmap the model and force a buffer load. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the is_directory(package_root) branch in CreateSessionAndLoadModelImpl that loaded a model package directly from a directory passed to CreateSession. Model packages are loaded through the experimental OrtModelPackageApi (CreateModelPackageContext -> SelectComponent -> CreateSession); this legacy inline path was meant to be removed when that API landed and it never merged variant session/provider options. Migrate the three end-to-end tests that exercised the directory path to the experimental API via a CreateSessionFromModelPackage test helper, preserving coverage for factory-based selection, PREFER_CPU policy selection, and compiled-model compatibility scoring. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- CreateSessionAndLoadModelImpl: fail early with an explicit message when a directory path is passed, pointing callers at the model package API instead of falling through to a generic file-open error. Add a test for it. - model_package_context.h: include <string_view> directly for IsModelPackagePathSessionOption instead of relying on transitive includes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jambayk
force-pushed
the
jambayk/model-package-ext-data
branch
from
July 6, 2026 23:57
96209f8 to
4410f86
Compare
chilo-ms
approved these changes
Jul 7, 2026
tianleiwu
pushed a commit
that referenced
this pull request
Jul 7, 2026
…acy directory load path (#29501) ### Description Two changes to the model package flow, enabled by the file-path external initializers support: **1. Fold `external_data` into `session_options` with path resolution.** - Path-valued session options (an allowlist: `session.model_external_initializers_file_folder_path` and `ep.context_file_path`) are resolved against the package (`sha256:<hex>`, relative, or absolute) at variant-parse time, using the same rules as `model_file`. - The dedicated `external_data` variant field and its special session injection are removed; the model is always loaded from the selected variant path. - On the advanced path (caller supplies their own `OrtSessionOptions`), path-valued options are carried over from the variant for keys the caller did not set, so a model that needs its external-initializers folder still loads. **2. Remove the legacy directory-based `CreateSession(package_dir)` path.** - Removes the `is_directory(package_root)` branch in `CreateSessionAndLoadModelImpl`. Model packages are loaded through the experimental `OrtModelPackageApi` (`CreateModelPackageContext` -> `SelectComponent` -> `CreateSession`). - The three end-to-end tests that exercised the directory path are migrated to the experimental API via a `CreateSessionFromModelPackage` test helper, preserving coverage for factory-based selection, `PREFER_CPU` policy selection, and compiled-model compatibility scoring. ### Motivation and Context The file-path external initializers folder support (#29459) lets the model package flow drop its workaround of memory-mapping the model and forcing a buffer load: it sets the folder option and loads from the selected variant path directly. Building on that, the dedicated `external_data` field folds into the general session-options mechanism. A variant declares `session.model_external_initializers_file_folder_path` (or other path-valued options) in its `session_options`, and ORT resolves those values against the package at parse time. This removes special-case code and lets other path-valued options such as the EPContext file path be resolved the same way. An allowlist is used rather than value-syntax sniffing because session-option values are arbitrary strings; only known path-valued keys are resolved, so ordinary values pass through untouched. The legacy directory-based `CreateSession(package_dir)` path was meant to be removed when the experimental `OrtModelPackageApi` landed. It only did variant/EP selection and never merged the variant's `session_options`/`provider_options`, so a package loaded via `Ort::Session(env, dir, so)` silently ignored its manifest session options, inconsistent with the experimental API. Removing it leaves a single, consistent way to load a model package. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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
Two changes to the model package flow, enabled by the file-path external initializers support:
1. Fold
external_dataintosession_optionswith path resolution.session.model_external_initializers_file_folder_pathandep.context_file_path) are resolved against the package (sha256:<hex>, relative, or absolute) at variant-parse time, using the same rules asmodel_file.external_datavariant field and its special session injection are removed; the model is always loaded from the selected variant path.OrtSessionOptions), path-valued options are carried over from the variant for keys the caller did not set, so a model that needs its external-initializers folder still loads.2. Remove the legacy directory-based
CreateSession(package_dir)path.is_directory(package_root)branch inCreateSessionAndLoadModelImpl. Model packages are loaded through the experimentalOrtModelPackageApi(CreateModelPackageContext->SelectComponent->CreateSession).CreateSessionFromModelPackagetest helper, preserving coverage for factory-based selection,PREFER_CPUpolicy selection, and compiled-model compatibility scoring.Motivation and Context
The file-path external initializers folder support (#29459) lets the model package flow drop its workaround of memory-mapping the model and forcing a buffer load: it sets the folder option and loads from the selected variant path directly. Building on that, the dedicated
external_datafield folds into the general session-options mechanism. A variant declaressession.model_external_initializers_file_folder_path(or other path-valued options) in itssession_options, and ORT resolves those values against the package at parse time. This removes special-case code and lets other path-valued options such as the EPContext file path be resolved the same way. An allowlist is used rather than value-syntax sniffing because session-option values are arbitrary strings; only known path-valued keys are resolved, so ordinary values pass through untouched.The legacy directory-based
CreateSession(package_dir)path was meant to be removed when the experimentalOrtModelPackageApilanded. It only did variant/EP selection and never merged the variant'ssession_options/provider_options, so a package loaded viaOrt::Session(env, dir, so)silently ignored its manifest session options, inconsistent with the experimental API. Removing it leaves a single, consistent way to load a model package.