onnxruntime
86907281 - Add Python bindings for EPContext data callbacks (#32271)

Commit
35 days ago
Add Python bindings for EPContext data callbacks (#32271) ### Description <!-- Describe your changes. --> Exposes stable named EPContext data read/write callbacks through Python. - Provides allocator-backed read buffers, callback-scoped write views, status propagation, GIL/reentrancy handling, and retained session/compiler callback snapshots. - Uses callback/state-only native registration. `max_data_size` is retained and enforced by Python-owned callback state; no removed native read-options API or native size-policy field is used. - Tests retained buffer limits, exact-limit allocations, oversized rejection, copied options, and callback ownership. - Merges #32265 at `e0cc266cdefef4e27104b14e4091a9d61f75a214`, including its main-branch update, retained-NHWC READ-support validation, and provider-specific callback preflight before capability-time I/O. - No additional Python callback signature change is required by this refresh; capability preflight stays in the core runtime. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> This independent binding PR remains stacked on #32265. It enables bounded, application-managed EPContext I/O without reintroducing payload policy into the stable native transport ABI. The latest core checks provider-specific callback requirements before capability discovery, including AOT, NHWC, and ORT-format paths, rather than relying solely on checks immediately before `Compile()`. Existing Python callback failure and lifetime behavior is preserved. Retarget to `main` after #32265 lands. ### Testing Revalidated on Windows using the existing isolated Python environment: - `cmake --build .\build\WindowsBindings\RelWithDebInfo --config RelWithDebInfo --parallel 8 --target onnxruntime_pybind11_state example_plugin_ep` — passed after merging `e0cc266cde`, including regeneration for the updated core dependencies. - Verified that the build's native/core/public-header/example-EP sources match `e0cc266cde` and that Python imports the freshly rebuilt 1.31.0 module with the callback API present. - From `build\WindowsBindings\RelWithDebInfo\RelWithDebInfo`, `python -m pytest C:\Users\gnallasamy\Codes\ort-bindings-471c3cdf\python\onnxruntime\test\python\onnxruntime_test_python_compile_api.py -q` — 14 passed, 2 hardware-dependent skips. - Scoped `ruff check`, `ruff format --check`, and `git diff --check e0cc266cdefef4e27104b14e4091a9d61f75a214 HEAD` — passed. The source-tree package emitted its expected missing build/package-metadata warning. GPU/hardware-provider-specific preflight paths and non-Windows runs were not performed. --------- Co-authored-by: Gopalakrishnan Nallasamy <gopalakrishnan.nallasamy@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
Parents
Loading