Wink Pings

One RTX 3060, Ten Git Commits: He Built an Inference Engine to 98% of vLLM

Eason Huang wrote an inference engine from scratch with Qwen3-0.6B on an RTX 3060, and ten optimization steps pushed throughput from 150 tok/s to 2143 tok/s. The biggest jumps came from paged KV cache and the final line of torch.compile; FlashAttention was just one step along the way.

One RTX 3060, 12GB VRAM, Qwen3-0.6B, bf16. Eason Huang wrote an LLM inference engine from scratch and pushed maximum throughput from 150 tok/s to 2143 tok/s. On the same card, vLLM ran at 2176 tok/s and SGLang at 2187 tok/s, so his engine reached about 98% of the upper bound.

tok/s means how many tokens are emitted per second; time to first token determines how long you wait to see the first token.

Eason Huang’s inference engine optimization results

An inference engine turns model weights into tokens one by one, and it must manage queuing, batching, memory allocation, and operator scheduling itself. vLLM and SGLang are the industry-grade benchmarks in this field. Eason’s approach wasn’t novel, but it was deliberately simple: each optimization got a git tag, breaking the black box into ten steps.

Inference engine architecture overview: scheduling, overlapped scheduling, irregular batching, paged KV cache, and the Qwen3 model

The first naive loop version was unbearably slow. Every time it emitted a new token, it had to run the entire history through the 28-layer network again. With KV cache added, single-step decoding dropped from 83.6 ms to 11.2 ms, and throughput barely reached 150 tok/s.

KV Cache reuses historical keys and values

But static batching makes the entire batch wait for the slowest request, dragging median time to first token to 2.24 seconds. Switching to continuous batching, where finished requests are immediately replaced by new ones, cut median time to first token to 57 ms. Then chunked prefill smoothed out the stalls caused by new requests cutting in, reducing ITL p99 from 75.9 ms to 65.7 ms, at the cost of time to first token rising slightly to 75.1 ms.

Static batching vs. continuous batching

Once the queue was sorted out, FlashAttention took the stage. It avoids writing the full n×n attention matrix to HBM and, together with irregular tensors, eliminates useless padding. Throughput jumped from 222 to 577 tok/s.

Scoring each query against all keys

By ordinary intuition, once a top-tier attention operator was in place, most of the speedup should have been captured. The next commit changed direction: without touching the compute core, Eason borrowed the idea of virtual memory from operating systems and wrote paged memory management. Previously, every request, regardless of length, locked a full 2048-token block of VRAM as soon as it arrived, allowing at most 8 concurrent requests. After switching to on-demand allocation in 16-token pages, the same 3060 could fit many more requests, and throughput doubled from 577 to 1315 tok/s. This was the largest jump in the entire path.

Contiguous KV fragmentation vs. paged blocks

He also added shared prefix caching, so repeated prompts in multi-turn conversations could be reused directly. Under shared-prefix workloads, time to first token p50 dropped from 47 ms to 17.8 ms, and p99 dropped from 98 ms to 31 ms. Then something strange happened: the GPU was computing extremely fast, but overall speed got stuck. The CPU’s queueing time for launching operators one by one was already longer than the GPU’s actual compute time.

So the optimization focus moved back to the CPU. CUDA Graphs recorded the entire decoding action as one instruction and replayed it with one click. Then overlapped scheduling let the CPU queue up the next step while the GPU computed the current one. Single-step decoding was reduced to 6.1 ms, and throughput reached 1451 tok/s.

Launching one by one vs. a single CUDA graph

CPU runs one step ahead

The final commit was almost comically simple: just add one line of torch.compile to fuse scattered operators into fewer VRAM round trips, and casually increase the single-step budget and page-table pool. compile alone raised maximum throughput from 1451 to 1911, and tuning brought it to 2143 tok/s. The structure built over the previous nine steps was pushed a little further by that last line of code.

Operator fusion reduces VRAM round trips

This scorecard has caveats. The test used a single-card 0.6B small model, and Eason’s benchmark called directly in-process, skipping the few milliseconds of overhead that vLLM and SGLang pay for HTTP serving and tokenization. Even accounting for that tailwind, the fact that code hand-written from scratch by one person can reach about 98% of the throughput of top engines still makes the point: the secret of modern inference speed is scattered across ten clear engineering steps. The biggest step was memory management, and the last line of code also contributed a surprising amount.

Eason put the full code and the diff for every step on GitHub; the blog has more diagrams and explanations. Links below.

Load sweep: TPOT and arrival rate

发布时间: 2026-12-04 11:31