Skip to content

Promote EPContext data callbacks to stable API - #32265

Merged
Gopalakrishnan Nallasamy (GopalakrishnanN) merged 20 commits into
mainfrom
GopalakrishnanN/stable-epcontext-data-api
Oct 5, 2026
Merged

Gopalakrishnan Nallasamy (GopalakrishnanN) merged 20 commits into
mainfrom
GopalakrishnanN/stable-epcontext-data-api

Conversation

@GopalakrishnanN

@GopalakrishnanN Gopalakrishnan Nallasamy (GopalakrishnanN) commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Promotes the experimental EPContext named-buffer callback transport to the stable ONNX Runtime 1.31 C and C++ APIs.

  • Adds stable read/write callback registration and immutable EP-facing snapshots of the callback and application-state pointers.
  • Implements review option 3: removes max_data_size and the proposed read-options type, constructor, getter, setter, and release APIs. Registration and retrieval carry only callback/state pointers.
  • Leaves allocation limits to the application callback and data validation/deserialization limits to the EP. ORT does not invoke the callback or inspect its result. The sample helper can enforce an EP-selected limit without putting that policy into the stable ABI.
  • Adds append-only GetEpContextDataCallbackSupport READ/WRITE advertisement, gated on plugin API version 31. Unsupported participating EPs are rejected before Compile(), including the ORT-format read path. Registered callbacks cannot silently fall back to filesystem I/O.
  • Removes the experimental EPContext lookup entries and C++ wrapper; experimental APIs have no stability guarantee.
  • Updates the C++ wrappers, provider bridge, example EP, tests, and design document.
  • Retains the early support query for providers that can produce external context data without Compile(), with VitisAI's direct-assignment lifecycle rationale documented.
  • Includes the upstream GPU build fix from Replace old use of routing_record with routing_snapshot_ in onnxruntime/contrib_ops/cuda/moe/moe_quantization.cc. #32932 and the previously approved 2 KiB Android size-budget adjustment.

Provider/binding adoption follows in QNN (#32266), OpenVINO (#32267), C# (#32270), and Python (#32271). Those follow-ups need to use the finalized callback/state-only signatures.

Motivation and Context

This graduates the transport introduced experimentally by #28624 and refined by #29294 and #31195. Applications can keep external EPContext data in encrypted or application-managed storage without silently falling back to plaintext filesystem I/O.

Following the payload-policy review, the stable contract is limited to transport, ownership, and support negotiation. Centralized result-size validation would not itself prevent allocation inside the callback; passing a limit to the callback would still depend on callback/EP enforcement. Removing the policy avoids permanent API surface for a guarantee ORT does not provide.

Testing

Windows VS18 builds:

  • cmake --build build\WindowsEpContextStable\RelWithDebInfo --config RelWithDebInfo --parallel 8 --target onnxruntime_shared_lib_test onnxruntime_autoep_test onnxruntime_test_all — passed.
  • cmake --build build\WindowsEpContextMinimal\MinSizeRel --config MinSizeRel --parallel 4 --target onnxruntime_shared_lib_test — passed; minimal configuration disables exceptions, RTTI, and ML ops.

Tests run from build\WindowsEpContextStable\RelWithDebInfo\RelWithDebInfo:

  • .\onnxruntime_shared_lib_test.exe --gtest_filter=EpContextDataApiTest.* — 14 passed, including immutable snapshots, cloning/lifetime, unchanged error outputs, and callback clearing.
  • .\onnxruntime_autoep_test.exe --gtest_filter=*EpContext* — 25 passed, 2 skipped for unavailable Windows symlink privileges. Covers strict support negotiation, callback/file paths, and EP-selected helper size-limit boundaries.
  • .\onnxruntime_test_all.exe --gtest_filter=InternalTestingEP.*EpContext*:InternalTestingEP.Nhwc* — 19 passed.

Tests run from build\WindowsEpContextMinimal\MinSizeRel\MinSizeRel:

  • .\onnxruntime_shared_lib_test.exe --gtest_filter=EpContextDataApiTest.* — 2 passed.

Formatting and git diff --check passed. No references to the removed read-options API or runtime size fields remain in tracked files.

Not validated locally: GPU/Android builds, VitisAI/VAIP hardware behavior, other hardware EP integrations, or the full suite. The VitisAI lifecycle discussion remains open for reviewer confirmation.

Promote named-buffer EPContext callbacks to the stable C and C++ APIs with a required finite read-size policy. Add immutable EP config snapshots, strict participating-EP support negotiation, V28 compatibility shims, hardened sample helpers, example plugin adoption, documentation, and focused API/auto-EP tests.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Promotes EPContext callback transport to the stable ONNX Runtime 1.30 APIs with bounded reads and EP capability negotiation.

Changes:

  • Adds stable C/C++ callback registration, configuration snapshots, and compatibility shims.
  • Enforces read-size limits and READ/WRITE support advertisement.
  • Migrates the example EP and expands compatibility and failure-path tests.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
onnxruntime/test/shared_lib/test_ep_context_legacy_header.c Checks legacy C header compatibility.
onnxruntime/test/shared_lib/test_ep_context_data_api.cc Tests stable and legacy APIs.
onnxruntime/test/autoep/test_execution.cc Tests support negotiation end-to-end.
onnxruntime/test/autoep/library/example_plugin_ep/ep.h Declares stable config and support hook.
onnxruntime/test/autoep/library/example_plugin_ep/ep.cc Advertises callback support.
onnxruntime/test/autoep/library/example_plugin_ep/ep_test_hooks.h Adds support-advertisement test option.
onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc Configures support and stable snapshot.
onnxruntime/test/autoep/library/ep_context_data_utils.h Enforces bounded reads.
onnxruntime/test/autoep/ep_context_data_utils_test.cc Tests oversized payload rejection.
onnxruntime/core/session/provider_bridge_ort.cc Bridges callback configuration.
onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.h Declares plugin support query.
onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc Implements versioned support query.
onnxruntime/core/session/plugin_ep/ep_api.h Declares stable EP APIs.
onnxruntime/core/session/plugin_ep/ep_api.cc Implements EP config snapshots.
onnxruntime/core/session/ort_apis.h Declares stable read setter.
onnxruntime/core/session/onnxruntime_c_api.cc Appends the read setter.
onnxruntime/core/session/inference_session.cc Passes callback state to partitioning.
onnxruntime/core/session/experimental_c_api.cc Forwards legacy APIs.
onnxruntime/core/session/compile_api.h Declares stable write setter.
onnxruntime/core/session/compile_api.cc Implements and registers write setter.
onnxruntime/core/session/abi_session_options.cc Stores and exposes callback policy.
onnxruntime/core/session/abi_session_options_impl.h Declares callback accessor.
onnxruntime/core/providers/shared_library/provider_wrappedtypes.h Wraps provider callback access.
onnxruntime/core/providers/shared_library/provider_interfaces.h Extends provider-host bridge.
onnxruntime/core/framework/session_options.h Stores maximum read size.
onnxruntime/core/framework/graph_partitioner.h Adds callback-registration input.
onnxruntime/core/framework/graph_partitioner.cc Enforces EP support flags.
onnxruntime/core/framework/ep_context_options.h Defines callback snapshot data.
include/onnxruntime/core/session/onnxruntime_experimental_cxx_api.h Aliases deprecated C++ wrapper.
include/onnxruntime/core/session/onnxruntime_experimental_c_api.inc Deprecates V28 lookup APIs.
include/onnxruntime/core/session/onnxruntime_experimental_c_api.h Redirects types to stable API.
include/onnxruntime/core/session/onnxruntime_ep_c_api.h Adds EP config and support APIs.
include/onnxruntime/core/session/onnxruntime_cxx_inline.h Implements stable C++ wrappers.
include/onnxruntime/core/session/onnxruntime_cxx_api.h Declares stable C++ wrappers.
include/onnxruntime/core/session/onnxruntime_c_api.h Defines stable callback contracts.
include/onnxruntime/core/framework/execution_provider.h Adds default support query.
docs/design/Compiled_Model_Encryption.md Documents the stable contract.
cmake/onnxruntime_unittests.cmake Builds the legacy-header test.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread include/onnxruntime/core/session/onnxruntime_experimental_cxx_api.h Outdated
Comment thread onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc
Comment thread onnxruntime/core/framework/graph_partitioner.cc Outdated
Mark the strict-read flag unused when ONNX partitioning is excluded, and preserve the V28 EPContext config shims directly in minimal builds where the plugin EP API implementation is intentionally not linked.
@GopalakrishnanN

Copy link
Copy Markdown
Contributor Author

Python binding follow-up: #32271

Gopalakrishnan Nallasamy and others added 3 commits August 25, 2026 23:51
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread include/onnxruntime/core/session/onnxruntime_experimental_cxx_api.h Outdated
Comment thread include/onnxruntime/core/session/onnxruntime_c_api.h Outdated
Comment thread include/onnxruntime/core/session/onnxruntime_cxx_api.h Outdated
Comment thread include/onnxruntime/core/session/onnxruntime_cxx_api.h Outdated
Comment thread include/onnxruntime/core/session/onnxruntime_cxx_api.h Outdated
Gopalakrishnan Nallasamy and others added 3 commits August 26, 2026 14:09
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.

Comment thread onnxruntime/core/session/inference_session.cc
Comment thread docs/design/Compiled_Model_Encryption.md Outdated
Comment thread include/onnxruntime/core/session/onnxruntime_cxx_inline.h
Gopalakrishnan Nallasamy and others added 2 commits August 29, 2026 09:27
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Scott McKay (skottmckay) added a commit that referenced this pull request Sep 8, 2026
Pulls minimal pieces from #32265 so that should be checked in first.
This was referenced Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants