DEV Community

illusion
illusion

Posted on Edited on

Optimizing Local AI Engines for Your Hardware: From 22 to 166 Tokens/Second on a 125B Coding Model

Running a Local AI Coding Model at 139–170 Tokens/Second on a Radeon

I use AI coding assistants all day. Cloud services work, but they cost money every month, they interrupt flow with rate limits, and they send your code to someone else's server with every prompt. So I run these assistants on my own computer: no limits, private, and fast enough to feel like part of the editor.

The reputation of home-run AI — slow, and slowest on AMD graphics cards — is true for a default setup. It is not true by default. With the right approach, my desktop (a 24 GB Radeon RX 7900 XTX plus a spare NVIDIA card) runs a large coding model at 139–170 tokens per second. Most of that speed came from four specific changes, not from buying hardware.

Here is the machine, the easy baseline, what actually moved the number, and the traps.

The machine

Part What I run
GPU 1 Radeon RX 7900 XTX 24 GB
GPU 2 GeForce RTX 4070 12 GB
CPU Core i5-13600K
RAM 96 GB DDR5-4800

The system RAM matters more than it sounds. For the models below, RAM is where most of the model lives.

The easy baseline

The standard free tool is llama.cpp. Its Vulkan mode works on any graphics card — a small download, no special toolkit. On both my cards, a 35-billion-parameter coding model (Qwen4-35B) runs at 79–82 tokens/second for code, with 64K of context (how much text the model can see at once). For many people that is good enough, and I recommend starting there.

But two things leave speed on the table: AMD's best kernels do not come through this path, and the default setup ignores what makes these newer models special.

Why the new models are different

Modern large models are not one brain. They are many small "experts," and for each word, only a handful of them do the work. (This design is called Mixture-of-Experts, or MoE.)

That changes what you need. You do not need all 35 billion parameters in graphics memory — only the busy experts need to sit close and fast. The quiet ones can live in ordinary system RAM and be fetched when a word needs them.

That is the whole trick: keep busy experts on the graphics card, park the rest in RAM. A 24 GB card can serve a 35B model because of this.

Strata is a free engine built around this idea. My setup runs a patched version — the patches, measurements, and tuning work are public: llamacpp-tuner.

How much model fits in 24 GB?

A useful rule from my testing: total size matters less than where the busy parts live. The experts a word actually uses, plus each conversation's working memory, need to sit in fast memory. The rest can live in system RAM — and with a fast SSD, part of it can even live on disk.

On my machine (24 GB graphics memory + 96 GB RAM):

  • A 35B model at 6-bit fits across graphics memory and RAM with room to spare — enough for several conversations at once.
  • A 125B Mixture-of-Experts model (Flash-Next) fits at reduced 3-bit precision, with part of its memory on disk. Slower to start, fast once running.
  • A 320B model does not fit — it needs ~120 GB just for the weights at 3-bit. Not worth trying; you would wait on disk for every token.

Less system RAM lowers the ceiling the same way. Size the model to graphics memory + RAM, not graphics memory alone.

Where the speed came from

It started with Qwen3.8-Flash-Next — a 125-billion-parameter model that fits on my machine at reduced precision, with part of its memory kept on disk. Plain llama.cpp gave about 22 tokens/second on the same file. With tuned settings and my engine patches it reached 166 tokens/second on code and 122 on prose, measured the way real clients run it — and it became my daily driver for long coding sessions.

Most of the lessons below were learned on that model first.

1. Faster math for my specific chip

Generating each token is limited by how fast memory can feed the chip. So I rewrote the low-level GPU programs (kernels) for the RX 7900's chip — 33 patches in total, mostly kernels and scheduling.

Same model, same cards: 139–170 tokens/second for code. About 2x the easy baseline.

2. The spare NVIDIA card helps too

My RTX 4070 drives my monitors and games. But a branch of Strata I maintain lets the engine store a share of the experts on the NVIDIA card as well — more expert memory without buying a bigger AMD card. That branch is mine, not merged upstream yet.

3. Running several assistants at once

Each running chat keeps a memory of everything said so far (the "KV cache"), and that memory fills the graphics card fast. My fix: finished chats get moved aside and restored when needed — a 189K-token chat comes back in 3.7 seconds instead of 96. That is what makes several coding agents on one card practical.

4. Tuning AMD's own engine

AMD ships an inference engine called Loom (open source, part of ROCm/hrx-system). With my changes — smaller conversation memory, a faster attention step, better sampling — it runs 29–48% faster on another model: Inkling-2-Mini at 171/132 tokens/second with over 200K context.

5. A rule that keeps the numbers honest

Every speedup in my stack must produce the same output as before (or differ only by rounding), and I measure at the setting real clients use — temperature 1, which controls how random the output is. Benchmarks run at temperature 0 with lossy shortcuts overstate speed. I switch off any trick that makes numbers look better but output worse.

What did not work — and two traps

Pooling cards mostly loses. Measured or reported on comparable hardware:

  • Mixing two card brands in one split runs slower than the big card alone when the model fits it: one reported setup did 30 tokens/second split, 40 on the big card alone.
  • A weaker second card drags the strong one down. One reported run fell from 55 to 45 tokens/second, because every step waits for the slowest card.
  • My own estimate: splitting the same model across my two cards ran ~25 tokens/second, versus 122–166 on the big card alone with experts placed well.

Splitting pays only when the model does not fit one card. Otherwise: one strong card, experts placed well, wins.

Two traps:

  • An idle AMD card goes to sleep. After ~5 seconds idle, the card powers down, and a server that wakes it runs 10–20% slower. Keep the card awake while a server runs.
  • AMD's software stack (ROCm) crashes roughly 1 request in 90. Not your prompt — a bug in how the driver manages memory copies. I reproduced it without the engine and fixed it with a one-line patch. Without that patch, build retries into anything you run on local models.

The numbers, together

One desktop (specs above), one chat, temperature 1. Speed rows are tokens per second (code / prose):

What Before After
125B Flash-Next, XTX alone 22 — plain llama.cpp 166 / 122 — tuned engine + my patches
35B MoE model, both cards 79–82 / 71 — llama.cpp Vulkan 139–170 / 107–110 — tuned engine + my patches
Inkling-2-Mini, XTX alone stock Loom engine 171 / 132 — Loom + my changes (+29–48%)
Restoring a 189K-token chat 96 s 3.7 s
ROCm copy-engine crash ~1 request in 90 0 — one-line patch

Contexts tested: 200K+ chats on Flash-Next (112 tokens/second even after a 200K prompt), 256K × 4 chats on the 35B, 204,800 on Inkling-2-Mini.

What you can do today

  1. Start with llama.cpp on Vulkan. Any card, small download. Expect around 80 tokens/second for a 35B MoE model on comparable hardware:
   llama-server -m models/qwen4-35b-Q4_K_M.gguf -ngl 99 -c 32768 -fa on
   # API now live at http://localhost:8080 — point any coding assistant at it
Enter fullscreen mode Exit fullscreen mode
  1. If the model is a Mixture-of-Experts type, move to an engine that places experts (like Strata). Placement is worth more than raw kernel speed until you have it right.
  2. Have a spare NVIDIA card? It can hold experts beside your AMD card. Free memory for the busy parts.
  3. Measure with your real settings before trusting any number — including mine.

Honest limits

One desktop, temperature-1 measurements, code and prose scored separately. Your numbers depend on your memory speed and your model choice. Nothing here needs exotic hardware — but it does need care about where experts live, how the math is written, and how you measure.

Home-run coding assistants are not a party trick anymore. A 24 GB Radeon and 96 GB of RAM is a real development box.

What are you running locally? I am curious whether the expert-placement trick holds up on cards with less than 24 GB.

Top comments (0)