Case study
Kevin AI
A from-scratch C99 inference engine that runs Qwen3.5-4B and Gemma 4 E4B on a 2016 desktop CPU with no GPU: about 4 tokens/s, verified against a float64 oracle. Source is public.
- C99
- AVX2
- Python
- Vite
- React
- TypeScript
- Qwen3.5
- Gemma 4
- MCP
- SearXNG
Problem
Small language models are usually run through large frameworks and a GPU. I wanted to know what it takes to run a current 4-billion-parameter model on a cheap, old machine, and to understand every byte on the way: a Dell OptiPlex 3050 with an i5-6500T (four cores, AVX2, no AVX-512), about 11 GB of RAM and no usable GPU.
Approach
A C99 engine written from scratch, about 12,600 lines, with no BLAS and no framework. It implements two architectures: Qwen3.5-4B (Gated DeltaNet linear attention, three layers to one full attention) and Gemma 4 E4B (per-layer embeddings, KV sharing across layers, logit softcap). Weights load either as the original bf16 safetensors, exact but slower, or as a q8 file of int8 weights with one f32 scale per 32 weights, memory-mapped and kept resident.
Correctness comes before speed. Each model passes a golden gate on a tiny synthetic checkpoint, checked against a float64 Python oracle; the Gemma oracle agrees with Hugging Face transformers to 5e-9. The AVX2 and NEON kernels are checked bit for bit against the scalar path, and there are 26 unit-test files, sanitizer builds and shell tests for the command-line tools.
Around the engine sit lm-chat, an OpenAI-compatible lm-serve with streaming, a prefix cache that restores a shared system prompt instead of feeding it again, and lm-quant. The context window is chosen from free memory rather than a fixed constant.
The repository also holds the chat interface people actually use, in web/: a Vite, React and TypeScript app that talks to lm-serve. Conversations are kept in the browser only; it reads PDFs, text files and images, renders Markdown, tables and math, and lets the model use tools, including MCP servers, a self-hosted web search and a registered project it can read, edit and commit to, with approval cards and rules the owner sets and the agent cannot change. It loads no remote scripts or fonts, runs axe in its test suite, and scores 100 in every Lighthouse category on desktop and mobile.
Result
Both models run on the real checkpoints on the target machine. Qwen3.5-4B in q8 generates 3.4 to 4.0 tokens/s and reads a prompt at 11.6 to 13.5 tokens/s; Gemma 4 E4B generates 2.8 to 3.1 tokens/s, at about 5 GiB resident. Replies read about 4.75 GB per token, so they are bound by memory bandwidth, not by the cores.
Measuring found real problems. The first AVX2 kernels compiled to about three times more instructions than needed; batching the prompt so inputs stay in the L1 cache made the multiply 1.35x faster. A non-genuine power adapter had silently held the CPU at 800 MHz, which made every reply about three times slower until it was found and replaced. Speculative decoding with Qwen's own draft head accepted 78% of drafts yet ran at 0.91x the plain speed on this CPU, so it stays opt-in. Source is public under Apache-2.0, with the benchmark tooling that reproduces every number.