OpenVINO Model Package (EPContextBinaryGenerator + ORTModelPackage)#

Creating an ONNX Runtime .ortpackage for OpenVINO takes two passes:

  1. EPContextBinaryGenerator compiles an ONNX model into an EPContext model for each selected OpenVINO device (NPU, GPU, or CPU).

  2. ORTModelPackage assembles EPContext models into an .ortpackage through ONNX Runtime’s onnxruntime.ModelPackage authoring API. It is not specific to OpenVINO; the execution provider comes from the workflow’s accelerator.

The package directory is the deliverable.


Prerequisites#

  1. Python 3.12, the OpenVINO stack for the selected device.

  2. Olive with the OpenVINO plugin EP:

    pip install "olive-ai[openvino-ep]"
    

    This installs Olive, onnxruntime, the onnxruntime-ep-openvino plugin and openvino, which is enough for EPContextBinaryGenerator. (From an Olive source checkout, use pip install -e ".[openvino-ep]" instead.)

  3. For ORTModelPackage, update ONNX Runtime to 1.32 or later:

    pip install -U "onnxruntime>=1.32"
    

ONNX Runtime version requirements:

Feature

Minimum ONNX Runtime

EPContextBinaryGenerator with the OpenVINO plugin EP

1.23

Weightless compilation (ep.enable_weightless)

1.30 (older releases use ep.enable_weightless_ep_context_nodes)

Per-device binary naming with target_devices and aot

1.32 (without it, each binary keeps ORT’s default name in its device folder)

ORTModelPackage

1.32 (the first release with the onnxruntime.ModelPackage authoring API and the stable OrtModelPackageApi used to load packages)


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:

ep_registration_name

Devices exposed

"ovep_registration.virtual"

Virtual cross-compile devices

"OpenVINO" (any plain name)

Physical OpenVINO devices on this machine

Known virtual NPU device IDs:

Device

ID

Lunar Lake (LNL)

643E

Panther Lake (PTL)

B03E

Nova Lake (NVL)

D71D


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

session_options key

model_compiler_options key (aot only)

Embed the compiled binary inside the .onnx file

embed_context

ep.context_embed_mode

embed_compiled_data_into_model

Fail instead of falling back to CPU

disable_cpu_fallback

session.disable_cpu_ep_fallback

-

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_name

Package/component name. Defaults to the shared-asset model’s file stem. Must be a single path component (no separators or ..); the same applies to package_name + package_suffix.

session_options

Runtime session options written into each variant’s executor_info.ort.session_options. They are not inherited from EPContextBinaryGenerator; set the ones needed at load time (e.g. ep.enable_weightless for weightless models). Keep ep.context_file_path set to the EPContext model file name; without it the package builds but fails to load. ONNX Runtime requires string values, so numbers are converted to strings and booleans to "1"/"0"; other value types are rejected.

provider_options

Runtime EP options written into each variant’s executor_info.ort.provider_options; ONNX Runtime applies them on top of the selected device’s defaults when the package is loaded without caller-supplied session options. Not inherited from EPContextBinaryGenerator. Values are converted to strings like session_options.

variant_name_template

Variant naming. Fields: package_name, device, variant. Defaults to {package_name}.{device}_{variant}.

create_shared_asset

Stage the original model and its external-data files once as a content-addressed asset that weightless variants read their weights from.

shared_asset_model_path

Original ONNX model for the shared asset. Defaults to the source_model_path attribute set by EPContextBinaryGenerator.

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 model_components. Each can be in its own folder.

EPContext .bin files

Not passed separately. They are copied from each EPContext model’s folder: files referenced by the model’s EPContext nodes (ep_cache_context, as a relative path inside that folder) and <model stem>*.bin files next to it. Keep them beside, or below, the EPContext model.

Original model and its weights

shared_asset_model_path points to the original .onnx. The external-data (weight) files recorded in that model are copied from its folder, so keep them where the model expects them.

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.