Skip to content

fix: run each batch of long texts in one CPU run under CoreML - #932

Merged
joein merged 1 commit into
perf/coreml-gpufrom
coreml-cpu-run-budget
Dec 2, 2026
Merged

joein merged 1 commit into
perf/coreml-gpufrom
coreml-cpu-run-budget

Conversation

@joein

@joein joein commented Dec 2, 2026

Copy link
Copy Markdown
Member

Follow-up to #916 and #931, opened against perf/coreml-gpu.

Under CoreML, each batch of long texts now runs on the CPU in one go, as without CoreML. Batching and the CoreML runner each decide how many long texts go together, and they used different budgets. Since #931, batching gives texts longer than 512 tokens the CPU's budget, scaled by 16 divided by the model's attention heads, as on the plain CPU path. The runner split its CPU runs at a flat 2048 tokens, so for many lengths it broke a batch into several runs, and each extra run released the CPU memory pool. The runner now gets the same scaled budget.

For batches that iter_length_sorted_windows forms from texts of 513 to 8192 tokens, sampling every third length, the lengths where the runner split a batch went from 512 to 0 for 8 heads (jina-v2-small) and from 247 to 0 for 12 heads (jina-v2-base, nomic).

Checked on an M2 Max with jinaai/jina-embeddings-v2-small-en, 64 short texts and 256 texts of 2043 tokens: 128 CPU runs of 2 texts instead of 256 runs of 1, 54.6 s instead of 62.9 s, and identical embeddings.

@joein
joein merged commit 6954000 into perf/coreml-gpu Dec 2, 2026
9 checks passed
@joein
joein deleted the coreml-cpu-run-budget branch December 2, 2026 13:49
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