Repository navigation
Vulkan: batch the remaining per-step, prefill, readback and reset submissions, 3% to 8% less run time on an M1 Max and 19% to 26% on an RTX 5060 Ti - #5193
Conversation
2a7a02e to
71d1bf1
Compare
|
Thanks @joshuaswarren. This submission batches per-step, prefill, greedy-readback, and reset work without changing shaders itself. The submitted stack nevertheless still contains the same omarchy-mlx code identified in the #5215 review: 18 explicitly noticed shaders/headers, including STOP on that inherited provenance. Preserving the MIT notices does not make copied or adapted engine code eligible. The lower stack needs the documented-behavior rewrite and the related correctness/attention fixes before fresh exactness evidence is useful. Your plan to keep #5193 open is the right one. After the rewritten base exists, we handle this submission's rebase. No new device run is needed before then.
|
9afd525 to
6255bf2
Compare
|
[Joshua agent] Rebased onto the clean-room
|
|
/atc depends 2038 |
|
Thanks @joshuaswarren. The provenance rewrite holds up: the remaining
The final nine submission files otherwise preserve the requested descriptor, hazard, base-position, greedy and reset semantics. This was a source-only review; I did not run builds, shaders or devices. We rebase for contributors.
|
|
A correction to my note above, @joshuaswarren: main's
|
…rted preservation
… -Dcontract-root option The contract runner built only the Q4 projection's shaders. Each later operator registers in the same runner, so it now imports the stage 1 to 5 shader modules (norm, rope, attention, GDN, greedy and the data-movement kernels) that the operator probes already build, and the stage modules are hoisted out of their probe blocks so both can share them. -Dcontract-root points the runner at another root file, so one operator group can be built and run on its own.
…nel contract The stage 4 GatedDeltaNet images (conv_dw1d, gdn_conv_decode, gdn_split, gated_delta_prefill_ash and gated_delta_decode in its ASH_QWEN35 raw-gates mode) register as eight kernels through the production Gdn wrapper, so the wrapper's binding tables — the read-only g slot and the single-chunk snapshot dummy among them — are the ones under test. f32 state flows in and out of place, the interior chunk snapshot is bound exactly when chunks exceed one, and the decode loop chains the carried state. References are the stage 4 fixture's f64 walkers made parametric in tokens; every depth a spec states is a function of the token count (one ~130-deep state update per token, the fixture's stated derivation). The f32 state parts prove fp32 sums with an engineered stress fill whose kv partials overflow fp16; the bf16 parts declare bf16=0 with the reason the output's own rounding hides the sum error, as HIP's mamba and CUDA's gdn_prep do. The host suite cross-checks the walker against the fixture's bit for bit and proves the generated fills against the references without a GPU. contract_gdn_main.zig runs the group alone via -Dcontract-root and prints the same LIMITS lines, records audit and runAll tally as contract_main, plus live local-size and shared-memory evidence for all seven pipelines. Proven: zig build vulkan-host-test (20 gdn contract tests, walker parity with fx.RecurWalk/fx.Decode, stress fp16 margins >= 100x); both contract runners build; the runner refuses the software Vulkan device fail-closed. GPU gates 1-4 pending on the M1/M2 devices (none reachable from this host: llvmpipe only).
…e run Three fixture bugs the M1 Max's first run surfaced, none of them shader bugs: the split parts uploaded one combined output buffer where the wrapper binds soa, g and beta separately (OutOfRange on every gate); the decode conv's unchanged-check listed the host chain scratch as an input while indexing one device buffer fewer, so input_now's tail was never filled (a false 'a run changed its inputs'); and the prefill recurrence's random fill used the stage 4 fixture's ranges, which only ever ran at 8 tokens - at 130 the walk outgrew f32. The random fill now decays (g, beta and the whole soa at 2^-3 scale or less), so any token count stays bounded. Also the sums replay the gates ran: every dot re-summed in the requested accumulator and order, the conv chains replayed from the uploaded initial state, exactly as computeWant walks them. Proven: vulkan-host-test green; runAll on Apple M1 Max (G13C C0) Honeykrisp - prefill conv, decode conv and decode state pass gates 1-4 fully; prefill y, hf+snap and split classes settle with the fill fix pending the next device run.
…the soa sums proof The M1 Max run showed the split g shapes gate failing where a random a_log above ~2.4 drove g into f32 subnormals the device flushes - the exact case the stage 4 fixture's census deferred to Main. The served random fill now draws a_log in [-6, 0] (g >= e^-4.5, normal), with the census case named in the fill; the subnormal-flush decision stays with Main. The split soa sums gate moves to f16=0 with the measured reason: the fixture budget's magnitude term at the output's scale is wider than any fp16 miss the stress can engineer, and gate 3's shapes already bound the norm's sum to f32 quality (a bf16-summed ss misses ~2^-8 relative against an observed worst of 0.037 of bound). Proven: vulkan-host-test green.
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.
…clean-room qmm.comp
…dy shaders for ashhart#1544 Rewrites the omarchy-derived Vulkan compute shaders from the behavior spec, from cast/copy through the gated-delta state machines to the argreduce pair. omarchy_trig.h becomes vulkan_trig.h (single inv_freq helper, Synthena #6), gated_delta_prefill_ash becomes gated_delta_prefill_oracle, accepting both -DASH_QWEN35 and -DORACLE_QWEN35. PRESERVE_F32 requests OpExecutionMode DenormPreserve (f32) via spirv_execution_mode; sdpa_decode_native pins the single-key bit-exact V transport (Synthena #7) and the 7168-key shared bound. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…x SDPA & composed baseline
…ows_f32q contract (ashhart#1990)
6255bf2 to
e65e777
Compare
|
Thank you @joshuaswarren. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
- binary_vec.comp: bf16_add_bits integer path is only safe for exponent <= 7 (32-bit accumulation overflows at exponent 8); larger operands take the fp path, which is exact there since no sum can be subnormal - stage2_fixture_ops.zig: classes case plants the reported failing pair (0x0500+0x0500 -> 0x0580) plus a sweep around the exponent 7/8 bound - vulkan probe: compile qmm.comp -DACT_F32 and upload scales/biases as bf16 u16, matching ops_q4.zig's ABI; probe fails when the compiled binding widths and the fixture disagree - qmm/q4 shaders + gdn_split: rewrite the imported bf16_store as stack-local q4_bf16/bf16_rne (truncate-then-carry RNE) now that the omarchy-mlx notice is gone
|
All three confirmed and addressed; thank you for the close read, especially the license catch.
Fixes are open as #5579. |
- binary_vec.comp: bf16_add_bits integer path is only safe for exponent <= 7 (32-bit accumulation overflows at exponent 8); larger operands take the fp path, which is exact there since no sum can be subnormal - stage2_fixture_ops.zig: classes case plants the reported failing pair (0x0500+0x0500 -> 0x0580) plus a sweep around the exponent 7/8 bound - vulkan probe: compile qmm.comp -DACT_F32 and upload scales/biases as bf16 u16, matching ops_q4.zig's ABI; probe fails when the compiled binding widths and the fixture disagree - qmm/q4 shaders + gdn_split: rewrite the imported bf16_store as stack-local q4_bf16/bf16_rne (truncate-then-carry RNE) now that the omarchy-mlx notice is gone
Stacked on #2038 (head
7a81e167d9191db7f9940afb7a707d809ec98df8). This pull request owns one commit:2a7a02e968f0. The commits below it belong to #2038 and the PRs under it.On Qwen3.5-2B 4-bit, batching the remaining per-step, prefill, greedy readback, and state-reset queue submissions cuts run 2 time by 3.0% to 8.4% on a 16-inch MacBook Pro (M1 Max, Honeykrisp) and by 25.1% to 30.5% on an NVIDIA GeForce RTX 5060 Ti eGPU. Run 1 (without
Engine.reset()) drops 2.9% to 7.1% on the M1 Max and 11.2% to 20.3% on the RTX 5060 Ti. Every run matches the #2038 baseline bit for bit on both logits and token IDs, and no shaders change.Measurements
Each cell is the median (min to max) of 5 interleaved ABBA pairs (10 measured processes per input, after 1 discarded warm-up pair) with
MESA_SHADER_CACHE_DISABLE=true, 0 failures, and 0 GPU timeouts. Run 1 is prefill plus 64 greedy decode steps with per-step logits readback. Run 2 addsEngine.reset()before the second pass. Total isrun2-doneminusengine-ready.16-inch MacBook Pro (M1 Max, Honeykrisp, Mesa 26.3.0-devel)
NVIDIA GeForce RTX 5060 Ti eGPU (driver 615.78.08)
All 30 measured runs on the 16-inch MacBook Pro (M1 Max) match #2038's published
logits_bf16_sha256digests (e946185d64ae,3188aaae7d11,82c353787e89). All 30 measured runs on the RTX 5060 Ti match the #2038 base binary's digests (d284b8622f0a,c1383d4697ff,d3f9bb0aebf7). Every run matchesgenerated_ids_hash(6bfbb1a55a3e,8901e17ccef7,a472a62c7e22).I also screened a bit-exact
wg32QMM workgroup shrink (qmm_q4_tilelocal_size_x = 32,qmm_q4_tile_rowslocal_size_x = 64), which regressed on the RTX 5060 Ti (+5.2% on unicode-24 and +3.5% on document-1024) and was dropped.What changes and why it is safe
Even with #2038's hazard-tracked barriers, each decode step still forced around 10 synchronous
vkQueueSubmitandvkWaitForFencesdrains: one staged upload for the 4-byte token ID, six repeated staged uploads of the same 4-bytebaseposition infullLayer, mid-step batch flushes at 128 dispatches across a 420-dispatch step, and two submits insideGreedy.select. Prefill added one staged upload per 32-token chunk (32 drains on document-1024), andState.resetran 84+ staged host-zero uploads over the bus.This commit removes those drains across eight files without changing any shader or arithmetic:
zig/src/vulkan/commands.ziganddevice.zig: addfillInBatch(vkCmdFillBuffer),updateInBatch(vkCmdUpdateBuffer, capped at Vulkan's 64 KiB 4-byte-aligned inline limit), andzeroBuffers(one on-GPU zero submission). Before recording a conflicting in-batch transfer,fillInBatchandupdateInBatchcheckcmds.hazards.conflictsand emit a fullgpu_stages -> gpu_stagesbarrier beforecmds.hazards.clear(), so unrelated tracked writes remain visible to later compute dispatches. Non-conflicting calls leavecmds.hazardsintact. Both emit a trailingtransfer -> gpu_stagesbarrier so later compute and transfer commands see the written bytes.zig/src/vulkan/dispatch.zig: raisebatch_maxfrom 256 to 1024 (batch_flushfrom 128 to 512) so a full 24-layer step fits inside one submission while keeping every pipeline well inside its descriptor ring.zig/src/vulkan/attention.zig,forward.zig, andengine.zig: switchAttention.setBasePositiontofillInBatchand hoist it once at the start ofrunLayersinstead of repeating it six times per step. Switchdecodetoken-ID writes tofillInBatchandprefillChunktoken-ID writes (at most 128 bytes) toupdateInBatch.zig/src/vulkan/greedy.zig: fuse the 12-bytevkCmdCopyBuffer(g.resultstostaging) and itstransfer -> hostbarrier into the same submission aftercombine.record'sdispatchBarrier, leaving one fence wait per draw.zig/src/families/qwen3_5/backend/vulkan/state.zig: replace the 16 MiB host-zero upload loop inState.resetwithcommands.zeroBuffers. It checks device ownership and 4-byte alignment on every buffer before recording, records all 84vkCmdFillBuffercalls in one command buffer, and waits on the fence before resettingcommittedandparity.Checks
zig fmt --checkon all 8 touched files: exit 0.python3 tools/zig/lean_check.py: zero findings on all 8 touched files (commands.zigis 587 lines).zig build vulkan-host-test qwen35-model-host-test model-host-test compile-native-vulkan-server -Dvulkan=true: exit 0, including a new host unit test incommands.zigcoveringfillInBatch,updateInBatch, andzeroBuffershazard barriers, inline size bounds, alignment refusals, and submit counts.Not covered
CHANGELOG.md: left for Ash.Part of #1420.
[Joshua agent]