A Tiny GPU Inside Qwen
What if a language model's next token were the clock of a programmable machine?
In this article
I gave a modified Qwen model two 16×16 matrices and a program. It returned the exact product, cell by cell, after scheduling 928 instructions in a single generation call.
The run emitted 20,167 machine tokens. Those tokens were not a written explanation of multiplication. They were the visible control and state updates of a small processor compiled into the model. The host supplied the program and input, then let generation advance the machine. All 256 output cells matched an independent scalar calculation. A clean download of the checkpoint reproduced the result on another CUDA GPU.1
That is an awkward way to multiply matrices. A real GPU can do the arithmetic incomparably faster. The interesting result is that the model did not merely describe a GPU program or memorize an answer. It kept program counters, registers, memory, and scheduling state across a sequence of generated tokens, and used them to execute the program.
The question behind the trick#
Language models already run on GPUs. Putting a GPU inside one sounds redundant until the two meanings of “run” are separated. The physical accelerator multiplies tensors to evaluate Qwen. Qwen-GPU is a logical machine represented by specially constructed model weights. Its warps and memory are state within the inference process; they are not new silicon.
The project began with a narrower question: can a model do more than answer questions about computation? Can its next-token process become the execution loop of a machine with instructions, persistent state, and data-dependent control flow? QwenCPU had explored the CPU version. A GPU-shaped machine adds a harder problem: many lanes must follow one instruction while taking different branches, sharing memory, and meeting at barriers.
The useful standard is not whether the model can print a plausible matrix. It is whether an uploaded program can change what happens, whether the same state survives from one instruction to the next, and whether an external checker can inspect the entire trace. A single lucky final number would tell us very little.
Building the machine#
Qwen-GPU starts from Qwen3.5-9B and uses Qwenputer to compile exact computational circuits into a derived checkpoint. This is a deliberate weight construction, not a prompt that asks the base model to imagine a GPU. The checkpoint retains the pretrained text model alongside the added machine. The source and reproducible build path are public.2
The current machine has two warps of eight lanes per workgroup. Each warp can fetch from a 32-instruction program, perform 32-bit integer and address operations, loop, diverge, reconverge, and synchronize at a barrier. Workgroups can run sequentially or interleave. There are 512 bytes of programmable global memory, with separate workgroup-shared and lane-private storage. The matrix path also uses its bounded tile banks. This is a small instruction set and a small address space, but the instructions and initial data are supplied at launch rather than baked in as one fixed calculation.3
A lane mask makes the GPU part more than a name. If only some lanes satisfy a condition, the machine saves which lanes are active. An inactive lane keeps its registers and does not write memory. When the branch ends, the parent mask is restored. A barrier adds another constraint: a warp that cannot proceed must wait while the scheduler chooses useful work elsewhere, or the machine must report a deadlock. These are observable rules, not analogies.
What happens on a tick#
Think of a generated token as a clock edge. The launch prompt uploads the programs, operands, and initial control state. During generation, the model chooses a runnable warp, fetches its instruction, reads the relevant registers and memory, and emits the next control or writeback token. Subsequent forwards consume those tokens while the inference cache retains the machine's state. The model can therefore choose a loop back edge or a warp switch based on values produced earlier in the same launch.4
There is a subtle boundary here. Some state is written into the model's recurrent banks; other updates travel as model-generated tokens that the host relays back into the next forward pass. The host also supplies the launch and enforces an instruction budget. It does not compute the answer or choose each next instruction from a reference interpreter. Still, this is not a host-free processor: the token relay is part of the execution protocol. Calling it “fully internal” would hide the most interesting unresolved engineering problem.
Why the relay? A value computed late in one model forward cannot automatically alter a register bank that an earlier layer already read. Feeding back a generated token bridges that order. A runtime cache-copy experiment reduced the traffic, but it changed the runtime contract; the released stock-generation checkpoint keeps the token path. The distinction matters because a machine encoded entirely in weights has a different claim from one whose host performs a hidden state transition.5
The matrix test#
A 16×16 product makes the pieces depend on one another. A lane needs an address, a warp needs a schedule, partial products need to accumulate, and later panels need the results left by earlier ones. The program divides the output into eight panels. Qwen schedules the panels inside one generation call and keeps their state in one cache. The resulting trace is long enough that a program counter reset, stale register, missing barrier, or incorrect writeback would tend to surface as a wrong intermediate state before it reached the final matrix.
1 generation call928 instructions7 model-selected panel transitions256 of 256 cells exact
- Panel 1C rows 0–7C cols 0–7k 0–7
- Panel 2C rows 0–7C cols 0–7k 8–15
- Panel 3C rows 0–7C cols 8–15k 0–7
- Panel 4C rows 0–7C cols 8–15k 8–15
- Panel 5C rows 8–15C cols 0–7k 0–7
- Panel 6C rows 8–15C cols 0–7k 8–15
- Panel 7C rows 8–15C cols 8–15k 0–7
- Panel 8C rows 8–15C cols 8–15k 8–15
The verified run performed 928 instructions and produced 256 correct cells. The checker compared generated tokens, control state, and final memory against independent expectations. The same restored package also passed a seeded tile run and a native-text probe on a separate 96 GB CUDA GPU. This is stronger evidence than a screenshot of a product matrix, because it checks the path the machine took to get there.6
What the evidence says#
The fixed v4 checkpoint passed 27 inherited tile fixtures, eight workgroup fixtures, 31 common compute requests, seven raw memory cases, and the full matrix run on merged Qwen3.5-9B CUDA. A text check compared 24 prompts with the base model: all 24 first greedy tokens matched, while 21 of 24 short continuations matched. Three continuations diverged. That supports a narrow claim that ordinary text still works on the tested prompts, not that the derived model is linguistically identical to the base model.7
| Check | Result |
|---|---|
| Inherited tile fixtures | 27 of 27 |
| Workgroup fixtures | 8 of 8 |
| Common compute requests | 31 of 31 |
| Raw memory cases | 7 of 7 |
| 16×16 matrix, one generation call | 256 of 256 cells; 928 instructions |
| Text against the base model, 24 prompts | 24 of 24 first tokens; 21 of 24 short continuations |
| Apple MPS | Full v4 qualification pending; a standalone export passed two CPU smoke traces |
| 32-bit atomic operation | Not in any released checkpoint |
Reproducibility also has a physical side. The merged checkpoint is roughly 86 GB. Its corrected v4 package is distributed through a public GitHub release, with checksum and clean-restore records. The Hugging Face repository currently serves the separately verified v3 checkpoint; it should not be mistaken for v4. Source code, test inputs, and reports live in the repository, so the claim can be checked against artifacts rather than this essay alone.8
Where the machine stops#
Qwen-GPU is a bounded programmable GPU-like processor, not a replacement for a CUDA GPU. Two eight-lane warps and 512 bytes of global memory are enough to demonstrate cooperation and useful small kernels; they are far from the scale or throughput of general GPU computing. Every generated token incurs model work. The 20,167-token matrix trace is a correctness demonstration, not a performance result.
The fixed v4 release is qualified on CUDA. A standalone export passed two CPU smoke traces, but full Apple MPS qualification of v4 remains open. The released instruction set also lacks a 32-bit atomic read-modify-write operation. There is a reference contract and isolated circuit work for one, but no released checkpoint implements it. Those boundaries matter if “complete GPU” is taken to mean broad programs with concurrent writes, arbitrary kernels, and competitive speed.9
Why build it?#
The point is not to beat a GPU at its own job. It is to test how much exact, inspectable computation can live inside the same object that produces language. The surprising part of the matrix run is not the arithmetic; a pocket calculator has that covered. It is that a pretrained language model can carry a separate programmable machine, schedule its cooperating warps, and still answer ordinary text prompts with the same derived weights.
That leaves a useful question rather than a triumphal ending. If a token can be a clock tick and a model cache can be machine state, what other programs can be embedded there without making the host quietly do the real work? Qwen-GPU gives one measured answer, with the trace and the limits visible.
Notes
- Qwen-GPU, independent v4 restored-copy replay, including the 16×16 trace and exact output check. ↩
- Arya Somu, Qwen-GPU source and reproduction guide; Qwenputer, compiler source. ↩
- Qwen-GPU, current capabilities and scope and limits. ↩
- Qwen-GPU, resident generation and register-bank protocol. ↩
- Qwen-GPU, writeback design and host-relay boundary. ↩
- Qwen-GPU, restored-copy validation and release receipt. ↩
- Qwen-GPU, fixed v4 CUDA summary and full validation record. ↩
- Qwen-GPU, corrected v4 GitHub release and publication review. ↩
- Qwen-GPU, 32-bit atomic instruction gate and standalone v4 export status. ↩
Cite this essay
@misc{somu2026tinygpuqwen,
title = {A tiny GPU inside Qwen},
author = {Somu, Arya},
year = {2026},
url = {https://aryasomu.com/writing/a-tiny-gpu-inside-qwen}
}