Repository navigation
DeepSeek-V4.1 EXL3 Metal follow-up to #2373: exact tiled decode, fused chains, prefill chunking, last-row and Sinkhorn fixes - #3382
Conversation
…kernels, streamed Engram, drafted decode, retained prompt cache
The glm_dsa exes take the tokenizer module from the engines import table (the file was compiled twice, once per module). The reference suite calls encodeDiagnostic with prof and segs. The four prof clocks guard Windows, where std.c.clock_gettime does not compile; those builds read 0 from an instrument that never runs there.
bench/ (the round scripts and the two patch diffs), tf_ids_tmp and its tf-ids target, and the r519 bf16 experiment with its fixture leave the diff. The repo-wide *.log ignore line goes (upstream keeps its own). glue_tmp.metal was load-bearing, so it is glue_rows.metal now, with the records file, the contract tests and every comment following. No kernel text changed.
Dead code under the copy rule: no lane file dispatches tf_gather_qmm_*; zig/tests/mlx_gather.zig and the tf-mlx-gather entry existed only to time the reference. Removes core/mlx/ (mlx_steel.h + gather.metal), the core_mlx_steel embed, the test and its build entry. Gates: fmt, native, test-deepseek-v41, dev-tools.
…switches The diff adds comment blocks that carry experiment labels and measured numbers; this pass keeps the technical statements and drops the history. Core is family-neutral again: the round-trip profiler and its clock leave lanes/engine.zig, the resumed-tail switch moves to prompt_cache.Rules (set by the DSV4.1 lane host), and the family metal-mirror shell check hangs off test-deepseek-v41 instead of zig build native. Gates: zig fmt --check, native, test-deepseek-v41, dev-tools.
Every file in the branch is under 600 lines: lanes/engine (pipelined round), core/prompt_cache (marks), server/cli (scalar helpers), weights (source helpers, int8 sidecar), backend (policy, run), and the index Metal sources (scalar + tensor-unit). Moves are function-for-function, with in-struct aliases for the methods; no arithmetic moved. Gates: zig fmt --check, test-native, test-deepseek-v41, dev-tools.
…he release R1's first half. TF_DSV41_Q_RMS, TF_DSV41_MTP_Q_RMS and TF_DSV41_Q_RMS_DEBUG and their ones/dump buffers are gone; the release has no per-head query RMS (it normalizes qr before wq_b, which is the shipped path). The provenance comments in model.zig/attention.zig now state the release's order (wq_a -> q_norm -> wq_b -> rope; wkv -> kv_norm -> rope; sparse attention; inverse rope; wo_a groups -> wo_b) and the DSpark block forms, with no sibling-engine citations. No default-path arithmetic moved: every removed arm defaulted off. Gates: zig fmt --check, native, test-deepseek-v41, dev-tools.
…ement The top-1/KL receipt the review asks for needs a divergence term over the whole next-token distribution, not only argmax and NRMS. `qualify.zig` already runs the independent CPU teacher (FP32 or FP64 over the release pack's weights) against the GPU decode; this adds KL(teacher || engine) per row, its mean and worst, in f64 with a max-subtracted softmax. The fields are added with defaults, so existing oracle JSON readers keep working. Gates: zig fmt --check, test-deepseek-v41-reference.
…MM moves lane-side core/affine_mm.metal and prefill/gemm_nax.metal are byte-identical to upstream's (sha a91a3539 / 16a1d78a). The router gate's fp32-destination GEMM is the lane's own copy under deepseek_v41/gate_gemm.metal, registered in the metal sources and loaded by ops.zig; the gate bench reads the lane source and the contract records keep their names. The unused int8/weighted-GLU affine delta (only a flag-gated FP64 ground-truth test) is removed with its header and test. It was dead in the lane and carried a whole-file port attribution, so re-homing it would not clear the copy rule. Gates: zig fmt --check 0; check_dsv41_metal_mirrors 86/86; zig build native 0; test-deepseek-v41 0; dev-tools 0.
The drafter's conditioning, noise-token rows and Markov head chain cite the release's Transformer.forward_spec / DSparkBlock.forward_embed / forward_head (inference/model.py, revision 314113f8) instead of the sibling engine. The remaining port language is gone. Comments only: no non-comment line changed. Gates: zig fmt --check 0; zig build native 0; test-deepseek-v41 0; dev-tools 0.
…y leaves the comments The EXL3 files no longer name another engine or a round. The funnel/dig forms, the register-only decode, the pair and the multi-row dense body are described by their arithmetic and their own shapes; the model-facing order cites the release (inference/model.py, revision 314113f8). Comments only: no non-comment line changed. Gates: zig fmt --check 0; zig build native 0; test-deepseek-v41 0; dev-tools 0.
…ured numbers The five files the earlier pass skipped (attention, model, the EXL3 projection Zig glue, and both EXL3 Metal files) now carry the same comment rule as the rest of the diff: no ROUND-/R- labels, no handoff or other-engine references, no measured figures. Comment text only; git diff -U0 over the five shows no non-comment line changed, so the kernels and the host glue are bit-identical by construction.
…duplicated code go hc_boundary.metal's header no longer claims a whole-file port: it cites Block.hc_mixes, hc_pre and hc_post in the release's inference/model.py at revision 314113f8, and the duplicated mix-product and two-stage reduction code is one pair of helpers. The arithmetic, the thread mapping and the lagged collapse are unchanged, so the kernels stay bit-identical; the mHC GPU tests pass. The remaining comparator/MLX/Bob references in the diff are reworded to describe the form by its arithmetic or removed. The other files here change comments and bench output strings only; no engine path changes.
… walk The prompt tile no longer carries an inline decode job: TfExl3DigJob holds the resident pack slice, the k/n strides, the width/codebook and the live tile extents, built once from the call args and the route. TfExl3DigWindows holds the lane's eight-state cursor (slot, word offset, shift, word distance) and is shared by the default tensor-unit prefill body, the grouped table body and the scalar prefill twin (the named TfExl3ScalarWindow fields replace the packed map word). The arithmetic, the k order and the MMA order are unchanged, so the kernels are bit-identical by construction; the shared prefill and grouped-tile GPU tests in test-deepseek-v41 pass, and the prefill spot rows report zero parity mismatches. The model-facing order cites the release (inference/model.py, revision 314113f8); the trellis arithmetic and the cursor are our own pack format. Gates: zig fmt --check 0; zig build native 0; test-deepseek-v41 0; dev-tools -Doptimize=Debug 0.
…nd row walk The register-only routed decode and its paired form no longer rebuild the pack slice and the lane cursor inline. TfExl3DecodeJob names the trellis, k/n strides, width and codebook for one row (the dense call takes its own trellis, the routed call the expert's descriptor); TfExl3RowWalk names the lane's first word, bit offset, shift/mask and the next two words. The pair body uses the same two structs, so the duplicated setup is one place. The arithmetic, the k order, the product order and the reduction tree are unchanged: the shared prefill, grouped-tile and resumable-window GPU tests in test-deepseek-v41 pass, and the single-row/pair bodies are the same code with named fields. The release is cited for the MTP/draft projection shapes (inference/model.py, revision 314113f8); the pack layout and the row walk are our own. This is the register-only single-row and pair pass. The funnel, wide and multi-row dense bodies still carry their inline setup; they are named as remaining R3 work in the record. Gates: zig fmt --check 0; zig build native 0; test-deepseek-v41 0; dev-tools -Doptimize=Debug 0.
…walk The tensor-unit decode's three remaining bodies no longer rebuild the pack slice and the lane cursor inline. The multi-row routed decode, the 128-column dense decode and the column walk build TfExl3DecodeJob (the expert descriptor or the call's own trellis, the k/n strides, width and codebook); the eight-state cursor is the shared TfExl3DigWindows walk, now with the tile's column stride and the ring's next words, so the funnel, two-word and general paths take rel/off/sh/at from it. The single-row and pair register bodies keep TfExl3RowWalk. The arithmetic, k order, MMA order, product order and reduction tree are unchanged: the walk is the same map arithmetic with named fields, and the cursor was checked for halves 4, 6, 8 and 16 on every lane. The file compiles standalone with the default, funnel, two-word, compact and table defines. The body comments also lose the last task label, the probe measurement and the orphan possessives the earlier attribution strip left behind. Gates on the tree: zig fmt --check 0; metal compile 0 (default plus the named defines); zig build native 0; test-deepseek-v41 0 (the csa2 diagnostic and failed-command line are the same on the base 1530351); dev-tools 0; test-exl3 0.
The copy-rule comment pass left orphan possessives ("are 's"), a task label and a
measurement in the rewrite-set files. This restores the sentences: the EXL3 glue
describes the single-tile body, the backend notes drop their round numbers and the
one measurement, and the docs drop the round cross-references. Comment and prose
only; no non-comment line changed in the Zig sources.
…gures; the partial files carry their status
…implying a finished rewrite
…h order is kept and proved byte-identical The file started from BobClawblaw/TensorFold deepseek-v41-main 72a552e. It is now written from the release's Block.hc_mixes, hc_split_sinkhorn_kernel, hc_pre and hc_post (inference/model.py and inference/kernel.py at 314113f8): the mix projection over the flattened stream, the Sinkhorn split, the lagged collapse, the norm and the post expansion. The two launches and the reduction order are unchanged by design. The split cannot read the 24 mix totals until the first launch finishes and Metal has no grid-wide barrier; the one-threadgroup fold was built and measured 2.4x slower at the decode's row counts. The reduction order is the canon's. A byte-for-byte A/B against the previous kernel over rows 1, 2, 5 and 17 and every expand/mixes combination (16 cases) is identical in every output buffer, so no reply can move. The harness and its log are in the plan record, scratch/hc-ab-20261106/. Metal compile and the fast gates pass.
The attention encode is now the release's decomposition (inference/model.py, revision 314113f8): the query's low-rank pair and its norm, _window_kv's norm, rope and fp8 pack, _compress_kv/_compress_topk_idxs' compressor and pick, sparse_attn over the two sources, and the grouped wo_a/wo_b close. The stage context carries the views the stages hand forward, so each stage reads as the release's step instead of one inline block. The dispatch order, the fused forms' arithmetic, the k order, the split counts and every A/B arm are unchanged: the bodies moved, they were not retyped. The trellis arithmetic, the ring layout and the scan remain this lane's pack format. Gates: fmt 0; metal-mirrors 86/86; native 0; test-deepseek-v41 0; test-exl3 0; dev-tools 0; umbrella test 0 (COMBINE GATE 45056/0); reference 0.
…stages The drafter's block attention is now the release's DSparkAttention.forward (inference/model.py, revision 314113f8): the draft query's low-rank pair and norm, the draft key's norm and rope, the packed window, the scan over the main model's window rows, and the grouped wo_a/wo_b close, with the draft rows' publish last. The stage context carries the encoder and the views the stages hand forward, so each stage reads as the release's step. The dispatch order, every rope/scale/mask arm, the debug dumps and the prof splits are unchanged; the bodies moved, they were not retyped. The pack arithmetic, the ring layout and the scan remain this lane's pack format. Gates: fmt 0; metal-mirrors 86/86; native 0; test-deepseek-v41 0; test-exl3 0; dev-tools 0; umbrella test 0; reference 0.
…eaders state the rewrite
…e variant headers state the rewrite
…tal engine The shared host tests and the Linux cross-compile reach model.zig and load.zig, so keep main's neutral owners there and move the Metal model and loader to model_metal.zig and load_metal.zig. Guard F_NOCACHE to macOS and drop the token-map CLI's optional unwraps.
|
Thanks @ashhart. Refreshed as asked, this one first and then the three on top of it (each by merging
What you listed.
One structural change you should know about. The first refresh failed the Linux Checks on Receipt on the hardware (M5 Ultra, macOS,
Not run: |
|
Follow-up after the first refresh: the Linux Heads now (each contains |
…+up call A five-token window's fused gate+up call names seventy descriptors (two blocks of the backbone's six picks plus the merged shared expert's two, a token), and the register-only bodies stopped at `moe_split_rows`, which is the split reduction's bound: the window's later rows changed to the tensor-unit compact body inside one window. A body is a rounding order, so those rows no longer carried the one-row bits and a four-draft window decoded differently from plain decode. The bodies now serve any call up to 112 descriptors, the eight-token window's fused count, so a decode window and a prompt chunk of the same token count run the body a one-row decode runs. One- to three-draft windows name fifty-six descriptors and below and keep their bodies; the only other calls past sixty-four descriptors are prompt chunks of five to seven tokens, which now match a one-token decode of the same rows. The host test pins the arithmetic: the fused call is fourteen descriptors a token, five tokens pass the split reduction's bound, and eight tokens stay inside the body's bound.
Measured on the eight reference prompts, solo and four-at-once, and on the ten code prompts: the four-draft window's hashes now equal plain decode's (7 of 8 and 5 of 10 differed before), the 5-row round's event p50 is 61.2 ms, and the default config's hashes and timings are unchanged.
The multi-row dense bodies switch at two rows and at four; a GPU test compares each window's rows against one-row dispatches of the same matrix for both codebooks, so a body that is not row-invariant fails here instead of in a reply.
…its merge Concurrent dispatch mode put the attention scan ahead of the dense-table pass that fills it and the split merge ahead of the scan that writes its partials: TF_DSV41_CONCURRENT=1 moved the reply. Both dependencies now have an explicit barrier, and a GPU test runs the chain on a concurrent encoder against the serial one.
|
Folded the three follow-ups from the fork as four commits on this branch, then merged
Checks on |
# Conflicts: # CHANGELOG.md
The resolution had dropped the engine's import and pointed hy4_flash's config at the file instead, which failed the hy4 flash host test: its config reached the readers by path while the engine declared them as a module. Keep main's side byte for byte.
The readers live in config_number.zig, which the metal graphs declare as a module for hy4_flash's config. The family's config still reached the file by path, so a graph with both owned it twice. Import it by name and declare the module on the roots that compile the family's config themselves.
…lings The core modules re-exported the file while main's inkling2 opener imports it directly, so a graph with both owned it twice. Read it by path from the family and drop the two re-exports.
|
CI on |
|
Thank you, @BlivionIaG. The module ownership repair is present, and the reported focused host passes, multi-row rounding fix and concurrent barriers are credited. The pinned community EXL3 pack is acceptable. Two things remain. First, please map the README's three projection failures to the newer passing suite, say what its skip covers, and update which served results still qualify after the attention repairs; the older GPU's skipped concurrent test does not establish the tensor path's exactness. Second, the copy rule from our #2373 review: the projection kernels and drafter code there followed mlx-serve line for line. That code has to be rewritten from TensorFold's own code, or shown to have been written independently, before the stack can land.
|
|
Thanks @ashhart. Projection failures and the skip. The README's three failures are three tests in Tonight on the M5 Ultra,
On the M4 Pro the same build gives Served results. Everything measured before the attention repairs ( Copy rule and authorship. The projection kernels and the Metal drafter that the #2373 review traced to mlx-serve are #2373's code, and they are not mine. This stack keeps authorship as it was committed: #2373's 87 commits are EugeneClaw's (84) and Eugine's (3), unchanged and in order, and I compared the text of the stack against the full public histories of mlx-serve, mlx-stream and turboexl3 (15,681 source files): no copied text, the longest common run is 3 normalized lines (TensorFold's own What this PR proposes is my work on top: the fixes and measurements in my 39 commits (tiled decode, fused gate+up and window-bound fixes, the projection-order repair and the receipts). They build on #2373's bodies, so they can't land ahead of the gate you set; I'm keeping them as separate commits under my name so they can be reviewed, rebased onto whatever replaces #2373's code, or dropped on their own. I'm not claiming independence for #2373's code and I'm not rewriting it on its author's behalf; if you want it rewritten from TensorFold's own code, that needs its author or a decision from you on who does it. |
|
Merged |
Draft, stacked on #2373 (head
bec140d545). The gate is agreed in #3385 with two conditions (below); #2373 is being rebuilt as a series againstmain, so this is the reference draft until that series is visible. Nothing here is claimed as release qualification.What this changes
Before: the DeepSeek-V4.1 EXL3 Metal lane in #2373 decodes at about 40 tok/s on an M5 Ultra, fails the 128-token full-model numerical band (band ratio 1.855 against the 1.10 limit), and expands the wrong row in the fused boundary for a multi-row last-row window. After: exact tiled half-FMA decode bodies, fused attention and expert chains, batched decode attention, memory-sized prompt chunks that yield to live decoders, suffix-cone prefill, matching-suffix proposals ahead of paid trained ones, a Sinkhorn reduction order that matches the unfused split, and the last-row fix. The band ratio is 0.967; decode is about 52 tok/s and a cold 64k prompt takes 27 s instead of 57 s. One lane, one checkpoint family, Metal only.
It is one pull request because its parts cannot be qualified apart. I built the three-slice stack and ran it: the decode-bodies slice and the lane-scheduling slice each fail
one-row fused wq_a+wkv matches the two separate projectionson M4 (it also fails at #2373's head; its fix is in the numerical commit), and the contract registrations for the new chain, native-row and attention-row kernels land with that commit, so neither earlier slice could pass the kernel contract (--only exl3reports 0 kernels at both). The commits below keep their order and their own messages; I have not pushed that stack.bec140d545. The diff againstmainis this delta's commits plus a merge ofmainat4c79cfe346; the merge resolved six files, all mechanical:CHANGELOG.mdanddocs/optimization-ledger.md(both sides extend the lists),zig/src/core/lane_stream.zig,zig/src/core/lanes/drafted.zigandzig/src/core/lanes/recorder.zig(main's wrapper/refactor plus this branch'ssnap_atanddecoding_rows), andzig/tests/contract/metal_limits.zig(both sides' dispatch cases). It also moved the EXL3 contract suites' registration into the dsv41Suitesaggregate, becausezig/tests/contract/metal_main.zigwould otherwise pass 600 lines, and dropped the duplicateconfig_numbermodule registration that clashed withtensorfold'sdeepseek_v41_configexport (file exists in modules 'owner' and 'config_number') now thatmain'sconfig.zigimports that file.atc overlap --json --base bec140d545(ATC 0.9.6, 2026-11-15 09:08 UTC, run on heada99384be17after the last push, coverage incomplete:myPullRequestsLimit,otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit; the repository has 371 open pull requests and the tool reads three pages of 100, so no run can be complete): 10 textual conflicts, 136 not testable. Conflicts with qwen35 cuda: fuse the dense MLP's NVFP4 prompt gate and up projections into one launch #2410, idol: Idol's denoiser on CUDA (stacked on #1766) #1767, fix(cuda): allocate Qwen3.5 scratch at load #1879, glm cuda: TF_GLM_GRAPHS=1 replays verify windows as CUDA graphs (#1490) #2279, Living Weights: a refused round re-draws wordings and keeps the open fit; fallbacks continue as main does #2650, DeepSeek-V4.1: read the pack's weight spans past the page cache (core/direct_io) #1924, Living Weights: slide-forget counting only with --slide-forget, Metal's mask shift for wide pockets (#678) #2026, qwen27 metal: qk projections, flat glue and Metal 4 verify passes, each bit-identical and switchable #2342, CUDA: #1764's BF16 prompt tile for Qwen ModelOpt, Nemotron and Dory, plus two exact Qwen prompt kernels (#1762) #2008 and dsv41 metal: decode experts decode an expert's weights once for all of its rows (stacked on #1720, #2973) #2983. They are in CHANGELOG,docs/environment.md,environment.zig,docs/kernel-contract.md,metal/sources.zig,contract/registry.zig, the optimization ledger andnative/cuda.zig, all append-style or registration lists; the first run at 01:29 UTC listed CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 as well and read 365 as not testable. dsv41 metal: decode experts decode an expert's weights once for all of its rows (stacked on #1720, #2973) #2983 and dsv41 metal: launches of 6 to 16 rows run their FP8 projections on a matrix tile (stacked on #1720) #2973 (the FP8 DSV41 Metal lane stacked on dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720, not EXL3) share CHANGELOG,docs/kernel-contract.mdandmetal_dsv41_main.zigwith this delta; whichever lands second resolves those lists. I have not contacted their author.Review guide
GitHub shows this pull request against
main, so its file list includes #2373's 243 files. This delta alone is 124 files, 11,113 lines added and 820 removed (about 4,600 lines of Zig source, 1,500 of Metal, 4,500 of tests, 1,700 of receipts): bec140d545...a99384be17, orgit log --reverse bec140d545..a99384be17.Read it in these groups; sizes are changed lines per commit.
1. Decode arithmetic and fused chains (the speed)
f84866800bMetal EXL3: accelerate exact decode with tiled half-FMA bodies (Metal 463, source 108, tests 6)54c9114187Metal EXL3: fuse exact attention and expert projection chains (source 1688, Metal 483, tests 6)a298334537Metal EXL3: qualify pipelines and reject invalid NAX tile widths (source 150)2. Lane scheduling: batched attention, suffix-cone prefill, prompt chunks, Engram staging
86e69be6c2DeepSeek EXL3 Metal: batch decode attention and yield between prompt chunks (source 565, Metal 290, tests 225, tools 4)49605ca481DeepSeek EXL3 Metal: retain exact suffix-cone prefill per prompt (source 783, tests 56, Metal 5)c4d5e484f3DeepSeek EXL3 Metal: overlap Engram staging and bound head scratch (source 209, Metal 134)0d3a3034daDeepSeek EXL3 Metal: size prefill chunks by memory and live decoders (source 78, tests 22)3. Corrections found by the qualification (read last: they touch what 1 and 2 add)
e37bb2b418Metal EXL3: integrate validated controls and preserve backend chunk hints (tests 150, source 91)59535dad91Metal EXL3: keep failed-open allocation cleanup single-owned (source 4)0870c860f4Metal EXL3: make cone verification independent and fail closed (source 27)e070123319Metal EXL3: retain generic indexed widths and align small dense reductions (Metal 48, source 44)128cfe743aMetal EXL3: size shared-down check scratch for every encoded stage (source 2)6aa834fdb4Qualify EXL3 Metal projections and correct batched merge strides (tests 928, receipts 443, tools 92, source 58, docs 24)efdf7a464eMetal EXL3: fix last-row expansion, Sinkhorn reduction order and lookup-first proposals (tests 3130, receipts 1066, source 680, Metal 42, docs 32)4. Settings: what is registered and what was removed
e9e06ee0b1Metal EXL3: read the drafter switch through the registry in the lane host log (source 4)dd80dd7164Metal EXL3: drop the per-fusion kill switches (source 82, docs 2)a80eddd9a6DeepSeek EXL3 Metal: keep tile groups, chunked prefill and Engram lookahead fixed (source 34, docs 3)5. Documentation, CHANGELOG and receipts (no code)
9be9ce5322Document the EXL3 Metal optimization follow-up and qualification scope (docs 67)26592f0ed3Record the final qualification of the EXL3 Metal follow-up source tree (receipts 45)3d56a5f39eCHANGELOG: name the follow-up pull request (docs 2)a4320a20b4CHANGELOG: name the follow-up pull request on the bullet's first line (docs 4)d83fdf4549Record the final qualification, cold prompt speed and decode of the EXL3 Metal follow-up (receipts 60)581d738626Record the settings sweep, resumed, 128k, M4 and local CI results of the EXL3 Metal follow-up (receipts 114)a99384be17Record the eight-stream comparison against the parent (receipts 16)The largest commit,
efdf7a464e, carries three small fixes (last-row expansion, Sinkhorn reduction order, lookup-first proposals) and their regressions: 3,130 of its changed lines are tests and 1,066 receipts. The production change in it is about 680 lines of source and 42 of Metal.What to check, in order: (1) every new kernel is registered with the contract and has a planted control (
zig/tests/contract); (2) the exact bodies keep the unfused arithmetic, so same-engine hashes match (receipts README, "Final qualification"); (3) every token still goes through the lane rounds (zig/src/families/deepseek_v41/model*.zig,backend*.zig); (4) settings are read throughplatform/environment.zigonly (docs/environment.md, "DeepSeek EXL3 Metal controls").Checks on this head
5d1f3d6418(four folded commitsd62498c304,a6730a4c04,61cd8d8a97,c56e962f4fon top of69f93351a7, plus a merge ofmain4c79cfe346). The qualified code tree is the one ofa80eddd9a6;581d738626,a99384be17and this fold add the receipts README, the committed numbers and the three follow-ups' fixes and tests.python3 tools/zig/lean_check.py, base4c79cfe346against this head: 165 problems on the base, 164 on this head, 0 new.pr_check --base 4c79cfe346 --pr 3382: 0 errors, 0 warnings (330 changed files).zig fmt --check build.zig zigandgit diff --check: clean. No Zig file this delta adds or edits passes 600 lines.a80eddd9a6(before the folded commits and the main merge): tests, M5 Ultra,zig build test test-golden dev-tools native tf-dsv41-run test-deepseek-v41-lifetime -Dcpu=apple_m1 -Doptimize=ReleaseSafe: 977/977 steps, exit 0, 11392 of 11503 tests passed, 111 skipped. M4 Pro, the same command withtf-kernel-contract: 979/979 steps, exit 0, 11874 of 11984 passed, 110 skipped.zig build test-cuda-host: 345/345 steps, 131 tests, on both. Counts exclude cached work.zig build metal-kernel-contract-limits test-metal-launch-map-host test-deepseek-v41 -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3: 50/52 steps, exit 1. The launch map reports 1270 registered launches, 2 controls, 0 missing, and its 8 tests pass;test-deepseek-v41has 74 tests: 70 pass, 4 skip.zig build test-exl3-gpu -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3: 41 tests, 40 pass, 1 skip, exit 0. Counts exclude cached work. The one limit problem is inherited:flashnext penalties fz_penalize_rowshas no launch source, andmainfails the same step with an uncaughtUnknownLaunchafterPASS limits: 1093 selected registered Metal launches … 0 problems.TF_DSV41_CONCURRENT=1reply equality is not re-established on this machine.a80eddd9a6as below, and nothing in this fold touches them except the build-file lines listed under Stacked on.mlx_lm; the full unfiltered kernel contract (it aborts inmetal_lfm3_attention_sums.zig:39, an integer overflow in a file this delta does not touch).Receipt
mainhas no DeepSeek-V4.1 EXL3 lane, so the baseline is DeepSeek-V4.1-Flash on Metal: the EXL3 2.9 bpw lane #2373's head. Tables below.deepseek_v41EXL3 lane only. Other families, CUDA, HIP and the shared lane code are not changed by behavior.platform/environment.zig, documented indocs/environment.mdwith their accepted forms and defaults):TF_DSV41_EXL3_FMA_TILES(0,1,2,4; default2),TF_DSV41_BATCH_MAX(1-8; default4),TF_DSV41_BATCH_ATTN(0/1; default1),TF_DSV41_CONE(0-2; default2),TF_DSV41_CONE_PARK(0-3; default3), andTF_DSV41_MTP_DRAFTS(default0; DeepSeek-V4.1-Flash on Metal: the EXL3 2.9 bpw lane #2373 already read it, this registers it). Each has a production caller and a measured benefit: with the others at their defaults, turning it off or down cost 4% to 65% in some cell (TILES=0-15%,BATCH_MAX=1-33% with four short streams,BATCH_ATTN=0-7%,CONE=0-38% on four long prompts and +65% cold TTFT,CONE_PARK=0-5%, the weakest). Three more settings I had added (TF_DSV41_EXL3_FMA_TILE_GROUPS,TF_DSV41_PREFILL_INTERLEAVE,TF_DSV41_ENGRAM_LOOKAHEAD) showed no slower arm in the same sweep and are gone, and the nineTF_DSV41_NO_FUSE_*switches are gone because a fusion is taken when its shape and pipeline checks admit it. The sweep table is in the receipt README.deepseek-ai/DeepSeek-V4.1-Flash-1017at1bae0e1088993b9b82de08f59de5be5a34e42170as an EAQ v1 EXL3 2.9 bpw pack with the original Engram shards.bench_concurrent.py --alone --serial, 64 tokens, three repetitions, temperatures 0 and 1.0 at 1 and 4 streams, short and long prompts: all cells equal to their solo run in both builds (0 unequal), and the same in all 13 non-default settings arms. Served checks on this tree: 33 plain, drafted and shared responses with equal full hashes, 41 completed responses, a cancelled 8192-token request, two unload/reload cycles. Resumed against fresh: the first request is cold, the next three reuse the cache (8064 of 8192 and 32640 of 32768 tokens), and every reply has the cold run's hash (a 2048-token prompt is below the reuse size). Tokens differ from DeepSeek-V4.1-Flash on Metal: the EXL3 2.9 bpw lane #2373's build in long greedy decodes (256 tokens, both public prompts) because the parent's arithmetic did not match its own reference; 16-token cold replies are token-equal at 2k, 8k, 32k, 64k and 128k.bench_openai.py --tokens 256 --reps 3 --temperatures 0: 40.23 tok/s (code) and 40.22 (chat) for the parent against 52.37 and 52.35 for this head.bench_cache.py --require-cold,--prompt-cache-gib 0, context 70000, one lane, exact token arrays, one request per size (128k: context 131072, 131008 tokens, parent measured once on the sweep tree's run):The 2048 row follows the decode run on the same server, as the parent's did; a cold first request on a fresh server measures 3.48 s.
bench_concurrent.py, 64 tokens (bench_exl3_compare.pyrefuses the pair because tokens differ, so this is an observation):tools/bench_cache.py,bench_openai.pyandbench_concurrent.pyare the committed tools.Kernel contract
exl3-metal(tf_exl3_matmul, fourteentf_exl3_matmul_decode_fma*bodies,tf_exl3_matmul_prefill_nax31);exl3-chain(tf_exl3_qkv_epilogue,swiglu_prerotate,rotate_out_in,rms_rotate_in,rotate_out_rope,rope_rotate_in,gateup_swiglu_prerotate,down_combine), each replacing the unfused launch sequence it fuses and checked against it (exl3_chain_unfused.zig);dsv41-native-rows(dsv41_rope_rows,dsv41_kv_glue_rows,dsv41_publish_rows) anddsv41-native-attention(dsv41_dense_kv_rows,dsv41_sparse_nax_rows), replacing the per-slot path;tf_hc_boundary_mix. Records are inzig/src/core/contract/*_records.zigandlimits.zig.tf-kernel-contract --only dsv41 --rotary-accuracy rotary.json --offline, exit 1:SUMMARY 102 kernels: 102 pass gates 1-4, 0 fail, 0 known findings; 237 controls: 237 red as planted, 0 missed; 6 limit problems; gates 109600 ms, limits 117497 ms. The six limit problems (xp_quant,fp4pack,fp4rt,hcmix,hcpost,joinpost: offline M1/M2 builds) are identical at DeepSeek-V4.1-Flash on Metal: the EXL3 2.9 bpw lane #2373's head, whose run reports89 kernels: 89 pass ... 6 limit problems.--only exl3, exit 0:SUMMARY 296 kernels: 296 pass gates 1-4, 0 fail, 0 known findings; 1186 controls: 1186 red as planted, 0 missed; 0 limit problems; gates 191983 ms, limits 20033 ms.--only dsv41, exit 1:SUMMARY 94 kernels: 94 pass gates 1-4, 0 fail, 0 known findings; 203 controls: 203 red as planted, 0 missed; 6 limit problems; gates 154729 ms, limits 208012 ms;--only exl3, exit 0:SUMMARY 35 kernels: 35 pass gates 1-4, 0 fail, 0 known findings; 142 controls: 142 red as planted, 0 missed; 0 limit problems; gates 31328 ms, limits 34502 ms.Gate agreed in #3385
The five parts, with where each is met on this tree (one M5 Ultra; the kernel contract also on an M4 Pro):
"draft": false(33 responses, equal full hashes); resumed equals fresh at 8192 and 32768 tokens; 1 cancellation and 2 unload/reload cycles left the next request valid (41 served responses)--only dsv41102 pass, 237 controls red as planted, 6 limit problems (the same 6 at the parent);--only exl3296 pass, 1186 controls, 0 limit problems. M4 Pro 94 and 35 pass, 203 and 142 controls. Each new kernel has a planted controlThe two conditions: each slice must be green on its own with its contract registrations and planted controls, which this single draft does not meet by itself (the slices cannot be separated while the registrations sit in one commit); and the token gates are the ones above, since #2373 is not on
main. The slices will be built on the series that replaces #2373.Checklist
"draft": false(33 responses with equal full hashes), a resumed prompt equals a fresh one (8192 and 32768 tokens), and concurrent equals solo (above).main. The fused Sinkhorn now uses the unfused split's FP32 row and column reduction order (1728 coefficients bit-identical to it); the other changed sums and their per-column FP64 fixtures are in the receipt README. The maintainers run their own device check.--draftergreedy and sampled no-slowdown against plain is in the served checks (95.2 against 52.5 tok/s greedy, 94.3 against 52.2 sampled). One machine only; the maintainers' hardware run is still to come.Commits in this delta
Copy rule and authorship
The projection kernels and Metal drafter that #2373's review traced to mlx-serve are #2373's code; its 87 commits (84 EugeneClaw, 3 Eugine) are kept unchanged in this branch's history. This PR adds 39 commits by BlivionIaG on top (42, 46 and 49 beyond #2373 in #3734, #3735 and #3736). A text comparison against the public mlx-serve, mlx-stream and turboexl3 histories finds no copied text (longest common run 3 normalized lines) but does not show independent design. Independence of #2373's code is not claimed here; this stack's own commits are proposed as separate improvements on top of it.