Repository navigation
Metal EXL3 projection: an exact one-row decode kernel for the DeepSeek-V4.1 dense shapes - #5050
Conversation
|
Thanks @BlivionIaG. The one-row mapping and compensated sum keep the existing order, with replacement byte comparisons in place. One setup fix remains: Suite.create does not unwind if probe initialization or either append fails, so it leaks the suite/probes and any acquired pipelines. Please protect each ownership stage and add a failure-path regression, including both appends. The changelog merge is on our side; unchanged arithmetic needs no repeat run for this cleanup.
|
|
@BlivionIaG, about the probe-registration cleanup our review asked for: the same two-append pattern was on main in 85 places, and #5058 (now merged) fixes it there with one helper, errdefer p.deinit(); // with errdefer s.a.destroy(p) after create, as the suite's teardown frees it
try ct.register(s.a, &s.probes, &s.kernels, p, p.kernel());Using it for this PR's new suites closes that item.
|
|
Thanks @ashhart. Merged main and used |
|
Thank you @BlivionIaG. The ownership fix is confirmed: The one-row arithmetic is unchanged. It retains the original placement, ascending-k products, TwoSum statements, and final compensated sum. The byte comparisons against Those review items are closed, and I found no remaining code change to request. The changelog attribution is a landing detail on our side. The supplied current-head Metal checks are recorded; no new device run is needed for this cleanup.
|
b9cb695 to
ba4453b
Compare
One unrouted row now goes through tf_exl3_matmul_row: each lane owns one output column, decodes that column's 16 values of each k tile and adds the exact fp32 products in ascending k with tf_exl3_matmul's TwoSum, so every output bit equals that kernel's, without threadgroup memory or barriers. Tests hold the kernel's decoded W_q bit-equal to exl3_format.zig at every codebook and width and to the oracle's real mcg 8.00 bpw block, and its sums bit-equal to a new serial reference (exl3_projection_row_ref.zig) and to tf_exl3_matmul_hoisted at the eight DeepSeek-V4.1 dense decode shapes. The kernel is registered with the contract as a replacement of tf_exl3_matmul_hoisted with a planted control (the TwoSum error term dropped), and tf-exl3-bench gains a row candidate.
…register A failed probe init, probe-list or kernel-list growth now frees the suite and every probe it took; test-dsv41-exl3-contract fails each allocation of create in turn on this GPU.
ba4453b to
1626323
Compare
|
Thank you @BlivionIaG. 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. |
What this changes
Before: Metal's EXL3 projection ran a decode row through
tf_exl3_matmul_hoisted, whose SIMDgroup owns eight rows and16 columns, so at one row half its lanes idle and every k tile passes through threadgroup memory and two barriers.
After: one unrouted row goes through
tf_exl3_matmul_row, in which each lane owns one column, decodes that column's 16values of each k tile and adds the exact fp32 products in ascending k with the same TwoSum, so every output bit equals
tf_exl3_matmul_hoisted's. The first piece of the DeepSeek-V4.1 EXL3 Metal lane rebuilt on main's own EXL3 code;no family serves Metal EXL3 yet.
on the Metal lane, the indexer, prompt attention and the drafter.
5c71eb84cd); one commit,b9cb695de1.atc overlap --json: not run (ATC is not installed on this machine).Checks on this head
b9cb695de1python3 tools/zig/lean_check.py, on the base and on this head: 164 and 164, 0 new(
python3 tools/pr_check.py --base 5c71eb84cd: 0 errors, 1 advisory warning, the--prnumber not yet known).zig build test-exl3 test-exl3-gpu test-metal-launch-map-host test-kernel-contract -Dcpu=apple_m1:56/56 steps, 324 pass, 0 fail, 0 skip.
zig build tf-kernel-contract -Dcpu=apple_m1, thentf-kernel-contract --only exl3(SUMMARY below) andtf-kernel-contract --no-gates --only exl3 --offline DIR(M1 and M2 build the kernel for 32 threads).zig build test-exl3 test-exl3-gpu -Dcpu=apple_m1: 12/12 steps, 40 pass, 0 fail, 0 skip (the same float64line, 6.464e-5);
tf-kernel-contract --only exl3: SUMMARY below.test-exl3-gputests; a wrong tile placement fails 10.
zig fmt --check build.zig zigandgit diff --check: clean.zig build test test-golden(the full host suite) was not run on this head, only the EXL3, launch-map andkernel-contract steps above.
Receipt
tf-exl3-bench --mode oneon M4 Pro (GPU seconds, mean of 30, 6 halves mul1),tf_exl3_matmul_hoistedagainsttf_exl3_matmul_rowat K x N: 5120 x 2304 372/303 us, 2304 x 5120 235/171, 1280 x 32768 746/460,4096 x 1024 289/225, 8192 x 5120 801/569, 5120 x 1280 357/300, 5120 x 512 359/280; every run's output bits equal the
baseline's. On M5 Ultra, the same: 358/293, 173/145, 222/133, 299/244, 561/454, 363/297, 385/312.
exl3_projection.encodewithcount == 1); no family.b9cb695de1on main5c71eb84cd, Zig 0.17.0, Xcode's Metal toolchain; Apple M4 Pro (48 GB, macOS 27.2) and AppleM5 Ultra (macOS 27.0); no checkpoint
(synthetic trellises, and the real mcg 8.00 bpw block of
UnstableLlama/Qwen3.5-2B-exl3-8.00bpwinzig/tests/fixtures/exl3_oracle.bin).exl3_projection.encodeat one rowwithout routes or descriptors; Metal only. Ran M4 Pro and M5 Ultra; not M1 to M3.
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: n/a, no servedpath; instead (a) the kernel's decoded W_q is bit-equal to
exl3_format.unpackat every codebook and width and tothe oracle's real block, (b) its pre-rotation sums are bit-equal to the new serial reference
zig/src/core/exl3_projection_row_ref.zigand totf_exl3_matmul_hoistedatwq_a,wkv,wq_b, awo_agroup (as a column view),
wo_b, the shared w1/w3 and w2 andix_wq_b, (c) float64 agreement, reported and not agate: on the real block, max |gpu - f64| 6.5e-5 at max |y| 0.48 (the format's fp16 rotated input).
can't): no checkpoint path reaches it yet; the bench above is the same-machine comparison.
tools/bench_openai.py: n/a, no family serves Metal EXL3.How it was derived:
docs/receipts/dsv4.1-exl3-rebuild/p1.mdlists the main files and lines consulted, thearithmetic (window ends, the inverse placement table, the codebooks' single fp16 rounding, the k order and TwoSum
rounding points), and states that no file of the #2373-derived stack was opened.
git blameattributes every addedline to this commit; the normalized-line comparison against the mlx-serve, mlx-stream and turboexl3 histories gives a
longest run of 1 to 2 lines in the new files (abstracted: 1 to 4), against 1 to 2 (abstracted 1 to 4) for main's own
EXL3 files as the control.
Kernel contract, only when a GPU kernel is new or changed
tf_exl3_matmul_row(mcg 2 and 8 bits,mul1 2.5 and 4 bits, 3inst 6 bits; bf16 and f32 out), replacing
tf_exl3_matmul_hoistedand bit-equal to it at theeight DeepSeek-V4.1 dense decode shapes and the N and K edges, each row launched alone; launch record
dsv41 exl3 row tf_exl3_matmul_row(32 threads, reserved by the source).posing as
tf_exl3_matmul_hoisted: red atshapes(bytes differ at 1x32768x1280).SUMMARYline and exit status:SUMMARY 5 kernels: 5 pass gates 1-4, 0 fail, 0 known findings; 1 controls: 1 red as planted, 0 missed; 0 limit problems; gates 24710 ms, limits 40 ms, exit 0.SUMMARY 5 kernels: 5 pass gates 1-4, 0 fail, 0 known findings; 1 controls: 1 red as planted, 0 missed; 0 limit problems; gates 11744 ms, limits 378 ms, exit 0 (the control red at the same shape and byte).Checklist