A custom CUDA runtime that runs a local Qwen coding model 2.7x faster on an 8 GB RTX 4060
- Models & engines
- Qwen3.8 9B, compressed to 4-bit (5.78 GB)
Baseline: llama.cpp at 44 tok/s - Key gotcha
- llama.cpp still reads a brand-new prompt faster than his runtime does, which is why prefix caching matters for coding agents
What they built
Omer Chandna had been running a local coding model in OpenCode on his own PC and found it slow: llama.cpp topped out at 44 tok/s on his 8 GB RTX 4060. After an inference workshop he set himself a challenge to get more out of the card without buying hardware or swapping the model.
The result is qwen-coder-kernel, a custom CUDA runtime for Qwen3.8 9B with a small OpenAI-compatible server so it plugs straight into OpenCode. Every speedup had to produce exactly the same text as running the model the normal way.
He works out that one token needs the GPU to read about 4.9 GB of weights, so the card's roughly 246 GB per second caps plain decoding at about 45 tok/s. The gains come from getting more tokens out of each pass and never reading the same prompt twice.
Setup
- NVIDIA RTX 4060, 8 GB of memory
- Qwen3.8 9B, compressed to 4-bit (5.78 GB)
- OpenCode, connected through a small server he wrote
- Baseline: llama.cpp at 44 tok/s
How it works
- Kernels for every step of the model work on the 4-bit weights directly, replay each token's GPU jobs with CUDA graphs and merge back-to-back steps
- Speculative decoding checks up to 12 guessed tokens in one pass, using the model's built-in multi-token guesser or text copied from the prompt
- Because most layers keep a running state, the checking step saves a checkpoint after each token so a wrong guess rewinds
- Prompts are read in batches, and a checkpoint is saved at the end of each message so the next agent step only reads what's new
- An opt-in 8-bit KV cache (--kv8) with one scale factor per 32 values makes the cache 47% smaller
Results & numbers
- 119 tok/s vs llama.cpp's 44 on writing tests (2.7x), 127 vs 44 on refactor, 106 vs 44 on explaining code
- With later improvements, six coding tasks ran at 100 to 352 tok/s, the top speed on refactoring a function
- A 6,000-token prompt loads in about 3 seconds; in a real OpenCode session to fix two bugs in stats.py, the whole task took 13.6 seconds
- The 8-bit KV cache doubled the context window from 40,000 to 80,000 tokens; a 78,000-token prompt still got a sensible answer at 57 tok/s
Gotchas
- llama.cpp still reads a brand-new prompt faster than his runtime does, which is why prefix caching matters for coding agents
- The runtime is Windows-only today
- The 8-bit KV cache stays opt-in until it has been used in more real coding sessions
- Several fixes that sounded great made no difference; measuring with a profiler first found the real wins
“Proof that you don't always need a bigger GPU, just a better understanding of the one you have.”— Omer Chandna
Do it yourself
- Get qwen-coder-kernel and its benchmarks from his GitHub
- Use an 8 GB NVIDIA card and a 4-bit Qwen3.8 9B
- Start its OpenAI-compatible server
- Point OpenCode, Continue or Aider at it as a local provider
- Try --kv8 if you need a longer context window
Similar setups
Letting a coding agent tune llama.cpp on an 8 GB AMD GPU: 3x faster prompt reading for OpenCode
Cliff K had his coding agent benchmark llama.cpp backends and flags for a Qwen3.6 35B MoE on a Radeon RX 6600 XT, at the context depths OpenCode really uses, and turned the process into an open-source skill.
Local AI Starter: a one-click Mac wizard that installs llama.cpp, Qwen3, and OpenCode in one folder
Kirill Lukyanov built an MIT-licensed double-click wizard that sizes a Mac’s RAM, downloads a pinned llama.cpp build plus a Qwen model and OpenCode, proves the model answers, then opens a sandboxed coding agent and browser chat.
Faster local Qwen on an AMD eGPU with the llama-cpp-rdna-boosts patches
A developer running a Qwen3.8-27B fine-tune on an AMD R9700 eGPU swapped vanilla llama.cpp for a small set of AMD-specific patches in a Podman image and roughly doubled prefill speed.
OpenCode on a CPU-only Intel i7 laptop talking to local Ollama coder models
Idada Osaigbovo James wires OpenCode on a Dell Latitude 5430 (i7-1265U, 32 GB RAM, Iris Xe) to Ollama’s local OpenAI-compatible API and runs Qwen2.5-Coder 1.5B/7B with no cloud subscription.