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

giancarlostoro16 replies#
Nice, I think this is the second time I see this here on HN, I always wondered why we need to shove the entire model into memory, I don't care who King Charles is every single time. It always felt as though we already figured out how to break up large files and parse them efficiently with very little memory.

Frontier AI feels like its full of people who are brilliant at making models, but when it comes to scale and practicality, they just leave it to whoever sets up infrastructure to worry about. I wouldn't be surprised if frontier AI could be drastically cheaper if they just finetune and optimize their models to not consume all available RAM to only access less than 10% of the models knowledge.

vorticalbox1 reply#
Putting the whole model in memory is far faster then swapping to disk.
giancarlostoro1 reply#
For local inference the cost of "speed" is not that bad I would think? I wouldn't mind a bit of a delay if it means I can run much larger models on my Mac.
pertymcpert2 replies#
It's pretty painful to have speeds < 30 tok/sec though. Especially if you're used to API providers at higher speeds. It makes any interactive work almost impossible to do efficiently because you have no choice but to context switch after every request.

Continue this thread — 2 replies

bigyabai1 reply#
You're kinda describing the MoE architecture; you can offload expert layers and stream them as-needed if the experts are small enough and the SSD is fast enough.

Dense LLMs typically perform better, but slow down much more than MoE models when you try offloading layers.

avadodin#
The issue is that the MoE knowledge is LLM "knowledge" and it still has a cost so, overall, it has a lower quality/cost ratio.

What he's envisioning is a dense 1B model that looks at the Python specification and your prompt and goes:
> Ah, I get it now! This is like Darmok and Jalad at Tanagra!
Or at least:
> Android UI development in Python? It's UNIX, I know this!
We do work like this sometimes but in general we rely on internalized knowledge so I don't know to what extent it is a viable strategy.

literalAardvark1 reply#
You're right, but the "just" in "just finetune" is doing _a lot_ of work here.

It's still early days and we "just" don't really know how to do it well.

giancarlostoro1 reply#
I mean, that's fair, I guess what I mean is, it feels like we're re-using well known solutions even if it takes a bit of effort to re-apply them into how we run inference (and maybe training as well). It will be interesting to see a lot of these approaches compound into anyone with a reasonable GPU or even a Mac running a model much larger than their machine can handle.
medicis1232 replies#
We did something similar - Streaming experts. Maintaining an expert cache, optimizing it to simulate running a multi-model agentic workflow on a 2-DGC Spark Cluster. The models we ran were: DeepSeek V4 Flash, Gemma 4 26B A4B, and Nemotron 3 Nano Omni 30B NVFP4. The results were very encouraging in terms of performance and model switching. Check it out here - https://woolyai.com/ai-compute-software/dgx-spark-inference-...

Continue this thread — 2 replies

gopalv#
> It always felt as though we already figured out how to break up large files and parse them efficiently with very little memory.

The A in 26B-A4B is the active weights.
The problem is that this is a per-token load/unload at best, not for the whole prompt.
The division happened until one of these can fit in a single GPU and they stopped scaling it down any more, because you can wire up 8 of them to do their share of the work.

swiftcoder4 replies#
> I don't care who King Charles is every single time

Always curious when someone will figure out how we can elide most of the data from an LLM (but retain the logical ability). I don't actually need an LLM to have a very big internal knowledge base to be useful, so long as it can invoke a search tool...

kanbankaren2 replies#
> Always curious when someone will figure out how we can elide most of the data from an LLM (but retain the logical ability). I don't actually need an LLM to have a very big internal knowledge base to be useful, so long as it can invoke a search tool...

I think this can be achieved already. Take a base model and train only on source code. In fact, the very early Granite models from IBM were like that though it didn't support reasoning which limited its performance.
You can do it too. I don't know how much it will cost to train on just source code repos. $10K in total? Not sure.

kccqzy1 reply#
I’m a bit skeptical. Without instructional materials from textbooks, programming language reference manuals and guides, as well as general knowledge about logic and discrete mathematics, I doubt a model could work very well.

Continue this thread — 1 reply

tyromaniac#
I'm skeptical that the "logical ability" is much more then the elided data. Obviously some things get fully memorized and other things don't, but I don't think there's anything like functional circuits.
plandis1 reply#
Isn’t this essentially what MoE partially solves with varying levels of accuracy?
musebox351 reply#
Sadly no. Despite the name, the experts are not routed per concept or topic but per token. So for the same sentence you might activate multiple experts for different tokens. What it solves is the distributed training and inference problem. As long as each expert fits a single gpu, coordinating the model evaluation is much easier and it is faster. It does not buy as much for running on a single device though still less costly than a dense version.

Continue this thread — 1 reply

anentropic1 reply#
I suspect there's a conceptual problem here

to what extent is "retain the logical ability" meaningful without attaching it to some knowledge

swiftcoder#
> to what extent is "retain the logical ability" meaningful without attaching it to some knowledge

Some knowledge is obviously required, I'm just less sure that a specific task like coding benefits all that much from having Shakespeare in the training set...

apothegm1 reply#
That’s the thing. LLMs don’t have any logical ability. Only predictive ability. They’re not the same. And that’s why LLMs are a) unreliable and b) not a path to AGI.
myrmidon#
How do you know that human logic is any more/better/qualitatively different from the LLMs "predictive ability"? It's already pretty easy to find humans that are strictly worse at reasoning and logic than a decent LLM.
Keyframe8 replies#
I don't care who King Charles is every single time

that's the trick and a multi-billion dollar question, how would an llm engine know that? it's an active research area how to cull the initial layer surface and do the optimal traversal path through the layers and it's a damn hard problem. It's definitely an area where a ton of performance is left on the table still.

IdontKnowRust2 replies#
This makes me think (by full ignorance) how quantum computing can be useful in this field of things reach a stable-ish point
s0a#
they will not. quantum computers as understood today will never run an LLM. read = destroy. and no cloning. wanna reload the entire model for each token? preparing quantum states is slow by any standard.
nosyke#
it's just not something you would ever use a quantum computer for
ComputerPerson#
Seems to me like there's a conflict of incentives in the current era of market capture.

Not to say the cost-cutting wouldn't be valuable; today's race is predominantly about the model's reasoning capacity or "how hard of a math problem can the model solve".
It'll be a nice day when research-oriented human capital gets redirected to things that benefit us layfolks's pockets more directly

Continue this thread — 6 more replies

Continue this thread — 10 more replies

xenonite3 replies#
With my M1 MBA, I am still on macOS 15. To compile it, just remove the two lines with

  opts.languageVersion = .version4_0
or surround them with

  if #available(macOS 26.0, *) {
    opts.languageVersion = .version4_0
  }
You'll miss out on a prefill speedup of 2.4x (as it yields 11.24x faster attention), according to the git comments, but it works. (On the 8-GPU-core MBA M1, I get 5-6 tok/s.)
gitpusher421 reply#
Thank you! That’s useful. I might try lowering the minimum version later. The 2.4x prefill improvement will only work on the apple10 GPU family. The M1 uses apple7 as I remember
wilj#
I'm looking forward to trying it, but not willing to upgrade to Tahoe, so I'd appreciate it for sure!
quasarj3 replies#
Why are you still on 15?
jchook1 reply#
New macOS is bloatware that makes your computer slower
fsflover3 replies#
So install Asahi Linux?

Continue this thread — 3 replies

tedd4u#
I went back to 15 after accidentally upgrading to 26 because on MBA 13" screen the new UI design uses a lot of extra padding everywhere wasting screen space which is already at a premium (especially vertical). Hoping 27 fixes a lot of these issues.
dudefeliciano#
me too, everyone says it sucks and to wait for Golden Gate to release.
tedd4u#
To build this (on macOS 15) I also had to do this (in Package.swift):

    @@ -4,8 +4,7 @@ import PackageDescription
     let package = Package(
         name: "TurboFieldfare",
         platforms: [
    -        .macOS(.v26),
    -        .iOS(.v26),
    +        .macOS(.v15)
         ],
         products: [
             .library(name: "TurboFieldfare", targets: ["TurboFieldfare"]),
pwython5 replies#
Ran this on a 64 GB M4 Max MacBook. I figured having Gemma available with a small footprint would be a nice setup. No more unloading models when I need more RAM for work? Hell yea.

Got 48 tok/s decode at 1.9 GB RSS (2.4 GB peak), faster than the 24 GB M5 Pro mentioned in the benchmarks. The ~2.0 GB/s SSD number quoted for M4 is the base chip. This M4 Max does ~7 GB/s.
Page cache seems to be why it beats the M5 Pro. With 64 GB the whole 12 GB packed_experts set stays resident, and iostat shows only ~1.6 GB per run actually reaching disk, against the ~79 GB that 98 fully cold tokens would need.
I then tested with DaVinci Resolve open and under load (playback): 42.6 tok/s. Also held 38 GB of incompressible memory to squeeze the page cache: 41.8. At 48 GB it ranged 32 to 41.5. Degrades gradually rather than a cliff. It's a beautiful thing.

fouc1 reply#
M4 Max is typically better than M5 Pro for inference IIRC.
harrouet#
It depends on what you are looking at.

Time to 1st token is faster on the M5 because of HW accelerators helping the prompt interpretation (and it is CPU-bound).
Token generation after that is GPU-bound and will profit from the higher bandwidth of the M4 Max.

sznio#
at that much ram you can just load it outright without tricks. it will be much faster even if it ends up swapping.
gitpusher42#
Thank you very much for sharing! Great results and useful info!

Continue this thread — 2 more replies

tredre311 replies#
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.

Continue this thread — 11 replies

Load more comments