I wanted a local coding model on my gaming PC, and I wanted the PC to stay a gaming PC. It has an RX 9070 XT, so any model shares 16 GB of VRAM with whatever I feel like playing. It also runs Bazzite, so the model has to live in a container, with nothing added to the OS image.
Here's where I ended up: a 27B model with a 128K context, generating 28 to 36 tokens per second. It pauses itself and hands the VRAM back when a game launches, and I can use it from my phone through a Cloudflare tunnel. This post covers the setup, the numbers I measured, and the places it broke.
If you're on a 16 GB card and short on time, skip to "Fitting 128K into 16 GB". That section is the reason any of this works.
The machine
The VRAM row drives every decision below.
| Item | What it is | What it means for the LLM |
|---|---|---|
| OS | Bazzite (SteamOS on Fedora) | Container-only, nothing installed on the image |
| GPU | AMD RX 9070 XT | 16,304 MiB of VRAM, about 696 MiB in use at idle |
| RAM | 31 GB | Overflow is possible, but I measured it and did not want it |
| Disk | 527 GB free on /var | Room for several models |
| Containers | Podman 5.8.9 | Runs rootless, managed by systemd |
Two Bazzite defaults saved me work. It exposes /dev/dri/renderD128 and /dev/kfd to all users, so a rootless container gets the GPU without any group changes. The firewall also already has the user port range (1025 to 65535) open, so publishing a port needed no firewall change. If your setup is different, check both before you start:
ls -l /dev/dri /dev/kfd
firewall-cmd --list-ports
One default worked against me. The machine suspends itself when idle, which is lovely for a gaming PC and terrible for a server. During setup I blocked it with systemctl mask --runtime on the sleep targets, which only lasts until reboot. Once the model had proved useful, I kept the machine awake for good. Whether an always-on gaming PC is worth the power is your call.
One endpoint, loaded on demand
I don't run llama-server directly. llama-swap sits in front of it: a small proxy that exposes one OpenAI-compatible API, starts whichever model a request asks for, and stops it when it goes quiet. That turned out to be most of the design. The GPU is free when nothing is running, and the API looks the same whether there is one model on disk or five.
The unified-vulkan image bundles llama.cpp with the Vulkan backend, which suits AMD on Linux and saves chasing ROCm. I run it as a rootless Podman quadlet, so systemd owns the container and restarts it if it dies:
[Unit]
Description=Local LLM server (llama-swap + llama.cpp Vulkan)
[Container]
Image=ghcr.io/mostlygeek/llama-swap:unified-vulkan
ContainerName=llm
AddDevice=/dev/dri/renderD128
SecurityLabelDisable=true
Volume=%h/llm/models:/models:ro
Volume=%h/llm/config:/etc/llama-swap/config:ro
PublishPort=9292:8080
[Service]
Restart=always
RestartSec=5
TimeoutStartSec=120
[Install]
WantedBy=default.target
The llama-swap config lives in ~/llm/config/config.yaml. It reloads without restarting the container, which is what made the tuning in the next section practical. Models live in ~/llm/models, mounted read-only:
healthCheckTimeout: 300
globalTTL: 1800 # unload 30 minutes after the last request
sendLoadingState: true
macros:
"server": >-
llama-server --port ${PORT} --host 127.0.0.1
--n-gpu-layers 999 --threads 8 --parallel 1
models:
"qwen3.8-27b":
name: "Qwen3.8 27B (UD-Q3_K_XL)"
aliases: ["qwen", "default"]
cmd: >-
${server}
--model /models/Qwen3.8-27B-UD-Q3_K_XL.gguf
--ctx-size 131072 -ctk q4_0 -ctv q4_0 -fa on
--batch-size 1024 --ubatch-size 256
--reasoning-budget 1024 --no-reasoning-preserve
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0
The model is Qwen3.8-27B at Q3_K_XL: 12.24 GiB, with thinking and tool calling. It's the newest serious option that fits a 16 GB card. I couldn't find a head-to-head benchmark for it, so treat "the smartest that fits" as a judgement call.
The endpoint is http://<machine>:9292/v1 and it has no API key, so anything on the LAN can use it. I'm fine with that on a network I trust. For access from outside I leave this port alone and put real authentication on a separate path, described further down.
Fitting 128K into 16 GB
The first configuration didn't work.
I started with a 65K context. The model takes 12.24 GiB, and a full-precision KV cache for that much context didn't fit in what was left, so llama.cpp spilled the rest into system RAM. The model still answered, but once a prompt got long, speed collapsed to about 11 tokens per second. I then tried using the 31 GB of system RAM as overflow on purpose. That was worse: 6 to 10 tokens per second, even on short prompts. At those speeds the model is no use as a coding agent.
I also lost time to a smaller bug. My first config carried --no-mmap, and this build of llama-server doesn't recognise it. The server exited the instant it started, which looked exactly like a GPU problem. If yours dies at startup with no obvious error, check every flag in your macro against llama-server --help before you blame the driver.
The fix came from a report by someone running the same card. Their recipe was to quantise the KV cache:
-ctk q4_0 -ctv q4_0
The KV cache is where the context lives, and it grows with context length. Compressed to 4-bit, a full 128K context fits in the VRAM left over after the model. Flash attention (-fa on) came with the same recipe, and I capped the thinking budget at 1024 tokens so a long chain of thought can't eat the context.
Measured on this card:
| Measured | Result |
|---|---|
| Generation speed | 28 to 36 tokens/s, with prompts up to 101K tokens |
| Prompt processing | About 800 tokens/s on the earlier 65K config |
| Cold start | 21 seconds from an unloaded endpoint |
| Context | 131,072 tokens, holding at 15.1 GB of VRAM with no spill |
| VRAM while paused | Drops from 15.7 GB to 0.5 GB |
The last two rows are the ones to remember. The whole context sits in VRAM without spilling, and a pause hands almost the entire card back, which is what keeps this a gaming PC.
On a bigger card you can probably skip the KV quantisation and keep more of the context at full precision. On 16 GB, test for spill before you test your prompts. Watch /sys/class/drm/card*/device/mem_info_vram_used and the GTT counters while a long prompt runs. If either climbs, the model is in RAM, and the slow speed you're measuring is the speed you'll keep.
Giving the GPU back to games
The 30-minute idle timeout doesn't help here, because a game won't wait for it. I wanted the model to notice the game and get out of the way.
On Bazzite, Steam launches every title, including non-game shortcuts, through a process that shows up in /proc as reaper SteamLaunch AppId=N. So the guard is a small user service that polls for that process and asks llama-swap to pause:
API = "http://127.0.0.1:9292/api/models"
POLL_SECONDS = 3
REASSERT_SECONDS = 30
# Steam shortcuts that are not games: Kodi, Chrome.
IGNORED_APPIDS = {"3095802263", "2215658897"}
def running_game():
for path in glob.glob("/proc/[0-9]*/cmdline"):
try:
with open(path, "rb") as f:
argv = f.read().decode(errors="replace").split("\0")
except OSError:
continue
if os.path.basename(argv[0]) != "reaper" or "SteamLaunch" not in argv:
continue
for arg in argv:
if arg.startswith("AppId=") and arg[6:] not in IGNORED_APPIDS:
return arg[6:]
return None
def post(action):
req = urllib.request.Request(f"{API}/{action}", data=b"", method="POST")
with urllib.request.urlopen(req, timeout=20) as resp:
return resp.status
paused = None
last_sent = 0.0
while True:
game = running_game()
want_paused = game is not None
now = time.monotonic()
if want_paused != paused or (want_paused and now - last_sent >= REASSERT_SECONDS):
post("pause" if want_paused else "resume")
paused = want_paused
last_sent = now
time.sleep(POLL_SECONDS)
A few choices in there need explaining:
- The ignored AppIds are Kodi and Chrome. Both are Steam shortcuts on this machine, and neither should pause the model.
- The guard re-sends the pause every 30 seconds while a game is running, which covers a game that respawns its process.
- The pause is blunt. While it's on, every request gets a 503 saying inference is paused, so an agent pointed at the endpoint learns quickly that the PC is busy and can retry later.
So far I've only tested the guard with fake reaper processes, so the first real game will be the first thing it hasn't seen. With a three-second poll, the pause should land within about three seconds of launch.
Reaching it from outside the house
The model's endpoint is LAN-only on purpose, and I didn't open a port to change that. What sits on the public path is the coding agent, with my Cloudflare login in front of it. The model itself is never exposed.
The agent is OpenHands, running in a container on my dev machine, and it talks to the model over the LAN. From phone to GPU, the chain looks like this:
Diagram 1 as text
7 steps. Starts at “Phone browser”.
Phone browser (a starting point)
- Go to Cloudflare
Cloudflare
- Go to cloudflared tunnel on the always-on server, when Access policy: owner only
- Reached from Phone browser
cloudflared tunnel on the always-on server
- Go to SSH reverse tunnel to the dev machine, loopback only
- Reached from Cloudflare, when Access policy: owner only
SSH reverse tunnel to the dev machine, loopback only
- Go to OpenHands Agent Canvas
- Reached from cloudflared tunnel on the always-on server
OpenHands Agent Canvas
- Go to llama-swap gaming PC :9292, when LAN, no key
- Reached from SSH reverse tunnel to the dev machine, loopback only
llama-swap gaming PC :9292
- Go to Qwen3.8-27B RX 9070 XT
- Reached from OpenHands Agent Canvas, when LAN, no key
Qwen3.8-27B RX 9070 XT
- Nothing leads out of this step.
- Reached from llama-swap gaming PC :9292
I built it in this order:
- OpenHands, in a container. The agent runs in a Docker container on the dev machine, with only the project folders mounted. It's a user service, so systemd restarts it. The container can reach the LAN, which is how it gets to the model, but it holds no credentials it shouldn't have.
- A Cloudflare Access policy, created first. I made the Access app for
code.example.devbefore I made the tunnel route, so the address could never be live without a login in front of it. The policy is the default "allow the owner" one. It checks that you're signed in to your Cloudflare account, which means the phone's browser is the only client that ever needs setting up. - A tunnel route on the always-on box. I already ran a Cloudflare tunnel on the home server, so I added a route from
code.example.devtohttp://localhost:8000on that server. That needs no inbound ports or firewall holes, and I have no DNS of my own to maintain. - An SSH reverse tunnel. The dev machine isn't the always-on box, so a user service on it holds a persistent SSH connection to the server and forwards the server's loopback port 8000 back to the dev machine's loopback. The Cloudflare tunnel ends up pointing at a localhost port that only exists while the dev machine is awake, and nothing outside the house can address the dev machine directly.
The first time you open code.example.dev, it redirects to the Cloudflare login, and then the browser lands on the OpenHands first-time setup instead of a session. The wizard walks through choosing the agent, confirming the backend, and pointing the LLM at the model. That last step is the only one to set deliberately: the custom model id, the base URL at the llama-swap endpoint, and a placeholder key, since the model has no key of its own.
After that, the browser is a full client: pick a repo, start a session, approve shell commands when the agent asks. A new phone just opens the address and gets the same agent. There's no pairing link to generate and no long-lived token to leak, and the Cloudflare login is the only thing in front of it.
Here is what I've tested. From outside, I sent 48 unauthenticated requests to the address and got 48 redirects to the login page, with no content leaking. On the LAN, I pointed a chat client at the endpoint from three different machines and watched the model load, answer, and unload on its own schedule. The full signed-in chain I have only run from inside the house.
The remote path has two limits. The agent is only as available as the dev machine, so if that's asleep, the tunnel lands on nothing. And while a game is running, every request gets the 503, including requests from the phone, because the model is off the GPU.
What to watch
- Spill fails silently. If speed drops as context grows, the KV cache is in system RAM. The
-ctk q4_0 -ctv q4_0pair is what keeps it out. Check the VRAM and GTT counters before you tune anything else. - Quantisation costs quality. Q3 for the weights and 4-bit for the KV cache is what fits, and it's a real trade. If the model starts repeating itself or losing the plot on long tasks, reduce the context size first and leave the quant alone.
- The guard is a poller. It sees a game within about three seconds, and only if Steam launched it through that
reaperprocess. A game started some other way won't pause the model. - No API key means I'm trusting the LAN. I'd add one before pointing this at any network I don't control. The remote path doesn't inherit the problem, because it never reaches the model directly.
- Waking the machine is only partly tested. Wake-on-LAN works from suspend on this box and takes about 15 seconds. From a full shutdown it may want the power button. If you rely on the machine as a server, make that trade deliberately.
The whole thing is two containers, one config file, and about 60 lines of Python. The remote side is one Cloudflare route, one Access policy, and an SSH tunnel that has survived being left alone. If you have a 16 GB card in a machine you also want to game on, start with the KV cache flags. Everything else in this post is logistics around them.