Repository navigation
Feature/openvino model package - #2717
Preetha Veeramalai (preetha-intel) wants to merge 16 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved path-safety, registration-lifecycle, and package-completeness issues can cause unsafe or unusable output.
Review effort: Balanced
Findings: 2
Open (8)
Protect shared registrations from premature unregistration · New Prevent path traversal in external-data staging · New Use the correct weightless option for supported ORT versions · New Reject missing requested device IDs unless partial packaging is enabled · New Reject duplicate generated variant names · New Handle weights when shared-asset staging is disabled · New Copy EPContext binaries using recorded relative paths · New Traverse all subgraph and attribute tensors for external data · New
What changed in this PR
Adds OpenVINO model packaging for ONNX Runtime’s OrtModelPackageApi, with per-device variants and shared weights.
Changes:
- Supports compilation and packaging of precompiled models.
- Extends EPContext generation with OpenVINO plugin support.
- Adds pass registration, configuration examples, documentation, and tests.
| File | Description |
|---|---|
test/passes/openvino/test_openvino_model_package.py |
Tests packaging and registration behavior. |
olive/passes/openvino/model_package.py |
Implements compilation, asset staging, and manifests. |
olive/passes/openvino/examples/model_package_config_template.json |
Provides an example workflow. |
olive/passes/onnx/context_binary.py |
Adds OpenVINO compilation and plugin registration handling. |
olive/olive_config.json |
Registers the pass and supported providers. |
docs/README_OpenVINO.md |
Documents configuration, usage, and package format. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Mayuresh Varerkar (MayureshV1)
left a comment
There was a problem hiding this comment.
Preetha Veeramalai (@preetha-intel) . Can you please fix the below suggestions.
Also, overall guidance was to hold off merging this PR till Model Packaging support becomes a stable ABI, which is expected to be soon.
| } | ||
|
|
||
|
|
||
| class OpenVINOModelPackage(Pass): |
There was a problem hiding this comment.
i'm a little bit confused about this pass. we have a CLI generate-model-package to generate a model package. I'd like to split this into 2 steps: EPContextBinaryGenerator and generate model package. the generating model package logic should be generic and all other ep can use it as well.
There was a problem hiding this comment.
does this pass only create npu package? if we want to add support for cpu, gpu as well to ort-package. will this pass work? that's why i'm thinking having a generic packaging logic will be better here.
There was a problem hiding this comment.
The CLI generate-model-package is a GenAI specific model packaging which manually creates the manifest.json and component.json. But the OpenVINOModelPackage builds the package through ORT's ort.ModelPackage API. ORT owns the manifest, component and variant metadata, and the shared-asset hashing and URI.
I agree the packaging should be generic, and it already is in the pass. The ort.ModelPackage calls don't depend on OpenVINO, and only discovery and compile are OpenVINO-specific. Splitting it by moving the ORT-API packaging out of this pass can be done as the follow up once other EP's also want to accomodate the Olive but the CLI's GenAI packaging and the pass's ORT packaging are two different formats, so it can't be one generic CLI path without making it a different mode.
|
I've moved the context binary logic into #2732. can you check this pr? |
9bc198e to
a68d4b7
Compare
a68d4b7 to
b67a720
Compare
I agree on the design where we have the EpContextBinary seperate from model packaging. Initially when this pass was added only OpenVINO use case was there hence this got swayed towards OV support. I have now modified to have a seperate generic EPContextBinary and ORTModelPackage which uses the ORT modelPackage authoring API's which is very different from the CLI generate-model-package (Made specifically for GenAI where genai_config.json is a neccessity). Xiaoyu Z (@xiaoyu-work) Can you review the updated code as it handles the end-to-end flow |
Mayuresh Varerkar (MayureshV1)
left a comment
There was a problem hiding this comment.
Thanks for the restructuring into a generic EPContextBinaryGenerator + ORTModelPackage on top of ORT's authoring API, and for addressing my earlier comments (NVL, load_config removal, failing on missing devices). A few small doc and cleanup items are inline. I'll sync with you offline on sequencing with #2732 and the ORT 1.32 dependency (#33640) before the next round.
Could you also refresh the PR description? It still mentions package_only mode, allow_partial_package and docs/README_OpenVINO.md, which no longer match the code.
|
Preetha Veeramalai (@preetha-intel) thanks for the quick turnaround on Fixed in this update ✅
Could you resolve the two doc/comment threads that are now fixed? Still to address
|
ac1c3d9 to
c1f3b46
Compare
Mayuresh Varerkar (MayureshV1)
left a comment
There was a problem hiding this comment.
Preetha Veeramalai (@preetha-intel) thanks for the updates in aaecfaa/c1f3b46. The registration fallback warning and the runtime session_options cleanup look good, and the refreshed description matches the code now.
Still open:
embed_context/weight_sharing/disable_cpu_fallbackon the OpenVINO path. See my follow-up in that thread.- Mocked
ORTModelPackagetests. They will likely fail on ORT < 1.32 because of the version check (inline). create_shared_asset=Falseweights check. It is skipped when the source model comes fromsource_model_path(inline).- Overlap with #2732. Both PRs still change the OpenVINO compile path in
context_binary.py. Let's settle which PR owns it before the next round. - ORT 1.32 / microsoft/onnxruntime#33640. Thanks for moving the PR to draft. Please post local native-test results once a build with the bindings is available.
Xiaoyu Z (@xiaoyu-work) could you take a look at your two open threads? The split into EPContextBinaryGenerator + ORTModelPackage landed in 578fcbc, and the <=1.23.2 question has an answer.
Mayuresh Varerkar (MayureshV1)
left a comment
There was a problem hiding this comment.
Preetha Veeramalai (@preetha-intel) thanks for a9d4da1. It covers the version-patched fixture, the source_model_path weights check, the registration-fallback tests and the enum ValueError. Three items are still open, inline:
- The new EPContext option mapping overrides values the user sets explicitly.
_read_compatnow calls a function thatonnxruntimedoesn't export.- The doc and docstring still say options are passed verbatim.
…on handling - Validate package_name and package_name + package_suffix as single path components - Set source_model_path for single-model OpenVINO EPContext output so ORTModelPackage defaults work - Reject update_genai_config/genai_config_role for OpenVINO instead of ignoring them - Share typed session option handling (log_severity_level, log_verbosity_level) with the plugin EP path
There was a problem hiding this comment.
lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Mayuresh Varerkar (MayureshV1)
left a comment
There was a problem hiding this comment.
Preetha Veeramalai (@preetha-intel) thanks for e5af08c/579e7e1. The embed/CPU-fallback precedence, the _pybind_state restore and the README mapping table all look good, and the tests cover them.
None of the items below depend on #2732, so they can go in now:
-
CI:
Python formatfails (job). Everything it reports is in the new tests, apart from one advice-level item inmodel_package.py:test_context_binary.py:150:from pathlib import Pathinside the test reimports and shadows the module-level import (W0404/W0621). Please drop it.- RUF043 (
match=with unescaped metacharacters). Use raw strings orre.escape:test_context_binary.py:593, 600test_ort_model_package.py:204, 295
- SIM117 (nested
with):test_context_binary.py:637, 650. Combine them into a singlewith. test_context_binary.py:487, 490: RUF012 (mutable class attribute__members__) and B008 (FakeEnum()as a default argument).- W0212 (protected access) throughout both files, and W0621 for the
mock_model_package/native_model_packagefixtures. Add a file-level# pylint: disable=protected-access,redefined-outer-namelike other Olive tests, or use@pytest.mark.usefixtureswhere the fixture value isn't used. - Advice R0916 (too many boolean expressions) at
model_package.py:399in_safe_relative_location. Optional: split the check into named conditions.
Please run
lintrunner -alocally to confirm it's clean. -
PR description. It still says "ORT options are passed through verbatim; Olive sets no EPContext keys." After
a9d4da1, Olive setsep.context_enable,ep.context_embed_modeandsession.disable_cpu_ep_fallback(plusembed_compiled_data_into_modelforaot) fromembed_context/disable_cpu_fallback. Please update it to match the README. -
Nit:
test_read_compat_reads_from_ort_pybind_modulepatches withcreate=True, so it still passes ifget_compatibility_info_from_modelis missing from_pybind_state. Droppingcreate=True(and skipping when the attribute is absent) would catch a rename.
Still open, tracked separately: the overlap with #2732, and ORT 1.32 / microsoft/onnxruntime#33640. Please post the local native-test results once a build with the bindings is available.
|
Xiaoyu Z (@xiaoyu-work) and I agreed to close #2732 and make #2717 the single PR for OpenVINO plugin-EP compilation and ORT model packaging. Thanks Xiaoyu Z (@xiaoyu-work) for #2732! Its improvements will be merged into #2717, and the PR will then be made available for review. High-level plan for the next update of #2717:
I'll work with Preetha Veeramalai (@preetha-intel) to get the PR ready for review soon. It stays in draft until the ORT model-packaging bindings (microsoft/onnxruntime#33640) are merged, since Xiaoyu Z (@xiaoyu-work) since #2717 will carry the only version of the |
- Register onnxruntime-ep-openvino automatically in maybe_register_ep_libraries when no library path is configured. - Lower the plugin-EP ORT floor to 1.23; require 1.30 only for ep.enable_weightless and call ModelCompiler.set_ep_context_binary_information only when the binding exists. - Select OrtEpDevices by the accelerator's device type and compare device ids numerically (case, 0x prefix, leading zeros, integers); reject malformed ids. - Validate the compiled output (EPContext nodes present, referenced binaries exist) and remove the partial output of a failed attempt so the output path can be retried. - Move the model-package doc under docs/source, add ORTModelPackage to the pass reference and add an openvino-ep install extra. - Fix lint findings in the new tests.
|
The changes are updated to accomodate #2732 |
|
Preetha Veeramalai (@preetha-intel) thanks for
The lint and A few things before this is ready for maintainer review:
Once CI is green and the results are posted, I'll re-review and clear my earlier change request. |
…indings fix CI build errors EPContextBinaryGenerator: - Type compile_flow as Literal["aot", "jit"]; reject jit with model_compiler_options before registering the plugin - Accept integer enum values for model_compiler_options and validate bool/int options strictly via pydantic TypeAdapter - Move the virtual NPU preference out of the generic _select_ep_device into an OpenVINO prefer_ep_devices hook that logs when it fires - Keep device_id with npu_platform in per-target device filters - Require the metadata key to exist when matching ep_device_filters - Record ep_device_filters and provider_options on target_devices components and the composite, matching the single-target path ORTModelPackage: - Normalize session_options to string values as ORT requires at load - Add provider_options, written to executor_info.ort.provider_options - Treat a missing EPContext embed_mode as embedded (schema default 1) - Raise a clear error for an invalid variant_name_template - Prefer a public get_compatibility_info_from_model when available Port the microsoft#2732 tests for incomplete output cleanup, existing-output refusal, option parsing and plugin discovery, and update the docs.
The comments are addressed along with porting from #2732 completely to #2717. Xiaoyu Z (@xiaoyu-work) Can you kindly help retrigger the pipelines. |
|
Preetha Veeramalai (@preetha-intel) thanks for Xiaoyu Z (@xiaoyu-work) this is ready for you: could you approve the CI runs on |
Mayuresh Varerkar (MayureshV1)
left a comment
There was a problem hiding this comment.
Changes look good. Waiting for CI to pass to approve !
|
There is a failed test: |


Describe your changes
This is the single PR for compiling ONNX models with the OpenVINO plugin EP and assembling the results into an ONNX Runtime model package. Thanks to Xiaoyu Z (Xiaoyu Z (@xiaoyu-work)) for #2732: its improvements are merged here, so #2732 can be closed.
New / extended passes
EPContextBinaryGeneratorcompiles with the OpenVINO plugin EP (aotviaModelCompiler, orjit). Withtarget_devicesit produces one EPContext model per device as a composite model.ORTModelPackage(olive/passes/onnx/model_package.py) assembles the compiled variants into an.ortpackage.Plugin registration
OpenVINOExecutionProvideris registered automatically during workflow setup fromonnxruntime-ep-openvino, the same wayonnxruntime_qnnis handled. An explicit library path still wins.Device selection
OrtEpDevices are filtered by the accelerator's device type beforeep_device_filtersis applied.B03E,b03e,0xB03E,0x00B03Eand integers are equivalent. Malformed IDs are rejected.target_devicesis normalized and de-duplicated.npu_platformis selected.Output checks and retries
EPContext options
embed_contextanddisable_cpu_fallbackmap toep.context_embed_mode/session.disable_cpu_ep_fallback(andembed_compiled_data_into_modelforaot). A setting is on if any source turns it on; the pass flag wins over an explicit "off" and logs a warning. Olive always setsep.context_enable=1. All other options are passed to ORT unchanged.weight_sharing,update_genai_configandgenai_config_roleare not supported for OpenVINO and raise aValueError.ORT versions
ep.enable_weightless(raises aValueErroron older ORT)set_ep_context_binary_information, skipped with an info log if the binding is missing) andORTModelPackageDocs and install
docs/source/features/ihv-integration/openvino-model-package.md, linked from the IHV index andopenvino.md.ORTModelPackageis added to the pass reference.Testing
test_context_binary.py,test_ort_model_package.py,test_ort_inference.py). They run with mocked plugin devices on ORT 1.32.Release note: Olive can compile ONNX models with the OpenVINO plugin EP for one or more NPU/GPU devices and package the results as an ONNX Runtime model package. Install with
pip install olive-ai[openvino-ep]; requires ONNX Runtime >= 1.23 (>= 1.32 for model packaging).