fix(retrieval): run the reranker on CPU under CoreML - #33
Conversation
The reranker session registered the CoreML execution provider whenever the
backend was onnx-jina-coreml. No prebuilt reranker ONNX export can run on the
CoreML GPU, and the assumption behind that was that ONNX Runtime would
therefore partition zero nodes and fall back to CPU on its own.
It does not. ORT still assigns a fused subgraph to CoreML. The session builds
successfully, so the CPU retry in LocalReranker::new_with_ep never fires, and
the failure lands at inference instead:
Non-zero status code returned while running
..._CoreML_..._3 node. Name:'CoreMLExecutionProvider_..._3_3'
Status Message: Error executing model: Unable to compute the prediction
using a neural network model (error code: -1)
In practice searches did not error out. They logged "reranker unavailable,
returning unreranked results" and returned BM25 and vector fusion order, so
the CoreML backend silently lost cross-encoder ranking while still exiting 0.
vera doctor --probe reported it as a probe-tiny-inference failure.
Select the CPU provider for the reranker up front via a small mapping
function next to RERANKER_ONNX_FILE, where the reasoning about reranker
assets already lives. This makes the behaviour that doctor's
probe-reranker-coreml-cpu warning and the troubleshooting docs already
describe actually true, and it is unit testable without model assets.
Verified on an Apple M4, macOS 26.6.1, ONNX Runtime 1.24.4, backend
onnx-jina-coreml:
before: probe-tiny-inference fails; search logs "reranker unavailable";
[timing] reranking: 166ms
after: probe-tiny-inference and probe-provider-confirmation pass;
search reranks normally; [timing] reranking: 6418ms
Embedding still runs on CoreML; only the reranker moves to CPU.
|
@coderabbitai review @cubic-dev-ai review |
@lemon07r I have started the AI code review. It will take a few minutes to complete. |
|
Follow-up commit 9b743a2 pushed: the two stale comments (local_models/mod.rs near RERANKER_ONNX_FILE, doctor.rs probe-reranker-coreml-cpu) now describe the explicit CPU pinning via reranker_execution_provider instead of claiming ORT silently falls back on its own. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 3 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe reranker now maps CoreML execution to CPU before session construction. Other providers remain unchanged. Tests cover the mapping, and diagnostic and troubleshooting text describe CoreML inference behavior. ChangesCoreML reranker execution
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change makes CoreML reranking use the CPU provider while preserving CoreML for embeddings, restoring reranked search results on the affected backend. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Closes #41.
Problem
On an
onnx-jina-coremlbackend the reranker fails at inference:vera doctor --probesurfaces it as aprobe-tiny-inferencefailure, withprobe-reranker-sessionstill green. Reproduced deterministically on three consecutive runs.The user-visible effect is worse than the probe suggests. Searches do not fail. They log
and return fusion order, so the CoreML backend silently loses cross-encoder ranking while the command still exits 0.
Root cause
build_sessioninlocal_reranker.rsregisteredCoreMLExecutionProviderwhenever the backend was CoreML.#25 established that no prebuilt reranker export runs on the CoreML GPU and moved every backend onto the quantized INT8 export. The premise recorded alongside that change is that the CoreML EP can execute none of those ops, so ORT partitions zero nodes and falls back to CPU on its own, and
vera doctor'sprobe-reranker-coreml-cpuwarning was added on that basis.That premise does not hold here. The failing node name carries a
CoreMLExecutionProvider_prefix and a subgraph index, so ORT did assign a fused subgraph to CoreML. Partitioning and CoreML model compilation both succeed, which is whyprobe-reranker-sessionpasses; only the prediction fails.The existing CPU retry cannot catch this. It wraps session construction only, and construction succeeds, so inference runs with no fallback behind it.
This is not an ORT version drift:
ORT_VERSIONis1.24.4at v0.12.13, at #25's merge commit, and at v1.0.0.Fix
Select the CPU provider for the reranker up front, through a small mapping function placed next to
RERANKER_ONNX_FILEwhere the reranker-asset reasoning already lives. This makes the behaviour thatprobe-reranker-coreml-cpuanddocs/troubleshooting.mdalready describe actually true.Embedding still registers CoreML. Only the reranker moves to CPU, which is what the quantized INT8 export is already chosen for.
The mapping is a pure function, so the regression is unit testable without ONNX Runtime or model assets. The pre-existing
test_local_rerankercould not have caught this: it pinsOnnxExecutionProvider::Cpuand early-returns when ORT is unavailable.docs/troubleshooting.mdis corrected to stop asserting that ORT falls back on its own.Verification
Apple M4, macOS 26.6.1, ONNX Runtime 1.24.4, backend
onnx-jina-coreml, index of this repository (375 files, 4790 chunks). Same index and query for both runs.probe-tiny-inferenceprobe-provider-confirmationreranker unavailable, returning unreranked results[timing] rerankingcargo fmt --checkclean.cargo clippy -p vera-core --libintroduces no new warnings; the 5 reported are pre-existing (pip_package_for_ep,CUDA_RUNTIME_LIBRARY_PREFIXES,parse_cuda_major_from_runtime_library_entry, an unused import, an unused variable). New test and thelocal_modelssuite pass.Note
Unrelated to this change and present on both binaries against the same index:
vector search failed, falling back to BM25-only resultswithstorage error: vector search failed. Not addressed here.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
Documentation