Repository navigation
[CoreAI] Prepare source bundles - #23390
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23390
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. |
9d457ae to
84780b8
Compare
f74a984 to
68a8b17
Compare
|
@claude review this PR |
|
Claude finished @metascroy's task in 2m 44s —— View job PR Review: #23390I found no blocking correctness bugs. The main issues are that source publication skips the full device flush that bookmark publication uses, even though a damaged bundle is never replaced; the failure paths described in the README are not tested; and the Detailed reviewSummaryThis PR adds Code Quality
API Design
Testing
Performance
RecommendationNeeds Discussion Nothing here is a crash or a data race. Before merging, it's worth settling the durability-vs-no-replacement point (add |
84780b8 to
e36e1ed
Compare
68a8b17 to
65217f5
Compare
|
@claude review this code Updated head: Context on the previous findings: cache identity is supplied by the caller and already includes the selected bundle's export-time digest plus platform/SDK context. We documented that contract rather than deriving a digest-only key inside source preparation. The no-replacement policy and absence of runtime content hashing are intentional. Abandoned-temporary recovery must not blindly sweep another active loader's files; it is separate from normal failure cleanup. Batching repeated directory syncs remains a potential optimization requiring measurement and care with durability ordering, not an established correctness defect. Durability, error propagation, and focused failure-path coverage were strengthened. |
|
Claude finished @metascroy's task in 4m 9s —— View job PR Review: #23390The fixes from the last round hold up and I found no blockers: the manifest path check doesn't account for macOS filename case folding or Unicode normalization, and a few failure-path tests are weaker than they appear. Detailed reviewSummaryThis PR adds The changes from the last round are correct:
The issues below are about manifest path validation and how strong the tests are. Code Quality
API Design
Testing
RecommendationApprove Nothing here blocks merging. The case-folding and Unicode checks in |
65217f5 to
afd4d5a
Compare
e36e1ed to
aaf5f40
Compare
Summary:
Materialize the selected Core AI source bundle on disk under the assets root,
so the SDK can specialize it.
- Source preparation (`runtime/coreai_assets.{h,mm}`): read inline bundle
files through `NamedDataMap` and write them unchanged under the assets root,
keyed by the export-time bundle digest (no runtime payload hashing). Reuse
checks the exact file set, sizes, entry types and directory structure.
Incomplete or malformed existing sources fail without being replaced, since
an SDK model may still be using them. Same-size content changes are not
detected.
- Cold publication stages into `.staging-<uuid>` and publishes with
`renameatx_np(RENAME_EXCL)`, with inspection, staging and publication all
relative to one open root descriptor. If another loader publishes first, its
bundle is validated and used.
- Tests: adds the filesystem snapshot helpers used from here on.
- SDK acquisition is not included here.
- README: the "Asset storage" materialization, publication and completeness
text.
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`, which adds the source suite.
ExclusivePublicationValidatesWinnerAndRemovesLosingStaging covers the
concurrent `RENAME_EXCL` race.
Summary: Strengthen publication durability because damaged stored bundles cannot be replaced safely. Keep failures visible and retries under caller control, preserve meaningful errors, and make content-identity requirements explicit. Test Plan: Ran the native host suite on macOS 27: 79 tests passed and one existing APFS invalid-UTF-8 test skipped. All 18 source-bundle tests passed five consecutive runs. Fault injection verified flush ordering, errors without automatic retries, temporary cleanup, and complete contents after post-rename failure. Malformed existing bundles and incomplete concurrent winners were preserved. The Python suite remains blocked during collection by the existing torch/torchao mismatch: torch.ao.quantization.quantizer is missing.
Summary: Allow canonically equivalent Unicode paths to survive filesystem conversion without changing delivered names or bytes. Ensure reused sources are durable before returning and preserve syscall error and interruption handling throughout publication. Test Plan: Reproduced the composed-Unicode materialization failure before the fix. All 96 native tests passed with zero skips, including Unicode cold/warm loads, alias rejection, flush failures and retries, staging cleanup, and permission errors. All 113 CoreAI Python tests passed. Formatting and whitespace checks passed.
Summary: Keep temporary source directories consistent with the default permission policy without weakening exclusive staging creation. Restore the actual original permissions in access-failure tests instead of assuming owner-only directories. Test Plan: All 118 native host tests and 113 Python backend tests passed. Published-directory permissions and access-error recovery passed under umasks 0000, 0022, and 0077.
Consume immutable selected bundles and lock-owned cache identities, with explicit inspection, staging, publication and recovery stages. Share fd-bound two-pass removal with strict and maintenance policies while preserving durability and no-follow checks. Adapt fixtures and add exact-tree, removal-race and corrupt-replacement coverage. Test Plan: 132 native tests and scoped CoreAI CTest passed; 113 Python tests passed. Scoped lint, all CoreAI Objective-C++ formatting and whitespace checks passed. Generic Buck owner validation is unavailable for this checkout.
69dcfe9 to
cdfeb59
Compare
54afb00 to
b9a5ca5
Compare
Adds the private bridge between ExecuTorch's Objective-C++ code and the
Swift `CoreAI` framework, and packages it for CMake consumers. No
ExecuTorch delegate yet; a later PR wires this into `CoreAIBackend`.
* `runtime/ETCoreAIBridge.h`: Objective-C protocols for model
acquisition, prepared models, sessions and tensor transfer, plus
availability, device architecture and loader factory entry points.
* `runtime/ETCoreAIModel.swift` (module `CoreAIBridge`):
* Restore models from bookmarks, specialize source bundles with the
persistent default SDK cache, bind named functions with ordered
inputs/outputs, and evict cache entries.
* Asynchronous SDK calls run in detached tasks and report through
completion blocks. Only an SDK nil result is a cache miss; thrown errors
keep their underlying cause.
* Inputs are borrowed from caller storage through Core AI raw views;
outputs use one `memcpy` for dense row-major arrays and strided copies
otherwise.
* `runtime/ETCoreAITensor.mm`, `runtime/coreai_bridge.mm`: tensor
wrappers and C entry points, built as the private `coreai_bridge_obj`
object library so the delegate can absorb them and host tests can
substitute a fake bridge.
* Build (`backends/apple/coreai/CMakeLists.txt`): requires CMake 3.31
and Ninja/Xcode, keeps ExecuTorch's numeric preprocessor definitions
away from swiftc, applies an OS 27 minimum only to Core AI targets, and
builds `coreai_swift`. `cmake/PublishSwiftHeader.cmake` publishes the
generated header for Xcode.
* Tests: `runtime/test/SwiftBridgeTests.swift` is built with the bridge
sources into the `coreai_swift_bridge_test` XCTest bundle (Ninja, macOS)
and run by CTest under `xcrun xctest`. The invalid-URL case uses a
non-file `coreai-test:` URL.
* README: "SDK Bridge" and the build requirements in "Building".
* Changes outside `backends/apple/coreai` are CMake and CI only, and
only take effect when `EXECUTORCH_BUILD_COREAI=ON`:
* `tools/cmake/ExecuTorchCoreAIDependencies.cmake` (new): resolves
Foundation, CoreAI and Swift runtime link paths from the consumer's SDK;
fails configuration for SDKs older than 27.
* `CMakeLists.txt`: install that file into the package config.
* `tools/cmake/preset/default.cmake`: note the SDK 27 requirement.
* `.github/workflows/coreai.yml`: also trigger on changes to
`ExecuTorchCoreAIDependencies.cmake`.
Stack: 5 of 9, based on #23390. Review only this PR's commit. Next:
#23392.
Test plan: built locally for macOS 27.0; `ctest -N` lists
`coreai_host_test` and `coreai_swift_bridge_test`, which the Core AI
workflow runs on the macOS 27 runner. The XCTest bundle links CoreAI, so
it only runs there (first CI run of it). `lintrunner` is clean.
Persists the raw SDK bookmark for a selected Core AI bundle, so later
loads can restore a specialized model without re-reading the payload
(`runtime/coreai_bookmarks.{h,mm}`).
* Store raw opaque bookmarks (at most 8 MiB) with atomic publication.
* Keys include the bundle digest, platform, architecture and persistence
policy, but not function bindings or delivery location.
* Per-key OS locks coordinate threads and processes; independent keys
proceed in parallel.
* SDK acquisition and cache removal are not included here.
* Tests: the bookmark suite in `coreai_host_test`, including a
cross-process lock test that spawns child processes.
* README: the "Asset storage" key derivation, bookmark bound and locking
text.
No changes outside `backends/apple/coreai`.
Stack: 3 of 9, based on #23388. Review only this PR's commit. Next:
#23390.
Test plan: built locally for macOS 27.0; `ctest -N` lists
`coreai_host_test`, which the Core AI workflow runs on the macOS 27
runner. `lintrunner` is clean.
Materializes the selected Core AI source bundle under the assets root so the SDK can specialize it (
runtime/coreai_assets.{h,mm}).NamedDataMapand write them unchanged, keyed by the export-time bundle digest (no runtime payload hashing)..staging-<uuid>and publishes withrenameatx_np(RENAME_EXCL), all relative to one open root descriptor. If another loader publishes first, its bundle is validated and used.coreai_host_test, plus the filesystem snapshot helpers used from here on.ExclusivePublicationValidatesWinnerAndRemovesLosingStagingcovers the concurrentRENAME_EXCLrace.No changes outside
backends/apple/coreai.Stack: 4 of 9, based on #23389. Review only this PR's commit. Next: #23391.
Test plan: built locally for macOS 27.0;
ctest -Nlistscoreai_host_test, which the Core AI workflow runs on the macOS 27 runner.lintrunneris clean.