Repository navigation
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 14, 2026
ashhart
added a commit
that referenced
this pull request
Nov 15, 2026
ashhart
force-pushed
the
lead/dsv41-attn-dec
branch
from
November 15, 2026 12:46
c5f38f5 to
ab9c2ee
Compare
ashhart
force-pushed
the
lead/dsv41-attn-dec
branch
from
November 17, 2026 01:01
ab9c2ee to
c02ea70
Compare
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
…there and the rest by decode fmas The simdgroup kernels already ran near the fp32 MMA rate. On M5 GPUs (macOS 27) a routed expert's 32-wide group now goes to the tensor unit, fp4 weights read as stored, when its act_quant codes bound every fp32 partial sum below 2^24 times their lowest set bit: then any summation order gives the decode chain's bits. Other groups (about 0.2% up, 0.3% down on layer 2) run the decode kernels' 32 fmas in k order. The chains, scale fmas and tree are the decode kernels'; one simdgroup runs a chain and the tree joins them in threadgroup memory. Down's input halves and flags come from a small prep pass over act. Other GPUs keep the simdgroup kernels; the contract gates both sets, and both match the decode kernels per row. -- 2.43.0
…generation 17 runtime_sources/dsv41.zig called the experts' source with the old three arguments; it now lists the simdgroup source and, where the loader would take it, the tensor-unit source, so the runtime compile gate builds experts_units.metal. The tensor-unit kernels now run only on generation 17 (M5), the one checked; the modes test holds the runtime list to that rule. CHANGELOG: 155 ms, #3330. -- 2.43.0
TF_CTL 6 sends every group to the tensor unit. The down gates' random data now carries one group that decode's fmas round (2^24, 2^23, 2^16, then four terms of half an fp32 ulp, landing on a bf16 tie) and exact sums do not: the kernels match the oracle through the fallback, and the control goes red at the shapes gate. -- 2.43.0
…nd on an M5 units_test.zig checks xu_exact's rule against exact integer sums: a safe group's fp32 sum is exact in six orders, and past the bound some order rounds. On an M5 it builds rows at and past the bound (tops at the largest code, lows at the lowest bit, columns that swing and cancel), runs the production act_quant and dprep, then the tensor unit as xu_chain does and decode's fmas as the fallback does. Every safe sum matches the exact sum on both paths, past the bound the two paths split, and the kernels' flags equal the rule. TF_DSV41_UNITS_BATCHES sets the batches (2). -- 2.43.0
…ough bfloat tf_dsv41_attn_pre gives each simdgroup one row and two heads, so both heads' dots use one load of each key. Keys come straight from device memory (no window tiles or barriers), widen through the bfloat type, and a selected run's indices load four at a time. Each key is one step: both dots, the pair-order butterfly, a rescale of any head whose max rose, then each head's weight and sums, the steps of tf_attn_update. Bits equal main's and the decode kernel's.
…tched to 64 rows tf_attn_lo and tf_attn_hi widen through the bfloat type (the same values), so the decode kernel's dots and sums spend fewer instructions a key; the prompt kernel's own widening copy goes. With that, loading each step's keys a step ahead wins at every row count measured, so decode launches take the prefetch pipeline up to 64 rows. A 72-row decode shape keeps the plain pipeline under the contract. Bits equal main's.
ashhart
force-pushed
the
lead/dsv41-attn-dec
branch
from
November 18, 2026 03:48
c02ea70 to
b573e1c
Compare
Owner
Author
|
Both changes here are on main now: the prompt attention change (two heads a simdgroup, bf16 widened through bfloat) landed as 8116c32 with #3351, and the decode attention change (bf16 widening, keys prefetched to 64 rows) as 596c059 with #3459. A rebase onto current main leaves no difference beyond one comment line, so I am closing this as included.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #3351 (this branch carries its commits; it lands after it).
DeepSeek-V4.1 on Metal: the decode attention kernel (
tf_dsv41_attn_dec) gets #3351's bf16 widening, with the same bits:tf_attn_lo/tf_attn_hiwiden through thebfloattype (same values), so both kernels share onetf_attn_x16.prefetch_rowsgoes from 2 to 64. With the widening in, loading the next step's keys a step ahead beats the plain pipeline at every row count measured (1 to 64).Kernel-only A/B on an M5 Ultra, µs (output bytes equal to main at every row count):
Release layer 2 decode (
time-dsv41-metal-real, main and this alternated twice in one run): attention 47.5 / 46.5 / 53.9 / 52.7 µs -> 45.5 / 44.8 / 44.1 / 43.7 µs at 1 / 2 / 3 / 4 rows. Output and KV-state hashes are identical to main at 1 and 4 rows. The whole layer goes 632 -> 627 µs at 1 row and 1046 -> 1034 µs at 4 rows.Served, 16 prompts at 512 tokens, on the decode stack (#3287, #3288, #3292, #3296, gilby's #2973/#2983) plus the prefill PRs, back to back in one run: greedy 89.5 -> 90.3, sampled 72.8 -> 73.4,
"draft": false51.6 -> 51.5 tok/s. All 48 reply hashes equal the reference.One-row attention barely moves. Removing any single part of the work at 1-2 rows (exp, the shuffle tree, most of the dot fmas, the ballot, the PV fmas) changed nothing, so load latency and the per-step arithmetic chain cost about the same.
Tried and slower or level, all keeping bits:
Checks on an M5 Max:
Kernel contract
--only dsv41_attnpasses gates 1-4 on 22 decode shapes, with the 5 planted controls red.zig build test-dsv41-metal(1,135 checks, prompt vs decode rows 0 differ) andtest-dsv41-metal-servepass. Lean: 0 new.Synthena (Ash's Agent)