Repository navigation
dsv41 metal: faster long-prompt indexer passes - #3669
Conversation
|
Thanks @gilby. It applies cleanly to current main. The three parts read as exact: a key block skipped by the
|
49e71c3 to
afc377f
Compare
|
Addressed all three points from your review and re-verified on M5 Ultra and M3 Ultra (receipts and scrubbed logs in the updated Gist, head 1. M5 Ultra cold prefill rerun (
|
| Prompt | main mean (s) |
Branch mean (s) | Speedup | token_sha256 (all arms equal) |
|---|---|---|---|---|
| 2048 | 2.5307 | 2.5332 | 0.9990x | 330cd07dd3cf9c94be53d7f60da903a20c09fa92ef93c07770cfbca645f62b69 |
| 8192 | 7.1923 | 7.0459 | 1.0208x | b2da1b2b327db99418d423e402ede4d80b44a7735bd6348c07f1ab237a6a64ce |
| 32768 | 23.9373 | 23.8813 | 1.0023x | 0e3f2ebade352a4c79bcc121ddbb4f400d7e936262b65eb01e35bbdf16cc5836 |
| 131072 | 95.4618 | 95.9260 | 0.9952x | 1e2921aaf09463439be75b450cf3146ebd46b1d2321b318e9e608d5bbcd7bfb2 |
2. Extra scratch reserve and minimum supported Mac RAM tier
- Doubling
ix_rowsfrom64 -> 128reserved+301,989,888B (+288 MiB) at--context 1048576(target: 15.7 GiB -> 16.0 GiBof buffers;6.8 GiBat--context 262144/+72 MiB). - The smallest Mac RAM tier this
~285 GBcheckpoint (284.2 GiB kept wired between requests, inside 70% of 512 GiB of RAM) fits on is512 GB, where both15.7 GiBand16.0 GiBfit. - After reverting
prompt.zigix_rowsback to64, extra scratch is+0B (target: 15.7 GiB, matchingmain).
3. topk512.metal and index.metal cleanups
- Reverted the
TF_CTLline-6 comment rewording and the three0 -> 0uloop literal changes intopk512.metal. - Generalized the
CMcandidate block check inindex.metalas anUNR for (uint kf = 0; kf < IXKT; ++kf)loop (andfor (uint b = b0; b <= b1; ++b)) instead of hardcodingkf_live[0] || kf_live[1]forIXKT == 2. - Verification on
afc377f83: M5 Ultra--only dsv41(107/107pass,205/205controls red,0limit problems) &test-dsv41-metal-all(48/48), M3 Ultratest-dsv41-metal-all(47/48,1skip) &--only dsv41(104/104pass,196/196controls red, only the4pre-existingdsv41 xmma unitsLibraryLoadchecks), plustools/pr_check.py --pr 3669(0errors). All 9 required GitHub Actions checks are green onafc377f83.
|
Thanks @gilby. All three items are closed: the ablation isolated the regression to the 128-row pass and reverting it removed both the slowdown and the extra scratch, the masked specialization turned the 8,192 cell into a gain with every hash equal, and the small cleanups are in. The contract runs on both Macs and the green checks on the head close it. Nothing is left from our side.
|
afc377f to
f4a3b05
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
Speeds up long-context indexer passes in
deepseek_v41Metal prefill by specializing candidate-masked vs unmaskedtf_dsv41_ix_scoresexecution (MASKED=falsekeeps the straight-line unpredicatedtf_ix_tile<IXKT>loop with zero mask overhead;MASKED=trueusessimd_anyper block overIXKTto skip dead candidate blocks or dispatch a single straight-linetf_ix_tile<1u>block when only one block is live), aggregatingtopk512.metalpass-0 bin-3 (-inf) histogram atomics per simdgroup, and fixingr1maskedsource mask setup inprompt_time.zig(prompt.zigkeepsix_rows = 64so scratch reserves are unchanged vsmain).deepseek_v41Metal).main(813ff4ccbf9d6610e991a96d53fda2b628f56347; 1 commitafc377f83ae0e521c88f9e70e1d7d3d510821787across3files:index.metal,topk512.metal,prompt_time.zig).Checks on this head
afc377f83ae0e521c88f9e70e1d7d3d510821787python3 tools/zig/lean_check.py, on the base (813ff4ccb) and on this head (afc377f83):191and191,0new (python3 tools/pr_check.py --base origin/main --pr 3669:0 error(s), 1 warning(s), max touched source file342lines).zig fmt --check build.zig zigandgit diff --check origin/main..HEADpass.afc377f83):zig build dsv41-metal-serve tf-kernel-contract test test-golden --summary all->912/912 steps succeeded; 477/492 tests passed (15 skipped)(322/335+55/55equal to server goldens,0unexpected differences)zig build test-dsv41-metal-all --summary all->9/9 steps succeeded; 48/48 tests passed(33+15)./zig-out/bin/tf-kernel-contract --only dsv41->exit 0(107kernels pass gates 1-4,205controls red as planted,0limit problems)afc377f83):zig build tf-kernel-contract -Doptimize=ReleaseFast->43/43 steps succeededzig build test-dsv41-metal-all --summary all->9/9 steps succeeded; 47/48 tests passed (1 skipped)(32 pass, 1 skip+15 pass)./zig-out/bin/tf-kernel-contract --only dsv41->exit 1(104/104pass gates 1-4,196/196controls red;4pre-existingdsv41 xmma unitsLibraryLoadcheckstf_dsv41_xu_{quant,up,dprep,down})afc377f83(No GPU/zig,No GPU/zig-b,No GPU/zig-windows,No GPU/zig-macos-dev-tools,No GPU/pytest,No GPU/benchmark-clientsUbuntu & Windows,No GPU/release-paths,Zig format/fmt;host-nightly-{linux,macos}skipped as scheduled).tf-kernel-contractstops onUnrecordedRotaryCompileronmacOS 27.2.1, so contract checks ran with--only dsv41; M1–M4, CUDA, HIP, Windows, and mobile targets were not run.Receipt
813ff4ccb) against branch (afc377f83): Cooled M5 Ultra 4-pass A-B-B-A served receipts (2K–131Kcold prefill + decode) and 1-layer stage timings are in the public Gist. Allcached_tokens == 0,token_sha256identical across every arm.afc377f83vs813ff4ccb,bench_cache.py --require-cold, 4-pass A-B-B-A;5total requests/arm at2048,6at8192/32768,2coldbench_cold_single.pyrequests/arm at131072):mainmean (s)token_sha256prefix330cd07dd3cf)b2da1b2b327d)0e3f2ebade35)1e2921aaf094)49e71c32fvs077998f7d9; decode0/20slower,0mismatches):20486.0828 -> 5.9359s(1.0248x),819213.1531 -> 13.0820s(1.0054x),3276840.5642 -> 40.5371s(1.0007x),131072160.0994 -> 159.7526s(1.0022x), identicaltoken_sha256prefixes above. (afc377f83re-verifiedtest-dsv41-metal-all+--only dsv41on M3 Ultra.)test-dsv41-metal-prompt-timeon M5 Ultra (4096rows,ixrows=64,reps=5):layer 2, source(unmasked,mask_stride == 0):pos 28672ix_score 20.98 -> 20.92 ms(total 164.93 -> 165.45 ms);pos 122880ix_score 78.16 -> 78.06 ms,ix_select 10.77 -> 10.80 ms(total 230.32 -> 230.86 ms), bit-identical stage hashes (87d886cc2239db1b,6df19c701050059b).layer 2, r1masked(candidate-masked, branch initializes.r1candidate mask perprompt_time.zigfix):pos 28672ix_score 39.46 -> 39.77 ms,ix_select 7.40 -> 5.51 ms(total 178.67 -> 178.62 ms);pos 122880ix_score 154.40 -> 104.87 ms,ix_select 29.33 -> 23.33 ms,total 315.91 -> 261.83 ms(12966 -> 15644 rows/s,1.207x).deepseek_v41Metal prompt indexer (index.metal,topk512.metal) andprompt_time.zig.n/a— no environment variable added.813ff4ccband headafc377f83;deepseek-ai/DeepSeek-V4.1-Flash-1017Hugging Face revision1bae0e1088993b9b82de08f59de5be5a34e42170; Zig0.17.0; Apple Metal32023.922; macOS27.2.1on Apple M5 Ultra512 GBand macOS26.6.2on Apple M3 Ultra512 GB; served flags--context 1048576 --parallel 4 --prompt-cache-gib 0 --vision.afc377f83), M5 Max on earlier head; M1/M2/M4 and non-Metal backends not run.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:token_sha256identical across all M5 Ultraafc377f83cold-prefill (2K–131K) and decode (T=0, 1.0,4cells) A-B-B-A arms (4unique decode SHA sets matching acrossA1/B1/B2/A2);test-dsv41-metal-serveconfirmsdraft:false == draftedon both M5 Ultra and M3 Ultra.tools/bench_openai.py: M5 Ultra (afc377f83vs813ff4ccb,tokens=256,reps=3):fibonacci-rawT=071.74 -> 71.69 tok/s(0.9994x),T=1.067.62 -> 67.49 tok/s(0.9981x);gpu-chat-no-thinkT=056.80 -> 56.71 tok/s(0.9985x),T=1.056.77 -> 56.80 tok/s(1.0005x).ttft_sfromtools/bench_cache.py --require-coldon a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: At32768:23.9373s -> 23.8813s(1.0023x); first-only24.3873s -> 23.6796s(1.0299x). At131072(2cold requests/arm acrossA-B-B-A):95.4618s -> 95.9260s(0.9952x,B1min93.5985svsA195.1861s).n/a— uses existing release weights and built-in drafter.Kernel contract, only when a GPU kernel is new or changed
dsv41 ix(index.metal) anddsv41 topk512 tf_topk512(topk512.metal) in place.dsv41 ixcontrols anddsv41 topk512controls pass red as planted on M5 Ultra and M3 Ultra.SUMMARYline and exit status:--only dsv41):SUMMARY 107 kernels: 107 pass gates 1-4, 0 fail, 0 known findings; 205 controls: 205 red as planted, 0 missed; 0 limit problems; gates 129203 ms, limits 42 ms(exit0)--only dsv41):SUMMARY 104 kernels: 104 pass gates 1-4, 0 fail, 0 known findings; 196 controls: 196 red as planted, 0 missed; 4 limit problems; gates 131162 ms, limits 320 ms(exit1;4pre-existingdsv41 xmma unitsLibraryLoadcheckstf_dsv41_xu_{quant,up,dprep,down})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