Implementing a Modern LLM in 700 Lines of C
Critical_Physics8 · reddit · 2026-08-28
The author released gemma4.c, implementing the full inference runtime for Google's Gemma 4 E2B model in approximately 700 lines of C.
Project Features:
- Single-file implementation, no external dependencies, easy to read
- Implements tokenizer, Transformer, KV cache, sampling, and CPU kernels from scratch
- Designed to help developers understand the code-level details of LLM inference
Performance Optimizations:
- Int8 weights and activations quantization
- OpenMP parallelization
- AVX2 and AVX-512 VNNI instruction set support
Benchmarks (Ryzen 7 7700):
- Prefill: 639 tok/s (512 tokens)
- Generation: 25.9 tok/s
- Outperforms llama.cpp
GitHub Repo
Related event: Gemma 4 Inference Runtime Implemented in 700 Lines of C(2 posts)→
More from Infra
- open-daytona: rootless gVisor sandbox pool runs 1,536 concurrent agent-RL sandboxes on Slurm — victor_explore · 2026-11-30
- Notes on 'Looking Back at Postgres': Extensibility, No WAL, Open Source — sh_reya · 2026-11-30
- NRDC concedes BAAJA makes data centers pay grid costs, countering 'giveaway' claim — zacharynado · 2026-11-30
- NIDO 0.1.131: A Fully Offline Phone AI Assistant With No Account, No Cloud, No Analytics — NIDO_007 · 2026-11-30
- Ibiden to spend ~¥2T on four new plants as AI chip substrate demand extends past 2030 — BenBajarin · 2026-11-30
- Simulated FP64 matmul runs 83x faster than native on NVIDIA B300, ETH Zurich paper shows — JiliJeanlouis · 2026-11-30