Repository navigation
[CoreAI] Backend-local PTE inspection - #23394
Conversation
🔗 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. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
c14c6ea to
836b175
Compare
7094d5e to
f69015e
Compare
836b175 to
a6f16ff
Compare
f69015e to
011fb30
Compare
|
@claude review this PR |
|
Claude finished @metascroy's task in 2m 44s —— View job PR Review: #23394I found no correctness bugs. The main issue is that Detailed reviewSummaryThis PR adds
Code Quality
Testing
RecommendationApprove. Nothing blocks merging. Before landing, I'd recommend either trimming the validation back to |
011fb30 to
ba2439e
Compare
a6f16ff to
ed11289
Compare
|
@claude review this code Updated head: Context on the previous findings: unrelated method-metadata validation, unique-name checks, and the second header comparison were removed. One correction to the earlier review: required method metadata is checked by We intentionally retained FlatBuffer verification, overflow/range checks, checks for references actually dereferenced by this reader, and the exact returned-buffer-size guarantee. The exact-size check is not redundant with a minimum-size check: it rejects oversized buffers that would otherwise be returned intact. Those cases now have focused coverage, alongside malformed CoreAI references, bounds, alignment, and release-on-failure tests. Misalignment returns |
|
Claude finished @metascroy's task in 3m 45s —— View job PR Review: #23394 (head
|
95295f1 to
f2259cb
Compare
f2259cb to
e87ff80
Compare
fcc39d9 to
d07e206
Compare
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:
```
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
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`.
Summary: PTE inspection should not reject programs for metadata unrelated to extracting delegate payloads. Remove those requirements and redundant checks while preserving bounds and buffer-ownership guarantees, and verify both compatibility and malformed-input handling. Test Plan: All four Core AI CTest suites passed on macOS 27. New native tests confirmed acceptance of missing method metadata and duplicate method names alongside normal program loading, and acceptance of empty processed buffers. Malformed references, invalid header and segment ranges, misaligned images, and short or oversized loads were rejected with owned buffers released. The full Core AI Python suite passed: 113 tests.
Skip unselected delegates with missing IDs, match runtime missing-reference errors and legacy headers, share the backend identifier, and clarify ownership. Cover semantic validation, unknown locations, safe legacy bounds, and inspection of a real exported PTE. Test Plan: CMake build and all five CTest suites passed (183 native tests, 18 Swift tests, real exported-PTE comparison, portable/AOT source lifetime, registration smoke). Full Python suite: 124 passed. Formatting, Ruff and whitespace checks passed. Generic Buck owner validation still fails without diagnostics.
Keep header parsing, program verification, inline borrowing and segment loading backend-local. Carry verified storage with its program view and preserve runtime-compatible bounds, error codes, method order and loader ownership. Test Plan: Fresh native build and all five scoped CoreAI CTest targets passed, including exported-PTE inspection and existing bounds, short-load, late-failure and ownership coverage. Scoped lint and formatting passed. No Python code changes or Python suite run.
e87ff80 to
d981f5d
Compare
Adds backend-scoped cache clearing with a shared identity for loading, specialization, and deletion. - `clear_cache(coreai_assets_dir)` clears every discoverable keyed entry in an explicit backend assets root. It is not an SDK-wide cache wipe. - `clear_cache_for_pte(loader, dir)` and `clear_cache_for_pte(pte_path, dir)` inspect all Core AI delegate manifests and bundle digests before deleting anything. They clear every matching stored device and specialization variant in that root without constructing a Program/Method, materializing assets, or querying the current device or specialization policy. A null directory selects the backend default root. - Composite keys contain a model hash, readable device component, and specialization hash. The model prefix permits all-variant matching without attribution sidecars. Key construction, validation, and parsing share one module. - An immutable loader-owned snapshot supplies both SDK specialization options and their stable descriptor. Default options retain the existing default specialization hash; non-default descriptors use versioned deterministic encoding. The coordinator reads the descriptor once before lookup. - Inventory includes both bookmark files and staged entries, so interrupted source preparation remains discoverable. Older single-hash entries are not discovered by the new inventory. - Per key, clearing evicts the SDK entry, removes staging, then removes the bookmark. Errors preserve retryable state. Keys are processed in sorted order; missing entries are no-ops. Lock stripes remain bounded, and collisions intentionally serialize. - Specialization uses the default SDK cache with storage-pressure-only purging. Deleting staged source does not make the entry eligible for purging, while storage pressure can reclaim orphaned artifacts. Restoring an existing persistent entry does not update its retention policy. - Callers must unload affected models and stop concurrent loads, inference, and maintenance until clearing returns. Per-key locks are not a whole-root barrier. Unkeyed temporaries, lock files, and unrelated files are not removed. Stack: 9 of 9, based on #23394. Review relative to that base. Test plan: - All five native CTest targets passed: host regressions, PTE export, Swift bridge, real-SDK source lifetime, and runtime smoke. - Regressions cover specialization isolation, descriptor stability, policy flags, all-variant clearing, staging-only cleanup, filename limits, and retry behavior. Real-SDK tests cover restoration after staged-source deletion. - Complete CoreAI Python suite: 124 passed. - Lint, iOS syntax checks, and whitespace checks passed. The standalone stress runner rebuilt successfully; it was not rerun for this update.
Adds a private reader that extracts Core AI processed buffers from a PTE without constructing a
ProgramorMethod, so cache maintenance can find a program's Core AI models without loading it (runtime/coreai_pte.{h,cpp}).inspect_coreai_pte(DataLoader&)returns theCoreAIBackendprocessed buffers in method/delegate order.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.CoreAIBackenddelegates are loaded, keeping their originalFreeableBuffercallbacks; unrelated payloads and named data are not loaded.CoreAIPteDataowns the program image and buffers; it is move-only and the loader must outlive it.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.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 -Nlistscoreai_host_test,coreai_swift_bridge_testandcoreai_runtime_smoke, which the Core AI workflow runs on the macOS 27 runner.lintrunneris clean.