Lurker News
Hi HN,

I built a specialized inference engine for running 4-bit Gemma 4 26B-A4B-IT on any M-series Mac using about 2 GB of RAM. It is called TurboFieldfare and is written in Swift and Metal.
I have always adored on-device AI. It feels like magic that you can run a powerful NN on your Mac or iPhone. So I wanted to push the limits a bit and run a model whose weights don’t fit in memory.
The model’s 4-bit quantized weights occupy roughly 14 GB, which makes running it with conventional inference tools almost impossible on an 8 GB or even 16 GB Mac once the OS, applications, and KV cache are included.
The trick is to keep the shared part of the model and the KV cache in RAM, then stream only the routed experts needed for each token from SSD. An SSD is way slower than RAM, so the runtime uses a small expert cache and bounded parallel `pread`. While those reads are in flight, the GPU runs the shared part of the layer.
I ran more than 100 experiments. Most didn’t work. A few got me here. The experiments are described in the GitHub repo.
It currently generates 5–6 tok/s on an 8 GB M2 MacBook Air and 31–35 tok/s on an M5 MacBook Pro.
I also added an experimental OpenAI-compatible local server. It supports streaming and tool calls, and reuses one prompt prefix from the KV cache.
Try it! The Mac app is easy to install. On the first run, it will download 15 GB of weights from Hugging Face. The model is surprisingly capable.
I would love any kind of feedback!

Comments (342) 81 threads

Earlier comments
mmastrac3 replies#
I have a project that's almost ready to run DiffusionGemma as well. The two project might potentially work well together. I'm getting ~20tok/s on a 36GB M3 and there's strong possibility we might be able to crib faster kernels from each other.

Feel free to reach out.
(currently at https://github.com/mmastrac/diffgemma but not in a releasable state yet)

mmastrac#
TBH, I think there's some truth to that. I spent _ages_ tuning the kernels to match the tested FLOP count of my M3's processor. I only have an M3 though and wasn't able to push int8 very far on it, but I think there's a chance that M5-class machines and higher might have more capability in this regard.

What I also learned is that MLX/vLLM is probably within ~20% or so of the absolute max perf on Mac. I found some improvements over what they were doing, but we're at the point where it's challenging to optimize without per-stepping kernels.
I found a few improvements over stock DiffusionGemma along the way, like using top-k attention, which drastically improves perf on my mac without sacrificing any of the benchmarks I was able to throw at it.
FWIW some of the issues with Gemma being slow on Mac are specific choices they've made in the architecture that make it challenging to make use various optimizations that have popped up recently. I think a Kimi K3-style network hybrid with the diffusion bits of DiffusionGemma could have some serious sway.
I think that diffusion still has an edge locally, but with some architecture tweaks and CPU improvements it would actually be a winner (ie: training the network for smaller token batch sizes or flexibility in attention heads, a less expensive attention mechanism, and others).

gitpusher421 reply#
It is super cool! Diffusion Gemma was released around the middle of my project, and I seriously considered switching to it. But I decided to finish the project as it was.

I believe it would be a perfect match!
Feel free to use any parts of my project or drop me a message. There’s my LinkedIn link at the end of the readme. Or I will drop you a message later!

mmastrac#
Awesome. I may need to finally bite the bullet and upgrade my macOS to test out the MPP approach you've taken.

I've got a number of tiled-load kernels, and a top-k attention kernel that you might find interesting.

nl1 reply#
I tried out one of the NVidia diffusion models, and from memory it only worked on MLX but seemed to leave a lot of features out. Would your work support non-Gemma models too?
mmastrac#
Which one? Nemotron Diffusion? It's impossible to say for sure, but I have a fairly deep library of metal kernels that _might_ cover some of the nvidia model's architecture.
woadwarrior017 replies#
> The measured result is a reference point, not a performance ceiling.

Claude was here.

sebmellen1 reply#
I grind my teeth when I see it. It's so pervasive that I worry I'll pick up the same ticks by reading so much Claudeslop.
micromacrofoot1 reply#
you're absolutely right
0x20cowboy10 replies#
But here’s the thing nobody tells you, it’s a repository not a spaceship. Not a pizza, not a cow, but an undeniable disco boot. Let’s delve into this.

Continue this thread — 10 replies

UmYeahNo#
"I ran more than 100 experiments. Most didn’t work. A few got me here."

And here.

jddj#
I'm sure it was a chatgptism first, but I wouldn't accuse a western company of distillation.

In all fairness, maybe it's just that they let some post-2022 recipe blogs get into the training runs around ~4.6-4.8 time

andrehacker6 replies#
Let my karma burn for saying this: Maybe it is time to let this go man. These comments are really the new incarnation of "grammar policing". (1)

They don't add anything of value, did the author use an LLM to fix his prose but no useless slop was added in the process: who cares ? Is the article useless slop: fine, downvote it to oblivion.
(1) For those not old enough to remember that wonderful practice please use your nearest LLM to find out or, you know, visit a library and do your own research.

woadwarrior011 reply#
I'm not making any moral judgements based on it, merely observing it.
rpdillon1 reply#
The criticism is not that it's moralizing, but that it's boring.

Continue this thread — 1 reply

itsdesmond3 replies#
The writing is made worse by a specific choice which the commentator identified. That’s actionable feedback.
govping8 replies#
how is it made worse in this case?

Continue this thread — 8 replies

e12e#
I don't know what the author's native language is, but I assume it's something I'd need machine translation for anyway. Having it in good (if not Nobel prize level great) English is much easier - and will probably be easier to find again via search.
trinix912#
If they feel the need to polish their texts with LLMs because they’re not comfortable with English, how would they tell the output is bad?

I can tell you first hand it’s sometimes hard to figure out what is LLM writing and what isn’t, English isn’t my first language either.

wellthisisgreat#
I am with you in principle.

There is 0 wrong with using AI to write a draft.
However catching the glaring LLMisms shows that the person did a pass and tried to edit the obvious LLMisms.
For me, unprocessed AI output is perfectly fine as the means to the end, but not as a final output.

latexr1 reply#
> Is the article useless slop: fine, downvote it to oblivion.

You can’t downvote submissions on HN, only flag them. Identifying when text was written by LLMs is a useful signal. Maybe you don’t like these repeated comments, but I’d bet the people making them hate even more that they feel they wasted their time reading it.

rpdillon#
This attitude will just cause people to write the same thing with AI and then ask it to strip out all the tells. I found it works just fine, but then you push usage underground, making it harder to detect, which isn't in your best interest, assuming you want to be able to detect and avoid low-effort writing.
JSR_FDED2 replies#
Why would you want to signal low effort for your writing and the related project?
jryle701 reply#
It's not low effort. The author had to write in English, not their native, and then used LLM to polish it. The sentence itself conveyed a real point. They cared how their article came across. That's much more effort than the boring "Claude was here" comment that took a second to write but costs real energy to appear, and once again spurred a worthless debate.

Let it go FFS.

Continue this thread — 1 reply

Almondsetat#
The world is not the Unites States
gitpusher42#
Thank you! Text is not the main part of this repo. The main part is the technology and the list of experiments (and some useful knowledge I got from this project, haha). I have always been bad at writing or editing text (in both my native language and English), but without text it is impossible to share this project online.

Text was the last and most difficult part for me. It is not perfect (and this project is not perfect as well), but I believe it does the job of communicating my ideas

gitpusher421 reply#
I am not native, my English is far away from perfect. I am using LLMs for checking my texts or grammar. I always trying to edit it properly, but sometimes I missing parts like that because I don't really have this "language feeling" as natives. Apologies for this
sebmellen1 reply#
Friendly feedback: write in your native language and use https://deepl.com to translate. I am fluent in both German and English. I find Deepl does a much better job at capturing the direct translation of what I’m saying than using Claude/ChatGPT, etc. Results may very for your language…

Very nice work! Sorry that the AI comments partially overshadowed it.

gitpusher42#
Thanks! Will try!
apothegm1 reply#
Okay, I’m the first to get annoyed at LLM-ese. But language requires the ability to say that something is A and not B. There are certain phrasings of that that are painfully Claude-esque, but ffs the one you quoted is the type of thing an actual human being is just as likely to say.
nsonha1 reply#
I don’t get why that construction is associated with Claude. I’ve never picked it up from reading Claude output.

As a English-as-a-second-language speaker I’ve been using that formation long before llm and it has legitimate usage

Continue this thread — 1 reply

Continue this thread — 1 more reply

ycui19862 replies#
There are a lot of SSD streaming engines these days. But few to actually try some hard features.

There is one that could really improve the speed. Given almost all major models come with MTP head for speculative decoding. The same MTP head could also be used to speculative prefetch the expert weight residing on the SSD. If the expert weight can be preloaded before the GPU actually need them, the speed penalty from VRAM cache miss will be quite reduced.
If the technology demonstrates successful token rate improvement. future models could also come with pretraining heads to preload expert weights, and even make the training be aware of it.

hacklas1 reply#
Worth mentioning why this is harder than it looks.

There is a different set of experts at every layer, and each layer has a small router that decides which ones to use.
The router needs to look at the state produced by the experts below it.
Drafted tokens from the MTP head can be used to predict which experts the first layer will want, but not beyond that. To know what layer 10 experts needs, you have to run layers 1-9 which means loading their experts.
So, yes, instead of a next-token drafter like MTP, you'd want something trained to predict the expert activation across all layers at once.

IsTom1 reply#
That kind of sounds like a branch predictor in a CPU.
ycui1986#
exactly. we need branch predictor for expert weight.
zozbot234#
> The same MTP head could also be used to speculative prefetch the expert weight residing on the SSD. If the expert weight can be preloaded before the GPU actually need them, the speed penalty from VRAM cache miss will be quite reduced.

When using SSD streaming, the GPU is practically always waiting for the SSD to fetch the right expert, rather than the other way around. There is basically zero slack on the SSD side, so I'm not sure how "prefetching" is supposed to help. It would mostly hurt by fetching the wrong predicted experts, which already makes conventional MTP practically unhelpful for typical (not widely batched) SSD streamed inference.

nvch1 reply#
12 tok/s and almost instant response on M1 Max Mac Studio (with faster SSD than laptops) are impressive – gives hope that large models may run locally from SSDs instead of memory.
gitpusher42#
Thanks for sharing! SSD read speed is the biggest limiting factor here, unfortunately

Load more comments