Repository navigation
Vulkan: prefill chunks of 64 rows, 5% to 11% less run time at 1024 and 7105 tokens on four GPUs with the same outputs (stacked on #2038) - #3401
Conversation
…to 32-column tiles A decode step reads each weight row k/2 bytes apart, so every 16-byte load of a 32-lane group touches 32 cache lines. The new image reads the same vectors from a tile layout, [tile][k/32][lane] for the words and [tile][group][lane] for the scales and biases, so a group's load is one 512-byte run. The loop, the order of the sums and every value are qmm_q4_vec4's; only the address formulas change. vk.tile repacks on the host (pure moves of 16-byte vectors and 2-byte scales). The Qwen3.5 loader tiles each projection whose n is a multiple of 32 and whose words fit one binding, when the arena alignment keeps x 16-byte aligned, and Quant.tiled sends it to ops_q4.projectTiled. The tied lm head is a second, tiled upload of the embedding table: the embedding gathers rows and keeps the row layout. Projections that do not fit (n = 16, devices with a small storage range) keep the vec4 image. stage1_probe runs the tiled image on every tileable projection case and requires bytes equal to the default image; the fixture gains four served shapes (n 4096 and 6144 at k 2048, n 2048 at k 6144, m 1 and 32). Proved by: every Vulkan host suite passes; stage 1 probe 21 of 21 on a software Vulkan device with the tiled image identical on all 6 tileable cases there. Not measured on a GPU yet.
…tes as qmm_bf16 The contract runner gets a launch record and a fourth fixture for the tiled image. Its inputs are repacked into 32-column tiles after the float64 reference is computed from the row layout, so the same served shapes, bound, guards and input checks apply. Shapes that cannot be tiled are refused like the other edges the kernel does not serve. The fixture's kernels table is now 10 entries. Proved by: the runner builds and its limits gate passes for qmm_q4_tile on a software Vulkan device (which cannot hold the large shapes). The SUMMARY lines on the Apple GPUs are in the receipts commit.
…with zero columns The kernel contract refused qmm_q4_tile on 1x16x64: a registered kernel must serve every shape the contract serves, and n = 16 is not a multiple of 32. The repack now stores n rounded up to whole tiles and fills the extra columns with zeros. The kernel never computes a column past n, so no sum changes. The loader tiles every projection whose padded words fit one binding, including the n = 16 ones, and projectTiled checks the padded geometry. The contract fixture and the stage 1 probe size their buffers the same way. Proved by: every Vulkan host suite passes; stage 1 probe 21 of 21 on a software Vulkan device with the tiled image identical to the default image on all 11 cases that fit one binding there (n 8, 16 and 257 included).
…-inch M1 The receipts folder holds the identity probe (21 of 21, the tiled image byte-identical on all 12 projection cases), the contract runner's output (3 kernels pass gates 1 to 4, 8 of 8 controls caught), the pre-registration with its addendum, a summary generated from the raw run files, and the SHA-256 of each raw file. Against the vec4 build a run took 19%, 50% and 63% less time on three inputs, with the same logits digest in all six processes of each case.
… keeps its name Layers 0-3 store f32. The restack tiled every projection and handed those views to qmm_q4_tile, which reads packed bf16. projectTiled now refuses a non-bf16 view, and the loader keeps row weights unless the layer's activations are bf16. Fixture.kernel applies the name field again, so vec4 and tile no longer report as qmm_bf16. Proved: zig build stage1-host-test model-host-test -Dvulkan=true, 87/87 steps succeeded. The new tests failed first (expected error.Invalid, found void; fixture name stayed the default).
The first figures (19%, 50%, 63%) came from heads before the float32 fix, on an older kernel and Mesa build. On the fixed heads, on a 13-inch M1 with Linux 7.3.0-2-20261110.1-lab-ARCH, the three cases took 10.9%, 35.6% and 44.9% less time than with qmm_q4_vec4 (three pairs each, one logits digest per case). The gain depends on the environment; these runs do not separate the cause. The stage 1 probe and the kernel contract output are from the earlier builds and were not re-run. Signed-off-by: joshuaswarren <816217+joshuaswarren@users.noreply.github.com>
The f32 layers kept row weights because qmm_q4_tile only read bf16 x. ACT_F32 builds the same accumulation over tiled words, so every layer tiles. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
A planted-input fixture runs qmm_q4_tile_f32 through gates 1-4 with f32 activations: x is the bf16 values widened exactly, and the output is f32 with the same guard words. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The zig lean check allows one-line comments within 120 columns only. Comment change, no code change. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
…le_f32 Adds the P-core pinned ashhart#1990 against ashhart#2015 timing on the 13-inch M1 (28.6%, 54.4%, 66.8%, equal logits digests), the output of the ten contract and stage runners at 2a5a06c including qmm_q4_tile_f32, and replaces the earlier-build kernel contract and identity probe files. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
…ce per batch Every Pipeline.run was its own submission with a fence wait. On a 13-inch M1 the 31,104 dispatches of a 64-step Qwen3.5-2B run (486 a step) cost about 90 us each in submit and wait alone, about 40 percent of the run. Run now records into the open command buffer and Commands submits when 128 dispatches are waiting, or when the next upload, download or fill needs the queue, so a readback still sees every earlier dispatch and no kernel's arithmetic changes. A pipeline holds a ring of 256 descriptor sets: bind fills the next one and record binds the current one, so a set is never rewritten while a recorded dispatch still uses it (a flush at 128 keeps the ring from wrapping). Commands.begin returns the open buffer instead of resetting it; submit with nothing recorded is a no-op. Proved by: every Vulkan host suite passes; stage 1 to 5 probes on a software Vulkan device: 21 of 21, 9 of 9, 4 of 4, 6 of 6 and 7 of 7. Not measured on a GPU yet.
…on a 13-inch M1 The receipts folder holds the stage 1 probe on the GPU (21 of 21, the tiled image equal to the default image on all 12 projection cases), the contract runner's output (3 kernels pass gates 1 to 4, 8 of 8 controls caught), the pre-registration, a summary generated from the raw run files, and the SHA-256 of each raw file. Against the tile build a run took 68%, 49% and 30% less time on three inputs, with the same logits digest in all six processes of each case.
…nd that the fence timeout covers a batch
…ontracts gates.runAll converts every kernel error, Timeout and InFlight included, into a FAIL verdict. An unguarded GPU call let a fence timeout unwind into the rig's frees and vkDestroyDevice with work possibly in flight, instead of the tree's exit-124 and exit-1 doctrine (commands.zig:104,122). Guard the datamove rig's upload and download and the four fixture launches with vk.orExit. In the greedy contract the draw arm returned select()'s Timeout and InFlight past the fixture boundary and the control arm submitted raw; guard both. A NonFinite refusal still reaches the refused marker. Host tests lock the swallowing channel and the refusal.
…t call fails A host allocation can fail between a recorded dispatch and the submission that drains it. gates.runAll catches the error and the next prepare frees buffers the still-open command buffer references, so a later submit would dispatch on freed device memory. Commands.discard resets the open command buffer and clears the batch state. The qmm fixture and control, the datamove rig, the greedy rig and its device teardown call it before they free anything. Two failures left the stream usable after it should be terminal, and a gate wrapper that catches and continues could reuse it. A vkResetFences failure after a signaled wait left the fence signaled, and a failed vkEndCommandBuffer left an invalid open buffer for the next begin. Both now store a terminal error in Commands: begin and every later submit refuse without recording or queueing, and vk.orExit ends the process. Host tests drive discard through a stubbed vkResetCommandBuffer and force each failure. A further test plants a failed host allocation on the qmm fixture's and the control's allocator, then resets each with a dispatch still recorded. Without discard in those resets the dispatch stays open and the test fails.
Comment-only change: each two-line comment in the Vulkan sources becomes one line of at most 120 columns. Lean check drops the 13 multi-line comment problems this branch adds versus main; no code changed. Checked: lean_check adds zero problems versus main; vulkan-host-test 75/75 steps, 228/230 tests, 2 skipped.
The first figures (68%, 49%, 30%) came from heads before the float32 fix, on an older kernel and Mesa build. On the fixed heads, on a 13-inch M1 with Linux 7.3.0-2-20261110.1-lab-ARCH, the three cases took 57.8%, 34.1% and 16.6% less time (three pairs each, one logits digest per case). Earlier builds of the 256-token document in the same environment gave 20.5%, so the gain depends on the kernel and Mesa build; these runs do not separate the cause. The stage 1 probe and the kernel contract output are from the earlier builds and were not re-run. Signed-off-by: joshuaswarren <816217+joshuaswarren@users.noreply.github.com>
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> # Conflicts: # CHANGELOG.md
|
[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 ec445f5, 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. |
|
[Joshua's agent] The lean check failed on this head after the last merge of main: two comments went past 120 columns (engine.zig and qwen35_model_probe.zig). New head: a19c05f. Comment text only, no behavior change, pushed as a plain commit with no rebase. |
|
Thanks @joshuaswarren. The engine, GDN scan and served prompt cap now agree on 64 rows, and the device comparisons support the chunking change. Please post a serial greedy server comparison against the parent at the 32- and 64-row seams, including streamed/nonstreamed replies, cancel/reset followed by a fresh request, token hashes and prompt progress. The 7105-token free-running reference mismatch remains an open parent gate; teacher forcing does not close it. This stays on hold until that receipt and the required zig, zig-windows, pytest and fmt jobs are green at a19c05f. Please include the final build hashes with the receipt.
|
|
[Joshua's agent] Read, thanks. I will post the serial greedy server comparison against the parent at the 32- and 64-row seams: streamed and non-streamed replies, cancel/reset then a fresh request, token hashes, prompt progress, and the final build hashes at the head I test. I am not claiming anything on the open 7105-token free-running parent gate; I will report what the comparison shows there and treat it as open. Required jobs at the final head will be checked before I say it is ready. |
|
[Joshua's agent] Ready note: the serial greedy server comparison is done on a 13-inch M1, parent 692b4c3 vs head a19c05f, five consecutive clean runs. What ran: serial (one request at a time) greedy decoding, temperature 0, thinking off, 64 reply tokens per prompt, streamed and non-streamed replies compared per prompt. Fit targets the /v1/tokenize count; the served render adds 2 template tokens, so I fit 2 under and state both counters per case. Reset between main and repeat is a server restart (the server exposes no in-process session reset; /health?reset_peak=1 resets memory gauges only). First-token ms and usage.prompt_tokens stand in for progress (no request-progress route exists). Boundaries, server prompt tokens with streamed-vs-nonstreamed equality and matching token hashes on both binaries: 31/32/33, 63/64/65, 96, 128 all exact; stream_eq true everywhere, e.g. 32-token seam hash d49cad4f174bc17f and 64-token seam hash 775321d540504d9a identical parent vs head. Mid-stream cancel then fresh, and restart then fresh, both MATCH the uninterrupted reference. The 7105-token report-only arm generated 64 tokens on both binaries (ids 47324ea6222b1fe0, text 00e1a52193085e22); fit 7102 renders 7104 server-side, +64 = exact 7168 fill. Two findings, not failures: prompts fitting tokenize-count 127 and 129 cannot render exactly (counts jump 126->128 and 128->131 across one char); the cases record actuals and the runs continue. Nothing in this run record closes the open 7105-token free-running parent gate; that stays open. CI at this head: 8 success, 2 skipped (host-nightly). Run record files: w7P-seam3401-.receipt (VERDICT DONE) with the four case JSONs on the 13-inch host. |
|
@joshuaswarren, the chunking change is supported by the device comparisons - the engine, the GDN scan and the The PR stays on hold for the serial greedy server comparison against the parent at the 32- and 64-row seams: Post that receipt with the four jobs green at the head you test, and it returns to the landing queue.
|
|
[Joshua's agent] Pointing at the posted receipt: the ready note of 01:12Z already holds the serial greedy 32/64-seam comparison — streamed and non-streamed MATCH at every seam prompt with identical parent-vs-head hashes (32: d49cad4f174bc17f, 64: 775321d540504d9a), cancel-then-fresh and reset-then-fresh MATCH, five consecutive clean runs on the 13-inch M1, and the 7105 arm generating 64 tokens on both binaries with the open parent gate explicitly not claimed. If that receipt is insufficient, the hold needs one new specific: name the missing field and I will run it. |
|
Thanks @joshuaswarren. The posted seam hashes, streamed comparisons and cancel/restart checks already answer those requests. The missing fields are the SHA256s of the two tested server binaries and the per-case prompt counts and first-token timings from that run. Please attach those existing results. We will handle the stack, body and CI checks; the parent reference gate remains open.
|
|
[Joshua's agent] Attaching the missing fields from the posted seam run (13-inch M1, serial greedy, parent vs head, streamed and non-streamed agreeing at every case): Binary SHA256s:
Per-case rendered prompt tokens and first-token ms (streamed; stream_eq = streamed ids and text equal the non-streamed result for that case; every case has stream_eq=true):
The cancel31 case (cancel after 10 tokens, then a fresh completion): fresh ids hash ecde540956b72f28 on both arms, matches the uncancelled reference on both. Parent-vs-head token ids are identical at every seam count, so the seam behavior is unchanged; the first-token deltas above are single-sample timings on an otherwise idle machine and I make no gain claim from them. The 7105-token arm ran with the same 64-token reply as the seam cases. |
…2/vulkan-dispatch-batch # Conflicts: # CHANGELOG.md
…/vulkan-qmm-tile-rows # Conflicts: # CHANGELOG.md
…b2/vulkan-barrier-hazards # Conflicts: # CHANGELOG.md
a19c05f to
c405db2
Compare
c405db2 to
a19c05f
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 |
a19c05f to
98e8995
Compare
|
[Joshua's agent] Measured rows only — from decode A/B runs already completed on the 13-inch M1 (jwm1-linux, Vulkan serve, Qwen3.5-2B Q4); no new runs were made for this comment. Each repetition alternates parent/head (ABBA) and decodes 256 new tokens greedy; "prompt tok" is the harness's rendered prompt token count (fit_tok); values are pooled medians of time-to-first-token in ms. Parent and head produced identical token-id hashes in every completed rep.
Caveats, straight from the receipts: (1) the 2026-11-18 4096-key runs split into two regimes — one s-run at ~44.7k/43.2k ms, the rest ~50.2k/49.4k; pooled median shown, per-run medians are in the receipts. (2) A minority of the 2026-11-18 512-key s-runs ran ~15% slower than their siblings; same handling. (3) The 8192-key row (2026-11-17, 8192x8r1) produced empty generations in all 8 reps — a null result, no timing to report. (4) An earlier 2026-11-17 2048x48r2 attempt was interrupted mid-run; the 2048x48r2b redo above is the completed one. Binary sha256s:
Binary provenance: p3401 was built from 692b4c3 (parent of the PR's first owned commit); h3401 was built from a19c05f, the PR head as fetched 2026-11-15. h3401 is NOT a build of the current head 98e8995: comparing a19c05f...98e8995 reports diverged (ahead 337 / behind 9, merge base 54f9b40). The table therefore covers parent 692b4c3 vs the 2026-11-15 head only; current head 98e8995 is not measured and would need a rebuilt binary. Raw rows and per-run medians: |
|
Rebased onto current main (the branch carried 442 restack-merge commits; now one squashed commit on |
|
[Joshua's agent] Fresh A/B on the current heads, all runs through the jw16-gpu queue as class=perf rows, on the RTX 5060 Ti eGPU (16-inch M1 Max host, PCI 0001:09:00.0, driver nvidia, Vulkan via nvidia_icd.json; gpu-timeouts 0 before and after every row). These are 5060 Ti numbers on a different card from the 13-inch M1 medians already posted — do not mix the two tables. Binaries, built natively on the host (zig 0.17.0,
Method: 5 alternating parent/head pairs (ABBA order) per case, one server process per rep, fitted prompt at the stated server-key target, 256-token serial greedy, temperature 0, first-token time from request start to first streamed token.
Per-rep first-token times — parent: 512 [663, 659, 662, 664, 665], 1024 [1159, 1167, 1163, 1160, 1220], 2048 [2273, 2276, 2275, 2276, 2265], 4096 [5038, 5040, 5045, 5051, 5042]; head: 512 [578, 580, 580, 576, 579], 1024 [982, 980, 981, 981, 1288], 2048 [1945, 1904, 1912, 1907, 1906], 4096 [4273, 4223, 4260, 4230, 4241]. Each side produced one single ids hash across all its reps and both sides agree with each other in every pair. Receipts: Honest notes: the measured gains (12.7% to 16.2%) sit above the 5% to 11% the PR title claims — I report what ran. The 1024 head rep 5 (1288 ms) is an outlier against its four ~981 ms siblings; the median excludes it. One of my queued rows for a later PR was stopped mid-window for another lane's solo run and re-run after; none of the four rows above was touched. CI at 98e8995: not re-checked for this comment; the queue-side receipts above are the new evidence. |
|
Thanks @joshuaswarren for rerunning the current head rather than relying on the older binaries. The five paired runs at each of 512, 1,024, 2,048 and 4,096 keys give identical token IDs between parent and head. The owned change sets both the prefill cap and the GDN scan chunk to 64 rows ( What remains is ours: the diff conflicts with current main in Two contract comments still describe 32-row prefill (
|
Stacked on #2038 (head
0abe3fcf), which is stacked on #2017, #2016, #2015, #1990 and #1544. This pull request owns three commits:5bb25cde(the change),432e77cf(a test bound) andeccdde25(contract cases and the probe label). The stack was brought up to main41a72fd2with merge commits (headb14adaf2); that changed no line of this pull request, and the measurements below used builds from before that merge.A prefill chunk is now 64 rows instead of 32, so a 1024-token prompt takes 16 chunk submissions instead of 32. On a Qwen3.5-2B 4-bit run, this head took 6.6% to 11.0% less time than #2038 at document-1024 and capacity-7105 on four GPUs. On a fifth, the 13-inch M1, it took 3.2% less at document-1024 and 2.5% less at capacity-7105. The outputs of the two builds are equal on every card. Every number in the table is run 2, the second greedy run in the same process (prefill plus 63 decode steps plus the logits readback). Each Apple cell is the median of the per-pair gains over three pairs (old, new, new, old, old, new), except the 13-inch M1 and 14-inch M2 Max document cells, which use five pairs after one discarded warm-up pair. The 5060 Ti and B60 cells use five pairs after two discarded warm-up processes.
The three Apple GPUs run Honeykrisp; the 5060 Ti and the B60 are eGPUs on the 16-inch M1 Max. At document-256 the gain is under 5% on the M2 Max and the 13-inch M1. On the 13-inch M1 the gains are smaller (2.1% to 3.2%) but steady. The document pairs ran at host load 0.39 with 0 GPU timeouts, and this head won all ten. They replace a three-pair run at host load 10.35 (-0.4% and 6.9%, spreads over 10%). The capacity-7105 pairs ran at host load 0.31 to 0.61, and both builds gave ids
b0e5a7cawith the known free-running exit code 1. The 14-inch M2 Max document pairs ran at host load 1.33 with 0 GPU timeouts; all 24 processes exited 0, the digests are equal, and this head won all ten. They replace three-pair cells of 4.8% (old spread 4.1%) and 7.7%. The unicode-24 rows are a control: a 24-token prompt is one chunk at either size. On the 13-inch M1 the two builds are within 0.7% of each other in every pair (12 processes exit 0, digests equal, host load 0.53). On the 14-inch M2 Max they are within 2% in every pair, and each build won some pairs (all processes exit 0, digests equal, host load 1.56, 0 GPU timeouts).The warmed B60 cells replace three-pair cells with no warm-up process (-7.2%, 8.3% and 11.2%, old spreads up to 73%). This head won all 15 warmed pairs, with 0 GPU timeouts. The B60 spreads are still wide (11.6% to 39.2%) because a job ran on the 5060 Ti of the same host during every document process and during part of the first three capacity pairs. Capacity pairs 4 and 5 ran alone and gained 11.3% and 9.2%. The logits digests are equal across builds in every process:
8901e17cat document-256,a472a62cat document-1024, and ids9164970aat capacity-7105 with the known free-running exit code 1.The 5060 Ti document-1024 cell replaces two earlier three-pair cells (9.7% and 9.3%) that had no warm-up process. The first process on a cold card is slow on both runs: in the warmed run the first warm-up process took 10583 ms on run 1 and 2380 ms on run 2, against about 5000 ms and 1900 ms after it. With the two warm-up processes discarded, the new build won 4 of 5 pairs on run 2. The median per-pair gain was 6.6%. The arm medians were 1905 ms and 1695 ms, so this head took 11.0% less time. The old spread of 19.7% comes from one slow old process (2151 ms against 1797 to 1906 ms). Run 1, the first greedy run in each process, showed no gain on the 5060 Ti once warm: the arm medians were 5047 ms (#2038) and 5167 ms (this head). The warmed run used
fea34bb7, whose tree equals432e77cf.The warmed 5060 Ti document-256 and capacity-7105 cells replace three-pair cells with no warm-up process (-0.7% and 5.4%). This head won all ten warmed pairs. No job ran on the other eGPU during this row, and there were 0 GPU timeouts. At document-256 all 12 processes exited 0 with logits digest
8901e17c; at capacity-7105 all 12 processes of both builds gave idsb684d7edwith the known free-running exit code 1.The whole stack, #1544's base (
8267ec10) against this head's build (run 2, five pairs after one discarded warm-up pair, host load 0.20 to 1.28, 0 GPU timeouts, all processes exited 0, equal digests):At unicode-24 the base arm's spread is over 5%, so its exact size is not firm; every pair gained over 91%.
What changes
max_prefill_rowsgoes from 32 to 64 (engine.zig). The GDN scan chunk follows the prefill cap, because a 64-row prefill with a 32-row scan chunk would need interior snapshots the forward pass does not pass (forward.zig). The arena grows to 16 MiB for the 64-row linear layer (about 11.1 MB of transients).chunkCounttests move to 64-row boundaries, and theextractQPlantest usesmax_prefill_rows + 1.result.jsonsays"chunked"instead of"chunk32";prefill_chunk_rowsalready carries the row count.Checks
b0e5a7ca, 5060 Tib684d7ed, B609164970a). Teacher-forced runs of the chain heads on the 16-inch M1 Max (oracle ids fed as the previous token, six builds) mismatch at step 1 only. So at capacity-7105 the oracle check is the teacher-forced mode, and the speed comparison uses Vulkan: a dispatch records a barrier only when it conflicts with an earlier one, 2% to 20% less run time on an M1 and an M1 Max with the same logits (stacked on #2017) #2038 as its reference. A regenerated oracle would not fix this, because the tie decides which of two near-equal ids wins on each GPU.qwen35-model-host-test,stage3-host-test,contract-pointwise-host-test.Not covered
CHANGELOG.md: the line is Ash's to write.Part of #1420.