Skip to content

[CoreAI] Backend-local PTE inspection - #23394

Draft
metascroy wants to merge 1 commit into
coreai-v2/05b-sdk-delegatefrom
coreai-v2/06-pte-inspect
Draft

metascroy wants to merge 1 commit into
coreai-v2/05b-sdk-delegatefrom
coreai-v2/06-pte-inspect

Conversation

@metascroy

@metascroy metascroy commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Adds a private reader that extracts Core AI processed buffers from a PTE without constructing a Program or Method, so cache maintenance can find a program's Core AI models without loading it (runtime/coreai_pte.{h,cpp}).

  • inspect_coreai_pte(DataLoader&) returns the CoreAIBackend processed buffers in method/delegate order.
  • Always runs the flatbuffer structural verifier, the supported-schema-version check and the runtime's semantic validator, even with ET_ENABLE_PROGRAM_VERIFICATION=0; also checks method metadata, unique method names, exact backend IDs, data ranges, alignment and CPU accessibility. Reuses the existing extended-header parser; no shared runtime code changes.
  • Inline buffers borrow the retained program image. Only external segments referenced by CoreAIBackend delegates are loaded, keeping their original FreeableBuffer callbacks; unrelated payloads and named data are not loaded.
  • CoreAIPteData owns the program image and buffers; it is move-only and the loader must outlive it.
  • Tests: a synthetic PTE builder (runtime/test/coreai_pte_fixture.{h,mm}) and a suite covering inline and segmented delegates, method-order routing, exact backend-ID matching, header formats, load-error propagation and buffer release on late failure. The PTE is treated as trusted exporter output, so malformed-PTE coverage is limited to the verifier and version checks.
  • README: "Backend-local PTE Inspection".

No changes outside backends/apple/coreai.

Stack: 8 of 9, based on #23393. Review only this PR's commit. Next: #23395.

Test plan: built locally for macOS 27.0; ctest -N lists coreai_host_test, coreai_swift_bridge_test and coreai_runtime_smoke, which the Core AI workflow runs on the macOS 27 runner. lintrunner is clean.

@pytorch-bot

pytorch-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23394

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 011fb30 with merge base 0b3d26d (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 3, 2026
@metascroy
metascroy force-pushed the coreai-v2/05b-sdk-delegate branch from c14c6ea to 836b175 Compare October 4, 2026 19:48
@metascroy
metascroy force-pushed the coreai-v2/06-pte-inspect branch from 7094d5e to f69015e Compare October 4, 2026 19:48
Summary:
Add a private reader that extracts the Core AI processed buffers from a PTE
without constructing a `Program` or `Method`, so cache maintenance can find a
program's Core AI models without loading it.

- `runtime/coreai_pte.{h,cpp}`: `inspect_coreai_pte(DataLoader&)` returns the
  `CoreAIBackend` processed buffers in method/delegate order.
- It always runs the flatbuffer structural verifier, the supported schema
  version check and the runtime's existing semantic validator, even when
  `ET_ENABLE_PROGRAM_VERIFICATION=0`. It also checks method metadata, unique
  method names, exact backend IDs, data ranges, alignment and CPU
  accessibility.
- It reuses the existing extended-header parser and verifier rather than
  duplicating program parsing. No shared runtime code changes.
- Inline buffers borrow the retained program image. Only external segments
  referenced by `CoreAIBackend` delegates are loaded, and they keep their
  original `FreeableBuffer` callbacks. Unrelated external payloads and named
  data are not loaded.
- `CoreAIPteData` owns the program image and buffers. It is move-only, and the
  loader must outlive it.
- Tests: a synthetic PTE builder (`runtime/test/coreai_pte_fixture.{h,mm}`).
  The suite covers inline and segmented delegates, method-order routing,
  exact backend-ID matching, header formats, load-error propagation and
  buffer release on late failure. The PTE is treated as trusted exporter
  output, so malformed-PTE robustness is limited to the verifier and version
  checks.
- README: "Backend-local PTE Inspection".

No changes outside `backends/apple/coreai`.

Test Plan:
```
# Local: configure and build only
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=27.0 -DEXECUTORCH_BUILD_COREAI=ON \
  -DEXECUTORCH_BUILD_TESTS=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
cmake --build build --target backends/apple/coreai/all
# CI (macOS 27 runner, .github/workflows/coreai.yml)
ctest --test-dir build/backends/apple/coreai --output-on-failure --no-tests=error
```
CTest runs `coreai_host_test` (adding the PTE inspection suite),
`coreai_swift_bridge_test` and `coreai_runtime_smoke`.
@metascroy
metascroy force-pushed the coreai-v2/05b-sdk-delegate branch from 836b175 to a6f16ff Compare October 5, 2026 03:14
@metascroy
metascroy force-pushed the coreai-v2/06-pte-inspect branch from f69015e to 011fb30 Compare October 5, 2026 03:14

This branch was successfully deployed

1 active deployment
cadence — 011fb302 Deployed Oct 5, 2026 by metascroy via hifi-op-test / hifi4 #31510
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant