[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-107549":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":15,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":24,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":16,"starSnapshotCount":16,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},107549,"qwenGPU","vixhal-baraiya\u002FqwenGPU","vixhal-baraiya","Qwen3.5-2B with a SIMT GPU inside its weights, 45 compiled layers in front of Qwen’s own, using its Gated DeltaNet layers as registers and memory.","",null,"Python",121,21,62,1,0,43,48.83,"MIT License",false,"main",true,[],"2026-11-01 16:48:11","2026-11-17 00:32:06","# qgpu: Qwen runs CUDA\n\n**qgpu is an experimental model: Qwen3.5-2B with a SIMT GPU compiled and inserted directly into\nits weights.** It is not a plugin, a tool or an emulator. The GPU is 45 transformer layers in\nfront of Qwen's own 24, and none of their weights are learned: a compiler computes every one.\nIt runs real CUDA, compiled to NVIDIA PTX, and the model itself writes every step of each\nlaunch.\n\n![qwenGPU running a dot product: the GPU's layers, registers and memory, token by token](docs\u002Fqgpu-demo.gif)\n\nA real launch, token by token ([full-quality video](docs\u002Fqgpu-demo.mp4)).\n\n## How it works\n\n**The GPU.** A 4-lane SIMT machine with 15 registers per lane, a 4-stage pipeline, a 32-block\nprogram ROM and 126 words of global memory, built from Qwen3.5's own layer types (Gated\nDeltaNet linear attention and SwiGLU MLPs). Registers and memory live in the layers'\nrecurrent state; each record the model writes runs one machine block (up to 4 instructions)\nfor one warp.\nIt supports integer arithmetic, comparisons and predicates, divergent branches, loops, global\nand shared memory, `atomicAdd`, `__syncthreads()` and warp shuffles.\n\n**A launch.** The host does what NVRTC and the CUDA driver do on a real GPU. It compiles the\nCUDA source to PTX with clang, lowers the PTX to the GPU's machine blocks\n(`qgpu\u002Flower.py`), and feeds the program image and the input arrays as tokens. From there the\nmodel writes the launch itself: each generated token is a record of which block a warp ran\nand the values it produced, until an end-of-launch token. The host then reads the result\narrays from the model's recurrent state. It never computes anything itself.\n\n**The merge.** `qgpu.merge` compiles the circuit with [Qwenputer](https:\u002F\u002Fgithub.com\u002Fdivagr18\u002Fqwenputer)'s\ntransformer compiler, widens Qwen's residual stream, puts the circuit layers in front of\nQwen's and adds the GPU's tokens to the vocabulary. Circuit dimensions that do not matter on\ntext share Qwen's dimensions (the overlay), and the circuit is muted on text tokens, so\nQwen's text is unchanged: the merged model's next-token distribution stays within a KL of\nabout 7e-4 of the original.\n\n**The chat.** `qgpu` is a terminal chat with the merged model. When a message asks for a\ncalculation, Qwen computes it on the GPU in its weights, in one of two modes:\n\n- **normal**: Qwen writes the arithmetic as an expression (`[1, 2, 3] @ [4, 5, 6]`), and each\n  operation runs as a ready-made CUDA kernel from `kernels\u002F`.\n- **advanced**: Qwen writes the CUDA kernel itself, guided by the\n  [qgpu CUDA reference](docs\u002Fqgpu-cuda.md) in its system prompt.\n\nA panel next to the chat shows the GPU live: the warp scheduler, program ROM, pipeline,\nregister file and memory light up as the model's tokens drive them.\n\n## Gated DeltaNet as GPU state\n\nLike [Qwenputer](https:\u002F\u002Fgithub.com\u002Fdivagr18\u002Fqwenputer), qgpu keeps its machine state in the\nrecurrent state of Qwen3.5's Gated DeltaNet layers. In the circuit's heads the gate is held\nopen and the write strength is 1, and every key is one-hot, so each update overwrites exactly\none row of a head's state and a one-hot query reads it back: each row is a memory cell.\n\n- **Program ROM**: each machine block's instructions, one instruction per stage, in heads of\n  their own.\n- **Registers**: 16 per lane for each warp (one always reads zero), in rows chosen by warp and\n  register.\n- **Global memory**: the kernel's arrays, one 32-bit word per row. Inputs are written by the\n  host before the launch; results are written by the circuit during it.\n\nA launch is a stream of tokens. The host writes the setup records: `PROG` and `LIVE` records\nload the program, `MEM` records load the inputs, and an `EXEC` token starts warp 0 at block 0.\nThen the model writes the rest. Each `EXEC(b, w)` token runs block `b` for warp `w` in one\nforward pass, and the `VAL` tokens after it carry the block's results, two 16-bit tokens per\nlane for each register a later block reads. Memory writes come back as `MEM` records, and\n`EXEC(0, warps)` ends the launch. The token stream is the GPU's execution log, and every value\nin it is exact in bf16.\n\n## What runs where\n\nQwen asks for a calculation with a tool call, in the format Qwen3.5 was trained on. Unlike\nQwenputer, the host does act on that call: it does what a real GPU's host side does.\n\n- **The host**: compiles the CUDA to PTX, lowers the PTX to machine blocks, writes the\n  program and the input arrays as tokens, and reads the result arrays from the model's state\n  when the launch ends. It decides nothing about the values and computes none of them.\n- **The weights**: every step of the launch. The model writes each `EXEC` and `VAL` token by\n  greedy decoding through its own layers: which block runs next, every register value, every\n  branch and every memory write.\n\nWith `--check`, each launch is replayed on a reference interpreter of the circuit and the\nmodel's tokens must match it exactly.\n\n## Results\n\nOn Qwen3.5-2B, on Apple silicon (MPS, bf16):\n\n- Every launch in our runs was exact. With `--check`, each launch is compared token for token\n  with a reference interpreter of the circuit, and that interpreter matched a real NVIDIA\n  Tesla T4 on 49 of 49 test kernels.\n- Text: the merged model's next-token distribution is within a KL of about 7e-4 of the\n  original.\n- Normal mode answered 20 of 24 sampled chat questions with numbers computed on the GPU.\n- Advanced mode wrote a correct kernel for 4 of 5 vector and matrix questions on the first\n  try (dot product, matrix product, squared length, vector addition). A 2B model's CUDA is still\n  unreliable; use normal mode for answers you rely on.\n\nA launch takes tens to a few hundred generated tokens, about 10-15 tokens per second on MPS.\n\n## Quickstart\n\nRequirements: Python 3.11+, [uv](https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002F),\n[just](https:\u002F\u002Fgithub.com\u002Fcasey\u002Fjust), about 16 GB of free memory for\nthe 2B model (Apple silicon, an NVIDIA GPU or a CPU), and for advanced mode a clang with the\nNVPTX backend (`brew install llvm`, or set `CLANG` to its path).\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fvixhal-baraiya\u002FqwenGPU && cd qwenGPU\njust setup\njust build\njust chat\n```\n\n`just build` downloads Qwen3.5-2B and compiles the GPU into it. In the chat, type `\u002F` for\ncommands. `just` lists every recipe, including `just check` and `just test`.\n\nOther entry points:\n\n```bash\nuv run python -m qgpu.bridge build\u002Fmerged-2b \"What is the sum of 12, 7, 30 and 5?\"\nuv run python scripts\u002Fmerged_check.py models\u002FQwen3.5-2B build\u002Fmerged-2b\nuv run python scripts\u002Feval_chat.py build\u002Fmerged-2b --samples 3\n```\n\n## Repository\n\n| Path | What it is |\n|---|---|\n| `qgpu\u002Fcircuit\u002F` | The GPU as transformer layers: the kernel circuit and its parts |\n| `qgpu\u002Fptx.py`, `qgpu\u002Flower.py` | The PTX parser and the driver that lowers PTX to machine blocks |\n| `qgpu\u002Fsim.py`, `qgpu\u002Fdriver.py` | A reference SIMT interpreter for the PTX subset |\n| `qgpu\u002Fmerge.py`, `qgpu\u002Foverlay.py` | Building a merged Qwen3.5 checkpoint |\n| `qgpu\u002Fruntime.py` | Launching a kernel on the merged model and reading results back |\n| `qgpu\u002Fcuda.py`, `qgpu\u002Fcalc.py` | Advanced mode (Qwen's CUDA) and normal mode (expressions) |\n| `qgpu\u002Fbridge.py`, `qgpu\u002Ftui.py`, `qgpu\u002Fmonitor.py` | The chat session, the terminal app and the GPU panel |\n| `kernels\u002F` | The CUDA kernel library and the PTX tests run against |\n| `docs\u002Fqgpu-cuda.md` | The CUDA reference for this GPU |\n| `tests\u002F` | Circuit, driver, runtime, kernel and app tests |\n\nRun the tests with `just test`. The circuit tests evaluate the compiled weights exactly;\nthe slowest take a few minutes.\n\n## Credits\n\nThe transformer compiler is [Qwenputer](https:\u002F\u002Fgithub.com\u002Fdivagr18\u002Fqwenputer) (MIT), which\ncompiles a RISC-V CPU into Qwen3.5-4B; qgpu uses it as a library and builds its own GPU,\ndriver and token format on top. If you use this work, please cite Qwenputer:\n\n```bibtex\n@software{agrawal2026qwenputer,\n  author  = {Agrawal, Divyansh},\n  title   = {{Qwenputer}: a computer compiled into the weights of a pretrained language model},\n  year    = {2026},\n  version = {0.1.0},\n  url     = {https:\u002F\u002Fgithub.com\u002Fdivagr18\u002Fqwenputer},\n  license = {MIT}\n}\n```\n\n## License\n\nThe code is MIT, see [LICENSE](LICENSE). A checkpoint built with `qgpu.merge` is a modified\n[Qwen3.5](https:\u002F\u002Fhuggingface.co\u002FQwen\u002FQwen3.5-2B) model (its config is widened and GPU layers\nare added; Qwen's own weights are unchanged), so its weights fall under Qwen's Apache-2.0\nlicense.\n","qwenGPU 是一个实验性AI模型，将轻量级SIMT GPU电路直接编译并嵌入Qwen3.5-2B模型权重中，实现模型在推理过程中原生执行CUDA程序。其核心包含45层预编译的Transformer电路（基于Gated DeltaNet和SwiGLU构建），模拟4路SIMT架构，支持整数运算、分支、循环、共享\u002F全局内存及原子操作；所有GPU指令由模型逐token生成并驱动，主机仅负责编译PTX与读取结果。该方案适用于需要模型内联执行确定性数值计算的场景，如轻量级符号计算、可验证算术推理或AI驱动的嵌入式GPU仿真研究。",2,"2026-11-24 04:32:13","CREATED_QUERY"]