Skip to content

Native Vulkan backend for Qwen3.5-2B (opt-in) - #1517

Closed
joshuaswarren wants to merge 15 commits into
ashhart:mainfrom
joshuaswarren:vulkan-engine-pr
Closed

joshuaswarren wants to merge 15 commits into
ashhart:mainfrom
joshuaswarren:vulkan-engine-pr

Conversation

@joshuaswarren

Copy link
Copy Markdown
Contributor

What this changes

Adds an opt-in native Vulkan backend for one model: dense Qwen3.5-2B, MLX Q4 group 64, one GPU, one stream, greedy decoding. It builds only with -Dvulkan=true. Outside the new Vulkan files, the diff touches four shared files: build.zig (declares the -Dvulkan option, default off, and adds the Vulkan build steps only when it is set), zig/src/server/cli.zig (adds vulkan to the --backend choices; the backend is offered only in a build that serves it), and THIRD_PARTY_NOTICES.md plus LICENSES/mlx-omarchy-MIT.txt (the MIT notice for shader code adapted from mlx-omarchy). The CUDA, Metal, HIP and XPU backends' code is unchanged. It uses the shared lane host and server, so there is no scheduler of its own. Part of #1420 (the issue this was agreed under); the submit-batching speedup is a separate follow-up PR, not in this one.

Scope limits, enforced in code: Q4g64 transposed projections only, 7168-token capacity ceiling, no sampling, no speculation or drafts, no tensor parallel, no vision. Unsupported flags are refused, not ignored. Presence/frequency penalties are not applied (the shared server already logs and ignores them for a backend that does not advertise them).

Receipt

  • Environment: this branch rebased on main db3fd5a (v1.1.7 included); Linux aarch64 on Apple Silicon, Mesa Honeykrisp Vulkan driver; checkpoint Qwen3.5-2B MLX 4-bit, revision 93760be4f1f69842a46bc13dbdc0f19e291392a3. M1 Max (G13C) and M1 (G13G).
  • Exactness against Ash's engine on Metal, on the first build (before chunked prefill; 16-step anchor): all 16 generated IDs equal on both chips, two fresh-reset runs each. Vulkan logits are byte-identical between the two chips; they are not byte-identical to Metal.
  • Exactness on the chunked-prefill build (this PR's source), nine prompts of 1 to 65 tokens, 64 free-running tokens except the 16-token anchor: IDs match Ash in 5 of 9 cases (unicode-24, prose-33, code-63/64/65). They diverge in 4: anchor at index 15, single-token at 9, prose-31 at 3, prose-32 at 2. So the first build's 16/16 anchor result does not carry over. This was run on the M1 Max only. This PR does not claim token parity with Ash.
  • Teacher-forced logits against Ash's, under the tolerances fixed beforehand (v1.1): three cases FAIL (unicode-24 row 62, prose-31 row 43, prose-32 row 42, zero-based). The earlier build failed unicode-24 and prose-31; prose-32 is new on this build. These FAILs are not waived.
  • Against a CPU f64 reference over the same dequantized weights (528 aligned rows): the median over rows of the per-row Vulkan/Ash RMSE ratio is 0.995 (median row RMSE 0.0233 vs 0.0231; Vulkan 0.9% higher). That says the error is comparable, not better. We then adopted looser non-inferiority margins (1.05 pooled, 1.15 per case) after seeing these numbers; they pass the known data, so this is a policy choice, not blind validation.
  • Server: on the first build (before chunked prefill) the shared server over this backend passed the 14 reviewed HTTP and lifecycle cases and both isolation proofs (status PASS_WITH_NOT_VERIFIED). It has not been rerun on this PR's source. Natural EOS was not observed in the bounded server test; structured output and tool calls are unavailable and unused.
  • Chunked prefill: prompts up to 65 tokens, 63/64/65-token code cases match; same-history prefill and decode agree byte for byte on 63 of 63 pairs. The four boundary refusals (late out-of-vocabulary token, prompt over 7168, capacity overflow, CLI context over 7168) all passed.
  • Decode speed before/after: n/a, this adds a backend, there is no earlier Vulkan path. Unoptimized: about 154 to 159 ms per token on the M1 Max, not measured on the M1 (see the batching follow-up for the speedup).
  • Prompt speed: n/a, no prior Vulkan path; prompts are cut into 32-row chunks.
  • Tests run: GPU-free host suites for the Vulkan operators, the family and native adapter, and the probe parser; the real server binary and the model probe cross-compile for aarch64. Counts from the branch rebased on main db3fd5a: 101/101 build steps succeeded; 141 of 146 host tests ran and passed, 5 skipped, none failed (test steps whose inputs had not changed were up to date from an earlier run of the same sources on 9ed939b, which ran 201 of 206 with the same 5 skipped). The host tests ran as Debug builds on the build host; the model probe and the server are ReleaseSafe aarch64-linux-gnu cross builds. No GPU code ran in these tests.
  • Not run: CUDA, HIP, XPU and Metal (none of their code changes; without -Dvulkan=true no Vulkan step is added to the build); any other checkpoint, device, driver, or AMD/Intel GPU; contexts of 256/1024/7105 tokens; sampling; long soak.

Checklist notes

  • Every token goes through the lane rounds; no serial path. No drafts are offered by this backend (speculate=false), so draft equality does not apply.
  • Precision: this backend does not trade precision for speed; it is a separate implementation with its own f32 accumulation and BF16 round-to-nearest-even output, and it is not bit-identical to Metal or CUDA (see the failures above).
  • New GPU kernels are Vulkan compute shaders compiled from GLSL at build time; they are outside the Metal/CUDA kernel contract registry. FLAG FOR MAINTAINER: say if you want them registered.
  • Platforms I ran: Linux aarch64 Vulkan on M1 Max and M1 only. Platforms I could not run: everything else.

@ashhart

ashhart commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Thanks @joshuaswarren. Yes, please register them. As we said on #1420, the Vulkan backend comes in on the same terms as HIP and Intel: every kernel in the kernel contract, with its float64 cases and planted controls. The harness in zig/src/core/contract/ is shared, so a Vulkan runner beside HIP's (zig/tests/hip/contract_*.zig, with launch records like hip_records.zig) is the shape: gates 1 to 4 for each shader at the shapes the engine serves, gate 5 for the devices you serve, and each run's SUMMARY line in the description.

Two more things before this leaves draft:

  1. The fidelity gate. Native Vulkan backend for Linux GPUs (Apple Silicon first) #1420 asked for it to be fixed in the PR before the run. The v2 margins were chosen after the v1.1 failures were known, so please put v2 in the PR as the gate and run it on fixtures that weren't used to choose it, keeping the v1.1 failures in the description. We'll judge it teacher-forced against float64 on the same checkpoint, no worse than the Metal engine, rather than by Metal's tokens.
  2. Size. This is the whole 2B engine in one PR (66 files, about 18,000 lines). Native Vulkan backend for Linux GPUs (Apple Silicon first) #1420's plan was smallest first: the device, buffers and the Q4 projection under the contract, then the 2B end to end, then submit batching. Split that way, the base can be reviewed and land on its own.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Thanks. We will split it as asked: a base PR with the device, buffers and the Q4 projection registered in the kernel contract (gates 1 to 4 on device, gate 5 from device limits, SUMMARY lines in the description), then the 2B end to end, then submit batching and penalties. The v2 fidelity margins go into the PR as the gate, and we will run it on new fixtures not used to choose it (contexts 256, 1024 and 7105), keeping the v1.1 failures in the description, judged teacher-forced against float64 versus the Metal engine. We are keeping #1517 as a draft only until the base PR is up.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

The base PR is up as a draft: #1526 (the Vulkan runtime and the Q4 projection registered in the kernel contract, with the SUMMARY lines from M1 Max, M1 and M2 Max). The 2B engine, submit batching and penalties will follow as separate PRs on top of it.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

This is superseded by #1544, the split you asked for: #1526 is the runtime and the Q4 projection, and #1544 (draft, stacked on #1526) is the engine plus every remaining kernel registered in the kernel contract, one runner per group, with the v2 fidelity gate in the description and the held-fixture result as a FAIL. The same six contract groups pass on M1 Max, M1 and M2 Max; the one known device finding (fp32 denormal flush) is recorded, not fitted. I'm leaving this draft open until you say whether to close it.

@ashhart

ashhart commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Thanks @joshuaswarren for splitting this up as asked. Since #1526 and #1544 now carry the work, we'll close this one to keep the queue clear. Review continues on #1526 first, then #1544. Thanks again for the careful work here.

@ashhart

ashhart commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Closing as superseded, as agreed: #1526 (the opt-in Vulkan runtime and the Q4 projection in the kernel contract) has landed on main, and the engine continues in #1544. Thanks again @joshuaswarren.

@ashhart ashhart closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants