Repository navigation
dsv41 metal: simdgroup MMA prompt matvec (mv_mma) - #3668
Conversation
|
Thanks @gilby. The change does what the description says: the prompt layer's compressor, indexer key and weight, and MoE gate matvecs move to the new MMA kernel at 16 or more rows and K of 32 or more, and the contract compares it byte for byte with
|
5c5cbea to
f4cb32e
Compare
|
Thanks @gilby. We rebased this onto current main: The second point still stands: please rerun the M3 Ultra 2048 and M5 Ultra 32768 (default settings) cold-prefill cells, main against the rebased branch on the same machine, with
|
f4cb32e to
13e8864
Compare
|
Thank you @gilby. 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
Replaces scalar/thread-per-row bf16 prompt matrix-vector dispatches (
glue.mvinprompt_layer.zigfor compressor, indexer key/weight, and MoE gate projections whenrows >= 16andk >= 32) with a 16 KiB threadgroup-tiledsimdgroup_matrixMMA kernel (mv_mma.metal), keeping exact float32 reduction inKorder bit-equal toglue.mv.deepseek_v41Metal).main(077998f7d9b14adebec3a2acc2caa47ff7ae6ec7; cleangit merge-treeagainst currentorigin/main699094f70570d547532f9d633502286202e7424a, 1 commit5c5cbeabbdc94ce361b087a47149590ed0010840).atc overlap --json: Run at2026-11-17T08:07:39Zagainstorigin/main(699094f705). Default scan hittimeLimit/pullRequestsLimitwith 0 local conflicts reported; targeted--pulls 1721,1722,2950,2951,2952,2954,2973returnedcomplete: trueand showed pre-existing open-PR file overlaps on unmerged stack PRs (1721,1722,2950,2951,2952,2954,2973), and cleanly merges against currentorigin/main(699094f705) and PR 2 / PR 5.Checks on this head
5c5cbeabbdc94ce361b087a47149590ed0010840python3 tools/zig/lean_check.py, on the base and on this head:221and221,0new (python3 tools/pr_check.py --base origin/main:0 error(s), 1 warning(s), max touched source file345lines).zig fmt --check build.zig zigandgit diff --check origin/main..HEADpass.zig build test test-golden --summary all->874/874 steps succeeded; 426/441 tests passed (15 skipped);zig build test-dsv41-metal-all --summary all->9/9 steps succeeded; 47/47 tests passed(32+15);zig build dev-tools-> exited0.zig build test-dsv41-metal-all --summary all->9/9 steps succeeded; 47/47 tests passed(32+15);zig build test-environment-host --summary all->3/3 steps succeeded.zig build test-dsv41-metal-allandzig build test-environment-host-> exited0.tf-kernel-contractstops onUnrecordedRotaryCompilerfor rotary probes onmacOS 27.2.1(Xcode 27.2), so contract checks ran with--only dsv41; M1–M4, CUDA, HIP, Windows, and mobile targets were not run (no hardware in this environment).Receipt
077998f7d9vs5c5cbeabb). Decode (20/20cells):SLOWER: 0/20; MISMATCHES: 0on both chips. Cold prefill TTFT (bench_cache --require-cold, 1 repeat):token_sha256330cd07dd3cf)b2da1b2b327d)0e3f2ebade35)330cd07dd3cf)b2da1b2b327d)0e3f2ebade35)PROMPT_UNITS=0)b2da1b2b327d)PROMPT_UNITS=0)0e3f2ebade35)1-layer
test-dsv41-metal-prompt-time(4096rows,layer 2, source, pos0/122880): M5 Ultra total143.46 -> 138.73 ms(pos0) and230.32 -> 225.57 ms(pos122880, matchingcore/out/posthashes); M3 Ultra247.84 -> 242.58 ms(pos0) and350.50 -> 345.28 ms(pos122880).deepseek_v41Metal prompt path (compress,indexerkey/weight,moerouter gate) whenrows >= 16andk >= 32.n/a— no environment variable or flag added.deepseek-ai/DeepSeek-V4.1-Flash-1017Hugging Face revision1bae0e1088993b9b82de08f59de5be5a34e42170(config.jsonsha2568be45ce0476004a3f529fd896115a4a2e800a129ad2d3ec05b16050f52e21879); Zig0.17.0; Apple M3 Ultra, 512 GB (macOS 26.6.2, Xcode27.2/27B52, Metal32023.922); Apple M5 Ultra, 512 GB (macOS 27.2.1, Xcode27.2/27B52, Metal32023.922); Apple M5 Max, 48 GB (macOS 27.0.1, Xcode27.1/27A9275, Metal32023.921); drafter: checkpoint built-in DSpark + copies (--context 1048576 --parallel 4 --prompt-cache-gib 0 --vision).M3 Ultra,M5 Ultra, andM5 Max(ran); MetalM1/M2/M4and non-Metal backends (not run).tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:0failed,0--aloneunequal,0--serialunequal across allN=1,2,3,4(T=0.0,1.0,chat/code) on both M3 Ultra and M5 Ultra;token_sha256identical across every decode and cold prefill cell (330cd07dd3cf,b2da1b2b327d,0e3f2ebade35).tools/bench_openai.py: M3 Ultra (T=0.054.5 -> 54.55fib,43.8 -> 43.8chat;T=1.050.5 -> 50.6fib,43.9 -> 44.0chat); M5 Ultra (T=0.071.2 -> 71.0fib,56.7 -> 56.65chat;T=1.066.85 -> 66.75fib,57.75 -> 57.7chat). All20/20decode cellswithin noise(0.997–1.002x) on both chips.ttft_sfromtools/bench_cache.py --require-coldon a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: See table above (e.g., M5 Ultra8k8.6837s -> 7.6902s,1.1292x, and32kwithTF_DSV41_PROMPT_UNITS=027.2024s -> 25.8778s,1.0512x; M3 Ultra8k13.1531s -> 12.9801s,1.0133x).n/a— uses existing release weights and built-in drafter.Kernel contract, only when a GPU kernel is new or changed
dsv41 mv mma tf_dsv41_mv_mma_f32anddsv41 mv mma tf_dsv41_mv_mma_bf16(128 threads, 16384 B threadgroup memory), replacingglue.mvinprompt_layer.zig(compress,indexer,moegate) forrows >= 16,k >= 32.CONTROL dsv41 mv mma control: a partial last K step dropped: red at shapes, as plantedCONTROL dsv41 mv mma control: non-finite inputs flushed: red at nonfinite, as plantedCONTROL dsv41 mv mma control: sums rounded to fp16: red at sums, as plantedCONTROL dsv41 mv mma control: writes past its output: red at repeat, as plantedSUMMARYline and exit status:--only dsv41):SUMMARY 94 kernels: 94 pass gates 1-4, 0 fail, 0 known findings; 199 controls: 199 red as planted, 0 missed; 0 limit problems; gates 123101 ms, limits 285 ms(exit0)--only dsv41):SUMMARY 94 kernels: 94 pass gates 1-4, 0 fail, 0 known findings; 199 controls: 199 red as planted, 0 missed; 0 limit problems; gates 119073 ms, limits 24 ms(exit0; with#3522tensorOnlycheck:119142 ms, limits 236 ms,0 limit problems, exit0)--only dsv41):SUMMARY 91 kernels: 91 pass gates 1-4, 0 fail, 0 known findings; 190 controls: 190 red as planted, 0 missed; 4 limit problems; gates 120431 ms, limits 327 ms(4pre-existingdsv41 xmmalimit failures inherited from077998f7d9; with#3522tensorOnlyfix applied locally:SUMMARY 91 kernels: 91 pass gates 1-4, 0 fail, 0 known findings; 190 controls: 190 red as planted, 0 missed; 0 limit problems; gates 120659 ms, limits 261 ms, exit0)Checklist
The title and description match the head commit, including the receipt and the stack.
New tests fail before the change, pass after it, and skip cleanly without their dependency.
Comments and docstrings are one line. No measurements or history in the source.
No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.No precision traded for speed. If the bits change, the description says which sums change and why.
Decode and prompt processing are no slower than main at one stream and the widest admitted; with
--drafter, no slower than without it, greedy and sampled