Letting a coding agent tune llama.cpp on an 8 GB AMD GPU: 3x faster prompt reading for OpenCode
- Hardware
- Ryzen 7 5700X, 32 GB DDR4 and a Radeon RX 6600 XT with 8 GB of VRAM
- Models & engines
- llama.cpp built with both the HIP (ROCm) and Vulkan backends, served through llama-server in router mode
Main model Qwen3.6-35B-A3B with experts partly in system RAM; also tested Gemma-4 12B, Qwen2.5-7B and Qwen2.5-Coder-3B - Key gotcha
- Gemma-4 12B only fit on Vulkan: HIP wanted 1.1 GB more compute buffer and ROCm can't spill to RAM.
What they built
Cliff K runs Qwen3.6-35B-A3B, a 35B mixture-of-experts model, as the main model for the OpenCode coding agent on an ordinary PC with an 8 GB Radeon RX 6600 XT. Long sessions felt sluggish, and every guide said to use llama.cpp with Vulkan on AMD, so he asked his coding agent to verify that and find the best config for every model he has.
The key idea is measuring where the agent really lives. OpenCode resends about 12K tokens of system prompt and tool definitions every turn and auto-compacts at roughly 49.5K tokens with a 64K context, so the tests ran at 16K to 48K tokens deep instead of on an empty prompt, then were confirmed in a real llama-server and on real agent tasks.
After a day of experiments he packaged the whole process as tune-my-llm, an open-source agent skill with scripts, so other people's agents can run the same tuning on their own hardware.
Setup
- Ryzen 7 5700X, 32 GB DDR4 and a Radeon RX 6600 XT with 8 GB of VRAM
- llama.cpp built with both the HIP (ROCm) and Vulkan backends, served through llama-server in router mode
- Main model Qwen3.6-35B-A3B with experts partly in system RAM; also tested Gemma-4 12B, Qwen2.5-7B and Qwen2.5-Coder-3B
- OpenCode as the coding agent, with a 64K context
How it works
- The agent inventories the hardware: GPU, VRAM, cores, RAM speed and channels, the real PCIe link and which models fit.
- It works out the agent's real context range from how OpenCode compacts its context.
- It compares backends fairly (same llama.cpp commit, flash attention on), then sweeps batch size, KV cache type, MoE offload and thread count at those depths.
- It confirms the winner in a real server and runs real agent tasks before and after.
- It prepares router presets so each model gets its own device and flags behind one server and one port, asking before sudo or touching anything live.
Results & numbers
- At 49K tokens, prompt reading went from 172 t/s (Vulkan) to 526-562 t/s (HIP/ROCm), and generation from 19.2 to 24-25 t/s.
- Re-reading a full 49.5K context dropped from about 4.8 minutes to about 95 seconds.
- On six real OpenCode tasks the tuned config passed 6/6 versus 5/6 before, and long-prompt tasks finished about 2x faster.
- The Qwen3.6 MoE was 47-55% faster at reading and 22-35% faster at generating on HIP, while dense 7B/3B models generated up to 28% faster on Vulkan.
- -ub 2048 nearly doubled prompt speed for the MoE with experts in RAM (328 to 599 t/s at 16K).
- On the same six tasks Gemma-4 12B passed 5/6, Qwen2.5-7B 2/6 and Qwen2.5-Coder-3B 0/6 without making a single tool call.
Gotchas
- Gemma-4 12B only fit on Vulkan: HIP wanted 1.1 GB more compute buffer and ROCm can't spill to RAM.
- q8_0 KV cache made generation 10% slower than f16 at 16K and 23% slower at 45K on HIP; he treats q8_0 as the floor for tool calling.
- Using all 16 SMT threads (-t 16) on the 8-core CPU halved MoE generation; 4 to 12 threads performed the same.
- llama-bench doesn't load vision encoders, so Gemma looked fine in benchmarks but spilled past 8 GB in the real server until --no-mmproj-offload was set.
- Gemma's own draft model for speculative decoding halved generation speed, and n-gram speculation did nothing measurable.
- OpenCode's small title requests evict the conversation from a single-slot server's KV cache; llama-server's RAM prompt cache (--cache-ram, on by default) restores it, so leave it on.
- The full workflow has only been run end to end on Linux with an AMD GPU; NVIDIA, Apple and Intel paths are untested.
“No flag fixes a model that can't drive the agent.”— Cliff K
Do it yourself
- Build llama.cpp with both backends (-DGGML_HIP=ON -DGGML_VULKAN=ON) and check that --list-devices shows ROCm0 and Vulkan0.
- Work out your agent's real context range, then benchmark at those depths rather than on an empty prompt.
- Sweep ubatch size, KV cache type, MoE offload and thread count, and validate the winner in the real llama-server, not just llama-bench.
- Give each model its own device and flags in a router preset file so switching models switches the whole config.
- Or install the tune-my-llm skill from github.com/cliffkoome/tune-my-llm and let your agent run its quick (20-40 min per model) or comprehensive (1.5-3 h per model) tune.
[qwen3.6-35b-a3b]
device = ROCm0
n-cpu-moe = 34
ubatch-size = 2048
cache-type-k = f16
cache-type-v = f16
[gemma-4-12b]
device = Vulkan0
ubatch-size = 1024
cache-type-k = q8_0
cache-type-v = q8_0
no-mmproj-offload = trueSimilar setups
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.
Getting OpenCode to work with a local Ollama model by fixing the 4,096-token context
OpenCode on a local Ollama model ignored files, invented tasks or looped, because each ~23k-token request was silently cut to fit Ollama's default 4,096-token context on a 16 GB GPU.
llama.cpp 1.0 on a handheld PC's integrated GPU: 2x faster long prompts with flash attention
Before-and-after llama.cpp 1.0 tests on an MSI Claw's Intel Arc 140V found long prompts read about twice as fast only with flash attention on, and the new MoE cache lost to full GPU offload.
Re-benchmarking local GGUF models for a coding agent after a llama.cpp upgrade
Jordi Marçal re-ran his fixed coding-agent benchmark on seven local GGUF models after three weeks of llama.cpp updates, and found the harness's generation caps, not the models, explained a sudden score collapse.