| ▲ | Show HN: Open-source engine running Gemma 4 26B in 2 GB RAM on any M-series Mac(github.com) | ||||||||||||||||||||||||||||
| 97 points by gitpusher42 an hour ago | 21 comments | |||||||||||||||||||||||||||||
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! | |||||||||||||||||||||||||||||
| ▲ | tredre3 8 minutes ago | parent | next [-] | ||||||||||||||||||||||||||||
I'm curious how your project compares to plain mmap! Because llama.cpp will already run 26B in 2GB of RAM if you really want to (mmap enabled, repacking disabled). It seems like the main difference is that your project synchronizes the SSD reads with inference activity, which you've presumably tuned to cause the least latency possible? Whereas the OS wouldn't care about any of that. | |||||||||||||||||||||||||||||
| ▲ | addaon 35 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
> It currently generates 5–6 tok/s on an 8 GB M2 MacBook Air and 31–35 tok/s on an M5 MacBook Pro. Where does this big a performance spread come from? I wouldn't naïvely expect SSD performance difference to be that big, and I would expect SSD performance to dominate... | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| ▲ | hsienchuc 9 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
I've run local video generation models on an 8GB graphics card and know firsthand that nothing runs smoothly when memory is insufficient. So seeing 14GB of weights crammed into 2GB of RAM is impressive. If running continuously for over an hour (like an overnight batch task), will a fanless MacBook Air overheat and throttle? Can the SSD handle the continuous weight reads and sustained output speeds? Great work, congratulations on the release! | |||||||||||||||||||||||||||||
| ▲ | greggh 5 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
It does exactly what it says it does. On my Mac mini M4 with 16GB of ram it is running at just over 5 tok/s. That jump from M4 to M5 is crazy. | |||||||||||||||||||||||||||||
| ▲ | mxmlnkn 32 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
This sounds really cool. My intuition was that the selected experts might change heavily for each token, resulting in slow SSD loads for each token. This seems to be wrong. Did you create some statistics on how often the experts need to be changed? What is the longest token run without any expert change? What does such a token run look like? In which cases do experts change frequently? | |||||||||||||||||||||||||||||
| ▲ | touwer 21 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
Cool! Is there any info on this doing harm to the SSD? (Or other parts?) | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| ▲ | h2aichat 28 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
Hope you can do it for Windows users also (and small graphics cards). Thanks | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| ▲ | sscarduzio 17 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
How does this compare to DwarfStar4? | |||||||||||||||||||||||||||||
| ▲ | yakupov_bulat 36 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
Wow, amazing! What if there is enough RAM to fully load the model? I assume in that case I shouldn’t use your engine. | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| ▲ | WithinReason 29 minutes ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
Nice job implementing expert caching! | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| ▲ | znpy 32 minutes ago | parent | prev [-] | ||||||||||||||||||||||||||||
I wonder if i can run this on my MacBook Neo! | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||