r/LocalLLaMA • • 2d ago

Resources I stuffed embedding into my Apple Neural Engine

Now you can too!

Super speedy, low power embedding with Gemma 300m for text or multimodal Gemma2, both faster than llama.cpp on M4 (Mac Mini) and M4 Pro (MacBook).

Haven’t tested on other hardware, but did find a couple of small issues sent to Apple’s CoreML folks.

Code by Claud, vibes from me, provided as-is with no guarantee.

https://github.com/headbouyJB/embeddinggemma-ane

6 Upvotes

13 comments sorted by

1

u/MIDZER0000 2d ago

Did you see the biggest speedup when embedding one query at a time or when indexing a batch of documents?

1

u/Green_Ocean90 2d ago

Both, roughly evenly. On the Mac mini (M4) it's about 2× llama.cpp Q8_0 when indexing chunks, and a single query takes about half the time (~5 ms for EmbeddingGemma 2, ~3.7 ms for 300M). On the M4 Pro the gap is smaller, about 1.2–1.3× on indexing, since its bigger GPU makes llama.cpp faster.
Just note the ANE models take one input at a time, so "batch" indexing is really a fast loop, and I measured it one chunk at a time on both engines. The other win is that the GPU stays free the whole time.

1

u/Adelka_Hermen 1d ago

how bad is the initial compilation overhead when loading the model for the first time? Sometimes that cold start penalty is the main bottleneck for local stuff.

1

u/Green_Ocean90 1d ago

A search query is embedded in about 12.5 ms over HTTP on the mini. Most of that is the model itself, about 5 ms for a short query.
Indexing notes runs at roughly 11–12k tokens/s, about twice llama.cpp's speed on the same machine, and leaves the GPU idle.
You only see the 6 s reload if the service itself restarts, which should be rare. The 3.4-minute compile is a first-install cost.

1

u/Aggravating-Push-207 1d ago

Claude doesn't like local AI so do a review pass with even free-tier Antigravity

1

u/Green_Ocean90 1d ago

Haven’t had any issues with clause optimising local ai kernels, helping me wire it up for agent work or indeed getting this Core ML task done 👍

1

u/Aggravating-Push-207 1d ago

1

u/Green_Ocean90 1d ago

Sure so how do you test whether you’re actually winning by switching provider or just seeing normal model vs model disagreement on ideal approach?

I’m measuring achieved vs theoretical hardware performance for my work, so I know how close Claude is getting to the limit, not just blindly ‘make this faster, make no mistakes’.

1

u/Aggravating-Push-207 1d ago

i mean it can't hurt, if gemini gets like any gains then... well you get free performance, amirite? All I am saying is that Anthropic does not really love the idea of on-device things and especially optimising LLM kernels, which embedding models still need

1

u/Green_Ocean90 1d ago

Why would Gemini like local inference any more? Haha

From everything I’ve seen, the ‘Claude Hates Local’ stuff is overhyped.
And with these embeddings on the Apple Neural Engine, there’s far less to tweak as well - you’re mainly building the recipe for CoreML to work from.