DECODE / 128 TOKENS
×4.80.432 → 0.090 s per token
From 2.3 to 11.2 tokens per second. A full 128-token turn goes from 55.6 to 12.0 s. PR #7 contributes ×1.2; PR #8 multiplies that by about 4.
Method and series in PR #8An inference stack in Zig.
Eight pull requests, with evidence.
THE PROJECT / ZML
ZML is a production inference stack built with Zig, MLIR and Bazel. Models compile through OpenXLA/PJRT to CPUs, NVIDIA, AMD and other accelerators. The work covered portability, resources, backend selection, metric exports and CPU decoding speed.
b71982fda7ef733e98362520b7cfe62e33eee985THE MEASURED RESULT
Qwen3.5-0.8B in BF16 on CPU, batch 1, greedy decoding. 48 processes in rotated order; medians of process medians, warmup excluded. Every process produced exactly the tokens of master, all 128 tokens of the long prompt included.
DECODE / 128 TOKENS
×4.8From 2.3 to 11.2 tokens per second. A full 128-token turn goes from 55.6 to 12.0 s. PR #7 contributes ×1.2; PR #8 multiplies that by about 4.
Method and series in PR #8PEAK MEMORY
−20%The fallback path converted every BF16 weight to FP32 on every call: about 1 GB of fresh memory per token for the 248k-row output layer alone.
Per-layer state in PR #7Ryzen 9 3900X (AVX2), shared host with a common lock, frequency not fixed. One model, two prompts, 32- and 128-token caps.
THE TWO CAUSES
Both optimizations start from a CPU profile. Neither changes the model; each removes work the runtime was doing for nothing.
Each linear-attention layer received the recurrent state of all 18 layers and copied it twice (18 MiB each time) to update one. Each layer now owns its buffers. In the profile, memcpy falls from 15.7 s to 0.3 s of CPU per run; decode is ×1.19–1.20 faster in every scenario.
XLA refuses vector dots to YNNPACK, so each batch-1 projection fell back to code that converts all BF16 weights to FP32. Duplicating the input row makes it a matrix dot that YNNPACK accepts. Microbenchmark on the output layer: 190 ms → 12 ms. Kernel page zeroing drops from ~30% to ~1% of CPU.
THE PULL REQUESTS
Each PR contains its change, its tests and the commands that were run. They are open for review on the fork before any proposal to ZML.
| Contribution | What changed | PR | Status |
|---|---|---|---|
Two-row BF16 dot on CPU | Route single-row BF16 Linear layers through YNNPACK. 30 test cases against the original dot and an f64 oracle; 8- and 64-row inputs unchanged bit for bit. | #8 | In review |
Qwen per-layer linear state | One state buffer per linear-attention layer. All layer states compared over prefill and 32 decode steps on CPU (1, 2, 4 partitions) and on an RTX 2080 Ti. | #7 | In review |
zml-smi CSV escaping | A field containing a comma or quotes broke the CSV export. Fields are escaped; tests fail before and pass after; output re-read by Python’s CSV reader. | #1 | In review |
zml-smi PCIe units | Prometheus applied a factor of 128 to NVML values reported in KB/s. Converted to bytes/s with the decimal convention of the existing TUI; checked through the real collector. | #2 | In review |
Qwen KV replication | Rebases the existing upstream fix zml/zml#602, keeping its author, and adds eight CPU regression graphs for dense and MoE models. | #3 | In review |
CPU runtime documentation | ELF dependencies of the CPU bundle and a NixOS recipe, checked in Debian 13, Debian 11 and NixOS VMs. | #4 | In review |
Backend selection tests | Ten scenarios cover backend selection and plugin loading errors; with GPUs hidden, auto-selection continues on CPU. | #5 | In review |
Portable attention on SM75 | Forced and automatic portable attention paths checked against an f64 reference on a real RTX 2080 Ti, at causal positions 0, 31 and 63. | #6 | In review |
Status snapshot: 2026-12-05 UTC. “In review” means open on the fork; nothing has been merged into ZML.
THE TOOLS / WHAT THEY ACTUALLY DID
The tools supplied evidence; reading the code turned it into patches.
Omn profiles with kernel symbols showed the state copies and the page zeroing; per-call timing of CopyThunk confirmed the copies. Two pieces of feedback went back to Omn; the first is already fixed. The tool did not change the code.
Debian 13, Debian 11 and NixOS VMs checked ELF loading, dlopen and access to the PJRT API for the CPU documentation. This is not inference and not an official support list.
VALIDATION & LIMITS
The integrated branch with all eight PRs passed the CPU tests, the SM75 attention test and a Qwen smoke run. Its speed matches PR #7 plus #8 within the measured spread: the other branches add no measured speedup.
REVIEW & REPRODUCTION
Each PR lists the commands that were run, the measured series and its limits. The benchmark scripts and raw data are published with PR #7.
Independent work by moha-bekh, assisted by AI for analysis and scripts. No endorsement by the ZML maintainers is implied.