Repository navigation
DeepSeek-V4.1 on Metal: prompt experts on M5 tensor units, bit-equal (exact groups only) - #3330
Merged
Merged
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 14, 2026
…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.
ashhart
added a commit
that referenced
this pull request
Nov 14, 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.
…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.
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.
…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).
ashhart
force-pushed
the
lead/dsv41-xmma-tiles
branch
from
November 15, 2026 12:46
44784df to
1c63e8e
Compare
ashhart
added a commit
that referenced
this pull request
Nov 15, 2026
…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.
4 tasks done
1 task done
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
…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
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
…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
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 18, 2026
…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
ashhart
added a commit
that referenced
this pull request
Nov 18, 2026
ashhart
added a commit
that referenced
this pull request
Nov 18, 2026
…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
ashhart
added a commit
that referenced
this pull request
Nov 18, 2026
ashhart
pushed a commit
to gilby/TensorFold
that referenced
this pull request
Nov 19, 2026
ashhart#3330 added four "dsv41 xmma units " launch records built only on GPUs with tensor units, without adding a pre-M5 gate in metal_limits.supported. On GPUs without tensor units, Gate 5 failed with LibraryLoad on those four records. Add metal_dsv41_limits.tensorOnly, gate "dsv41 xmma units " launches through metal_support.tensor in metal_limits.supported, and cover both xmma variants with a host test in metal_mapping_test.
ashhart
pushed a commit
that referenced
this pull request
Nov 19, 2026
#3330 added four "dsv41 xmma units " launch records built only on GPUs with tensor units, without adding a pre-M5 gate in metal_limits.supported. On GPUs without tensor units, Gate 5 failed with LibraryLoad on those four records. Add metal_dsv41_limits.tensorOnly, gate "dsv41 xmma units " launches through metal_support.tensor in metal_limits.supported, and cover both xmma variants with a host test in metal_mapping_test.
ashhart
added a commit
that referenced
this pull request
Nov 19, 2026
…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
ashhart
added a commit
that referenced
this pull request
Nov 19, 2026
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.
DeepSeek-V4.1 on Metal: on M5 GPUs (macOS 27), the prompt's grouped routed experts (gate/up and down) run on the tensor units. Every output stays bit-equal to the decode expert kernels, as it is on main.
Why it is exact. The decode kernels sum a 32-wide K group with 32 fmas in k order. A tensor unit sums in its own order, so in general its bits differ: on data built to round, 48 of 2M sums did. But some groups have every partial sum an exact fp32 number, and there any order gives the same bits. That holds here because:
low.12 * sum|v| < 2^24 * low, every partial sum of the group is an integer below 2^24 in units oflow/2, so it is exact in fp32.act_quant(and a smallxu_dpreppass for down's inputs) flags each (row, group) block safe or not. Safe groups run on the tensor unit (Metal 4matmul2d), with the fp4 weights read straight from the checkpoint layout. Unsafe groups run the decode kernels' 32 fmas in k order: 0.19% of up blocks and 0.27% of down blocks on release layer 2. The chains, scale fmas and group tree are unchanged. Other GPUs, and M5 machines on older macOS, keep the simdgroup kernels, and if the tensor-unit kernels fail to build, the simdgroup kernels load instead.The tensor unit keeps all 24 bits. A stress harness on an M5 Ultra ran groups that pass the check and sit at the bound. That includes sums within 0.1% of
2^24 * low, k-order partial sums reaching 99.9% of it, and 9.3M sums of at least 2^23 units with the lowest unit set.The unsafe controls (groups that fail the check) do differ: 115,500 and 135,903 of 5.6M / 9.3M sums against the exact sum. So the harness can see a difference when one exists.
Speed. Release layer 2, position 0, an M5 Ultra, ms (two main runs and two branch runs in one session):
The simdgroup kernels were already at about 82% of the simdgroup fp32 MMA peak, so retiling alone could give about 1.2x at best.
Checks:
--only "dsv41 xmma", both kernel sets):6 kernels: 6 pass gates 1-4, 0 fail; 16 controls: 16 red as planted, 0 missed; 0 limit problems.zig build test-dsv41-metalpasses, including grouped vs row kernels at chunks 64 and 300 (0 differ). Lean: 0 new.xe_up/xe_downhashes change run to run (the plan's atomics order pairs inside a slot). Hashing act and eout in pair-id order gives identical values on all four runs, and theexperts,sharedandposthashes equal main's.On M5 the prompt scratch grows by about 35 KB a chunk row (about 141 MB at 4096 rows) for the half codes and down's inputs.