A Tiny GPU Inside Qwen

What if a language model's next token were the clock of a programmable machine?

The verified 16×16 run at a glance. Qwen worked through four output tiles, each over two halves of k, in one generation call. The host uploaded the launch and relayed generated tokens back as input; the model selected each panel transition. Panels are drawn by instruction count, 116 each, not by time or token count.
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.

Figure 1Two warps, one workgroup
A snapshot of one workgroup. The scheduler issues only a warp that can make progress; if neither can, the machine reports a deadlock. Masked lanes keep their registers and do not write memory, and the parent mask returns when the branch ends. The lane count and memory size follow the released v4 machine; the program counters and mask are illustrative.

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.

Figure 2One tick of the token clock
The dashed path is the host relay. It is part of the released execution protocol, not a detail that has been removed. One instruction usually spans several generated tokens, such as an instruction ticket, register updates, and store commits.

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.

Figure 3Eight panels of the verified 16×16 run

1 generation call928 instructions7 model-selected panel transitions256 of 256 cells exact

  1. Panel 1C rows 0–7C cols 0–7k 0–7
  2. Panel 2C rows 0–7C cols 0–7k 8–15
  3. Panel 3C rows 0–7C cols 8–15k 0–7
  4. Panel 4C rows 0–7C cols 8–15k 8–15
  5. Panel 5C rows 8–15C cols 0–7k 0–7
  6. Panel 6C rows 8–15C cols 0–7k 8–15
  7. Panel 7C rows 8–15C cols 8–15k 0–7
  8. Panel 8C rows 8–15C cols 8–15k 8–15
Each square is the 16×16 output after that panel. A panel multiplies an 8-row block of A by an 8-column block of B across half of k and accumulates into one 8×8 tile of C. The tile stays in recurrent memory, so the panel for the second half of k continues from it without a new upload. Each panel runs 116 instructions. The kernel computes C + A·B modulo 216, and the checker compared every cell with an independent scalar calculation.

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

Table 1Fixed v4 checks and open limits
CheckResult
Inherited tile fixtures27 of 27
Workgroup fixtures8 of 8
Common compute requests31 of 31
Raw memory cases7 of 7
16×16 matrix, one generation call256 of 256 cells; 928 instructions
Text against the base model, 24 prompts24 of 24 first tokens; 21 of 24 short continuations
Apple MPSFull v4 qualification pending; a standalone export passed two CPU smoke traces
32-bit atomic operationNot in any released checkpoint
The first six rows ran on merged Qwen3.5-9B with CUDA. They are correctness checks, not timings or a comparison with a conventional GPU.

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

  1. Qwen-GPU, independent v4 restored-copy replay, including the 16×16 trace and exact output check. ↩
  2. Arya Somu, Qwen-GPU source and reproduction guide; Qwenputer, compiler source. ↩
  3. Qwen-GPU, current capabilities and scope and limits. ↩
  4. Qwen-GPU, resident generation and register-bank protocol. ↩
  5. Qwen-GPU, writeback design and host-relay boundary. ↩
  6. Qwen-GPU, restored-copy validation and release receipt. ↩
  7. Qwen-GPU, fixed v4 CUDA summary and full validation record. ↩
  8. Qwen-GPU, corrected v4 GitHub release and publication review. ↩
  9. Qwen-GPU, 32-bit atomic instruction gate and standalone v4 export status. ↩

Source and documentation · Run the checkpoint

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}
}