OpenVINO Model Package (EPContextBinaryGenerator + ORTModelPackage)#
Creating an ONNX Runtime .ortpackage for OpenVINO takes two passes:
EPContextBinaryGeneratorcompiles an ONNX model into an EPContext model for each selected OpenVINO device (NPU, GPU, or CPU).ORTModelPackageassembles EPContext models into an.ortpackagethrough ONNX Runtime’sonnxruntime.ModelPackageauthoring API. It is not specific to OpenVINO; the execution provider comes from the workflow’s accelerator.
The package directory is the deliverable.
Prerequisites#
Python 3.12, the OpenVINO stack for the selected device.
Olive with the OpenVINO plugin EP:
pip install "olive-ai[openvino-ep]"
This installs Olive,
onnxruntime, theonnxruntime-ep-openvinoplugin andopenvino, which is enough forEPContextBinaryGenerator. (From an Olive source checkout, usepip install -e ".[openvino-ep]"instead.)For
ORTModelPackage, update ONNX Runtime to 1.32 or later:pip install -U "onnxruntime>=1.32"
ONNX Runtime version requirements:
Feature |
Minimum ONNX Runtime |
|---|---|
|
1.23 |
Weightless compilation ( |
1.30 (older releases use |
Per-device binary naming with |
1.32 (without it, each binary keeps ORT’s default name in its device folder) |
|
1.32 (the first release with the |
Target devices#
EPContextBinaryGenerator.target_devices accepts OpenVINO device IDs as hexadecimal strings ("B03E",
"b03e", "0xB03E" and "0x00B03E" are the same device) or integers. It produces a composite model with one
EPContext model per device, each in its own <DEVICE_ID> directory (uppercase hex, no prefix). Each device must be
of the accelerator’s device type. The pass fails if a requested device is unavailable or compilation fails.
Whether those ids resolve to virtual cross-compile targets or the physical local
device is decided by ep_registration_name:
|
Devices exposed |
|---|---|
|
Virtual cross-compile devices |
|
Physical OpenVINO devices on this machine |
Known virtual NPU device IDs:
Device |
ID |
|---|---|
Lunar Lake (LNL) |
|
Panther Lake (PTL) |
|
Nova Lake (NVL) |
|
Run it#
Save a workflow config as my_model_package_config.json, set input_model.model_path and
engine.output_dir to your model and output location, then run:
python -m olive run --config my_model_package_config.json
Example my_model_package_config.json for virtual NPU targets:
{
"input_model": { "type": "ONNXModel", "model_path": "C:/path/to/your_model.onnx" },
"systems": {
"local_system": {
"type": "LocalSystem",
"accelerators": [ { "device": "npu", "execution_providers": [ "OpenVINOExecutionProvider" ] } ]
}
},
"host": "local_system",
"target": "local_system",
"passes": {
"ep_context": {
"type": "EPContextBinaryGenerator",
"compile_flow": "aot",
"ep_registration_name": "ovep_registration.virtual",
"target_devices": [ "643E", "B03E", "D71D" ],
"output_model_name": "model_ctx.onnx",
"session_options": {
"ep.context_enable": "1",
"ep.context_embed_mode": "0",
"ep.enable_weightless": "1"
}
},
"ov_model_package": {
"type": "ORTModelPackage",
"package_name": "my-model",
"session_options": {
"ep.enable_weightless": "1",
"ep.context_file_path": "model_ctx.onnx"
}
}
},
"engine": {
"search_strategy": false,
"evaluate_input_model": false,
"no_artifacts": true,
"output_dir": "C:/path/to/output"
}
}
For the OpenVINO path, each of these two settings can be given in up to three places:
Setting |
Pass option |
|
|
|---|---|---|---|
Embed the compiled binary inside the |
|
|
|
Fail instead of falling back to CPU |
|
|
- |
All of them default to off. A setting is on if any one of those places turns it on. For example,
embed_context: true, or session_options: {"ep.context_embed_mode": "1"}, or (for aot)
model_compiler_options: {"embed_compiled_data_into_model": true} each embed the binary.
If the places disagree, the pass option (embed_context / disable_cpu_fallback) wins: with
embed_context: true the binary is embedded even if ep.context_embed_mode is "0", and a warning is logged.
Olive then writes the final value to every place that applies, so ONNX Runtime never sees conflicting values.
Olive also always sets session_options["ep.context_enable"] = "1". update_genai_config defaults to false,
so the existing single-model and per-device compilation flows do not modify genai_config.json. When enabled,
genai_config_role selects the top-level model role to update, such as "vision"; the source config must appear
exactly once in model_attributes.additional_files.
For a decoder represented by a composite model with llm_pipeline metadata, the pass compiles its context and
iterator components and leaves the other components unchanged. Set update_genai_config: true with
genai_config_role: "decoder" to update the decoder pipeline stages. weight_sharing: true shares the context
binary between each corresponding context/iterator pair and requires compile_flow: "jit", embed_context: false,
equal-sized context and iterator groups, and external weights that use the same relative paths and refer to the same
source files. target_devices is not supported for these pipeline composites. To compile only a vision component
from a larger composite, select it with builds.<name>.components; this gives the pass a single ONNX model.
All other session_options, model_compiler_options and provider_options are passed to ONNX Runtime unchanged.
model_compiler_options keys must match onnxruntime.ModelCompiler constructor arguments and are validated before the
plugin is registered. Enum options (graph_optimization_level, flags) accept a member name, a |-joined set of names
for flags, or the integer value (for example "ORT_DISABLE_ALL" or 0). Boolean and integer options also accept
their JSON string forms ("false", "32"), but values such as 2 for a boolean or 3.7 for an integer are rejected.
compile_flow must be "aot" (the default, compiles with ModelCompiler) or "jit" (compiles by creating an
inference session). model_compiler_options only apply to "aot"; setting them with "jit" raises an error.
Physical devices (GPU, CPU, local NPU)#
A plain ep_registration_name such as "OpenVINO" exposes the physical devices on this
machine. List their IDs and types:
python -c "import onnxruntime as ort, onnxruntime_ep_openvino as ep; ort.register_execution_provider_library('OpenVINO', ep.get_library_path()); print([(f'{d.device.device_id:X}', str(d.device.type)) for d in ort.get_ep_devices() if d.ep_name == 'OpenVINOExecutionProvider'])"
Set the accelerator device to gpu, cpu, or npu, ep_registration_name to "OpenVINO", and
target_devices to the ID of the device.
Without target_devices, the pass compiles one EPContext model for the single OpenVINO device of the accelerator’s
device type. Set ep_device_filters (for example {"device_id": "B03E"} or {"npu_platform": "5010"}) only
when the plugin exposes more than one device of that type.
Output checks and retries#
After compiling, the pass checks that the output contains EPContext nodes and that every non-embedded binary they reference exists. A model whose nodes all fell back to CPU is rejected. If compilation or this check fails, the files written by that attempt are removed, so rerunning the workflow with the same output path works.
ORTModelPackage options#
Option |
Purpose |
|---|---|
|
Package/component name. Defaults to the shared-asset model’s file stem. Must be a single path component (no separators or |
|
Runtime session options written into each variant’s |
|
Runtime EP options written into each variant’s |
|
Variant naming. Fields: |
|
Stage the original model and its external-data files once as a content-addressed asset that weightless variants read their weights from. |
|
Original ONNX model for the shared asset. Defaults to the |
The variant field is the component name for a composite input model (the device ID when produced
by EPContextBinaryGenerator) and default for a single ONNX model.
Packaging existing EPContext models#
ORTModelPackage does not compile, so it can package EPContext models that are already available, even when
they are in different folders. Provide them as a CompositeModel input, with one ONNXModel component
per EPContext model. The component name becomes the variant. A single ONNX model input is also accepted
and becomes one default variant.
{
"input_model": {
"type": "CompositeModel",
"model_component_names": [ "643E", "B03E" ],
"model_components": [
{ "type": "ONNXModel", "model_path": "C:/path/to/lnl", "onnx_file_name": "model_ctx.onnx" },
{ "type": "ONNXModel", "model_path": "C:/path/to/ptl", "onnx_file_name": "model_ctx.onnx" }
]
},
"systems": {
"local_system": {
"type": "LocalSystem",
"accelerators": [ { "device": "npu", "execution_providers": [ "OpenVINOExecutionProvider" ] } ]
}
},
"host": "local_system",
"target": "local_system",
"passes": {
"ov_model_package": {
"type": "ORTModelPackage",
"package_name": "my-model",
"shared_asset_model_path": "C:/path/to/original_model.onnx",
"session_options": {
"ep.enable_weightless": "1",
"ep.context_file_path": "model_ctx.onnx"
}
}
},
"engine": {
"search_strategy": false,
"evaluate_input_model": false,
"no_artifacts": true,
"output_dir": "C:/path/to/output"
}
}
Where each file comes from:
Files |
How they are passed |
|---|---|
EPContext models |
One component per model in |
EPContext |
Not passed separately. They are copied from each EPContext model’s folder: files referenced by the model’s EPContext nodes ( |
Original model and its weights |
|
Set create_shared_asset to false if the EPContext models embed their weights. If they still read
external data, provide the weights folder through session_options
(session.model_external_initializers_file_folder_path). Paths that are absolute or contain .. are rejected.
This pass creates packages for ONNX Runtime’s model-package loader. Its output is not a
replacement for packages generated by olive generate-model-package for ONNX Runtime GenAI.
Applications that load these packages should use ONNX Runtime’s stable C/C++
OrtModelPackageApi, obtained from OrtApi::GetModelPackageApi. Package authoring
uses ORT’s onnxruntime.ModelPackage Python API.