跳到主内容
@wquguru
精选88MarkTechPost(RSS)技巧与观点

开发者将SIMT GPU编译进Qwen3.5-2B权重实现CUDA推理

Meet qwenGPU: Qwen3.5-2B With 45 Compiled GPU Layers That Run CUDA

原文
发到 X
推荐理由

硬核工程实践,展示LLM内部执行CUDA的创新路径,参数与流程清晰可复现,适合对AI底层机制感兴趣的开发者深入研究。

qwenGPU is an experimental model that compiles a SIMT GPU directly into the weights of Qwen3.5-2B. Developer Vixhal (@TheVixhal) released it on GitHub under the MIT license. The model runs real CUDA, compiled to NVIDIA PTX, inside its own forward passes. For developers, it tests one idea: exact computation inside a pretrained LLM, not beside it.

qwenGPU 是一个实验性模型,它将 SIMT GPU 直接编译为 Qwen3.5-2B 的权重。开发者 Vixhal (@TheVixhal) 在 GitHub 上以 MIT 许可证发布了该模型。该模型在其前向传播过程中运行真实的 CUDA,这些 CUDA 被编译为 NVIDIA PTX。对于开发者而言,它验证了一个理念:精确计算存在于预训练 LLM 内部,而非其旁边。

TL;DR

TL;DR(太长不看)

  • Size: Qwen3.5-2B (24 layers) along with 45 compiled GPU layers, 69 in total. Context: 262,144 tokens (base model).
  • Runs on: Apple silicon, an NVIDIA GPU or a CPU, with about 16 GB of free memory. No quantized build.
  • Performance: Every launch in the developer’s runs was exact; text drift is a KL of about 7e-4.
  • Best: The reference interpreter matched a real NVIDIA Tesla T4 on 49 of 49 kernels.
  • Worst: About 10 to 15 tokens per second on Apple MPS; Qwen-written CUDA passed 4 of 5.
  • 规模:Qwen3.5-2B(24 层),外加 45 个编译后的 GPU 层,共 69 层。上下文长度:262,144 tokens(基础模型)。
  • 运行环境:Apple Silicon、NVIDIA GPU 或 CPU,需约 16 GB 空闲内存。无量化版本。
  • 性能:在开发者的测试中,每次启动都是精确的;文本漂移的 KL 散度约为 7e-4。
  • 最佳情况:参考解释器在 49 个内核中的 49 个上与真实的 NVIDIA Tesla T4 匹配。
  • 最差情况:在 Apple MPS 上每秒约 10 到 15 个 tokens;Qwen 编写的 CUDA 通过了 5 个中的 4 个。

What is qwenGPU?

什么是 qwenGPU?

qwenGPU is Qwen3.5-2B with 45 compiled transformer layers placed in front of Qwen’s own 24. None of those layers are trained. A compiler computes every weight.

qwenGPU 是 Qwen3.5-2B,在 Qwen 自身的 24 层之前放置了 45 个编译后的 Transformer 层。这些层均未经过训练。编译器计算每一个权重。

How does a GPU fit inside model weights?

GPU 如何嵌入模型权重中?

The GPU is a 4-lane SIMT machine. It has 15 registers per lane, a 4-stage pipeline, a 32-block ROM and 126 memory words. It uses only Qwen3.5’s own layer types: Gated DeltaNet linear attention and SwiGLU MLPs.

该 GPU 是一台 4 通道 SIMT 机器。每通道有 15 个寄存器,采用 4 级流水线,拥有 32 块 ROM 和 126 个存储字。它仅使用 Qwen3.5 自身的层类型:门控 DeltaNet 线性注意力机制和 SwiGLU MLP。

The trick is the Gated DeltaNet recurrent state. In the circuit’s heads, the gate is held open and the write strength is 1. Every key is one-hot. Each update overwrites exactly 1 row, and a one-hot query reads it back. So each row works as a memory cell.

诀窍在于门控 DeltaNet 的循环状态。在电路的头中,门保持开启且写入强度为 1。每个键都是独热编码。每次更新恰好覆盖 1 行,而独热查询将其读回。因此,每一行都作为一个存储单元工作。

That state holds the program ROM, registers and global memory. The README lists 16 register rows per lane, with 1 that always reads zero. That matches the 15 usable registers in the X post.

该状态保存程序 ROM、寄存器和全局内存。README 列出了每通道 16 行寄存器,其中 1 行始终读取为零。这与 X 帖子中提到的 15 个可用寄存器相符。

The GPU supports integer arithmetic, predicates, divergent branches and loops. It also supports shared memory, atomicAdd, __syncthreads and warp shuffles.

该 GPU 支持整数运算、谓词、分歧分支和循环。它还支持共享内存、atomicAdd、__syncthreads 和 warp shuffle。

What happens during a CUDA launch?

CUDA 启动期间会发生什么?

The host plays the role of NVRTC and the CUDA driver. It compiles CUDA to PTX with clang, then lowers PTX to machine blocks. It feeds the program and input arrays to the model as tokens.

主机扮演 NVRTC 和 CUDA 驱动的角色。它使用 clang 将 CUDA 编译为 PTX,然后将 PTX 降低为机器块。它将程序和输入数组作为 tokens 馈送给模型。

From there, the model writes the launch itself. Each EXEC(b, w) token runs block b for warp w in 1 forward pass. The VAL tokens after it carry register results. Memory writes return as MEM records. The host reads results from the recurrent state and computes none of them.

从此处开始,模型编写启动指令本身。每个 EXEC(b, w) token 在一次前向传播中为 warp w 运行块 b。随后的 VAL tokens 携带寄存器结果。内存写操作以 MEM 记录形式返回。主机从循环状态中读取结果,且不计算任何内容。

In the demo video, a dot product of [1, 2, 3] and [4, 5, 6] returns 32. The model wrote that launch in 47 tokens.

在演示视频中,[1, 2, 3] 和 [4, 5, 6] 的点积返回 32。模型用 47 个 tokens 编写了该启动指令。

Meet qwenGPU: 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.

认识 qwenGPU:Qwen3.5-2B 的权重内部包含一个 SIMT GPU,在 Qwen 自身的模型之前有 45 个已编译的层,使用其 Gated DeltaNet 层作为寄存器和内存。

It runs real CUDA in its forward passes. The host compiles the kernel to PTX and loads it, then the model writes every… pic.twitter.com/iM5IETEbIv

它在前向传播中运行真实的 CUDA。主机将内核编译为 PTX 并加载,然后模型写入每一个… pic.twitter.com/iM5IETEbIv

— vixhaℓ (@TheVixhal) November 1, 2026

— vixhaℓ (@TheVixhal) 2026年11月1日

Does the GPU break Qwen’s text ability?

GPU 会破坏 Qwen 的文本能力吗?

Not by the developer’s measure. The circuit is muted on text tokens, and Qwen’s own weights are unchanged. The merged model’s next-token distribution stays within a KL of about 7e-4 of the original.

按开发者的衡量标准,不会。该电路在文本 token 上处于静音状态,且 Qwen 自身的权重未发生改变。合并模型的下一个 token 分布与原始分布的 KL 散度保持在约 7e-4 以内。

How accurate is qwenGPU?

qwenGPU 的准确性如何?

All numbers are self-reported, measured on Apple silicon with MPS in bf16:

所有数据均为自我报告,在配备 MPS 的 Apple silicon 上使用 bf16 精度测量:

  • Every launch was exact under --check replay.
  • The reference interpreter matched an NVIDIA Tesla T4 on 49 of 49 test kernels.
  • Normal mode answered 20 of 24 sampled chat questions with GPU-computed numbers.
  • Advanced mode wrote a correct kernel first try on 4 of 5 questions.
  • 在 --check replay 模式下,每次启动都完全精确。
  • 参考解释器在 49 个测试内核中的 49 个上与 NVIDIA Tesla T4 匹配。
  • 正常模式下,针对采样的 24 个聊天问题,有 20 个由 GPU 计算出的数字作答。
  • 高级模式下,首次尝试就在 5 个问题中的 4 个上写出了正确的内核。

In normal mode, Qwen writes an expression like [1, 2, 3] @ [4, 5, 6] for ready-made kernels. In advanced mode, Qwen writes the CUDA kernel itself. The README warns that a 2B model’s CUDA is still unreliable.

在正常模式下,Qwen 为现成内核编写类似 [1, 2, 3] @ [4, 5, 6] 的表达式。在高级模式下,Qwen 直接编写 CUDA 内核本身。README 警告称,2B 模型的 CUDA 生成仍不可靠。

How does qwenGPU compare with Qwenputer and Percepta?

qwenGPU 与 Qwenputer 和 Percepta 相比如何?

qwenGPU uses the transformer compiler from Qwenputer by Divyansh Agrawal. Qwenputer compiles a 32-bit RISC-V CPU into Qwen3.5-4B. Percepta built a WebAssembly interpreter into a transformer with 2D attention heads in March 2026.

qwenGPU 使用了 Divyansh Agrawal 开发的 Qwenputer 中的 Transformer 编译器。Qwenputer 将 32 位 RISC-V CPU 编译到 Qwen3.5-4B 中。Percepta 于 2026 年 3 月在具有 2D 注意力头的 Transformer 中构建了 WebAssembly 解释器。

FeatureqwenGPUQwenputer (RISC-V)Percepta
Base modelQwen3.5-2B, 24 layersQwen3.5-4BCustom transformer with 2D attention heads
Machine compiled in4-lane SIMT GPU32-bit RISC-V (RV32IM + Zba + bignum)WebAssembly interpreter
Programs it runsCUDA, lowered from PTXC and MicroPythonC, compiled to WebAssembly
Compiled layers4511Not disclosed
Where state livesGated DeltaNet stateGated DeltaNet stateExecution trace in context
Host roleCompiles CUDA to PTX, loads tokens, reads resultsLoads firmware; runs no computationNot disclosed
Correctness checkInterpreter matched Tesla T4 on 49 of 49 kernels0 mismatches in about 230,000 replayed positionsClaims millions of reliable steps
Reported speed10 to 15 tokens/s (Apple MPS)About 3,200 trace tokens/s (L4, Triton)30,000+ tokens/s (CPU)
Text drift vs baseKL about 7e-4KL 6e-4Not applicable
LicenseMIT code; Apache-2.0 checkpointMIT code; Apache-2.0 weightsNot disclosed
特性qwenGPUQwenputer (RISC-V)Percepta
基础模型Qwen3.5-2B,24 层Qwen3.5-4B带有 2D 注意力头的自定义 Transformer
编译机器4 通道 SIMT GPU32 位 RISC-V (RV32IM + Zba + bignum)WebAssembly 解释器
运行的程序CUDA(从 PTX 降级)C 和 MicroPythonC(编译为 WebAssembly)
已编译层数4511未公开
状态存储位置Gated DeltaNet 状态Gated DeltaNet 状态上下文中的执行轨迹
主机角色将 CUDA 编译为 PTX,加载 token,读取结果加载固件;不运行计算未公开
正确性检查解释器在 49/49 个内核上与 Tesla T4 匹配在约 230,000 次重放位置中无差异声称拥有数百万可靠步骤
报告速度10 至 15 tokens/s(Apple MPS)约 3,200 trace tokens/s(L4, Triton)30,000+ tokens/s(CPU)
与基座的文本漂移KL 散度约 7e-4KL 散度 6e-4不适用
许可证MIT 代码;Apache-2.0 检查点MIT 代码;Apache-2.0 权重未公开

The speed figures use different hardware and token types, so they are not directly comparable.

速度数据使用了不同的硬件和 token 类型,因此不可直接比较。

What do you need to run it?

运行它需要什么?

The quickstart needs Python 3.11+, uv, just and about 16 GB of free memory. Advanced mode also needs clang with the NVPTX backend. just build downloads Qwen3.5-2B and compiles the GPU into it. No prebuilt checkpoint is published. A built checkpoint falls under Qwen’s Apache-2.0 license.

快速入门需要 Python 3.11+、uv、just 以及约 16 GB 的可用内存。高级模式还需要带有 NVPTX 后端的 clang。just build 会下载 Qwen3.5-2B 并将 GPU 编译到其中。未发布预构建的检查点。构建后的检查点受 Qwen 的 Apache-2.0 许可证约束。

Key Takeaways

关键要点

  • qwenGPU compiles a 4-lane SIMT GPU into Qwen3.5-2B as 45 untrained layers.
  • Gated DeltaNet state serves as registers, program ROM and global memory.
  • The model writes every CUDA launch step; the host only compiles and loads.
  • The interpreter matched a Tesla T4 on 49 of 49 kernels.
  • At 10 to 15 tokens per second, it is a research demo, not a runtime.
  • qwenGPU 将 4 通道 SIMT GPU 编译为 Qwen3.5-2B 中的 45 个未训练层。
  • 门控 DeltaNet 状态充当寄存器、程序 ROM 和全局内存。
  • 模型写入每个 CUDA 启动步骤;主机仅负责编译和加载。
  • 解释器在 49 个内核中的 49 个上匹配了 Tesla T4。
  • 每秒 10 到 15 个 token,它是一个研究演示,而非运行时。

Check out the GitHub repo, the qgpu CUDA reference, the Qwen3.5-2B model card and the original X post. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

查看 GitHub 仓库、qgpu CUDA 参考文档、Qwen3.5-2B 模型卡片以及原始的 X 帖子。此外,欢迎在 Twitter 上关注我们,别忘了加入我们有 15 万+成员的 ML SubReddit,并订阅我们的新闻通讯。等等!你在 Telegram 上吗?现在你也可以在 Telegram 上加入我们。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件