← All how-to guides

Running Qwen4-35B-A3B on an AMD Strix Halo with llama.cpp (and Claude Code)

A capable coding model now runs well on a small box under a desk. This is the llama.cpp command we use on one of our test machines, the speeds we got, and two problems that will break every agent request if you don't fix them first.

IRelated service: AI strategy and governance →

Alibaba released Qwen4-35B-A3B in the first week of December 2026, and we put it on one of our test machines the same day: an AMD Strix Halo mini PC with 128GB of memory. We keep small machines like this around to find out how much real work an inexpensive box can do with no cloud behind it.

With this model the answer is a lot. It writes and debugs code through Claude Code, reads images, and holds a 256k-token context at a speed that is comfortable to work with.

It took a few days of testing to get there, and two problems cost us most of that time. This guide is the setup we ended up with. The speeds are from that one machine, so expect yours to be a little different.

This is a technical how-to. You need a Strix Halo class machine, or something similar with a lot of unified memory, about 40GB of disk for the model files, and some comfort with systemd and the command line. If you are still choosing hardware, start with the local AI hardware guide instead.

Contents

What you end up with

One llama-server process running a 35B model with a 256k context. Short prompts come back at 63 to 65 tokens per second.

It speaks the Anthropic Messages API, so Claude Code connects to it directly with no proxy. It also speaks the OpenAI style /v1/chat/completions API, so n8n and most other tools can use the same server. It reads images, it restarts itself if it crashes, and there is no per-token bill.

The hardware

  • AMD Ryzen AI Max+ 395 ("Strix Halo"), 128GB of unified LPDDR5X at about 256GB/s, Radeon 8060S integrated GPU (gfx1151).
  • Debian 13 on a recent 7.x kernel.
  • BIOS dedicated VRAM left at its minimum, 0.5GB. The GPU uses shared system memory, and by default Linux lets it map about 75% of RAM, which is roughly 94GB here. We did not change that, and nothing in this guide needs you to.

This machine does other test work at the same time, so we could not hand all 128GB to the model. That is why we picked the context size we did, and why we never run two copies of the model at once.

Why Qwen4-35B-A3B

A Strix Halo has plenty of memory but modest memory speed, and this model happens to suit that well:

  • Mixture of experts. 35B parameters in total, about 3B active per token. Speed depends on the active parameters, so it runs like a small model and knows what a much larger one knows.
  • Hybrid attention. 41 layers, of which only 10 use full attention (every fourth one). The rest are recurrent/SSM layers, which keeps the KV cache small. Native context is 1M tokens.
  • A built-in MTP head. Multi-token prediction ships inside the model, so you get speculative decoding without hosting a separate draft model.
  • Vision, through its mmproj file.

The model also comes with an "engram" n-gram embedding table (per_layer_token_embd) in a second GGUF file. Remember it when you add up memory. To see how this model compares with the others worth running, see open models by task.

How we tested it

We don't pick models on tokens per second. Our test has Claude Code use the model for three jobs: a quick smoke test, fixing a broken program, and adding a feature. Each job runs three times, and we check the result by running the code. The model we had on this machine before was Qwen3.6-35B-A3B, so that is the comparison.

Qwen3.6-35B-A3BQwen4-35B-A3B
Score, thinking off9/99/9
Score, thinking on9/9
Time per task5 to 24 s5 to 19 s
Turns on the debug taskabout 10about 7

Both got everything right. Qwen4 finished about 25% sooner, mostly because it needed fewer turns. With agents that counts for more than typing speed, because every extra turn means reading the whole prompt again.

Step 1: Get llama.cpp

You need build b12973 or newer. Support for Qwen4 (architecture qwen4exp) was added in early December 2026, and older builds will not load the model.

We use the official prebuilt Linux Vulkan binaries from the llama.cpp releases page instead of building our own. We compared Vulkan with a ROCm/HIP build on this chip earlier in the year. The output was the same and Vulkan was about 5% faster, so we have stayed with it.

Step 2: Get the model files

We run Unsloth's Qwen4-35B-A3B GGUF repo at quant UD-Q4_K_XL. Three files:

FileSizeWhat it is
Qwen4-35B-A3B-UD-Q4_K_XL-00001-of-00002.gguf24.7GBThe model
Qwen4-35B-A3B-UD-Q4_K_XL-00002-of-00002.gguf11.5GBThe engram table
mmproj-F16.gguf0.9GBVision

Point llama-server at the first shard only. It finds the second one itself.

Every model's vision file downloads as mmproj-F16.gguf, so we rename this one to mmproj-Qwen4-35B-A3B-F16.gguf to keep it apart from the others. That is the name used in the command below.

Step 3: The launch command

This is the command we run. Change the paths and the key to your own:

llama-server \
  -m /opt/llm/Qwen4-35B-A3B-UD-Q4_K_XL-00001-of-00002.gguf \
  --mmproj /opt/llm/mmproj-Qwen4-35B-A3B-F16.gguf \
  --host 0.0.0.0 --port 8100 --api-key YOUR_KEY \
  --alias local -ngl 99 -c 262144 --flash-attn on --jinja --parallel 1 \
  --metrics --no-webui \
  --chat-template-file /opt/llm/qwen4-relaxed.jinja \
  --chat-template-kwargs '{"enable_thinking":false}' \
  --load-mode mmap --lazy-mode on -ot per_layer_token_embd=CPU \
  --spec-type draft-mtp --spec-draft-n-max 2

What the less obvious flags do:

  • -ngl 99 puts everything on the GPU. You also want --flash-attn on, and --jinja so the model's own chat template is used.
  • --load-mode mmap --lazy-mode on -ot per_layer_token_embd=CPU saves memory. The 11.5GB engram table stays on disk and is read as needed, so it never has to be loaded into GPU memory.
  • --spec-type draft-mtp --spec-draft-n-max 2 turns on speculative decoding with the model's own MTP head, guessing 2 tokens ahead. Between 58% and 67% of the guesses were accepted, which took short prompts from about 44 tokens per second to 63 to 65. We did not try a depth higher than 2.
  • --chat-template-file points at an edited copy of the model's chat template. You need this one, and the next section explains why.
  • --chat-template-kwargs '{"enable_thinking":false}' turns thinking off unless a request asks for it, so scripts get quick, plain answers. We have a small relay on another port that turns thinking on for interactive Claude Code sessions.

Problem 1: every Claude Code request fails

If you run Qwen4 with its original chat template and thinking turned off, every request from Claude Code comes back as HTTP 500.

The cause took a while to find. Recent llama.cpp builds pass the client's effort setting to the template as reasoning_effort, and Claude Code always sends one, such as high, medium or max. Qwen4's template throws an error when thinking is off on the server and the client sends any effort value:

Conflicting thinking settings ... enable_thinking=false with reasoning_effort=high

--reasoning off gives the same error. The fix is to edit the template. Pull the original out of the GGUF metadata, make three changes, and pass your copy with --chat-template-file:

  1. Map the effort names the template does not know: medium to high, max to xhigh, minimal and none to low.
  2. Delete the two raise_exception('Conflicting thinking settings ...') checks, so the server's enable_thinking wins instead of the request failing.
  3. With thinking on, use effort = 'high' if (reasoning_effort is none or reasoning_effort == 'off') else reasoning_effort.

The mapping, in the template's own Jinja:

{%- if reasoning_effort == 'medium' -%}{%- set reasoning_effort = 'high' -%}
{%- elif reasoning_effort == 'max' -%}{%- set reasoning_effort = 'xhigh' -%}
{%- elif reasoning_effort == 'minimal' or reasoning_effort == 'none' -%}{%- set reasoning_effort = 'low' -%}{%- endif -%}

One more thing to watch. llama.cpp's Jinja engine would not accept a one-item tuple such as ('medium',). It failed with "Unexpected token: )". Use plain == comparisons with elif, as above.

Problem 2: Qwen4 sometimes answers twice

Ask Qwen4 for JSON and once in a while it gives an answer, spots a mistake in it, and writes a corrected JSON object straight after the first. A greedy regex like \{.*\} grabs both, and the parser fails with "Extra data".

Take the last complete JSON object in the reply. This is the helper we use:

def last_json(s):
    dec, out, i = json.JSONDecoder(), None, 0
    while (i := s.find("{", i)) != -1:
        try:
            o, e = dec.raw_decode(s, i)
            if isinstance(o, dict): out, i = o, e; continue
        except ValueError: pass
        i += 1
    return out

The last one is also the one you want, since the model wrote it to correct the first.

Step 4: Point Claude Code at it

llama-server speaks the Anthropic Messages API, so Claude Code needs nothing in between:

export ANTHROPIC_BASE_URL=http://your-box:8100
export ANTHROPIC_AUTH_TOKEN=YOUR_KEY
export ANTHROPIC_MODEL=local ANTHROPIC_SMALL_FAST_MODEL=local
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=262144
export DISABLE_TELEMETRY=1 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
claude --model local

n8n and other tools can use the same server through /v1/chat/completions.

How fast it is

These are from our machine with the setup above: llama.cpp b12973, Vulkan, the UD-Q4_K_XL quant and MTP at depth 2. Prefill is how fast it reads the prompt, and generation is how fast it writes.

PromptPrefillGeneration
Short63 to 65 tok/s
About 12k tokens835 tok/s53 tok/s
About 25k tokens717 tok/s54 tok/s
58k672 tok/s (87 s)36 tok/s
116k567 tok/s (205 s)32 tok/s
223k466 tok/s (478 s, about 8 minutes)28 tok/s

With MTP off, short prompts ran at about 44 tok/s. Qwen3.6 did 52.

Qwen4 reads prompts more slowly than Qwen3.6 did, by 12% to 20%. Part of that is the model and part is MTP, and running it both ways shows how much is which:

PrefillQwen3.6Qwen4, no MTPQwen4, MTP depth 2
About 12k tokens1035 tok/s915 tok/s835 tok/s
About 25k tokens810 tok/s795 tok/s717 tok/s

At 12k tokens most of the slowdown comes from the model. At 25k nearly all of it comes from MTP. What you get back is writing that is about 20% faster and agent tasks that finish about 25% sooner, which for agent work is well worth it. If your job is one huge prompt and a short answer, test it with MTP off before you decide.

Memory for the KV cache, in f16:

ContextKV cache
256kabout 5GB
512kabout 10GB
1Mabout 20GB

The weights take about 25GB of GPU memory, and the engram table is read from disk on top of that. In total Qwen4 used about 14GB more memory than Qwen3.6 did on the same machine.

Why 256k and not 1M

A 1M context fits in memory on this machine, but we run 256k. Memory is not what limits you here. Reading speed is. Going by the table above, a full 1M prompt would take about an hour to read before the model wrote a word, and it would write at well under 28 tok/s.

256k is more than a long agent session needs. For the rare job that needs more, start a second server with a bigger context for that job and stop it when the job is done.

Step 5: Run it as a service

We run llama-server as a systemd user service, so it comes back by itself after a crash or a reboot. Three lines in the unit matter:

  • Restart=always with RestartSec=5, so it restarts after a crash or an out-of-memory kill. Ours was back in 5 seconds when the kernel killed it during a test.
  • LD_LIBRARY_PATH set to the llama.cpp folder, so the prebuilt binary finds its own shared libraries.
  • WantedBy=default.target, which is the user-session equivalent of multi-user.target.

Save this as ~/.config/systemd/user/llama-qwen4.service:

[Unit]
Description=Qwen4 llama-server
After=network-online.target
Wants=network-online.target

[Service]
Environment=LD_LIBRARY_PATH=/opt/llm/llama.cpp
ExecStart=/opt/llm/llama.cpp/llama-server \
  -m /opt/llm/Qwen4-35B-A3B-UD-Q4_K_XL-00001-of-00002.gguf \
  --mmproj /opt/llm/mmproj-Qwen4-35B-A3B-F16.gguf \
  --host 0.0.0.0 --port 8100 --api-key YOUR_KEY \
  --alias local -ngl 99 -c 262144 --flash-attn on --jinja --parallel 1 \
  --metrics --no-webui \
  --chat-template-file /opt/llm/qwen4-relaxed.jinja \
  --chat-template-kwargs '{"enable_thinking":false}' \
  --load-mode mmap --lazy-mode on -ot per_layer_token_embd=CPU \
  --spec-type draft-mtp --spec-draft-n-max 2
Restart=always
RestartSec=5

[Install]
WantedBy=default.target

Then load it and start it:

systemctl --user daemon-reload
systemctl --user enable --now llama-qwen4
sudo loginctl enable-linger $USER

Don't skip the last line. Without lingering, a user service only runs while that user is logged in, so the model would not start after a reboot.

Don't run two copies of a 35B model at once on a machine that is doing other work. We started a second copy for a long-context test, the machine ran out of memory, and the kernel killed the first one. It restarted in 5 seconds.

Rollback

A model can pass every test and still let you down on real work. Going back takes two commands if you kept the old files and an afternoon if you didn't, so when you upgrade, keep:

  • The old GGUF files, including their chat template.
  • The old unit file, copied aside as something like llama-qwen4.service.prev.

To go back, copy the old unit over llama-qwen4.service, or change -m and --chat-template-file in the current unit to point at the old model. Then:

systemctl --user daemon-reload
systemctl --user restart llama-qwen4

We still have Qwen3.6 and its unit file on disk for this reason.

Things we would tell a friend

  • Test with the work you really do. Tokens per second would have picked the wrong model for us more than once. A model that types 20% slower but needs 30% fewer turns finishes first.
  • Run one copy. See the warning above.
  • Keep the old model and its unit file. Going back is then a copy and a restart.
  • Turn thinking off for scripts that set a small max_tokens. If you don't, the model spends the whole budget thinking and the script gets an empty answer. We learned that on an earlier model.
  • Fix the chat template before you connect an agent. When every request fails with HTTP 500, it looks like a network problem at first.

Checklist

  • llama.cpp build b12973 or newer, Vulkan binaries
  • Both GGUF shards plus the mmproj file on disk, llama-server pointed at shard 1
  • -ot per_layer_token_embd=CPU with --load-mode mmap --lazy-mode on
  • MTP speculative decoding on (--spec-type draft-mtp --spec-draft-n-max 2)
  • Relaxed chat template passed with --chat-template-file, effort names mapped, both raise checks removed
  • Context set deliberately (we use 262144) rather than to the model's maximum
  • JSON consumers take the last complete object in the reply
  • Scripts with a small max_tokens call with thinking off
  • systemd user unit with Restart=always, RestartSec=5 and LD_LIBRARY_PATH, plus lingering enabled so it starts at boot
  • Previous model and unit file kept for rollback
  • A real agent task run end to end, verified by running the code it writes

Want a straight answer on AI for your business?

No hype and no slide deck. Tell me how the business runs today and I'll tell you where AI actually pays off, and what to fix first.

Talk through your AI plan → Take the free scorecard