Repository navigation
[CoreAI] Add root and PTE cache clearing - #23395
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23395
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unclassified FailureAs of commit 5320ce4 with merge base 61ec450 ( NEW FAILURE - The following job has failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
7094d5e to
f69015e
Compare
4ab2733 to
d83126b
Compare
d83126b to
25e467e
Compare
f69015e to
011fb30
Compare
|
@claude review this PR |
|
Claude finished @metascroy's task in 2m 32s —— View job This PR adds root-wide and per-PTE Core AI cache clearing; it looks correct, but I'd fix four design issues before merge: the cache key is computed by a copy of the load-path logic, eviction is tested through a function only the tests call, Detailed reviewPR Review: #23395SummaryThe PR adds API Design
Code Quality
Testing
RecommendationRequest Changes The main blocker is the copied key derivation. If it drifts from the load path, clearing will silently do nothing. Moving the eviction tests onto |
011fb30 to
ba2439e
Compare
25e467e to
5b46516
Compare
|
@claude review this code Updated head: Context on the previous findings: the actual key hash already used the same Two intentional contracts remain: (1) incompatible delegates fail before any entry is cleared rather than being silently skipped. Incompatibility does not prove cache absence, and minimum OS is not part of the cache key; success after skipping could conceal incomplete clearing. (2) key validation remains at the destructive storage boundary and has direct invalid-key tests. Please evaluate those contracts explicitly rather than treating their removal as a required cleanup. |
|
Claude finished @metascroy's task in 3m 50s —— View job Head Detailed reviewPR Review: #23395SummaryThe PR adds API Design
Evaluation of the intentional contracts(1) An incompatible delegate fails the whole PTE clear. This is sound for minimum OS but not for platform or architecture mismatches.
(2) Key validation at
RecommendationNeeds Discussion Nothing is unsafe. Before merge, please decide how to recover entries the clear path can't read or evict (clearing an invalid bookmark is a small fix), and narrow contract (1) so that platform/architecture mismatches and an unavailable SDK don't block clearing. |
95295f1 to
f2259cb
Compare
c93235f to
419514c
Compare
f2259cb to
e87ff80
Compare
419514c to
86f50e7
Compare
Summary:
Add public APIs to clear Core AI cache state, either for a whole assets root
or for the models referenced by one PTE.
- `runtime/coreai_cache.{h,mm}`:
- `clear_cache(coreai_assets_dir)` clears every keyed entry in an explicit
assets root.
- `clear_cache_for_pte(loader, dir)` and `clear_cache_for_pte(pte_path, dir)`
clear only the entries for the current platform and architecture that the
PTE's Core AI delegates reference. They find those delegates with
`inspect_coreai_pte`, so no Program/Method is constructed and no Core AI
assets are materialized. Every selected manifest is validated before any
key is cleared. A null directory selects the backend's default root.
- Per key, clearing preflights the staged source tree, evicts the SDK entry,
removes staging, then removes the bookmark. The bookmark is kept until
staging removal succeeds so a failed clear can be retried. SDK errors other
than confirmed absence preserve the key's files. Keys are processed in
sorted order and the first error is returned. Each removal syncs the
directory it changed. Missing roots and entries are no-ops.
- Everything under a keyed `staging/<key>` directory belongs to the backend
and is removed with that key. Outside keyed entries, PTEs, other files, lock
files and unkeyed temporaries are never removed.
- Supporting changes: descriptor-relative keyed staging removal in
`coreai_storage`, bookmark inventory and removal in `coreai_bookmarks`, and
SDK eviction plus per-key clearing in `coreai_load_coordinator`.
- Tests: cache-clearing and eviction suites in `coreai_host_test`.
`coreai_runtime_smoke` also links every public cache-clearing overload.
- README: "Clearing cached assets".
Callers must unload affected models and stop concurrent loads, inference and
maintenance until these calls return. Per-key locks are not a whole-root
barrier.
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 cache-clearing and eviction suites),
`coreai_swift_bridge_test` and `coreai_runtime_smoke`.
Summary: Prevent loading and maintenance from drifting in how they select model assets, and let applications clear the default cache without reconstructing a private path. Exercise real clearing behavior for eviction failures and loaded models while preserving strict compatibility checks and storage validation. Simplify the public maintenance documentation. Test Plan: Built the CoreAI targets and ran all four CTest suites successfully, including native host tests, Swift bridge tests, SDK source-lifetime tests, and runtime smoke coverage. New tests verify portable/AOT load-to-clear identity, isolated default-root clearing, rejection before mutation, and production eviction failure/retry behavior. Ran the complete CoreAI Python suite: 113 passed. Whitespace checks passed. The generic validator could not complete its Buck ownership query; native and Swift validation passed through CMake.
Clear every recorded variant associated with a PTE regardless of host loading compatibility. Persist durable per-key attribution without changing existing cache keys, and report incomplete cleanup when older entries cannot be safely identified. Recover malformed local entries without following links, while preserving uncertain SDK eviction state for retry. Test Plan: Ran all five CoreAI CTest suites: 236 native tests, 18 Swift tests, PTE export, real SDK source-lifetime checks, and runtime smoke all passed. Coverage includes cross-platform and architecture variants, legacy attribution, malformed entries, publication/removal failures, retry durability, and preservation of outside files. Ran the complete CoreAI Python suite: 124 tests passed. Formatting and whitespace checks passed. The generic Buck Swift owner lookup still fails without diagnostics; CMake build and functional validation passed.
Log eviction request, confirmed SDK absence, and local cleanup completion. Add clear-aware stripe reuse and per-key isolation regressions, and cover durable-save and eviction failure log boundaries. Preserve the previously validated final implementation after placing storage and acquisition changes in their owning PR layers. Test Plan: Exact final CoreAI tree matches the saved validated snapshot: 256 native tests, all five CTest targets, 124 Python tests, and playground rebuild passed. Lower bookmark and acquisition layers were also built and tested independently during placement.
Reuse current cache identity for noncreating inventory and model-prefix selection. Keep SDK eviction and maintenance preflight/deletion under the entry lock, preserve separate strict runtime cleanup, and remove superseded sidecar attribution and migration paths. Update cache tests, documentation and data-loader linkage. Test Plan: Fresh native build and all five scoped CoreAI CTest targets passed. Final incremental build and 5/5 CTests passed after removing duplicate preflight. Scoped lint, explicit formatting and whitespace checks passed. No Python changes or Python suite run.
Make directory ownership and lifecycle responsibilities explicit, support configured symlink directories consistently, and remove ambiguous naming across export and runtime. Consolidate shared helpers and organize the bridge and tests while preserving cache durability and execution contracts. Test Plan: Backend Python suite: 124 passed. Static and shared CoreAI builds succeeded; each configuration passed all 5 CTest targets. One SDK source-lifetime test returned incorrect output during concurrent static/shared runs; the isolated static rerun passed. That unexplained failure is left for separate investigation. Scoped lint, Objective-C++ formatting, and whitespace checks passed. Generic Buck validation was unavailable because its owner query failed without source diagnostics.
Rename the per-key source bundle directory to sources/ and in-progress builds to .pending-<uuid>, so "staging" no longer names two different things. Split cache directory resolution into create and open entry points, which removes an unreachable check in the backend and documents the mode-dependent not-a-directory errors. Share the storage recheck-and-unlink and full-sync steps, return owned descriptors, and drop redundant identity and lock-stripe checks. Rename bookmark test files to cache entry and remove trivial test wrappers. Test Plan: Static CoreAI build of all targets succeeded; all 5 CoreAI CTest targets passed (coreai_host_test: 251 passed, 6 Info-log tests skipped as before). lintrunner CLANGFORMAT passed on changed headers. Shared build, Python suite, and CMake lint were not run.
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)andclear_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.Stack: 9 of 9, based on #23394. Review relative to that base.
Test plan: