Skip to content

fix: fall back when the CoreML export or cache is unavailable - #930

Merged
joein merged 4 commits into
perf/coreml-gpufrom
pr916-coreml-fixes
Dec 2, 2026
Merged

joein merged 4 commits into
perf/coreml-gpufrom
pr916-coreml-fixes

Conversation

@joein

@joein joein commented Dec 2, 2026

Copy link
Copy Markdown
Member

Two fixes for #916, opened against its branch perf/coreml-gpu.

Offline, CoreML no longer stops a cached model from loading. For the six models with a CoreML source, _init_coreml downloaded that repository in __init__ and let any error escape. With HF_HUB_OFFLINE=1 or local_files_only=True and the export not cached, TextEmbedding(...) raised "Could not load model ... from any source", although the model itself was cached. It now warns, names the missing repository, and runs the model on CPUExecutionProvider.

A read-only cache no longer breaks the first CoreML batch. _create_session always created <cache_dir>/coreml/<model> and a lock file in it, so with a read-only cache_dir the first batch of 4 or more texts raised OSError. If the folder or the lock can't be created, it now logs one warning and lets onnxruntime compile into a temporary directory. With a writable cache, the lock still makes processes compile one at a time.

tests/test_coreml.py covers both, and checks that a writable cache is still used. The tests stub the CoreML provider and sessions, so they run on Linux too. The first two fail on perf/coreml-gpu.

Checked on an M2 Max:

  • BAAI/bge-small-en with HF_HUB_OFFLINE=1 and its CoreML export not cached: one warning, runs on the CPU, vectors identical to a CPU-only model.
  • BAAI/bge-small-en-v1.5 with a read-only ModelCacheDirectory: one warning, compiled in 27 s, ran on CoreML with cosine 0.999999 against the CPU, and wrote nothing to the folder.

🤖 Generated with Claude Code

@joein
joein merged commit fc13ac7 into perf/coreml-gpu Dec 2, 2026
9 checks passed
@joein
joein deleted the pr916-coreml-fixes branch December 2, 2026 11:08
joein added a commit that referenced this pull request Dec 2, 2026
* perf: run text embeddings on the Apple GPU with CoreML

* fix: use np.flatnonzero so mypy passes with numpy 2.4 stubs

* chore: Address review

* chore: forward max_batch_tokens to CoreML workers

* refactor: move CoreML support into CoreMLMixin

* chore: run CoreML in the current process, ignoring parallel

* fix: fall back when the CoreML export or cache is unavailable (#930)

* fix: fall back when the CoreML export or cache is unavailable

* tests: remove CoreML fallback tests

* fix: lock CoreML session creation and load all lengths in the constructor

* fix: default to 3 CoreML lengths, document their cost and shorten load logs

* fix: keep the CPU batch budget for texts longer than the CoreML lengths (#931)

* fix: fall back quickly and quietly when the CoreML export can't be downloaded (#933)

* fix: download the CoreML export once and quietly

* fix: call the CoreML export the CoreML-compatible copy in the warning

* fix: run each CoreML batch of long texts in one CPU run (#932)

* docs: list CoreML models in the README and shorten its example

* fix: ignore parallel only for CoreML text models, with a warning (#934)

* fix: ignore parallel only for CoreML text models, with a warning

* fix: resolve parallel through a general hook that CoreML overrides

---------

Co-authored-by: George <george.panchuk@qdrant.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant