News for hackers. Stuff that matters.
Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by gitpusher42 on Wednesday July 29, 2026 @12:29PM (#49099602)
My first version used plain `mmap`. On the 8 GB M2, a cold 3.36 MB expert took 10 ms with mmap and 2.8 ms with `pread`. The full simulation was 0.50tok/s for `mmap` vs 4 tok/s for `pread`

With `mmap`, OS loads pages reactively as the model touches them. It doesn’t know which experts were selected or when their reads could overlap with GPU work

And common weights still use mmap for simplicity

So, I believe llama.cpp might run it under 2gb, but I assume it will be slower

Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by nijave on Wednesday July 29, 2026 @01:13PM (#49100260)
Any idea if madvise helps? Admittedly I have very limited experience and only on Linux
Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by kees99 on Wednesday July 29, 2026 @02:49PM (#49101455)
MADV_SEQUENTIAL might help a bit, but not that much. Biggest problem here is throughput-vs-latency.

With mmap()-ed file, for each pagefault, kernel will conservatively estimate block size to page in, so you'll have a ton of relatively small requests going to SSD. This would be IOPS-bound, and likely under-perform relative to maximum possible bytes/second throughput.

With explicit read()/pread(), kernel & SSD can work with much larger chunks, so it's easier to hit maximum bytes/second throughput.

Plus, with modern CPUs, IO-wait could be efficiently combined with number-crunching. So, if software knows in advance which data chunk (expert) it'll need for the next token, it can load that in parallel with computing current token.

Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by p0u4a on Thursday July 30, 2026 @01:59AM (#49106514)
> if software knows in advance which data chunk (expert) it'll need for the next token, it can load that in parallel with computing current token

You could actually use the model's MTP head to make a ~decent prediction on what experts would be activate in future tokens and preload them

Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by nijave on Thursday July 30, 2026 @07:19AM (#49108460)
>So, if software knows in advance which data chunk (expert) it'll need for the next token, it can load that in parallel with computing current token.

Yeah, I was thinking MADV_WILLNEED might work there but not sure

Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by gitpusher42 on Wednesday July 29, 2026 @04:23PM (#49102551)
I tried it. madvise didn't make mmap better than pread. I also tested F_RDADVISE, it helped on short decodes, but somehow got worse on longer decodes. Not very clear why, most likely problem somewhere at APFS and it is closed source and not much docs for it
Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by a-dub on Wednesday July 29, 2026 @12:47PM (#49099886)
for a given expert, do you have a sense for what the spatiotemporal access pattern looks like?
Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by gitpusher42 on Wednesday July 29, 2026 @05:59PM (#49103630)
Yeah, I checked it. One expert is about a 3.36mb block. If a cache miss happens I read whole block with one pread.

And there is some reuse. ~41% selected again for the next token, ~57% within two. Each layer has its own experts, so no reuse between these layers.

Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by a-dub on Wednesday July 29, 2026 @06:15PM (#49103801)
hm. in linux you have MAP_POPULATE which forces a prefetch where macos relies on page faults and lazy loading. if MADV_WILLNEED doesn't help, maybe readv to vector read directly or mmap+writev (write to a dummy fd, with an iovec for each page, hopefully resulting in a one-syscall-big-pagefault for mmap.) maybe also experiment with a loop that just reads one byte from each relevant page after mmap but before real computation?
Re:Show HN: Open-source engine running Gemma 4 26B in 2 GB R... by gitpusher42 on Thursday July 30, 2026 @07:03AM (#49108305)
uh, tried most of this

mmap benchmark did basically page touch experiment and cold reads were much slower, unfortunately (10ms vs 3ms)

I tried MADV_WILLNEED, F_RDADVISE and preadv. preadv reduced parallelism because requested experts are rarely adjacent in the file.

pread is still the fastest. And I think Flash-Moe got the same result too