Repository navigation
Metal EXL3 projection: exact multi-row bodies and a fused gate/up SwiGLU for the DeepSeek-V4.1 shapes - #5054
Conversation
|
Thanks @BlivionIaG. The row mapping keeps each row's original compensated chain, and the fused clamps and quantization expressions match main. The reported byte comparisons are recorded with their chip coverage. One new cleanup remains: if the private rows or pairs append fails, the initialized probe is not yet owned by the suite and leaks its pipelines. Please protect that transfer and test both failure paths. The inherited one-row setup cleanup also still needs the shared fix. The changelog merge is on our side.
|
|
@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.
|
|
M5 Ultra results at |
|
Thank you @BlivionIaG. The rows and pairs now transfer ownership through One new validation gap remains in Please add the two opposite-scratch
|
|
Thanks @ashhart. You were right: the cross |
|
Thank you for adding both opposite-output/scratch checks and the valid-encode control. The source now rejects Your supplied current-head device run records 31/31 GPU tests and 12 passing EXL3 kernels with 3 planted controls red. That closes the requested fix. It is ready to land once we resolve the listed current-main conflicts, which we will do; no additional device run is a prerequisite. Integration remains on our side, with no rebase request.
|
4da3a5c to
99c4f0c
Compare
… per row Lanes share a column's decode and each row keeps tf_exl3_matmul_row's TwoSum chain, so row r of a launch equals that row alone and tf_exl3_matmul_hoisted. tf_exl3_swiglu fuses both rotate_outs with tf_dsv41_f_swiglu's clamped SwiGLU and act_quant.
…egister A failed init, plant or list growth frees the probe once and unwinds the suite; test-dsv41-exl3-contract fails each allocation of create in turn, rows and pairs included.
The fused epilogue reads both matrices' sums while it writes y and yq, so each output must also be disjoint from the other matrix's scratch; a test expects error.AliasedExl3View for both overlaps.
99c4f0c to
28d0098
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 2 to 16 decode rows through
tf_exl3_matmul_hoisted(eight rows and 16 columns aSIMDgroup, every k tile through threadgroup memory and two barriers), and #5050's one-row kernel takes one row only.
After: 2 to 16 unrouted rows can go through
tf_exl3_matmul_rows{rp}x{q}, in which q lanes share a column's decode(16/q values each, the rest by shuffle) and each lane keeps rp rows, every row with
tf_exl3_matmul_row's chain, sorow r of a launch is bit-equal to that row launched alone and to
tf_exl3_matmul_hoisted. Two rows always take them;3 to 16 take them while the hoisted kernel would launch fewer than 12 simdgroups a GPU core (
Pipelines.gpu_cores, 0by default), the measured crossover on both machines.
exl3_projection.gate_upruns an expert's w1 and w3 and oneepilogue,
tf_exl3_swiglu(both rotate_outs, DeepSeek-V4.1's clamped SwiGLU and its act_quant), bit-equal to bothprojections then main's
tf_dsv41_f_swiglu. No family serves Metal EXL3 yet.lane, the indexer, prompt attention and the drafter.
25024cf736); one commit,4da3a5ca74.atc overlap --json: not run (ATC is not installed on this machine).Checks on this head
4da3a5ca74python3 tools/zig/lean_check.py: 0 new (python3 tools/pr_check.py --base <main>: 0 errors,1 advisory warning, the
--prnumber not yet known).zig build test-exl3 test-exl3-gpu -Dcpu=apple_m1: all steps pass (the GPU binary: 30 of 30 tests);zig build test-metal-launch-map-host test-kernel-contract -Dcpu=apple_m1: 46/46 steps, 257 pass, 0 fail.tf-kernel-contract --only exl3(SUMMARY below) andtf-kernel-contract --no-gates --only "exl3 rows" --offline DIR(M1 and M2 build all five pipelines for 32 threads).test-exl3-gputests; the up clamp dropped fails the gate/up test.zig fmt --check build.zig zigandgit diff --check: clean.there, on the same kernel body); CUDA, HIP and XPU are untouched; M1 to M3 have no device here (offline compiles
only);
zig build test test-goldenwas not run, only the EXL3, launch-map and kernel-contract steps above.Receipt
tf-exl3-bench --mode prefill --candidate rows(GPU seconds, mean of 30, 6 halves mul1, rotations included),tf_exl3_matmul_hoistedagainst the rows kernels at K x N and rows. M4 Pro: 5120 x 2304 2/4/8 rows 497/309,659/407, 944/634 us; 5120 x 1280 8 rows 894/356; 5120 x 512 8 rows 952/219; 4096 x 1024 4 rows 440/203; 2304 x 5120
2 rows 260/254. M5 Ultra: 5120 x 2304 8/16 rows 774/224, 772/383; 2304 x 5120 8 rows 357/191; 8192 x 5120 8 rows
1208/640; 1280 x 32768 2 rows 218/203. Where the rule keeps the hoisted kernel (e.g. 1280 x 32768 at 4+ rows on
both, 2304 x 5120 at 4+ rows on M4 Pro) the rows kernels ran up to 20% slower. Every run's output bits equal.
exl3_projection.encode), and the newexl3_projection.gate_up.encode; no family.Pipelines.gpu_coresis a field the caller sets; 0 keeps 3 to 16 rows on the hoisted kernel).4da3a5ca74on Metal EXL3 projection: an exact one-row decode kernel for the DeepSeek-V4.1 dense shapes #5050 (25024cf736, main5c71eb84cd), Zig 0.17.0, Xcode's Metal toolchain;Apple M4 Pro (20-core GPU, macOS 27.2) and Apple M5 Ultra (64-core GPU); no checkpoint (synthetic trellises).
exl3_projection.encodeat 2 to 16 rowswithout routes or descriptors and
gate_up.encodeat 1 to 16 rows; Metal only. Ran M4 Pro (tests, contract, bench)and M5 Ultra (bench); not M1 to M3.
and +-Inf in x, every row's sums and outputs equal that row through
tf_exl3_matmul_rowalone, the launch equalstf_exl3_matmul_hoisted, and one row equals the serial referenceexl3_projection_row_ref.zig; (b) at 1 to 16rows, routed both ways, the gate/up y and yq equal w1 and w3 through
tf_exl3_matmul_hoistedthentf_dsv41_f_swiglu, with both clamps reached. No float64 claim is made; everything is bit-equality.same-machine comparison.
tools/bench_openai.py: n/a, no family serves Metal EXL3.How it was derived:
docs/receipts/dsv4.1-exl3-rebuild/p2.mdlists the main and #5050 files consulted (main'sfused.metalfor the SwiGLU and act_quant expressions), the arithmetic and the row-group choice, and states that nofile of the #2373-derived stack was opened.
git blameattributes every line of the new files to this commit; thenormalized-line comparison against the mlx-serve, mlx-stream and turboexl3 histories gives a longest run of 1 to 3
lines in the changed files (abstracted: 1 to 4), against 1 (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_rows{1x2,1x4,1x8,2x8}through five registrations (mcg 2 and 8 bits, mul1 2.5 and 4 bits, 3inst 6 bits; bf16 and f32 out), replacing
tf_exl3_matmul_hoistedat 2 to 16 rows in one launch on the eight dense decode shapes and the edges; andtf_exl3_swiglu(w1 mul1 2.5 / w3 mcg 2 bits; w1 3inst 6 / w3 mul1 1.5 bits with biases) replacing w1 and w3through
tf_exl3_matmul_hoistedthentf_dsv41_f_swigluat 1, 2, 4 and 16 rows; launch recordsdsv41 exl3 rows ...(32 threads, reserved by the source).red at
shapes(bytes differ at 16x1280x5120 from byte 0);tf_exl3_swigluwithout the up clamp, red atshapes(1x2304x5120, byte 4).
SUMMARYline and exit status:SUMMARY 12 kernels: 12 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems; gates 56190 ms, limits 671 ms, exit 0.not run at this head.
Checklist