Skip to content

GLM Metal contract: runs to the end on M1 to M4 Macs, and gate 5 resolves routed-expert rows - #4397

Merged
ashhart merged 4 commits into
mainfrom
lead/glm-moe-rows-limits
Nov 21, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/glm-moe-rows-limits

Conversation

@ashhart

@ashhart ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

What this changes

Main's GLM kernel contract (tf-kernel-contract --only glm) did not run on Macs without tensor units (M1 to M4). Two test-side bugs stopped it:

  • Startup refusal. glm metal: vectorize pre-M5 Metal prompt, KDA, and indexer kernels #3921 made glm/kernels.zig put #define TF_GLM_M3_FAST 1 before the KDA prompt passes and glm_index_nax.metal on a GPU without tensor units. The KDA and index contracts still built those texts without it, so the loader check refused them ("GLM contract text is not one the loader compiles") and the run stopped before its first case. Both texts now follow the loader. Gate 5's pre-M5 texts carry the define too.
  • Gate 5 stop. The 14 glm moe rows … launch records (added 16 Nov) fell through to the generic glm branch of metal_limits.zig's resolver, which has no moe key, so gate 5 ended with error: UnknownLaunch. On M5 Macs too. They now resolve to tf.glm.wide.gather_source, the text the loader builds them from, as glm rows and glm gather already do.

Test code only; no kernel or engine source changes.

Checks on this head

Kernel contract, GLM, ReleaseFast, on an M3 Ultra:

  • main: stops at startup with NotTheLoadersLibrary, no case run.
  • this head: runs to the end. 102 kernels, 101 pass gates 1-4, 68 of 68 planted controls red, gate 5 complete.

It reports what the stopped contract had hidden on pre-M5 GPUs. These are separate kernel issues, not changed here:

  • glm_index_scores_nax (the pre-M5 form) differs from main's 32 x 32 kernel's bytes from byte 1,065,728 at 256 x 128 x 16384.
  • The same launch uses 18,432 threadgroup bytes where its declaration allows 17,408.
  • The five affine_mm glm m3 q4 non-finite cases stay as recorded known findings.

ashhart added a commit that referenced this pull request Nov 21, 2026
…oes; its record declares 18432 bytes

On a GPU without tensor units the case compiles glm_index_nax.metal with TF_GLM_M3_FAST (#3921, #4397), whose
threadgroups cover 32 rows with 4 simdgroups, but encode launched it as on M5: scoreRows' 64 or 128 rows a group and
2 x rows threads. Rows past 32 x the groups' count were never written (256 x 128 x 16384: rows 64 on, byte 1065728),
so the shapes gate compared unwritten floats against main's scores. The case now launches it as selectKeys does
(glm/prompt.zig: 32 rows, 128 threads); rows it wrote matched main's bytes already, and the kernel is unchanged.
Before M5 the planted control moves into the pre-M5 branch (both simdgroups of a row pair on the same 32 blocks),
since the M5 branch it edited is not compiled there. The pre-M5 kernel stages 128 x 72 bf16 (18432 bytes) of keys;
the record declared 17408 (the M5 tile, 64 x 136), so gate 5's limit now declares 18432.
@ashhart
ashhart force-pushed the lead/glm-moe-rows-limits branch from 498ebd5 to a8316bd Compare November 21, 2026 21:05
…for gate 5

The 14 'glm moe rows' records (9e52d73) fell to the generic 'glm ' branch of the Metal limits resolver, whose key,
'moe', names no generated kernel: the device pass stopped at error.UnknownLaunch after glm_rows_wide_q8. They take
the gather source the loader builds them from (glm/wide.zig), as 'glm rows ' does.
…r adds

#3921 made kernels.zig put `#define TF_GLM_M3_FAST 1` before the KDA prompt
passes and glm_index_nax.metal on a GPU without tensor units. The KDA and
index contracts still built those texts without it, so on an M3 the loader
check refused them ("GLM contract text is not one the loader compiles") and
the whole GLM contract stopped before its first case. Both texts now follow
the loader, and gate 5's pre-M5 texts carry the define too.
…oes; its record declares 18432 bytes

On a GPU without tensor units the case compiles glm_index_nax.metal with TF_GLM_M3_FAST (#3921, #4397), whose
threadgroups cover 32 rows with 4 simdgroups, but encode launched it as on M5: scoreRows' 64 or 128 rows a group and
2 x rows threads. Rows past 32 x the groups' count were never written (256 x 128 x 16384: rows 64 on, byte 1065728),
so the shapes gate compared unwritten floats against main's scores. The case now launches it as selectKeys does
(glm/prompt.zig: 32 rows, 128 threads); rows it wrote matched main's bytes already, and the kernel is unchanged.
Before M5 the planted control moves into the pre-M5 branch (both simdgroups of a row pair on the same 32 blocks),
since the M5 branch it edited is not compiled there. The pre-M5 kernel stages 128 x 72 bf16 (18432 bytes) of keys;
the record declared 17408 (the M5 tile, 64 x 136), so gate 5's limit now declares 18432.
@ashhart
ashhart force-pushed the lead/glm-moe-rows-limits branch from a8316bd to fc48bf2 Compare November 21, 2026 21:55
@ashhart
ashhart merged commit 4865250 into main Nov 21, 2026
1 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 21, 2026
…oes; its record declares 18432 bytes

On a GPU without tensor units the case compiles glm_index_nax.metal with TF_GLM_M3_FAST (#3921, #4397), whose
threadgroups cover 32 rows with 4 simdgroups, but encode launched it as on M5: scoreRows' 64 or 128 rows a group and
2 x rows threads. Rows past 32 x the groups' count were never written (256 x 128 x 16384: rows 64 on, byte 1065728),
so the shapes gate compared unwritten floats against main's scores. The case now launches it as selectKeys does
(glm/prompt.zig: 32 rows, 128 threads); rows it wrote matched main's bytes already, and the kernel is unchanged.
Before M5 the planted control moves into the pre-M5 branch (both simdgroups of a row pair on the same 32 blocks),
since the M5 branch it edited is not compiled there. The pre-M5 kernel stages 128 x 72 bf16 (18432 bytes) of keys;
the record declared 17408 (the M5 tile, 64 x 136), so gate 5's limit now declares 18432.
@ashhart
ashhart deleted the lead/glm-moe-rows-limits branch November 21, 2026 21:56
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.

1 participant