Skip to content

train 1119092521: #3458 #3575 (CI only) - #3937

Closed
ashhart wants to merge 47 commits into
mainfrom
lead/train-1119092521
Closed

ashhart wants to merge 47 commits into
mainfrom
lead/train-1119092521

Conversation

@ashhart

@ashhart ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

CI for a landing train: #3458 #3575 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.

…ed floor marks candidates, a merge selects among them), the same lists as glm_index_select

tf-glm-index-speed checks the new select against glm_index_select on real scores, ties, NaNs, signed
zeros, infinities, ramps, a hot span, a constant row and a row whose sampled blocks score high (the floor
overshoots, so the row is selected whole) at 15 positions and 1, 3 and 16 rows: 405 of 405 cases give the
same lists. On an M5 Max, a row at 90,000 tokens selects in 13.3 us instead of 26.6 us, at 120,000 in
13.3 us instead of 33.2 us.
…s at once, then the recurrence alone, kda_rows' values

glm_kda_window has kda_rows' buffers and arithmetic for every value; windows of two or more rows take it,
one-row steps keep kda_rows. tf-glm-kda-speed checks its outputs, final state and conv window against
kda_rows' bit for bit at 1 to 16 rows on three draws of inputs, for all 64 heads and TP2's 32: 96 of 96
cases are the same. On an M5 Max a 4-row step takes 27.5 us instead of 34.3 us, a 16-row step 79.2 us
instead of 106.3 us.
…x_select keeps rows of 3,073 to 8,192 blocks

The mark groups load their 16 words a simdgroup before the first compare, and the merge loads its
candidates' scores at once. On an M5 Ultra the mark took 8.3 us against 5.3 on an M5 Max, so the
sampled floor pays only past 8,192 blocks (32,768 tokens); up to there glm_index_select's one group a
row stays. tf-glm-index-speed: 405 of 405 cases give glm_index_select's lists; the speed tools warm
the GPU before timing. On an M5 Max a row at 90,000 tokens now selects in 11.8 us (26.6 us before the
new select).
…p against glm_index_select and kda_rows, with controls and launch records

The merge within 3,072 blocks and the mark and merge past 8,192 blocks (to rows past 65,536 blocks) run the loader's
glm_select.metal beside glm_index_select on the same scores; glm_kda_window and glm_kda_window_tp beside kda_rows and
kda_rows_tp at 2 to 16 rows. Gates 1-3 require the predecessor's bytes in every written buffer; each entry has a planted
source fault red at shapes. glm_launch_records.zig holds the four launches with this GPU's threadgroup bytes and the
M1/M2 limits from --offline.
…ll of them, each row the one-row launches' bits; tf-glm-attn-rows checks and times them
… and four down outputs from 2 rows, the generated kernels' bits; tf-glm-moe-rows checks and times the shapes
… sums on six threadgroups for windows up to 4 rows, the same sums; tf-glm-hc-rows checks and times it
…apes against main's launches, with controls and launch records

attendRows (glm_latent_scores_rows, glm_softmax_rows, glm_latent_values_rows) runs beside main's one-row scores,
softmax and values a row (a frozen glm_attn.metal) at 1 to 16 rows and 1 to 2,048 keys. core/hc.zig's boundary, with
tf_hc_expand_mix_parts and tf_hc_first_mix_parts to 4 rows, runs beside main's expand and split (a frozen
hc_boundary.metal) for separate streams, in place and at a first read, post and comb compared as raw words. The decode
experts at moe.zig's outputs a simdgroup run beside the four-output gathers at 1 to 8 rows. Gates 1-3 require the
predecessor's bytes; seven controls plant source faults red at shapes. The records add every launch with this GPU's
threadgroup bytes and the M1/M2 limits from --offline.
…h or the head, never the path; rows as a list
…ow, the collapse and norm on one and post with the Sinkhorn comb on the other, the same bits; tf-glm-hc-rows checks and times it

The one-group split ran simdgroup 0's 20 Sinkhorn steps between the mixes and the collapse, so every row's norm
waited on them. Group 0 now takes pre from the slice sums in each simdgroup (lanes 0-3, then shuffles) and norms
with one barrier; group 1's first simdgroup takes post and the comb, the old steps in the old order.
tf-glm-hc-rows checks the boundary against the one-group expand and the one-group split (kept in
tests/glm_hc_split_one.metal) at 1-16 rows on two draws, the second with wider values, zeros, -0 and large
streams: 2,842,400 outputs equal.
…d on two threadgroups, half the value columns each, then norms each row's head in a second launch, kda_rows' values; tf-glm-kda-speed checks and times it

At 64 threadgroups of 1,024 threads an M5 Ultra runs the step on about half its cores. glm_kda_parts gives each
head two groups of 512 threads: both take the rows' decays, q and k whole with kda_rows' sums, each its own 64
columns' v, gates, recurrence and state; the raw outputs go to y and the gates to gu, and glm_kda_norm norms and
gates each row's head in kda_rows' order. kernels.splitKda turns it on for a GPU named Ultra at one Mac's 64
heads and two or more rows; one-row steps, a Max (bandwidth bound) and TP2's 32 heads keep their kernels.
tf-glm-kda-speed checks it against kda_rows at 1-16 rows on three draws (the third with -0 and large inputs) for
outputs, state and conv window: 144 of 144 cases equal. With states past the caches on an M5 Ultra a step takes
16.8 us instead of 20.7 at 2 rows, 22.0 instead of 29.0 at 4 and 33.5 instead of 45.9 at 8. In a real window at
one row the second launch cost more than the split saved (the knock-out profile's KDA class 0.75 ms instead of
0.64), so one-row steps stay on kda_rows.
…before and reads blocks inside the keys unchecked, the same products in the same order; tf-glm-attn-rows checks and times it

The scores' 32 steps over the latent dims and the values' steps over the keys each waited on their own loads.
Both now load a step ahead, and a block wholly inside the keys reads without the per-element bounds (the same
values). tf-glm-attn-rows checks every window row against its own one-row launches of the previous kernels
(tests/glm_attn_ref.metal) at 1-2,048 keys and 1-16 rows: 13,492,480 outputs equal. On an M5 Max a layer's
dense attention at 400 keys takes 24.0 us instead of 32.2 at one row, at 2,048 keys 39.2 instead of 75.6.
…with row 0's sums alone, tf_route_logits' bits; tf-glm-route-one checks and times it

The core router kernel takes four rows a threadgroup and, for a one-row window, sums row 0 four times. GLM's
glm_route_logits_one (appended to core/moe_route.metal's source at GLM's two shapes, so Flint and Step-5 keep
theirs) does row 0's products, simd sums and partials in the same order and nothing else. tf-glm-route-one checks
it against tf_route_logits for the router (288 experts, fp32) and the indexer gate (128, bf16) on 64 weight copies
and three draws of rows, the third with zeros, -0, large and tiny values: 79,872 logits equal. On an M5 Max with
the weights past the caches a router launch takes 8.58 us instead of 10.98, an indexer gate 3.05 instead of 4.13.
…two-group split and prefetched attention, with controls and launch records

glm_route_logits_one at the router's fp32 and the indexer gate's bf16 outputs meets float64 at gates 1 and 4 with each
row its own one-row launch, and gives tf_route_logits' bits. glm_kda_parts then glm_kda_norm run beside kda_rows at 2
to 16 rows. The boundary entries now run the two-group tf_hc_split against main's split, and the attention entry runs
the prefetched score and value bodies against main's one-row kernels. New controls: a router partial left out, the
second KDA group on the first group's columns, the split's post from the pre mixes and a scores step multiplying the
prefetched block. The records add the parts, norm and both router launches and the split's threadgroup bytes.
…bers from each row's slots by expert and the groups' offsets from simd prefix sums, the same bytes; tf-glm-route-select checks and times it
…ghts take one launch, glm_rms', glm_layer_norm's and glm_scale's bits; tf-glm-mla-norms checks and times it
…kernel loads them, glm_scale's bits, one launch fewer an MLA layer; tf-glm-attn-rows checks and times it
…ch combines the picks' rows by their weights as the combine kernel did, the same bits, one launch fewer each MoE layer but the last; tf-glm-hc-rows checks and times it
… group replays the route select's picks with its routine, slot u takes pick u and the last pick's first group writes the picks and weights, the same bytes; tf-glm-moe-pick checks and times it
…s a fourth role, glm_rms' bits, one launch fewer an MLA layer; tf-glm-mla-norms checks and times it
…le, combining expand and one-row picked experts, with controls and launch records

tf_route_select runs beside main's select (a frozen moe_route.metal) at GLM's 288 experts, every expert or either held
half, and at Step-5's 352. glm_mla_norms with three and four roles runs beside main's glm_rms, glm_layer_norm and
glm_scale (a frozen glm_glue.metal). The attention entry's scores kernel scales the queries as it loads them, against
main's glm_scale and one-row launches. tf_hc_expand_mix_moe and its parts run beside main's combine then expand and
split. A one-row MoE layer's gate/up groups replaying the select run beside main's select then the one-row gathers.
Gates 1-3 require the predecessor's bytes; eight new controls plant source faults red at shapes. The records add the
seven launches with this GPU's threadgroup bytes and the M1/M2 limits from --offline.
…experts' gate/up and down, the shared expert's halves, the combine and the boundary by part, and takes a later chunk (GLM_PROFILE_AT) after the rows before it
…LM_STATE_HASH): KDA states, convolution tails, MLA keys and pooled keys
…ir tiles in groups of 32 column tiles, each group taking every row tile in turn: core/affine_mm.zig's tiles, staging and sums; tf-glm-mm-groups checks and times them
…ainst core/affine_mm.zig's gathers and matmul, with controls and launch records

glm_gather_glu_32/_64 and glm_gather_scatter_32/_64 run beside tf_affine_gather_glu and tf_affine_gather_scatter on one
route over six experts (means of 2, 43 and 183 rows: both heights of each launch), NaN and infinities planted in the
activations and in down's scales (the SwiGLU's clip keeps them out of the activations). glm_mm_grouped runs beside
tf_affine_mm at 4096, 2240 and 24896 columns (a partial last group). Gates 1-3 require the predecessor's bytes; two
controls plant source faults red at shapes. The records add the five launches (nax.h: no M1/M2 build ahead of time).
…ck from a recorded pass (GLM_PROFILE_TAPE), so a knock-out leaves later layers' expert loads and selections as served; the route and the selection are timed live against it
…locks, so a row's queries are read once a tile instead of twice, in 128-row tiles of 8 simdgroups (64-row tiles where those would leave the GPU half idle): the same products, head order and sums; tf-glm-prompt-select checks them against main's kernel and times them at long positions
…'s kernel, NaN and infinities planted in the queries and weights, with a control and a launch record
ashhart and others added 17 commits November 19, 2026 09:25
…cales and biases a step ahead, so the next step's weight reads overlap this step's products: the same tiles, products and sums; tf-glm-mm-groups times them from 128 rows with the weight bandwidth
…tep's codes again in place of the next step's
Gates 1-4 run the relu^2 stream tile at every width Nemotron's oQ
checkpoints store it (4, 5, 6 and 8 bits in groups of 64), each wider
width with a planted control that reads its codes as 4-bit and goes red
at gate 3. Gate 5 records the 24 launches at 5, 6 and 8 bits on the four
RDNA chips. The 1x8 tile at those widths spills to scratch on gfx1100;
the records name it as a known finding and a host test holds the list
to the records.
The loader, the memory plan and admission read config.json's per-module
widths: MLX affine 4, 5, 6 and 8 bits in groups of 64, one width per
tensor. Routed stacks are checked against their stated width. Other
widths, unquantized projections and an MTP head inside the model's
shards are refused by name. The uniform 4-bit checkpoint reads as before.

The MTP head file is still read at the model's own width, so admission
refuses it by name beside a model not stored 4-bit in groups of 64.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Landed: #3458 #3575 as main 174010e. This PR only carried their CI.

@ashhart ashhart closed this Nov 19, 2026
@ashhart
ashhart deleted the lead/train-1119092521 branch November 19, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants