Repository navigation
Native Vulkan backend for Qwen3.5-2B (opt-in): engine and kernel-contract registration (stacked on #1526) - #1544
joshuaswarren wants to merge 48 commits into
Conversation
92bb49d to
f280f25
Compare
|
[Joshua's agent] Two rows of the held packet are over the 1.0 absolute limit in the golden logits themselves. Max over the vocabulary, 64 teacher forced rows. A is your golden logits, R is a float64 CPU reference of the same checkpoint and token ids, F is that reference with every bf16 store point rounded to float32 instead. For this PR's kernels: document-256 |V-A| 4.50 and |V-R| 3.93 at row 28, a real miss on our side. document-1024 |V-A| 0.53 (row 43) passes, |V-R| 1.34 at row 57. We have not changed the limit and our gates keep |V-A| as written. From now on every report also carries a |V-R| column. Scorer, reference recipe, both scripts and per row |A-R| for all 64 rows: https://gist.github.com/joshuaswarren/834bd4bfd441e862007daf0154e7aa99 |
|
[Joshua's agent] Follow-up on document-256 row 28: it is a high-gain point, so |V-A| there measures a draw of rounding noise, not kernel accuracy. Perturbation test, float64 CPU model of the whole network. Every bf16 store input is first multiplied by 1 + eps*u (u uniform in [-1, 1], seeded), then rounded as usual. The hidden state is recovered from the logits through the tied head; e = |h_run - h_R| / |h_R| per row. Six seeds at eps 2^-9:
Limits: document-256 only (document-1024 row 57 not tested); the noise is applied at all stores jointly. Option for you: rows whose f64 perturbation gain is above a stated threshold (for example rms e at least 5 times the median row, which flags rows 28 and 52 here) are reported and not gated; the |V-A| and |V-R| limits stay as written on every other row. I withdraw my earlier restated-limit suggestion (|V-R| plus |V-A| only where |A-R| < 1.0): at row 28 |A-R| is 0.57, so it would still gate that row. We change nothing in the contract ourselves. Method, scripts and the per-row table: https://gist.github.com/joshuaswarren/f60e946cd5824225c9175d88e2dd144d |
|
Thanks @joshuaswarren for the careful analysis, and for keeping the gate as written while you report it. Adding the |V-R| column is welcome. We can't adopt a row-exemption rule for this run, because it would be chosen after seeing the result. For now the held-fixture result stays a FAIL at document-256 row 28. Your note that the golden logits are 1.022 and 1.210 from float64 at document-256 row 52 and document-1024 row 57 is useful. We'll check the goldens on our side. If the gate needs restating, we'll agree it on the issue first, and then it would be run fresh on fixtures not used to choose it. Separately, the diff on this PR currently shows as empty on our side. Could you check that the branch is pushed? Review will start with #1526. |
f280f25 to
b3ab9ba
Compare
|
[Joshua's agent] The diff is up: head b3ab9ba on the merged main, 32 commits (29 code, 3 style). Device gates on the M1 Max, M1 and M2 Max, each beside the build from before the rebase: the nine pilot cases and the four held runs give byte-identical logits in all 13 cases on every chip, contract QMM 1 kernel passes with 8 of 8 controls caught, datamove 7 of 7, stage 1 13 of 13. The held-fixture result stays a FAIL at document-256 row 28, as you said; the |V-R| column is in the body. Marking it ready. |
|
Thanks @joshuaswarren, the branch is up and the byte-identical reruns across three chips are reassuring. The held result is still the blocker: document-256 row 28 at |V−R| 3.93 is a real miss, and a gate restated after seeing it isn't one we can use. Your own numbers point to a way through. The CPU model that rounds to bf16 at this engine's 34 store points shows the same error on that row, and rounding them to float32 gives 1e-5. So there are two options, each followed by a fresh held packet with the scorer frozen first: 1. Keep float32 at the store points where the trace shows the error growing (the GatedDeltaNet state from layer 4 on), and rerun under the gate as written, with its cost measured. 2. Or propose, on #1420 and before any new run, a gate that scores |V−R| against a float64 model rounding at this engine's declared store points, so it measures the kernels and not the storage choice. We'd lean to option 1. On our side, we'll check the goldens at document-256 row 52 and document-1024 row 57. You're right that a more accurate build can't pass |V−A| ≤ 1.0 there. Three smaller items: - Planted controls for the datamove, attention and pointwise groups, which plant none today. - The lean check goes from 424 to 465 problems: nine files over 600 lines ( The changelog line you added is fine as it stands. |
|
Status of the Vulkan stack built on this PR. Each PR is stacked on the one before it, and each is ready for review and mergeable.
Each PR has its own receipts and kernel contract output on the Apple GPU. #1992 is a separate one-file fix to the contract fixture that blocks nothing here. Together, the same three inputs went from 15.6, 40.0 and 122.8 s (this PR) to 2.3, 5.2 and 15.7 s. Those are three paired comparisons from separate sessions, not one paired run. Would you rather have these squashed into fewer PRs? I can fold #1990 and #2015 into one, or all three, whichever is easier to review. [Joshua agent] |
|
The The 41 new problems were this PR's own. I split the files with code motion only, in ten commits:
Locally, [Joshua agent] |
c3e6be3 to
4875da9
Compare
|
Thanks @joshuaswarren for the lean split. The head now adds no lean problems: 424 here, the same as main. Splitting by The held packet is still the blocker. This push doesn't change any store point, and the body still reports
Either way, please freeze the scorer before the run and post its hash with the results. Three small items:
Once the held packet passes, the RTX 5060 Ti you offered is a good second GPU for the contract runners and the held |
|
The held packet remains FAIL: document-256 row 28 has |
|
Thanks @joshuaswarren. Yes to that plan: float32 at the GatedDeltaNet activation stores from layer 4 on, the scorer and held inputs frozen first, and the gate unchanged. Please report the scorer hash, |
|
Float32 from layer 4 on does not fix document-256 row 28 in the CPU model. Float32 in layers 0 to 3 does: |V-R| goes from 3.31 to 0.59. Scorer, frozen and unchanged since the 28 Oct held freeze (gate as written):
The float64 model with every store rounded to bf16, on document-256, one run per row (
Method, per-row values and the one-file change to the reference script: https://gist.github.com/joshuaswarren/ef2b3aa62f4cf34b2b58c7d7a178c340 What this does not show: it is document-256 only, one run per arm, on the CPU model and not the Vulkan engine. I chose the layer split after seeing this case, so it is not a result. The engine change is not built, and there is no engine |V-R|, time or memory cost yet. Next, in this order: I build float32 stores for layers 0 to 3 in the engine, choose fresh held inputs and post their hashes here, then run the fresh packet under the unchanged gate and report |V-R|, time and memory. If you want layers 4 on as you wrote, say so; the model gives 4.12 for that. One gate point stays separate: in every arm that fixes row 28 the worst |V-A| is at row 52 (1.03 to 1.16), where V is 0.05 to 0.22 from R and your golden is 1.022 from R. I am not asking to change the gate. [Joshua agent] |
|
Fresh held inputs, frozen before any run of the float32 build. Three new cases, 64 teacher-forced rows each, prompt token counts 305, 1209 and 7731. The texts are synthetic and deterministic: fixed sentence cycles, tokenized with the pinned tokenizer (tokenizer.json sha256
The scorer stays the one reported above, sha256 Still open: the goldens for these three cases, the float64 reference over them, and the engine build. Nothing has been run on these prompts yet. [Joshua agent] |
|
Thanks @joshuaswarren, that table is clear: layers 4 on don't reach row 28, and layers 0 to 3 do. Go with layers 0 to 3. As you say, choosing the split after seeing document-256 makes the fresh held inputs, with their hashes posted first, what turns it into a result. Please report the engine's |
… cross target The datamove test module was built for -Dtarget, so a cross build (aarch64 on the x86 build host) failed with 'unable to spawn foreign binary' in vulkan-host-test. It now gets its own host-target module like every other host suite. Proved by: vulkan-host-test and all stage and runner build steps pass with -Dtarget=aarch64-linux-gnu (224/224 steps).
… and u16 copy On a real device (Apple M2 Max, Honeykrisp) the shapes gate failed three kernels with the Zig error Misaligned: the gate's edge shapes include odd element counts, and a 16-bit range of an odd count is not bindable (dispatch.bind needs whole 32-bit words; View.init refuses the same ragged tail), so the fixture's view call raised an error that the gate scored as FAIL. The kernel refuses that edge, so prepare now returns false for it (an edge refused by the kernel, as the gates count them); served shapes (146x1, 3x700, 300x1, 2x520) are all even. Proved by: vulkan-host-test and stage1-gpu-build pass for aarch64 (81/81 steps, 210/212 tests, 2 skipped). Not proved: no device rerun yet.
…hat prepare sized The M2 Max's run of the gdn group died in gate 1 of the prefill_y kernel: "index out of bounds: index 524288, len 10248" at contract_gdn.zig's uploadBuffers, called from the nonfinite gate's prepare. 524288 is 2 * state_elems and 10248 is 5 * linear_dim + the guard words, so the sliced region belonged to a different kernel: the prefill arm uploaded the same buffers for prefill_y and prefill_state, and the state's region (prefill_y's out holds y only) was sliced out of a much shorter out. The upload path now lives in one place, uploadWords, which hands each device buffer the words it takes: a checked output its own region of out, an output no fetch reads fresh poison scratch, and every region bounded by what prepare sized, so a mismatch is an error the gate reports instead of a panic that kills the runner. The prefill_y and decode_state outputs that no fetch downloads take scratch, the checked ones keep out's region, and every other arm keeps the bytes it had. Proof: a new host test drives the gates' own shape sequence (gate 1 and 2's small() shape, gate 3's served and edge shapes, gate 4's stress shape) through prepare and the upload path with no device, and holds every upload inside the region prepare sized and the buffer count at what run() binds. It fails on the old sourcing with the same out-of-range region the device hit (outWords: OutputRegionOutOfRange) and passes on the fix; the whole host suite is 21/21 and the arm64 runner builds clean (100/100 steps). The split g gate's class finding (1 of 128 outputs: nan where float64 gives finite) is untouched: it is a device finding for the maintainer to decide on, not a fixture bug.
…assuming it Why: the repeat gate failed on the PR-B device run with 'a run wrote outside its outputs' (gates.zig intact check). The rig's input() uploaded only the data window at offset guard, so the shell's guard bytes never held the 0xa5 pattern intact() demands — fresh device memory reads as zeros, and the gate was false on every run of every shape. The draw itself never writes the shell (its outputs are the internal partials and results buffers, the same shape HIP's argmax contract declares via rig.scratch/rig.output), so the guard finding was a runner bug, not an overrun. What: Rig.input builds the full shell through a new shellFor (pattern, data, pattern) and uploads it at offset 0, the way the datamove rig's slot() already did. New host test pins the layout: guards patterned on both sides, data between, exact length — the invariant the old code never stated anywhere. Proof: zig build vulkan-host-test stage5-gpu-build contract-pointwise-build contract-pointwise-host-test (shared cache) green: 103/103 steps, 22/22 tests, including the new shell test. The gate's strictness is unchanged; a real overrun still fails intact(). The gate line's device-side pass still needs its device run, which is out of scope for this offline fix. Build log: scratch/atc-vulkan-native-20261026/prb-fix-gp-build.log
…ally built Why: the PR-B device run failed all three preserve-add cases and the plain add's classes case. The preserve fixture modeled a pipeline nobody builds: it filled f32 buffers and demanded exact f32 sums, but add_preserve_bf16 is binary_vec.comp with -DPRESERVE_F32 over the default bf16 storage — the -DUSE_BF16 the build passed alongside it matches no ifdef in the shader (storage variant is USE_FP16/default), so the device ran the bf16 add reading u16 halves of f32 bits. Every reported got matches that model bit for bit: cancel element 0 is widen(0x293a)+widen(0x293a) stored bf16 0x29ba (read back as u32 0x000029ba), random element 0 is 0xbed4fbc2, classes element 6 is the j=12 NaN 0x7fc0 beside the j=13 overflow +inf 0x7f80 = 0x7f807fc0. The plain add's classes failure was a runner gap: stage2's measured-property policy (allow_subnormal_flush from shaderDenormPreserveFloat32, as stage2_probe wires it) was never applied, so the subnormal rows were checked strictly regardless of the device's reported float controls. What: PreserveAdd and PreserveCase become aliases of stage2.Add/AddCase — one model of the pipeline (f32 add, one RNE bf16 store), two pipelines — and the preserve gate checks strictly (no flush qualification ever): a device that flushes fp32 denormals fails the subnormal classes rows as an honest finding, printed by a NOTE, never fitted away. addGate now wires the stage 2 policy from the device property and the device line prints preserve32/flush32 so the next run is decidable. The inert -DUSE_BF16 is dropped from both binary_vec build entries and the stale 'compiled without -DUSE_BF16 stores exact f32' comments are gone. A host test scans the embedded SPIR-V: add_preserve_bf16 declares OpCapability DenormPreserve (4464), add_bf16 does not — a define that matches no ifdef can never silently produce the plain add again. Proof: shared-cache build green, 103/103 steps, 22/22 tests, including the rewritten preserve tests (subnormal want 0x0002 must stay refused when a device flushes) and the capability scan; the generated images were verified directly (4464 present only in add_preserve_bf16). Build log: scratch/atc-vulkan-native-20261026/prb-fix-gp-build.log
gated_delta_decode, gated_delta_prefill_ash and gdn_split quieted every value whose exponent is all ones and whose top mantissa bits are zero: (bits & 0x7fff0000) == 0x7f800000. That test is true for +-inf (0x7f800000), so the helper returned 0x7fc0 (NaN) for an infinity; only a NaN with a payload in the low 16 bits was meant. In the gate chain s = bf16(a + dt) an infinite a became NaN, then softplus and g were NaN where float64 gives exp(-inf) = 0. Found by the kernel contract's nonfinite gate on Apple M1 and M2 Max (3 FAILs: split g 1 of 128, decode y 896 of 16384, decode state 16384 of 262144 outputs differ in class). The first diagnosis blamed exp(-inf) in the driver; a bit-level emulation of the helper shows 0x7fc0/0xffc0 for +-inf, so it was our helper. Every other shader here already uses isnan(value); these three now do too. Finite values are untouched (same bits), NaN stays a quiet NaN. Proved by: bit emulation, vulkan-host-test and every stage and runner build for aarch64 pass; not yet re-run on a device.
…device finding On Apple M1 and M2 Max under Honeykrisp the device reports shaderDenormPreserveFloat32 = false and flushes fp32 denormals, so the preserve-add classes case reads the bf16 subnormal sum 0x0002 as 0x0000. The runner now prints KNOWN (not FAIL) and counts it apart from passes when every mismatch is a subnormal sum read as a same-signed zero and the device reports no denormal preservation; a device that claims preservation and flushes, or any other mismatch, stays a FAIL. The RESULT line carries known=N. Proved by: host tests and the aarch64 build (224/224 steps); not device-run yet.
…etry, a run that always answers Why: the device run died with a bare 'error: Invalid' in the first gated-norm case and never printed RESULT. gatedNormGate called gdn.gatedNormPlan with the fixture's 2048-element weight, but the production gated norm is PER HEAD (gdn.Model: 16 head rows of 128 a token, the [128] gain indexed by the column within the head and shared by every head) and the plan refuses any other weight width — the gate had never reached a device. The fixture modeled a 2048-wide global row; nothing in the kernel computes that. What: - The fixture is the production geometry: tokens x 16 head rows of 128, head-major, the [128] gain at the column; the f64 reference computes the norm per head row and the poison cases prove head isolation (an inf/nan input poisons only its own head row). Served shapes are the tokens the engine serves: one decode row and a whole prefill chunk of 32 (qwen3_5 vulkan forward, max_prefill_rows), plus the controls on three. - The bound is re-derived for the 128-wide reduction, honestly: 256 threads over 128 columns = at most one square per thread (1 rounding) + 8 tree levels (zeros exact) + the mean divide = 10, depth stated 12; gamma(12, 2^-24) ~ 7.2e-6 against the old 2048-row figure gamma(20) ~ 1.2e-5 — the bound is TIGHTER, not loosened. ops 10 and the mids argument are unchanged (per-element, depth-independent). - No gate can kill the run: every case goes through a guard that prints 'FAIL <gate> case=...: <error name>' and the loop continues; the RESULT line (passed, known, total) always prints and the exit is nonzero exactly when passed + known falls short of total. - The preserve-add KNOWN case now prints only its KNOWN line (the reasoning folded into it); the FAIL and NOTE lines are kept for genuine mismatches. - Host tests: the plan accepts every fixture case's dimensions and refuses the old 2048-gain shape (the exact call that died on device), the fixture's element counts, the per-head reference (finite off controls, signed zeros, head-isolated poison), and the checker refusals. Proof: shared-cache build green — 106/106 steps, 178/180 tests passed with the 2 pre-existing skips (device/env-gated); a fully cached rerun shows zero failed steps. Build log: scratch/atc-vulkan-native-20261026/prb-fix-gn-build.log
Every comment the Vulkan engine change adds is now one line saying the same thing in at most 120 columns, the form the
maintainer's lean commit uses; no code token changes (the comment-stripped token streams of every touched .zig and .comp
file are identical, and every touched shader compiles to byte-identical SPIR-V). Original comment kinds are kept.
The previous commit joins each multi-line comment into one long line; its text is the full wording of every comment
(git show of that commit), so nothing was removed from the history. Facts that did not fit on one line are listed here:
- zig/kernels/vulkan/argreduce_chunk.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // ArgMin/ArgMax phase 1 of 2: one workgroup per (row, chunk of matrix_m, at most 4096 = 16 values a lane) writes its (value, index) pair. // The argreduce_suffix.comp rule, so every input gets the same index: extreme wins, first index on ties, first NaN wins, pairs start at (infinity, 0); a total preorder (value, then lower index) makes cutting and combining order-free. // Variants: float32 (default), -DUSE_FP16, -DUSE_BF16. Floats compare in float32. Grid: x = rows * chunks (at most 65535).
- zig/kernels/vulkan/argreduce_combine.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // ArgMin/ArgMax phase 2 of 2: one workgroup per row combines chunk.comp's (value, index) pairs (at most 256) by the same rule: strictly better wins, ties keep the lower index, first NaN wins; lanes past the count hold (infinity, 0).
- zig/kernels/vulkan/attention_gate.comp: // Attention output gate for the dense Qwen3.5-2B Metal oracle, replacing zig/kernels/metal/qwen3_5/layout.metal's qwen35_attention_gate on Vulkan. No existing house shader reads the oracle's interleaved q/gate projection layout or computes sigmoid(gate)*ctx, so this kernel is new. // Per token the q projection emits 16 interleaved 256-wide head blocks: q head h at h*512, its gate at h*512 + 256 (qraw row stride 4096). The Metal op is, per output element d of row r: gate = qraw[r*4096 + (d/256)*512 + 256 + d%256] s = bfloat(1 / (1 + exp(-gate))) -- one RNE bf16 rounding out = bfloat(float(ctx[r*2048 + d]) * float(s)) This kernel reproduces exactly that: f32 sigmoid rounded to bf16 once, f32 multiply, one RNE bf16 store per lane. Each thread owns one whole output word (two adjacent elements, same head, word-aligned gate pair). // Bindings (all bound at their base, element offsets zero): 0 ctx readonly packed bf16 words, rows*1024 words 1 qraw readonly packed bf16 words, rows*2048 words 2 out writeonly packed bf16 words, rows*1024 words // // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT
- zig/kernels/vulkan/binary_vec.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Reused from mlx-omarchy shaders/binary_vec.comp (MIT), comment-condensed. // Four-wide bf16/f16 binary add/mul/div/sub: float math on widened operands, one round to storage, dims == 0 modulo addressing (size == count: direct, else index % size). A thread moves four elements per 8-byte vector load. Host gate: count and both operand sizes multiples of four (an 8-byte load would run past a smaller scalar operand's binding) and every element offset 4-aligned.
- zig/kernels/vulkan/conv_dw1d.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Copied from mlx-omarchy shaders/conv_dw1d.comp (MIT), comments condensed. Depthwise 1-D conv, channels-last [N,L_in,C], weight [C,K], stride 1, no padding/flip: the Qwen3.5 GDN prefill conv. One thread per output, the K taps accumulate ascending from 0.0 on widened operands, one RNE store. Push constants: count=N*L_out*C, operation=K taps, lhs_size=L_in, rhs_size=L_out, reduce_size=C, lhs/rhs/output offsets (words 6..8).
- zig/kernels/vulkan/fast_norm.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Reused from mlx-omarchy shaders/fast_norm.comp (MIT), comment-condensed. // RMSNorm (-DLAYER_NORM off by default) over the last axis, matching mlx::core::fast fallback math: one workgroup per row, shared-memory reductions, grid-stride row loop, all math in float32. RMS: n = rsqrt(mean(x^2) + eps); y = x * n * w. A scalar weight (element count 1) broadcasts to every column. eps arrives in params.alpha.
- zig/kernels/vulkan/fast_norm_gated.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Copied from mlx-omarchy shaders/fast_norm_gated.comp (MIT), comments condensed. Fused RMSNorm epilogue (bf16). Mode 0: out = bf16(silu_f32(z) * widen(bf16( x * rsqrt(mean(x^2)+eps) * w))); the row reduction, the value*(norm*weight) association (precise) and the single final round match the composed FastRmsNormBF16 -> FusedChainF32(sigmoid, mul, mul) -> CastF32BF16 chain. Mode 1: RMSNorm scaled by the bf16-rounded f32 scalar in beta. One 256-thread workgroup per row, grid-stride row loop; eps rides alpha. Bindings: 0 x, 1 weight, 2 gate (z), 3 output.
- zig/kernels/vulkan/fast_norm_gated.comp: // GATED_ONLY builds have no runtime mode branch (the gated kernel used by RMSNormGated); the default build keeps both modes for RMSNormScaled.
- zig/kernels/vulkan/fast_rope.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Fused rotary embedding matching mlx::core::fast::RoPE (mlx/fast.cpp, pinned 0.32.2) whose upstream Metal reference is rope.metal. No shared memory, no barriers. // Contract cases the kernel implements: - traditional (interleaved pairs, flags bit 1) and half-split layouts - forward and inverse (flags bit 0; the inverse form serves the VJP) - inv_freqs from the base, exp((-i) * log(base)/(dims/2)) with beta precomputed on the host in float, or from a float32 freqs buffer (USE_FREQS: 1/freqs[i], matching reciprocal() = 1.0f/x) - per-batch int32 offsets read from device memory (stride matrix_m; 0 for a scalar offset), positions = (t + offset) * scale in float32 - float32, float16, bfloat16 storage; each intermediate rounds once to storage precision exactly like the eager elementwise/cast kernels the fallback composition dispatches, so the fused output matches the composed path bit for bit in float16 and bfloat16. Float32 lands within an absolute 1e-6: the driver may contract x*y - z*w into a fused multiply-add and the composed path can never do that because its intermediates cross kernel boundaries; cancellation can amplify the round-off to many ulps while the absolute error stays at or below ~1e-8 (observed; pinned at 1e-6 in the value tests). - strided inputs: row-contiguous, 3D strided, and the 4D head/sequence transposed layout (flags bit 4) read through their strides; partial rotation (flags bit 3) also writes the passthrough tail from the input; anything else the host materializes into a temporary first // The bfloat16 branch deliberately avoids a 16-bit-typed storage block: a uint16_t block compiled from this exact source returns recycled-memory garbage on llvmpipe (observed 2026-09-03, stable across -Os/-O0 and across arithmetic changes, while the float16 twin of the same shader is bit-exact). The workaround is the repo's proven form - 32-bit word IO with constant shifts and select chains only, as in reduce_general's load_truthy fix (commit cf68e7d) - not a new 16-bit form. The two lanes of one output word can belong to different invocations, so the packed output store is a disjoint-half atomicOr pair, not a read-modify-write. // The input and output bindings are readonly and writeonly and never alias: the host rotates into a fresh output buffer instead of updating the input in place. Binding one buffer readonly in one slot and writeonly in another and then aliasing them drops stores on llvmpipe (observed 2026-09-03: the even outputs kept their stale copy-in values), so no path may rely on that form. scatter.comp's in-place output stays a single binding for the same reason. // Sin/cos are the GLSL built-ins, the same calls the eager composition makes through elementwise.comp cases 11/12. The kTrigArgumentLimit gate (1e5, primitives.cpp) ran per eager Sin/Cos primitive; fusion removes those primitive sites while the theta construction is unchanged, so the trusted envelope documented there applies verbatim. RoPE::eval_gpu carries an equivalent magnitude gate; see rope_trig_gate in primitives.cpp. // No data-dependent shift-and-mask appears anywhere: the only shifts are the constant 16-lane shifts of the bf16 word IO and the even/odd pair split, the device-probed select-chain form (commit cf68e7d). // Push-constant mapping (ComputeParams fields): count B*N*T*(dims/2), or B*N*T*D with the passthrough flag alpha scale beta float(log(base)/(dims/2)), base variant only flags bit0 forward, bit1 traditional, bit2 head-seq transpose, bit3 passthrough (dims < D) dims dims/2 shape[0] N, the product of the middle dimensions shape[1] T shape[2] D, the rotated-axis extent (passthrough only) matrix_m offset stride, 0 for a scalar offset lhs/output/rhs/aux_offset item offsets of input/output/offset/freqs in_strides input strides (head matrix, time, feature) out_strides output strides (head matrix, time, feature)
- zig/kernels/vulkan/fast_rope.comp: // The input rides 32-bit words, two bf16 lanes per word, constant shifts and selects only: a uint16_t-typed block compiled from this exact source returns recycled-memory garbage on llvmpipe (observed 2026-09-03, stable across -Os/-O0 and across arithmetic changes, while the float16 twin of the same shader is bit-exact), so the loads take the repo's proven reduce_general form. The in-register rope_round calls reproduce the composition's intermediate roundings and the store applies the one final rounding, so bfloat16 stays bit-exact against the composed path. The output binding stores packed bf16 words. The rotate writes the repo's proven constant-shift form; every element is written exactly once but the two lanes of one word can belong to different invocations, so the lane stores are disjoint-half atomicOr - each word receives exactly two ORs (one zeroing the high half, one zeroing the low half), so the OR result is the correct packed value regardless of initial memory content or arrival order. The store applies the RNE float32->bf16 rounding the cast kernel applied in the old float32-temporary path, and the rope_round intermediates already are exact bf16 values, so output bits are identical to the composed path's final cast.
- zig/kernels/vulkan/fast_rope.comp: // Pair-granular bf16 main: each invocation owns whole 32-bit output words (two adjacent elements of one row) and computes both lanes itself, so plain stores replace the atomicOr pair that proved lane-lossy on Apple-hardware Vulkan (see receipts/2026-09-21-decode-kv-direct). Requires an even rotation half (dims % 4 == 0), an even passthrough extent, and even kv window element offsets - all host-guarded. params.count enumerates output WORDS: the host halves the element count for the passthrough branch only (the rotated branch already enumerates half_dims threads per row, each of which now emits two words).
- zig/kernels/vulkan/gated_delta_decode.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Copied from mlx-omarchy shaders/gated_delta_decode.comp (MIT), comments condensed. Fused gated-delta-rule decode step (T=1): state decay, kv reduction, delta, outer-product state update, output projection over the updated state. Dk==Dv==128, 128 threads per workgroup, 32 Dv rows per workgroup, the ROWS x Dk f32 state tile staged through shared memory (padded stride 129); every row reduces sequentially over Dk in ascending order, f32 throughout, output bf16 RNE, state f32 end to end. Flag bit 3: raw-gates prologue in-kernel — slot 3 carries a, slot 4 b (bf16), slots 8/9 A_log and dt_bias. Flag bit 9: A_log read as f32 (two little-endian u16 words) AND the kv walk order that matches the Metal chain (s*g then *k). bf16 roundings: x=a+dt, softplus, beta; g stays f32. Push: matrix_m=DK, matrix_n=Dv, matrix_k=Hv; shape[0]=a offset, shape[1]=state in, shape[2]=state out; in_strides[0]=A_log offset, [1]=dt_bias offset, [2]=Hv, [3]=Hk (GQA; the default arm ignores it).
- zig/kernels/vulkan/gated_delta_decode.comp: // Geometry: Dk == Dv == 128 (dispatch-gated), 128 threads per workgroup, ROWS Dv rows per workgroup, Dv / ROWS workgroups per head (gl_WorkGroupID.y). The ROWS x Dk f32 state tile is staged through shared memory with coalesced loads and stores (thread t owns column t of every tile row), so the per-row sequential walks read shared memory instead of one 512-byte-strided global word per lane per step. // Bit identity with the one-workgroup-per-head kernel this replaces: that kernel's source (`kv += s * g * k[i]`, `ns = s * g + delta * k[i]`, `out += ns * q[i]`) compiled, after Honeykrisp's rank-based reassociation of non-exact float chains, to kv = fma(s, k[i] * g, kv), ns = fma(s, g, delta * k[i]), out = fma(ns, q[i], out) (AGX NIR dump, measured against the hardware AGX dump). The same source reading a shared tile regroups differently, so the walks below are written so each step is a two-operand chain the compiler can only contract one way: k[i] * g is a per-workgroup table (one rounding, the same fmul), and delta * k[i] is precise, leaving s * g as the only product next to it. The walks and the gate prologue sit in their own functions because glslang propagates `precise` backward through everything that feeds a precise value inside one function.
- zig/kernels/vulkan/gated_delta_decode.comp: // kv = the composed chain's order: state_next = state*g rounded per element, kv term = state_next*k rounded per element, then the ReduceF32 serial ascending sum from 0.0. Selected by bit 9 (C++-fallback-equivalent arithmetic, the A_log-f32 models); the default walk keeps the Metal-kernel-equivalent association (k*g precomputed).
- zig/kernels/vulkan/gated_delta_decode.comp: // g = exp(-(exp(A_log) * softplus(x))) as the C++ raw fallback runs it: LogAddExp, Exp, Multiply, Negative, Exp, five kernels whose results are stored f32 between launches. `precise` on each later op keeps those rounding sites; without it the compiler folded the negate and the exp lowering's log2(e) scale into the product (g off by 1-2 ulp on ~4 of 32 heads, enough to break model-level identity). The softplus body stays imprecise in its own function (glslang stops `precise` propagation at the call) because the elementwise kernel compiles it imprecise.
- zig/kernels/vulkan/gated_delta_decode.comp: // A_log rides bf16 in the Qwen3.8 checkpoint; flag bit 9 selects an // f32 A_log (the Qwen3.5-9B conversion stores it f32) read as two // little-endian u16 words — the same f32 word the eager chain's // astype(f32) leaves untouched, so no rounding difference. // head runs over B * Hv (batched decode); A_log and dt_bias are per model // head, so they index head % Hv (in_strides[2] = Hv).
- zig/kernels/vulkan/gated_delta_decode.comp: // Ash8c Metal gdn_pre softplus: DIRECT log (not the corrected log1p // ratio form), rounded to bf16, regardless of the A_log dtype — // sp = bf16(max(x,0) + log(1 + exp(-|x|))) // g = exp(-exp(A_log_f32) * sp) (f32, like Metal) // beta keeps the bf16 sigmoid above. This replaces the MLX C++-fallback // reference choice (bit 9 keeping sp f32) for this oracle.
- zig/kernels/vulkan/gated_delta_decode.comp: // Native GQA decode (Hk < Hv): q and k keep their Hk heads. in_strides[3] // carries Hk (0 = q and k already have Hv heads), in_strides[2] carries // Hv. Value head j reads key head j / (Hv / Hk), the order mx.repeat on // the head axis produces, per batch row (head runs over B * Hv).
- zig/kernels/vulkan/gated_delta_prefill_ash.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // ASH arm of gated_delta_prefill.comp: the copied file with the u8 mask binding removed. A uint8_t SSBO requires storageBuffer8BitAccess, which the Device does not enable (storage16/int16 only). The Ash8c Metal oracle never passes a mask, so this fixed variant compiles the declaration and read out and the host rejects flag bit 1 before dispatch. The copied default (gated_delta_prefill.comp) is unchanged. Bindings: 0 q, 1 k, 2 v, 3 g (bf16, unused with bit2), 4 beta, 5 h0 (f32), 6 y, 7 hf (f32), 8 g f32 (bit2, read at shape[0]), 9 snapshot (f32). Push: 120 B; dims=T, chunk=C, chunks, matrix_m=DK, matrix_n=Dv, matrix_k=Hv; shape[0]=g offset, [1]=h0, [2]=hf; flags bit2 g f32, bit3 output pass; bit1 (mask) is refused by the host.
- zig/kernels/vulkan/gated_delta_prefill_ash.comp: // Parallel shared load: thread i stages k/q (and per-Dk g when present) into this token's double-buffer slot, then one barrier orders the load before every thread's token_step. The second slot lets the next iteration's writes (two steps later) safely wait on the single per-iteration barrier.
- zig/kernels/vulkan/gdn_conv_decode.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Copied from mlx-omarchy shaders/gdn_conv_decode.comp (MIT), comments condensed. GDN decode conv (T==1): the concat(state, x) is folded into the tap read and the shifted carry-out state is written in-kernel; one dispatch replaces two copies + conv + state view. Flag bit 0 folds nn.silu (store-round, sigmoid = 1/(1+exp(-v)), multiply, each RNE like the composed swiglu SILU_ONLY chain). Flag bit 2 folds a per-workgroup two-half 128-row rms-norm*scale epilogue (unused by the Ash arm). Bindings: 0 state [B,K-1,C], 1 x [B,1,C], 2 weight [C,1,K], 3 output [B,1,C], 4 state out [B,K-1,C]. Push: count=B*C, operation=K, lhs_size=K-1, reduce_size=C.
- zig/kernels/vulkan/gdn_conv_decode.comp: // GDN decode conv: the conv_input = concat(state, x) materialization is folded into the depthwise conv read (T == 1), and the shifted carry-out state is written in-kernel. One dispatch replaces CopyGeneral x2 (concat halves) + ConvBF16 + the trailing contiguous state view. // Bit-exact by construction: the concatenation is value-transparent (pure copies), so the conv reads identical values; the tap accumulation below is the conv.comp body verbatim (same loop shape, f32 widen, left-associated sum, RNE bf16 store), and the state rows move as raw uint16 bits. // Bindings: 0 state [B, K-1, C], 1 x [B, 1, C], 2 weight [C, 1, K], 3 output [B, 1, C], 4 state out [B, K-1, C]. Push constants: count B * C output elements operation K (kernel taps) lhs_size K - 1 (state rows) reduce_size C (channels per row)
- zig/kernels/vulkan/gdn_conv_decode.comp: // Flag bit 1 (GdnConvUpdate `qk_key_dim > 0`): per-workgroup rms-norm epilogue for the q/k head-rows (fast_norm_gated.comp mode 1 folded into this dispatch; F4). Each 256-thread workgroup owns 256 contiguous channels = exactly two 128-channel head-rows (q rows first, then k; v passes through), so the two mode-1 reduction halves run side by side in one shared block: threads 0..127 hold row 2g, 128..255 row 2g+1, and the stride 64->1 tree per half reproduces the mode-1 tree association exactly (its stride-128 step only ever adds +0.0). The wrapper gates count % 256 == 0 (one element per thread, one grid-stride iteration — the in-loop barriers deadlock otherwise), channels % 256 == 0, and key_dim % 128 == 0 (the q|k boundary may fall inside a workgroup, but it stays on a 128-lane half). APPLE_REDUCTION sums each half with four 32-lane subgroups and one second subgroup sum, the order FastNormGatedAppleBF16 uses for a 128-wide row. The host dispatch guard (apple_norm_shape_selected, primitives.cpp) serves the 128-wide halves from the deployed kernel, so this build runs only if that guard ever widens to 128.
- zig/kernels/vulkan/gdn_conv_decode.comp: // Per-workgroup two-half 128-row rms-norm*scale over the stored values (fast_norm_gated.comp mode 1, F4). The norm input is the value this dispatch stores and the composed norm kernel re-widens.
- zig/kernels/vulkan/gdn_split.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // GDN pre-stage split for the Ash8c Metal oracle (gdn_pre.metal, post-conv half): the depthwise conv has already run (conv_dw1d.comp over the [T+3, C] conv input), so this kernel reads the raw conv output and does the rest of gdn_pre: SiLU, the Q/K L2 norm split, the V passthrough and the a/b gate from A_log / dt_bias. One workgroup of 32 lanes per (token, head) mirrors Metal exactly: each lane owns 4 contiguous channels (PER = 128/32), the row sum is a 32-lane reduction over the per-lane partials, and every intermediate the Metal kernel rounds to bf16 is rounded here too. // Math per (t, head), C = 6144, DK = 128, NK = NV = 16: conv = widen(conv_out[t*C + head*DK + lane*4 + j]) (already bf16) sig = bf16(1/(1+exp(-conv))); vals[j] = bf16(conv*sig) q (head < 16) / k (16..31): inv = rsqrt(sum(vals^2)/128 + 1e-6/128), scale = bf16(1/128) for q, bf16(rsqrt(128)) for k, out = bf16(scale * bf16(vals[j]*inv)) v (head 32..47): out = vals[j] lane 0: s = bf16(a[t,hv] + widen(dt[hv])) sp = bf16(max(s,0) + log(1+exp(-|s|))) g = exp(-exp(A_log_f32[hv]) * sp) (f32, like Metal) beta = bf16(1/(1+exp(-b[t,hv]))) // The reduction order differs from Metal's hardware simd_sum (documented in gdn.zig; not claimed bit-exact). The gate chain is the same expression sequence gated_delta_decode.comp's raw-gates prologue uses. // Bindings (views bind at their base, so shader offsets start at zero): 0 conv_out bf16 [T, 6144] readonly 1 a bf16 [T, 16] readonly 2 b bf16 [T, 16] readonly 3 a_log f32 [16] readonly 4 dt_bias bf16 [16] readonly 5 qkv bf16 SoA [3, T, 16, 128] writeonly (q | k | v sections, each T*2048 elements) 6 g f32 [T, 16] writeonly 7 beta bf16 [T, 16] writeonly Push (the standard Params prefix; only these fields are read): count = T (tokens; grid x) lhs_size = C (conv row stride, 6144) rhs_size = T (SoA section stride in head-rows: T*16 heads * 128) output_size = 48 (heads; grid y) Local size 32x1x1; grid (T, 48, 1). Shared memory: 32 f32 (128 B).
- zig/kernels/vulkan/sdpa_decode_native.comp: // ------------------------------------------------------------------ The composition-exact bf16 arm. Every operation below reproduces the f32-score composition's observable arithmetic in the same order, so the route is bit-identical to the ten-dispatch path it replaces and no generated token can move: 1. q*scale once in f32 (the composition's elementwise multiply; the matmul alpha is 1.0 and its drain multiplies by it), 2. scores = per-dot ascending-d `acc += a * b` accumulation over 16-wide tiles with exact-zero tail padding, drained by 1.0f, stored f32 (matmul.comp), 3. softmax: 256-lane strided max scan + binary max tree, strided sequential exp-sum per lane + binary sum tree, normalizer 1.0/sum, probs = exp(score - max) * normalizer recomputed from the stored f32 scores (softmax_suffix.comp), 4. output = ascending-key `acc += a * b` over 16-wide tiles with exact-zero tail padding, drained by 1.0f (matmul.comp), stored through the cast.comp RNE bf16 pair. Threads 256..1023 share every barrier but do no phase work; the reduction trees only involve lanes 0..255, exactly as the 256-thread softmax kernel computes them. ------------------------------------------------------------------
- zig/kernels/vulkan/swiglu.comp: // Copyright © 2026 Joshua Warren / mlx-omarchy contributors. // SPDX-License-Identifier: MIT // Reused from mlx-omarchy shaders/swiglu.comp (MIT), comment-condensed. // Four-wide SwiGLU: sigmoid(gate) * gate * up, each intermediate rounded to the storage dtype exactly as the fused_chain interpreter rounds it (packHalf2x16 round trip for f16, bf16_store for bf16), so stored bits match. Host gate (dispatch_chain): two direct leaves and count and both leaf offsets multiples of four. materialize != 0 additionally stores sig/silu to bindings 3/4; the eager-fusion host path keeps those at 0 and leaves the buffers untouched.
- zig/src/families/qwen3_5/backend/vulkan/forward.zig: Every GPU call is routed through `vk.orExit` at the call site: a Timeout or InFlight ends the process before any destructor can free a resource the GPU may still be using. Nothing here falls back to the CPU.
- zig/src/families/qwen3_5/backend/vulkan/forward.zig: written out of place into `sum`
- zig/src/families/qwen3_5/backend/vulkan/forward.zig: Conv and recurrence are the state's ping-pong pair; the slot flips after the writes.
- zig/src/families/qwen3_5/backend/vulkan/forward.zig: pure and host-tested
- zig/src/families/qwen3_5/backend/vulkan/weights.zig: Admission is fail-closed: the pinned Qwen3.5-2B geometry, affine Q4 group-64 quantization, dense MLP, and every tensor's exact dtype and shape are checked before any byte is read; anything else is refused, never silently adapted.
- zig/src/families/qwen3_5/backend/vulkan/weights.zig: Ownership transfers exactly once: until the slot is registered in `keep`, this function alone cleans up (slot plus the Vk allocation) on every failure
- zig/src/vulkan/norm_mlp.zig: The host API is identical either way; the variant is fixed at build time, not a runtime option.
- zig/src/vulkan/norm_mlp.zig: the shader's lhs_size == 1 broadcast stays in the source, unused
- zig/tests/vulkan/contract_attention.zig: the fixture's fixed [8]f64 score buffer caps it at 8 visible keys
- zig/tests/vulkan/contract_attention.zig: Op order matches fx.Attend.init exactly.
- zig/tests/vulkan/contract_gdn.zig: the interior chunk snapshot is bound exactly when the prefill's chunks exceed one
- zig/tests/vulkan/contract_gdn.zig: `acc` null: the fixture's sequential f64 sum, bit-identical to fx.RecurWalk and fx.Decode
- zig/tests/vulkan/stage3_probe.zig: no model, no performance claim, no cross-backend bitexact claim — the fixture states each gate's budget
- zig/tests/vulkan/stage5_probe.zig: Exit 0 pass, 1 fail, 2 usage, 124 fence timeout.
- zig/build/vulkan_model.zig: the CUDA native server's entry point and checkpoint CLI, the factory's engine_api/core instances
- zig/src/vulkan/ops_q4.zig: Q4 affine projection out[m, n] = x[m, k] . dequant(w, scales, biases)[n, k], group 64, transposed
- zig/src/vulkan/ops_q4.zig: The gathered scale and bias rows ride the 32-bit transport, so tokens * (k / 64) must fill whole words
- zig/src/vulkan/ops_q4.zig: The three table views are single bindings, so each must fit maxStorageBufferRange whole; anything larger is refused before any dispatch, never silently chunked
- zig/tests/vulkan/contract_greedy_main.zig: finite_logits, argreduce_chunk and argreduce_combine behind one submission | the mirror of HIP's tf_ctl_fmax_max: a row max that drops a NaN | Gate 5 rides the device's own limits: dispatch.Pipeline.init checks workgroup, push and binding limits per device before creating anything
- zig/tests/vulkan/contract_pointwise.zig: checked STRICTLY (no measured-property qualification)
- zig/tests/vulkan/contract_pointwise.zig: the variant norm_mlp selects where the device declares shaderDenormPreserveFloat32 | the -DUSE_BF16 an earlier build passed alongside it matches no ifdef in the shader, so the pipeline was the plain bf16 add all along; no f32-storage variant of binary_vec.comp exists
- zig/tests/vulkan/contract_pointwise.zig: allow_subnormal_flush stays false — the preserve gate is where the GPU result must prove denormal preservation, so a flushing device fails the subnormal classes rows as an honest finding
- zig/tests/vulkan/contract_pointwise.zig: the f32 multiply's sign rule makes it deterministic. Nonfinite wants compare classes
- zig/tests/vulkan/contract_pointwise.zig: whose error is relative to |normed|, i.e. |want|/|silu(z)| — the fixture's gate floor |z| >= 0.25 keeps |silu(z)| >= 0.109
- zig/tests/vulkan/contract_pointwise.zig: that head row's sum goes infinite, norm 0: signed-zero outputs across the head row, nan at x[0]'s inf*0 | that head row's sum goes nan: a whole nan head row
- zig/tests/vulkan/contract_pointwise.zig: w the shared [128] gain at the element's column. nonfinite where the planted controls make it so; want == 0 carries the sign
- zig/tests/vulkan/contract_pointwise.zig: the reduction sums only squares | (a flushed or sign-flipped zero is refused); nonfinite wants compare classes; a finite want with a nonfinite output is refused outright
- zig/tests/vulkan/contract_pointwise.zig: A define that matches no ifdef — the -DUSE_BF16 an earlier build passed alongside it — silently produces the plain bf16 add instead; this catches that class of drift
- zig/tests/vulkan/qwen35_model_probe.zig: bad usage or bad inputs exit 2; a failed run exits 1; a fence timeout exits 124 (inside the engine's orExit) | PASS requires the exact oracle IDs (strict lowest-index ties, no epsilon, no known-ID special case) on two fresh-cache runs | the GPU greedy is the selector, never a CPU argmax | the raw logits are also compared element-wise against the oracle's file as a diagnostic only
- zig/tests/vulkan/qwen35_model_probe.zig: the diagnostic counter, pure and host-tested. Byte-pair compare: no alignment assumed
- zig/tests/vulkan/qwen35_model_probe.zig: Immutable metadata: the caller passes an arena allocator, nothing freed
- zig/tests/vulkan/qwen35_model_probe.zig: shared by the probe run and the opt-in load test so both exercise the shader set the server serves with
- zig/tests/vulkan/qwen35_model_probe.zig: --sequential-prefill instead issues one Engine.prefill call per prompt token for the boundary evidence
- zig/tests/vulkan/stage2_fixture.zig: nonfinite outputs by class (a driver may raise a different NaN payload)
- zig/tests/vulkan/stage2_fixture.zig: the largest minStorageBufferOffsetAlignment Vulkan allows
- zig/tests/vulkan/stage2_fixture.zig: The measured device properties, never a vendor name, qualify the three subnormal-class rows for signed-zero results when f32 preservation is unsupported
- zig/tests/vulkan/stage2_fixture.zig: The budget applies to the output RELATIVELY (see check): the sum is positive, so gamma(20) bounds its relative error in any order
- zig/tests/vulkan/stage2_fixture.zig: The reduction sums squares (positive), so its relative error stays under gamma(depth) in any order | A deliberately-absolute sum-of-squares budget here would allow ~1e3 of output error on dynamic rows and nonzero outputs on the zero row — that was wrong and is not this
- zig/tests/vulkan/stage4_probe.zig: Exit 0 pass, 1 fail, 2 usage, 124 fence timeout
- zig/tests/vulkan/stage4_probe.zig: the conv output and the split's soa/g/beta go against the f64 references, three byte-identical repeats, planted refusals, inputs unchanged
- zig/tests/vulkan/stage4_probe.zig: raw bf16 store — the split owns the single SiLU | then the split on the ACTUAL activated bits against SplitOne. Repeats, guards, unchanged inputs, negative controls on both stages
- zig/src/families/qwen3_5/backend/vulkan/engine.zig: the state's real zeroed regions come last. The engine pointer is stable for its whole life: the runtime, device and command stream are heap-owned before any view, pipeline or state exists, so no child pointer can ever dangle behind a move.
- zig/src/families/qwen3_5/backend/vulkan/engine.zig: A failure after the first chunk poisons (the partial RNN state is never reused)
- zig/src/vulkan/attention.zig: fast_rope compiles with -DUSE_BF16 -DASH_QWEN35 (the Metal-oracle variant: no intermediate bf16 rounding; the compiled passthrough path evaluates the theta 1e7 inverse frequency as exp(-i*beta) with beta = ln(1e7)/32, i.e. 1e7^(-i/32) up to exp-vs-pow ulps); ... fast_rope needs the repo-local omarchy_trig.h include path.
- zig/src/vulkan/greedy.zig: argreduce_chunk.comp and argreduce_combine.comp (mlx-omarchy sources copied verbatim, driven operation=max, one row)
- zig/src/vulkan/ops.zig: The caller owns index validation (see ops_q4.checkIds); the zero write is the shader's documented read.
- zig/tests/vulkan/contract_attention_main.zig: single-key transport exactness, planted refusals, inputs unchanged
- zig/tests/vulkan/contract_gdn_main.zig: the stage 4 module doc block, plus the prefill scan's [2][DK] staging the doc block predates
- zig/tests/vulkan/stage4_fixture.zig: inputs are exactly-bf16-representable dyadics so operand widening is exact; magnitude scale max|vals|^2; at |g|; at the largest intermediate state magnitude the walk saw; chunk=4 and chunk=8 must agree with the SAME serial reference; Every finite reference demands a finite output
- zig/tests/vulkan/stage4_fixture.zig: Never a sum of squares of outputs; always finite and positive (the 2^-133 floor), so dividing into a ratio is safe. Fixed bring-up acceptance: never enlarged after a GPU run without a new stated derivation.
- zig/tests/vulkan/stage4_fixture.zig: the split's lane-0 chain and the decode prologue's raw-gates chain share this formula ... Use `gateRefAsh` for checker references; this stays for the amplification evidence test.
- zig/tests/vulkan/stage4_fixture.zig: (gdn_split.comp ash_gate and gated_delta_decode's ASH_QWEN35 prologue) ... Every bf16 rounding and f32 op of the shader, on the host - the residual vs the GPU is f32 exp/log ulps, what the unchanged ops budget covers.
- zig/tests/vulkan/stage4_fixture.zig: (the shader's interior chunk boundary): the snapshot slot the prefill scan stores there
- zig/tests/vulkan/stage5_fixture.zig: The reference deliberately re-walks the widened row itself instead of calling production host helpers ... No oracle tokens: every expectation comes from this scan.
- zig/tests/vulkan/stage3_fixture.zig: Acceptance: these are fixed bring-up budgets, not cross-backend bitexact claims or Vulkan-spec proofs. RoPE's f64 reference applies ASH equations out[d<32]=x[d]*cos-x[d+32]*sin and out[32<=d<64]=x[d-32]*sin+x[d]*cos, angle pos*theta^(-i/32). Budget |got-want|<=budget(depth=2,ops=6,mids=1,|want|): f32 angle/pow/trig/products, one RNE bf16 store, and input bf16 rounding as mid. d>=64 must equal input bits exactly. Cache K rows base..base+rows-1 use rope reference at base+r; V rows preserve input bits via uint16 transport; rows outside window preserve planted poison. SDPA query r sees exactly prefix+r+1 keys; f64 reference softmaxes only those keys; depth=300 covers 256-term score dot and output sum at own magnitude plus GPU-read q/k bf16 roundings (mids=2). Causality has no budget: outputs must be bit-identical when every non-visible key is poisoned by a large finite value vs zeroed. Gate out=bf16(f32(ctx)*f32(bf16(sigmoid(gate)))); ops=3 (exp/add/div), mids=1 (bf16 sigmoid round), one bf16 store. Every finite reference requires finite output; wrong finite and nan/+inf/-inf plants must be refused.
- zig/tests/vulkan/stage3_fixture.zig: // Stage 3 fixture: half-split RoPE (head_dim 256, rotary 64, theta 1e7), the flat KV cache write, causal GQA SDPA (8 query heads, 2 KV heads, scale 1/16) and the interleaved attention output gate, against independent f64 host references. Host-checkable only; no device code here.
- zig/tests/vulkan/stage3_fixture.zig: // Acceptance (fixed bring-up budgets, stated; NOT cross-backend bitexact claims, NOT Vulkan-spec proofs): - rope: the f64 reference applies the ASH form out[d<32] = x[d]*cos - x[d+32]*sin, out[32<=d<64] = x[d-32]*sin + x[d]*cos (angle pos*theta^(-i/32)), x[d>=64] passthrough. Budget: |got - want| <= budget(depth=2, ops=6, mids=1, |want|): f32 angle/pow/trig/products plus the one RNE bf16 store, with the input's own bf16 rounding as the mid. Elements d >= 64 must equal the input BITS exactly. - cache: K rows base..base+rows-1 carry the rope reference at positions base+r; V rows are the input BITS exactly (uint16 transport); every row outside the window keeps the poison the fixture planted. - sdpa: query row r sees exactly prefix+r+1 keys. The f64 reference softmaxes over those keys only; budget depth=300 covers the 256-term score dot and the 256-term output sum at their own magnitude scale, plus the q/k bf16 roundings the GPU reads (mids=2). Causality is also checked WITHOUT a budget: outputs must be bit-identical when every non-visible key is poisoned with a large finite value vs zeroed. - gate: out = bf16(f32(ctx) * f32(bf16(sigmoid(gate)))); budget ops=3 (exp/add/div), mids=1 (the bf16 sigmoid round), one bf16 store. Every finite reference demands a finite output; planted wrong finite and nan/+inf/-inf outputs must be refused by the same checkers.
- zig/tests/vulkan/contract_greedy.zig: the harness's run hook is one prepared input set and one call, and the draw's three passes share one submission and its internal scratch (partials, the 12-byte readback) — finite_logits alone writes only verdict words, argreduce_chunk/combine alone write (value, index) pairs meaningful only to the fold and the decode.
- zig/tests/vulkan/contract_greedy.zig: HIP registers its tf_argmax_parts+join the same way, so the three launches ride inside run() instead of three registrations.
- zig/tests/vulkan/contract_greedy.zig: The stated rule the check hook enforces (greedy.zig's, unchanged Ash q.backend.draw): any non-finite anywhere in the row refuses it, winner or not; the largest value wins; exact ties (including +0/-0) go to the lowest index.
- zig/tests/vulkan/contract_greedy.zig: The planted control that breaks exactly this rule is zig/kernels/vulkan/contract_controls_greedy.comp, registered from the main with control = .nonfinite.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: Every region is real zeroed device memory: construction and `reset` write zeros on the GPU through the existing staged transfer (`commands.upload` through the caller's staging buffer) — never a metadata-only reset and no new kernel.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: The decode and prefill operators read one state half and write a disjoint other half (ping-pong), so no read aliases a write under the pipeline's validation; `flip` swaps the halves between steps.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: Capacity is bounded by the SDPA arm's visible-key limit (7168): a context beyond that is refused at construction, never silently truncated.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: Length commits only through `append`, after the writes that produced the rows completed; `deinit` is legal only when no submission touching any view can still be pending; `reset`'s transfers route in-flight errors through `commands.orExit` inside this module, before any unwind can free.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: The pinned config's `full_attention_interval`, checked against the family constants.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: This is the hard capacity it admits (attention.zig's limit).
- zig/src/families/qwen3_5/backend/vulkan/state.zig: Every buffer is heap-owned and never moved, so all views stay valid for the state's lifetime.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: `parity` selects which ping-pong half each linear layer's operators read and write next.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: The caller's staging buffer (any nonempty size; transfers chunk through it).
- zig/src/families/qwen3_5/backend/vulkan/state.zig: The slot registers in `created` as soon as the Vk allocation exists, so exactly one owner (State.deinit) ever frees it.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: `staging` zero page is bounded at 16 MiB.
- zig/src/families/qwen3_5/backend/vulkan/state.zig: There is no rewind: lowering the committed length after recurrence updates would leave the conv and GDN states silently wrong, so a future caller that needs speculation or prefix reuse must restore state for real (this module provides only a full `reset`).
- zig/src/families/qwen3_5/backend/vulkan/state.zig: the larger F32 geometry bounds both lengths.
- zig/tests/vulkan/contract_pointwise_main.zig: Stage 2's three through the production operator; the preserve add over the same pipeline's DenormPreserve image (binary_vec.comp + -DPRESERVE_F32, bf16 in and out), the gate and gated norm in the same dispatch shapes their wrappers use.
- zig/tests/vulkan/contract_pointwise_main.zig: The device line above prints the property, so a strict refusal on a preserving device is a decidable honest finding.
- zig/tests/vulkan/contract_pointwise_main.zig: every mismatch a subnormal sum read as the same-signed zero. That prints ONLY its KNOWN line (the reasoning folded into it); anything else — a device that claims preservation and flushes, a non-flush mismatch — keeps the FAIL, plus the NOTE when the want is a subnormal.
- zig/tests/vulkan/contract_pointwise_main.zig: The wrapper's own plan: out/y/z are tokens*2048 elements, the weight the [128] head row, rows = the TOKEN count, plan.rows = tokens*16 head rows.
- zig/src/families/qwen3_5/backend/vulkan/backend.zig: the state ceiling; the reply's decodes are admitted against it separately.
- zig/src/families/qwen3_5/backend/vulkan/backend.zig: the engine (device, weights, sequence) outlives it and its owner deinits it quiescent.
- zig/src/families/qwen3_5/backend/vulkan/backend.zig: The first call validates the whole request (ids, capacity footprint with the reply's decodes) before any reset or write; later calls resume at the engine's committed visible count, so `visible()` is the progress and no cursor state exists.
- zig/src/families/qwen3_5/backend/vulkan/backend.zig: The engine holds a single sequence with no rewind, so keeping a prefix is impossible.
- zig/tests/vulkan/stage1_fixture.zig: one output per 256-thread group and one past it, one and two groups per row, offsets, and a cancel fill.
- zig/tests/vulkan/stage1_fixture.zig: Every m*n is even (word-padded bf16 views).
- zig/tests/vulkan/stage1_fixture.zig: Binding bases sit at 256-byte multiples — the largest minStorageBufferOffsetAlignment Vulkan allows — so the offsets exercise the production aligned-binding contract on any device, not arbitrary offsets; Views guarantee only 4-byte alignment.
- zig/tests/vulkan/stage1_fixture.zig: with the 128 randoms the cast views stay word-padded.
- zig/tests/vulkan/stage1_fixture.zig: the copy exercises the production aligned-binding contract, not arbitrary offsets.
- zig/src/families/qwen3_5/backend/vulkan/engine.zig: Native Vulkan Qwen3.5-2B engine: heap-stable object runs single-sequence prefill chunks, decode, and greedy draws.
- zig/src/families/qwen3_5/backend/vulkan/engine.zig: Safety: gates (bf16, SDPA shmem, GDN subgroup) + admission precede weights; state last; child ptrs heap-owned first
- zig/src/families/qwen3_5/backend/vulkan/engine.zig: `vk.orExit` exits 124 on Timeout and 1 on InFlight.
- zig/src/families/qwen3_5/backend/vulkan/engine.zig: Post-write failures poison until reset; no rollback.
- zig/tests/vulkan/stage1_fixture.zig: tokens are even in every case: each gathered token contributes k/64 bf16 scales, and a ragged tail element would be refused by the typed view before any GPU work.
- zig/src/vulkan/commands.zig: // Fill `len` bytes of device buffer `dst` at `offset` with the repeating 4-byte little-endian pattern of `value`: one submission, transfer-write barriers before and after, finite fence wait. Timeout/InFlight go to the caller, which must orExit rather than free anything the GPU may still use.
- zig/src/vulkan/gdn.zig: // Qwen3.5 GatedDeltaNet GPU primitives on the shared set-0 storage / push-constant pipeline model, matching the Ash8c Metal oracle (zig/kernels/metal/qwen3_5/gdn_{pre,chain,post}.metal) op for op. // Kernels (kernels/vulkan/, -DUSE_BF16 --target-env vulkan1.2): conv_dw1d, gdn_conv_decode, gdn_split, gated_delta_prefill_ash, gated_delta_decode, copy_general -DUSE_U16 (copied mlx-omarchy, MIT), fast_norm_gated (copied, MIT). // Gate formula from the Metal oracle, not assumed: s bf16, softplus bf16-rounded, g = exp(-exp(A_log_f32) * softplus) stored f32, beta = sigmoid(b) bf16; A_log f32, dt_bias bf16; decode bit9 selects the f32 A_log read and the Metal kv-walk association. // Bindings vs dispatch.max_bindings = 10: conv_dw1d 3, gdn_conv_decode 5, gdn_split 8, fast_norm_gated 4, copy_u16 4, gated_delta_prefill_ash 10, gated_delta_decode 10. // Shared memory: gdn_split 128 B; prefill scan 1.5 KiB; decode about 18 KiB; fast_norm_gated 1 KiB; subgroup relative shuffles required for compute and subgroup size a multiple of 4 (checked in init, fail-closed); 16-bit storage + int16 required. // State lifetime: conv and recurrence states are caller-owned and must stay alive until every submission using them returned success; Timeout/InFlight routes through commands.orExit, never deinit; 18 layers keep 18 conv + 18 recurrence state buffers.
- zig/src/vulkan/gdn.zig: // Prefill conv: assemble the [tokens+3, C] conv input (conv state rows then the projection output), run the 4-tap conv and the gate split, store the trailing [3, C] window as the next conv state; writes are out of place.
- zig/src/vulkan/gdn.zig: // Gated-delta prefill recurrence over `tokens` in chunks of `chunk`: pass 0 writes per-chunk snapshots (skipped for a single chunk), pass 1 the bf16 outputs and the terminal state. q/k/v ride one SoA buffer (the split's output shape), g is the split's f32 gate, h0/hf are [16*128*128] f32 states; `tokens <= chunk` takes snap = null.
- zig/src/vulkan/gdn.zig: // Gated RMSNorm + SiLU epilogue (Ash8c Metal gdn_post): PER-HEAD 128-wide RMS, not a 2048 global row; out = bf16((gate/(1+exp(-gate))) * bf16(weight * (value * inv))). y/z/out are [tokens, 16, 128] bf16 head-major — exactly the recurrence's y layout; the weight is [128] bf16 indexed by the column within the head.
- zig/src/vulkan/norm_mlp.zig: /// RMSNorm computes x*rsqrt(mean(x^2)+eps)*gamma; View.init rejects scalar padding, so row gamma binds at offset 0.
- zig/tests/vulkan/stage3_fixture.zig: // Stage 3 fixture: half-split RoPE (head_dim 256, rotary 64, theta 1e7), the flat KV cache write, causal GQA SDPA (8 query heads, 2 KV heads, scale 1/16) and the interleaved attention output gate, against independent f64 host references. Host-checkable only; no device code here. Acceptance uses fixed bring-up budgets — NOT cross-backend bitexact claims, NOT Vulkan-spec proofs.
- zig/tests/vulkan/stage3_fixture.zig: // Focused bit-pattern proof of the production shader bug: attention_gate.comp fed bf16_bits(s) << 16 back into bf16_lane's lane 0, which shifts << 16 again; a bf16 word widened once is the sigmoid value, shifted 32 total it annihilates to 0.0 — lane 0 of every output word.
- zig/src/families/qwen3_5/backend/vulkan/backend.zig: The advertised scheduling step: the engine cuts each prompt pass into chunks of at most this many rows
- zig/src/families/qwen3_5/backend/vulkan/state.zig: Length commits only through `append`, after the writes that produced the rows completed / `reset`'s transfers route in-flight errors through `commands.orExit` inside this module
- zig/tests/vulkan/contract_pointwise_main.zig: through the same dispatch model their wrappers use (identical binding counts, push-block sizes and group math; the wrappers own the plans via attention.gatePlan and gdn.gatedNormPlan) / no model, no performance claim, no cross-backend bitexact claim
- zig/tests/vulkan/stage1_fixture.zig: against the contract's FP64 bound
- zig/tests/vulkan/stage1_fixture.zig: Every m*n is even (word-padded bf16 views)
- zig/tests/vulkan/stage1_fixture.zig: with the 128 randoms the cast views stay word-padded
lean_check read the three header lines as two multi-line comments, so the file failed the lean rule. The three facts do not fit in one 120-column line, so each stands on its own with a blank line between them: no comment is longer than one line and no fact is lost.
stage2_fixture.zig was 617 lines, over the 600-line lean limit, so no case could be added without splitting it. The cases and checkers move unchanged into stage2_fixture_ops.zig and the root re-exports them, so every caller keeps the same API. The tests stay in the root file, so every artifact that imports the fixture still runs them and the test counts do not move.
stage3_fixture.zig was 739 lines, over the 600-line lean limit, so no case could be added without splitting it. The cases and checkers move unchanged into stage3_fixture_cases.zig and the root re-exports them, so every caller keeps the same API. The tests stay in the root file, so every artifact that imports the fixture still runs them and the test counts do not move.
zig/src/vulkan/gdn.zig was 635 lines, past the 600-line lean limit. The six geometry plans (split, conv prefill, conv decode, the prefill recurrence, decode and the gated norm), the cast32 helper they share and their seven host tests move to zig/src/vulkan/gdn_plan.zig. gdn.zig keeps every plan name reachable under the same name through re-exports, so vulkan.gdn.splitPlan and the rest are unchanged for callers, and the plan tests still run in the vulkan module's own test binary. gdn.zig is 462 lines and gdn_plan.zig is 197. The moved code is byte-identical apart from the re-export lines, and the test counts do not move: vulkan-host-test reports the same 215/217 tests passed (2 skipped) and the same per-binary counts (60, 6, 6, 11, 2, 11, 9, 3, 17, 8, 2, 21, 24, 35 + 2 skipped). The lean checker no longer reports this file's line-count finding, and a plain zig build still succeeds.
zig/tests/vulkan/contract_datamove.zig was 646 lines, past the 600-line lean limit. The fixture rig (the guarded device buffers, the guard pattern and the payload views), the little-endian byte helpers and the failure-message buffer move to zig/tests/vulkan/contract_datamove_rig.zig. The contract file keeps every name reachable under the same name, so contract_datamove_main.zig and the contract's own gates are unchanged. contract_datamove.zig is 536 lines and contract_datamove_rig.zig is 122. The moved code is byte-identical apart from the pub markers the cross-file use needs, and the datamove host suite keeps its two tests: vulkan-host-test reports the same 215/217 tests passed (2 skipped), and the datamove contract build (stage1-gpu-build) succeeds with the same 25/25 steps. The lean checker no longer reports this file's line-count finding.
zig/tests/vulkan/qwen35_model_probe.zig was 646 lines, past the 600-line lean limit. The receipt shape (the result.json fields, the repeat and oracle echoes), its JSON writer, the execution-mode labels and the receipt's round-trip test move to zig/tests/vulkan/qwen35_model_receipt.zig. The probe keeps every name reachable under the same name, so the result.json bytes it writes are unchanged. qwen35_model_probe.zig is 558 lines and qwen35_model_receipt.zig is 98, which leaves room for the three lines the next change adds. The moved code is byte-identical apart from the pub markers the cross-file use needs, and the probe keeps its nine tests: model-host-test succeeds with the same 6/6 steps and vulkan-model-probe-build with the same 31/31 steps. The branch's lean checker now reports 463 problems against the 466 baseline, with none in the touched or the new files.
zig/build/vulkan.zig held every stage's build steps in one function and had grown past the house's 600-line lean limit. The per-stage and per-contract steps now live in zig/build/vulkan_stages.zig, one function per stage (hostAdmission, probeSteps, stage1 to stage5, contracts, kernelContract), called from vulkan.zig in the order the steps are created. The shader lists, the server's modules and the backend module stay in vulkan.zig, which the new file reads, the way vulkan_model.zig already reads it. Every step name, option and install path is unchanged: `zig build --help -Dvulkan=true` lists the same Steps and the same -D options before and after, and the 472 moved lines are verbatim apart from the context fields they now read. vulkan-host-test, stage1-gpu-build, stage3-gpu-build, stage5-gpu-build, tf-vulkan-kernel-contract and vulkan-model-probe-build build and pass, installing the same artifacts under zig-out.
zig/kernels/vulkan/omarchy_trig.h carried 29 multi-line comments: one run of 27 lines over the header and one of 4 over the tan wrapper. Each is now one line of at most 120 columns, the form the house's lean rule takes, and the code lines are untouched. The shader that includes it compiles to byte-identical SPIR-V (fast_rope.comp, -DUSE_BF16 -DASH_QWEN35). The facts the one-line comments keep: - the attribution: copied from the mlx-omarchy overlay's omarchy_trig.h, MIT, full text in LICENSES/mlx-omarchy-MIT.txt. - why: the built-in sin/cos/tan lose upstream accuracy above ~1e3 and collapse past ~1e6 (llvmpipe past ~1e7, measured), so every trigonometric argument not bounded by construction goes through these wrappers. - what: accurate to OMARCHY_TRIG_LIMIT, NaN above it, never a wrong finite value, and the raw built-in stays bit-identical below OMARCHY_TRIG_BUILTIN_MAX. - how: Cody-Waite with C1 = 6.28125 = 201 * 2^-5 (8 significant bits), exact for |k| <= 83601 and so for every argument up to 525371.9; the rest is a dyadic 2^-9 (exact for all k) plus two f32 correction terms; the three-subtract chain is marked precise so a driver may not reassociate it (Honeykrisp has a documented inexact-constant-reassociation defect); above the limit the argument leaves the exact-product zone and the wrappers return NaN. - tan reduces through the 2*pi-periodic sin/cos forms, which are exact period shifts, so the reduced argument serves; the relative error grows near the poles as at the built-in.
The stage 4 fixture (1035 lines) and probe (950 lines) each broke the 600-line lean rule, and the fixture's two-line header was a multi-line comment. The fixture is now four files (the shared core, the split fixtures, the state fixtures, and the root that keeps the public surface and the host tests) and the probe three (the shared helpers, the gates, and the root), all under 580 lines. Each file reaches the others through @import inside the same module, so zig/build/vulkan.zig is unchanged: the stage 4 host test still runs stage4_fixture.zig as its root, and the probe executable still roots at stage4_probe.zig. Every line of code is the original line, moved. The only new tokens are the import aliases, the pub on the helpers the parts share (violated, poisonedShell, f32Of, the gate and buffer helpers), and the one-line file headers. The fixture root re-exports the whole public surface (fx.Split, fx.SplitOne, fx.Conv, fx.RecurWalk, fx.Recur, fx.Decode, fx.Norm, fx.Model, fx.c, fx.budget, fx.gateRefAsh, fx.sampleDyadic, fx.tokens), so the probe and contract_gdn.zig are untouched; the probe root calls the gates through the gates module. Proven: tools/zig/lean_check.py reports no problem for any stage4_*.zig (the repo total falls from 466 to 463). `zig build stage4-host-test -Dvulkan=true` passes with the same 60 + 9 tests, `zig build stage4-gpu-build -Dvulkan=true` compiles tf-stage4-gpu, and `zig build test -Dvulkan=true` gives the identical summary before and after (543/549 steps, 2273/2313 tests; the 37 failures are the pre-existing originals_test ones, the same at the base commit). zig fmt --check is clean.
contract_gdn.zig was 1611 lines, over the 600-line lean limit, so no case could be added without splitting it. The served shapes, the specs and the f64 references move unchanged into contract_gdn_ref.zig, the fixture's buffers and launches into contract_gdn_ops.zig, and the host fills, references and upload order into contract_gdn_host.zig; the root re-exports them, so every caller keeps the same API. The tests stay in the root file, so every artifact that imports the fixture still runs them and the test counts do not move.
weights.zig: remove the .full_every = 4 admission pin and its drift-test field. The Spec field was removed in 89dff3d, so the pin no longer compiles on this branch. backend.zig: prefillStepFn takes the lanes contract argument max_rows (zig/src/core/lanes/backend.zig) and caps the prompt chunk when it is nonzero. Zero means uncapped. The host test passes zero. Proof, all with -Dvulkan=true on this branch: - zig build qwen35-model-host-test: 38/38 steps, 7/8 tests passed (1 skipped). - zig build: 31/31 steps succeeded. - zig build test: the only failing tests are core originals_test (12) and server slide_forget_test (1). The same tests fail on the base commit a24b24f on this filesystem, which refuses reflink clones (cp --reflink=always: Operation not permitted), so originals clone fails with CloneFailed. Those failures are environmental and predate this commit. (cherry picked from commit 845030f)
…es for the oracle Each shader taken from omarchy-mlx now opens with its source path and commit, what changed, and the copyright line; THIRD_PARTY_NOTICES.md lists every such file. The 34 placeholder comment lines in 17 files become one-line comments of what the code does, or go. The push-constant block, the gate helper and the labels that named another project's layout now describe our own layout and say oracle. No code changes. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
…t line ashhart's ashhart#1544 review item 3: every copied shader header and THIRD_PARTY_NOTICES.md now reads "Copyright © 2026 Joshua Warren; MIT", matching the statement on ashhart#1990, instead of the contributors form.
The port serves "vulkan" as a --backend choice (cli.zig line 136), so the
config-file case that expected the invalid-choice refusal for 'vulkan'
stopped testing the choice check: on builds without -Dvulkan it passed
the choice check and hit the not-served refusal instead. Use an unlisted
backend name ('vbogus') so the case tests the invalid-choice refusal on
every build. Step test-serve-flags-host green locally.
|
The
Gate: |
|
Thanks @joshuaswarren. The The two remaining landing requirements are still open. The notice continues to identify imported shader implementations; the copyright correction does not replace those implementations. The earlier comparison also reports four of nine prompts diverging from serial. The later paired-port and serving checks do not establish serial equality for this head. Please replace the imported shader implementations with code of your own (a notice doesn't make copied code acceptable here), fix any numerical differences, and post exact serial token counts for the final head, including the formerly divergent prompts and chunk boundaries. The published MLX checkpoint is fine as loaded. The build is opt-in; the shared CLI choice list still changes for other binaries, which continue to refuse Vulkan selection.
|
|
The two remaining requests are scoped and will land in the next push: (1) a test that calls Kernels.load directly and asserts the enablement call is present, so removing it fails; (2) a fresh-vs-cached-prefix comparison test. CI is green at head 08b13c4 (all four matrices pass). Will push both tests within the next lane window. |
What this changes
Follows #1526 (the Vulkan runtime, the Q4 projection and its kernel-contract runner), which is merged; part of #1420. Rebased onto main 14c907b: 29 code commits and 3 style commits (zig fmt, one-line comments, the changelog entry). This adds the rest of the native Vulkan backend for one model: dense Qwen3.5-2B, MLX Q4 group 64, one GPU, one stream, greedy decoding, built only with
-Dvulkan=true. It supersedes #1517, which stays open as a draft until you say to close it. Outside the Vulkan files nothing changes in the default build.-Dcontract-rootselects the GDN one): QMM (Vulkan base: runtime and the Q4 projection registered in the kernel contract (opt-in) #1526), datamove (7 kernels: Q4 dequant, two gathers, two casts, two copies;tf-stage1-datamove), attention (RoPE and SDPA at the served shapes;tf-attention-contract), greedy (the composed draw and its planted control;tf-vulkan-greedy-contract), pointwise (six closures: norm, add, preserve-add, SwiGLU, the attention output gate and the gated RMSNorm;tf-contract-pointwise), GDN (8 kernels, 5 planted controls; the kernel-contract runner built with-Dcontract-root=zig/tests/vulkan/contract_gdn_main.zig).Receipt
SUMMARY ... 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 caught, 0 missed; 0 limit failureson all three chips (gates 11159 ms on the M1 Max, 11071 ms on the M2 Max, 10950 ms on the M1); gate 2 reads the real kernel's four input buffers back from the device, and two planted controls (a write to its weights, a write to its biases) are red at repeat as planted. Datamove:RESULT datamove ...: kernels=7 passed=7 failed=0 controls=0 known=0on all three. Attention:RESULT attention-contract ...: passed=15 total=15on all three (worst 0.386 of the bound on the 32-row prefill case, M2 Max). Greedy:SUMMARY vulkan greedy contract ...: 1 kernel, 1 pass gates 1-4, 0 fail; 1 control: 1 red as planted, 0 missedon all three. GDN:SUMMARY ... gdn group: 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 caught, 0 missed; 0 limit failureson both (the planted controls print FAIL lines, each one caught); the limits lines are the same on all three: Honeykrisp Mesa 26.3.0-devel, subgroup size 32, 1024 invocations, 32 KiB shared memory, storage range 2147483647, storage offset alignment 16. Pointwise:RESULT contract-pointwise ...: passed=16 known=1 total=17on all three, with one KNOWN finding (below); its gated-norm gate (tokens x 16 head rows of 128, 1 and 32 tokens) is within 0.08 of its bound on every chip. The first device runs of that tip failed a number of cases that were bugs in our own contract runners or shaders, all fixed in this PR: odd 16-bit edge shapes (a 16-bit range of an odd element count cannot be bound; the casts and the u16 copy now refuse those edges and the gates count them as refusals, the served shapes are all even); a guard pattern the greedy rig never uploaded; the pointwise add built as the bf16-storage variant while the fixture modelled f32; a GDN upload slicing past the buffer; and a gated-norm fixture at the wrong geometry. One was a real shader bug the contract found: the bf16 store helper in three GDN shaders turned an infinity into a NaN (a planted +inf gate input gave NaN where float64 gives 0); the helper now matches the other shaders (isnan), finite values are unchanged, and a direct exp(-inf) probe on the M1 showed the driver itself returns the right values.a8b888dd(output byte-identical to this PR's unbatched engine) and on a compensated split-K variant. Under the frozen scorer the absolute ceiling is exceeded for both builds: document-256 max |V-R| 3.93 (serial) and 3.49 (split-K), both on row 28, and document-1024 max |V-R| 1.34 (serial, row 57). The scorer stops at the first case that breaks the ceiling, so there is no pooled number for the held packet. capacity-7105 (7105 prompt tokens, context 7168) is a mismatch against Ash on one id, at row index 1, for both builds; its rows are within the ceiling (max |V-R| 0.26 to 0.28). Nothing is relabelled and the policy is not changed.SUMMARY ... 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 caught, 0 missed; 0 limit failureson all three; datamovekernels=7 passed=7 failed=0; stage 1passed=13 total=13. capacity-7105 was not re-run on this head. The attention, greedy, pointwise and GDN contract runners were not re-run on this head; their lines above are from the earlier build.-Dvulkan=trueno Vulkan step is added); the server over this PR's source (the earlier server run, 14 reviewed HTTP and lifecycle cases and two isolation proofs, was on the first build before chunked prefill, PASS_WITH_NOT_VERIFIED, and is not repeated here); any other checkpoint, device or driver; AMD/Intel GPUs; sampling; long soak.Checklist notes
speculate=false), so draft equality does not apply.shaderDenormPreserveFloat32 = falseand flushes fp32 denormals, so the preserve-add case that needs a bf16 subnormal sum (0x0002) reads it as 0x0000; the runner prints it as KNOWN only when every mismatch is a subnormal sum read as a same-signed zero and the device reports no denormal preservation; a device that claims preservation and still flushes, or any other mismatch, is a FAIL. The residual-add subnormal class passes under the stage 2 flush policy (flush allowed only on a device that reports no preservation).Update, 9 Nov
3e3c9d21aonw7p/1544-gdn-f32) is ported and pushed as branchw7m/1544-f32-port(tipc30c1c063), stacked on Vulkan: qmm_q4_vec4 reads the 4-bit projection 16 bytes at a time, 34.8% to 43.0% less run time on an M1 with the same logits (stacked on #1544) #1990's branch because the f32 fixtures build on the qmm work there; it lands on this branch's line in stack order.memory.zigis byte-identical to this branch's, so no allocation counters ship. Faithfulness:git diff 3e3c9d21a w7m/1544-f32-port -- zig/contains only the oracle rename, the corrected copyright headers and the q4_vec4 machinery. Gates at the tip:zig fmt --checkclean, the vulkan/stage1-5/model/pointwise host steps and every device build step pass. The device contract battery on a 13-inch M1 is the next step and lands here as receipts. Known pre-existing failure on the base branch, not from this port:slide_forget_test(present onvulkan-qmm-vec4before the port).tf-qwen35-model, sha256e8a7b003c42f7ef93d5226bf81396ec97cccbe2fb44aac19e363cb88dd6d82f3, built 2026-11-07T23:52Z from the f32 working tree, which equals the frozen snapshot plus the counter instrumentation only; its logits hash matches the frozen oracle hash exactly. The frozen packet v4 probe did not run; the packet runner beside the results is fixed to hash the binary it runs and refuse a mismatch.RESULT-HASHES-20261109.md(packet SHA256SUMS27cec477...b2489c77, frozen source1c16f3b0...6bb99f4, frozen probe645f9576...1698e9, scorer5ba819a2...afc649a, three oracle token-id hashes, three frozen input hashes).zig/src/server/cli.zignow lists--backendchoices from the build's served set, sovulkanappears only where the root serves--backend=vulkan.docs/credits.mdnames what the Vulkan dense Qwen3.5-2B engine follows (the frozen dense-lane design, feat: lane kernels for 3- and 2-bit weights (exact drafting on smaller Qwen3.8-27B checkpoints, 3.4x on 3.50 bpw) #34) and that its compute shaders are new work. The planted controls per group are listed in the kernel-contract bullet above.