Running Qwen4-35B-A3B at 1M Context on Two Radeon AI PRO R9700s

ยท 2327 words ยท 11 minute read

Qwen4-35B-A3B came out December 4, and it can take a one-million-token prompt. I wanted to see what two Radeon AI PRO R9700s in the six-GPU box could do with something close to that, so I gave them a 950K-token prompt, roughly 700,000 words. They read the whole thing in about two minutes.

That’s about 7,900 tokens per second (tok/s). The rest of this post is how they do with shorter prompts and more people at once, and the config to run it yourself.

Cartoon: two blue graphics cards with arms and legs, each with a plaque reading R9700, carry a long paper scroll between them like a banner. The stretch of paper between the two reads 1M context, and the rest winds away into the distance behind them. Both are smiling with a sweat drop each. On the left a person in an orange hoodie watches with a mug of coffee.

The model and the setup ๐Ÿ”—

Qwen4-35B-A3B is a mixture-of-experts model. It has 35 billion parameters and uses about 3 billion per token (the A3B).

Three of every four layers are linear attention, which keeps a fixed-size state instead of a cache that grows with your prompt. The rest are sparse attention, which only looks at the best 512 blocks of four tokens. That’s how a one-million-token context fits on two 32 GB cards.

The engine is radiance 2.5.0 with StillDeadcode’s IQ8R file. IQ8R is radiance’s name for this 8-bit format, which rounds the weights to 8-bit integers (int8) with no calibration data.

RadixArk’s DFlash2 drafter is merged into the same file. It’s a small model that guesses a few tokens ahead for the big one to check.

The two cards run as one tensor-parallel server, which splits every layer across both (tp: 2 in the config, TP2 in the charts). The KV cache, which holds the results of reading tokens, is int8 too.

Each card is capped at 215 W. AMD rates them at 300 W.

Prefill from 2K to 950K tokens ๐Ÿ”—

Bar chart of prefill speed by prompt length on two R9700s. Blue bars for the 16-sequence, 262,144-context config: 2,009 tokens at 13,260 tok/s with the first token after 0.15 s, 7,847 tokens at 12,194 tok/s after 0.64 s, 31,193 tokens at 11,807 tok/s after 2.64 s, 124,580 tokens at 11,471 tok/s after 10.86 s, and 233,534 tokens at 10,950 tok/s after 21.33 s. Orange bars for the 4-sequence, 1,048,576-context config: 498,135 tokens at 8,687 tok/s after 57.34 s, and 950,064 tokens at 7,884 tok/s after 120.50 s.

Prefill is the server reading your prompt. Up to 233K tokens it runs at about 11K to 13K tok/s.

The two longest prompts (the orange bars) are slower, and they needed the server’s context set to 1M instead of 262K. Shorter prompts ran as fast at 1M as at 262K, so I’d put the slowdown on prompt length.

At 950K the read took about the same two minutes with the drafter off, but the answer then came out at about 50 tok/s instead of 150. On prompts this long I’d leave it on.

Recall in long documents ๐Ÿ”—

The recall test hides 40 five-digit access codes in filler sentences and asks for 8 by name, at low reasoning effort.

It returned 118 of 120 across six lengths from 24K to 900K tokens. It missed one code at 70K and one at 900K. I ran three documents at each length up to 145K and two at each longer one. With samples this small, I can’t say recall falls with length.

The drafter was off for the 900K documents and at its default of 7 tokens a pass for the rest. In radiance 2.5.0 that default has an open issue, where it changed greedy output (the model always taking its likeliest token) on 11 of 16 prompts.

I didn’t run 360K or 650K with it off. A four-card server has to run with the drafter off, though, and at the three shorter lengths it scored the same or one code better than two cards with it at 7.

Sixteen clients and the drafter ๐Ÿ”—

Bar chart of total tokens per second by client count, with three bars per group: the DFlash2 drafter at 7 tokens (the default) in grey, at 3 tokens in blue, and off in orange. With 1 client: 206 at 7 tokens, 234 at 3, 167 off. With 4 clients: 492, 552, and 437. With 16 clients: 781, 928, and 849.

At 7 tokens, the drafter gets you 23% more output with one client than no drafter. With 16 clients it costs you 8% of the total.

At 3 tokens it beat both other settings at every client count. Against no drafter, that’s 40% more with one client and 9% more with 16. I wouldn’t serve with the file’s default.

Cartoon in two scenes. Under 7 tokens, an orange robot labelled drafter holds out a strip of seven paper slips that reaches the floor. A sweating blue graphics card labelled R9700 checks it with a pencil while a long queue of robots waits, the first frowning at its watch. Under 3 tokens, the drafter is blue and its strip has three slips. The card smiles and hands a page to the first of three robots.

Agent sessions ๐Ÿ”—

A coding agent resends its whole conversation every turn, so its prompt keeps growing. I ran code-reading agent sessions over the radiance source tree, with real tool calls, for five minutes each. Each session grew to about 180K tokens. Nobody graded the answers, so this is cache behavior and speed only.

The server can skip what it has already read, but only from a saved snapshot of the session’s linear attention state. It has a set number of slots for those (checkpoint-slots), and I had it at 32.

With four sessions, 96% of prompt tokens came from cache and the median first token arrived in under a second. With twelve, the cached share fell to 85% and one request waited two and a half minutes for its first token. Twelve sessions were all reading and writing at once, so a long prompt had to share the cards with everyone else’s output.

Thirty-two is probably too few for twelve growing sessions. With 128, the cached share came back above 92% and output rose 42%. One request still waited 51 seconds.

Cartoon in two scenes. Under 32 slots, a small cork board is buried in pinned snapshots, with more on the floor. A sweating blue graphics card labelled R9700 reads a long orange scroll through a magnifying glass while the robot holding it and three more wait, one checking its watch. Under 128 slots, a wide board is mostly empty. The card holds up one snapshot and reads only the end of a robot’s scroll.

For agents I’d run the drafter at 3 or off. It guesses badly on tool-heavy traffic, at least on this one workload. At 7 tokens it had 17 to 19% of its tokens accepted, and turning it off produced 14% more output with a faster first token. At 3 tokens it had about a third accepted and landed between the two.

Four cards: two pairs against one server ๐Ÿ”—

The merged drafter can’t be split across four cards, so a tp: 4 server (TP4 in the chart) only starts with it off (num-speculative-tokens: 0). Otherwise you get this:

radiance: draft num_key_value_heads = 2 is not divisible by world_size = 4

Twice the cards got you 17% more output at 16 clients than two cards with the drafter off.

Prefill got slower, to about 10,200 tok/s for a 2K prompt and 8,800 for a 233K one. Most of the loss is the exchange between cards, since every layer now waits on four of them.

radiance has a lossy 6-bit wire format for that exchange (tp-wire: wht6). It brought prefill back to about 10,700 to 11,900 tok/s on prompts up to 125K.

You can also run four cards as two servers of two, and each pair keeps the drafter. I ran the same clients against both pairs at once, each with the drafter at 3 tokens, and added the totals.

Bar chart of total tokens per second on four R9700s. With 2 clients: 505 for two TP2 pairs with the drafter at 3 tokens, 325 for one TP4 server with the drafter off. With 8 clients: 1,147 and 751. With 16 clients: 1,562 and 991. With 32 clients: 1,880 and 1,209.

Two pairs gave about 55% more output at every count. It isn’t a fair fight, since only the pairs had the drafter.

You give up the one big cache. On four cards, the startup log reports the KV cache pool as 13.9 full-length sessions at 262K tokens, about 3.6 million tokens. On a pair it’s 1.8 at 1M, about 1.9 million, and one pair can’t use the other’s.

So a conversation has to keep going back to the same pair. For my agents I’d take the pairs and a router that pins sessions.

What I’d run ๐Ÿ”—

For a few long agent sessions on two cards, I’d set the context to 1M and the drafter to 3 tokens, which is the config below.

At 1M I only measured the drafter at 7 and off, so 3 there is my guess. Off was faster in the agent test, but those sessions stopped at about 180K tokens, and at 950K the answer without the drafter came out at about 50 tok/s.

For lots of short requests, change max-num-seqs to 16, max-model-len to 262144, and max-num-batched-tokens to 4096 in the same file. With four cards, run one server per pair, each with its own cards, port, and container name.

Run it yourself ๐Ÿ”—

The two-card 1M config runs in a Docker container with a systemd user unit to keep it up. Every command here was run on 2.5.0.

Diagram headed What runs where. On the host, a systemd user unit, qwen4.service, runs the launcher script ~/bin/serve-qwen4.sh, which starts the radiance 2.5.0 container with docker run. Three host paths go into the container: ~/qwen4.yaml, the config, to /etc/radiance.yaml; ~/models/rad, the 54.19 GiB model file, to /models read-only; and ~/models/rad-home-qwen4, the tuning cache from rad-tune, to /rad-home. The container serves an OpenAI-compatible API on port 8081 and reaches two R9700s through /dev/kfd and /dev/dri, each holding 17.91 GiB of weights. A note reads: the 19.07 GiB n-gram table is copied into pinned host RAM at startup.

What you need ๐Ÿ”—

  • Two R9700s, 32 GB each. The weights take about 18 GiB a card.
  • Docker, and your user in the render and video groups.
  • An amdgpu kernel driver that supports ROCm 10.1, AMD’s GPU compute stack. You don’t need ROCm installed on the host, according to radiance’s Docker guide. My box runs the driver that ships with kernel 7.0.6.
  • amdgpu.cwsr_enable=1 (compute wave save/restore), the driver’s default. It lets the driver pause GPU work and resume it later, and with it off the card can hang. radiance refuses to start without it. Check it with cat /sys/module/amdgpu/parameters/cwsr_enable.
  • 55 GiB of disk, on a fast drive if you use ngram-placement: disk.
  • 3 to 11 GiB of pinned host RAM (it can’t be swapped out) with two cards, plus 19 GiB if you pin the n-gram table in RAM. The config below pins about 23 GiB. The table is a 20-billion-parameter lookup of two- and three-token sequences.

Pull the image and the model ๐Ÿ”—

We’ll need the image, the model, and an empty directory for the tuning cache:

docker pull stilldeadcode/radiance:2.5.0
hf download StillDeadcode/qwen4-35b-a3b-iq8r-rtn --local-dir ~/models/rad/qwen4
mkdir -p ~/models/rad-home-qwen4

The config ๐Ÿ”—

radiance 2.x takes one YAML file. Save this one as ~/qwen4.yaml:

server:
  host: 0.0.0.0
  port: 8081
  radiance-home: /opt/radiance/share/radiance:/rad-home
  keep-alive-timeout: 120
cards: all
models:
  qwen4-35b-a3b:
    aliases: [Qwen4]
    model: /models/qwen4/qwen4-35b-a3b-iq8r-df2.rad
    tp: 2
    max-num-seqs: 4
    max-model-len: 1048576
    max-num-batched-tokens: 2048
    kv-cache-dtype: i8
    ngram-placement: ram
    num-speculative-tokens: 3

host: 0.0.0.0 lets anyone who can reach this machine use the server, and there’s no key. If only this machine calls it, use 127.0.0.1.

ngram-placement: ram copies the 19 GiB n-gram table into pinned host memory at startup, and disk reads its rows from the model file.

Disk saves you those 19 GiB. It cost about 4 to 5% on long prompts and at 16 clients (753 tok/s against 781), and about a quarter of prefill speed on a 2K prompt, one run each. disk is what I run on my daily server.

max-num-batched-tokens is the largest prefill step. At 1M tokens a step of 8192 doesn’t fit, and rad-tune, the optional tuning step below, defaults to 8192, which is how I found out:

qwen4exp: the QSA score plane would be 8192 MiB -- 8192 rows
(--max-num-batched-tokens 8192) by --max-model-len 1048576 / compress ratio 4. Lower either.

num-speculative-tokens: 3 is how many tokens the drafter guesses per pass. At 3, issue 816 reports output that matches no drafter.

The config leaves checkpoint-slots automatic, which gave 48 at 1M. If you run many long agent sessions at 1M, I’d raise it to 128. That’s what brought the cache hits back for twelve sessions in the agent test, where I set it by hand.

radiance’s guide warns that a large automatic count can stall output for tens of seconds on this model. It didn’t with 32 or 128 set: no request’s output ran below 10 tok/s, and the long waits came before the first token.

Choose the cards ๐Ÿ”—

The container only sees the cards you name in ROCR_VISIBLE_DEVICES. ROCr, ROCm’s runtime, numbers the R9700s from 0 in PCI order, and rocm-smi --showbus prints the mapping.

Diagram headed Which cards the container sees. Four R9700s are numbered 0 to 3. Cards 0 and 1 are blue and connect to the radiance 2.5.0 container, which carries ROCR_VISIBLE_DEVICES=0,1 and tp: 2. Cards 2 and 3 are dashed grey, with a note: The container can’t see these. They’re free for a second pair.

We’ll keep the Docker flags every radiance command shares in a shell array:

RAD=(
  --network host
  --init
  -e ROCR_VISIBLE_DEVICES=0,1
  --device /dev/kfd
  --device /dev/dri
  --security-opt seccomp=unconfined
  --ulimit memlock=-1
  --group-add "$(getent group render | cut -d: -f3)"
  --group-add "$(getent group video | cut -d: -f3)"
  -v "$HOME/models/rad:/models:ro"
)

seccomp=unconfined turns off Docker’s default syscall filter, because radiance uses io_uring (Linux’s fast async disk I/O) and that filter blocks it.

--check reads the config and exits:

docker run --rm "${RAD[@]}" \
  -v ~/models/rad-home-qwen4:/rad-home:ro \
  -v ~/qwen4.yaml:/etc/radiance.yaml:ro \
  stilldeadcode/radiance:2.5.0 \
  --config /etc/radiance.yaml \
  --check

Tune the kernels (optional) ๐Ÿ”—

rad-tune benchmarks radiance’s GPU kernels and writes the winners to the cache directory as root (deleting them takes sudo). The server runs without it, and I couldn’t measure a gain, so I’d skip it. To run it:

docker run --rm "${RAD[@]}" \
  -v ~/models/rad-home-qwen4:/rad-home \
  --entrypoint rad-tune \
  stilldeadcode/radiance:2.5.0 \
  -m /models/qwen4/qwen4-35b-a3b-iq8r-df2.rad \
  --home /rad-home:/opt/radiance/share/radiance \
  --tp 2 \
  --max-seqs 4 \
  --max-tok 2048 \
  --max-ctx 1048576 \
  --kv-cache-dtype i8

Those last five flags have to match the config (--max-tok is max-num-batched-tokens), and you’ll rerun it whenever they change.

Start the server ๐Ÿ”—

The launcher script needs a directory:

mkdir -p ~/bin

Save this as ~/bin/serve-qwen4.sh. It repeats the RAD array, since a script can’t see your shell’s:

#!/usr/bin/env bash

RAD=(
  --network host
  --init
  -e ROCR_VISIBLE_DEVICES=0,1
  --device /dev/kfd
  --device /dev/dri
  --security-opt seccomp=unconfined
  --ulimit memlock=-1
  --group-add "$(getent group render | cut -d: -f3)"
  --group-add "$(getent group video | cut -d: -f3)"
  -v "$HOME/models/rad:/models:ro"
)

# Remove a container left over from the last run.
docker rm -f qwen4 >/dev/null 2>&1 || true

exec docker run --rm --name qwen4 "${RAD[@]}" \
  -v ~/models/rad-home-qwen4:/rad-home:ro \
  -v ~/qwen4.yaml:/etc/radiance.yaml:ro \
  stilldeadcode/radiance:2.5.0 \
  --config /etc/radiance.yaml

Make it executable and run it in the foreground:

chmod +x ~/bin/serve-qwen4.sh
~/bin/serve-qwen4.sh

From another terminal, mine answered its health check in about 15 seconds:

curl -sf localhost:8081/health

Send a request ๐Ÿ”—

The API is OpenAI-compatible, and the model answers to qwen4-35b-a3b or the alias Qwen4:

curl -s localhost:8081/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "Qwen4",
  "messages": [{"role": "user", "content": "What is 17*23? Answer briefly."}],
  "max_tokens": 400,
  "chat_template_kwargs": {"reasoning_effort": "low"}
}'

Reasoning effort defaults to high, and there’s no medium. The server says the template “takes ’low’, ‘high’ and ‘xhigh’; ’none’ and ‘minimal’ turn thinking off”. Qwen’s model card says off, but radiance 2.5.0 rejects that with HTTP 400.

A limit this small can come back empty at the default effort, because reasoning can use the whole max_tokens. If you see that, raise max_tokens or set a lower effort.

Run it as a service ๐Ÿ”—

We’ll run it from a systemd user unit, ~/.config/systemd/user/qwen4.service:

[Unit]
Description=Qwen4-35B-A3B on 2x R9700 (radiance 2.5.0, TP2), port 8081
StartLimitIntervalSec=0

[Service]
ExecStart=%h/bin/serve-qwen4.sh
ExecStop=/usr/bin/docker stop -t 60 qwen4
ExecStopPost=-/usr/bin/docker rm -f qwen4
Restart=always
RestartSec=10
TimeoutStopSec=90

[Install]
WantedBy=default.target

Enabling it replaces the server you started by hand (the launcher removes its container):

systemctl --user daemon-reload
systemctl --user enable --now qwen4.service

I had help with this one. Claude set up the server, ran the benchmarks on the box, and helped me draft this post. I read all the words and checked the numbers, so the mistakes are mine.

Sources ๐Ÿ”—