Skip to content

glm53: the full GLM-5.3 on several Macs - #557

Closed
chadhurley25075-png wants to merge 1 commit into
ashhart:mainfrom
chadhurley25075-png:glm53-full
Closed

chadhurley25075-png wants to merge 1 commit into
ashhart:mainfrom
chadhurley25075-png:glm53-full

Conversation

@chadhurley25075-png

Copy link
Copy Markdown
Contributor

glm53: the full GLM-5.3 on several Macs

This adds a glm53 family: the full GLM-5.3 (GlmMoeDsaForCausalLM, 78 layers, 256 routed experts top-8, DSA sparse
attention with index_topk 2048, the layer-78 MTP head), served across four M3 Ultra Mac Studios (256/512/256/256 GB) over
Thunderbolt 5 with MCDMA. It sits next to the GLM-5.3-Flash glm family and is built the TensorFold way: fp32 partials
exchanged inside the command buffer and summed in slot order, so N Macs give exactly the bits one Mac gives with N slices.

Why four Macs (you need far less)

We run it on four Studios on purpose: we want to fill it with millions of tokens of context and keep room to run the rest
of your stack (MCDMA, Drift and friends) right beside it. The model itself needs much less. The 6-bit weights are about
670 GB, so two 512 GB Macs hold them with room left for a long context, and the family takes any number of ranks
("ranks": N). We've only measured the four-Mac setup, so the numbers below are for that.

Measured (4× M3 Ultra, 6-bit experts, BF16 indexer, MTP head)

Decode: short answer / 400-token story / 400 tokens of code 51.5 / 41.0 / 45.7 tok/s
Decode in a real conversation at 138K–183K positions 36.2–42.9 tok/s
Context cap 3,100,000 positions (layer-split latent cache)
Deepest recall needle at ≈1,015,896 positions in a 1.03M-position conversation, 38/38 checks
Endurance 3 h 41 min continuous up to 1.03M positions, no stalls
Exactness every switch on vs off: character-identical replies; oracle vs mlx-lm fp32 (argmax equal, rel-L2 ≤ 4.2e-7); same score as the fp32 reference on a fixed 70-question set

The first two rows were re-measured on this branch's binary, A/B against the build we serve: same speeds, same reply hashes on
all six long-conversation turns. The others were measured on that served build. Full table and setup in
docs/recipes/glm-5.3.md.

What's in it

  • N-rank exchange with per-peer send threads, a stall diagnostic that names the waiting rank, and fenced pieces for large
    partials (G53_XCHUNK) — without them the Thunderbolt link dropped an overflowing partial silently.
  • The DSA indexer, kept exact. GLM-5.3 picks 2,048 past tokens for every new one; long context lives on that choice. The
    indexer runs at fp32 over BF16 weights, scores two rows a threadgroup, and can split keys across ranks (G53_KSPLIT) or
    rows across ranks for prompts (G53_OWN_FRONT) — always the same picks. Keep the indexer BF16: on GLM-5.2 every 4–8-bit
    indexer quant we tried lost long context at ~3,000–4,700 tokens; BF16 held.
  • MTP self-speculative decode from the layer-78 head plus copy drafts, verified by the trunk — same tokens.
  • Layer-split latent cache (G53_LSPLIT): past a chosen position, each layer's latent cache and attention live on one rank,
    taking a 512 GB + 3×256 GB set from ~2.0M to 3.1M positions with the same replies.
  • Serve mode (JSON lines over TCP, cancel/stop_at, exact KV snapshots), oracle mode, tf-glm53-ixbench, a synthetic checkpoint
    for tests, and the MLA-pack / MTP-head converters. Every switch is off by default.

Limits

Measured on M3 Ultra only — not measured on M5. Needs ~670 GB of weights across four Macs. Past the split point decode is
~27–30 tok/s near 1M positions. Long-prompt Thunderbolt stalls are detected and reported; the root fix (flow control or
reconnect in MCDMA's Thunderbolt link) belongs in MCDMA.

Thanks

Ash, thank you. None of this exists without TensorFold and MCDMA — the kernel conventions, the exchange, the native engine
and, most of all, the exactness discipline are yours, and they made this the most enjoyable engine we've ever built on. The
"every switch must give the same bits" rule you hold everything to is what let us take the full GLM-5.3 to a million-token
needle without ever wondering whether an answer had drifted. This is offered as a gift to your project: take all of it, part
of it, or none of it, and if you'd rather it land as smaller PRs or live as a separate family, we're glad to reshape it.

The own-row prompt indexer follows MiaAI-Lab's prompt sequence-parallel select and drowzeys' TF_GLM53_SP_SELECT — thank you
to both.

🤖 Generated with Claude Code

A new family, tf-glm53, for the full GLM-5.3 (GlmMoeDsaForCausalLM: 78 layers, 256
routed experts top-8, DSA sparse attention with index_topk 2048, the layer-78 MTP head).
Each rank holds a share of every layer's heads, expert rows and vocabulary; fp32
partials are exchanged over MCDMA inside the command buffer and summed in slot order,
so N Macs give the bits one Mac gives with N canonical slices.

- fp32 activations end to end (the checkpoint's F16 scales promote mlx-lm's matmuls to
  fp32, so that is the reference); MLX-arithmetic 6/8-bit row kernels, simdgroup tiles
  for prompt blocks, split-K short matvecs; fp16 KV option.
- The DSA indexer at fp32 over BF16 weights, scores with the query staged once a span
  of keys (G53_IDX=3: two rows a threadgroup), radix top-k over many threadgroups for
  decode-sized blocks; sparse latent attention (G53_ATTN4H, G53_JOINB).
- MTP self-speculative decode from the layer-78 head with verify blocks on the row
  path, and copy drafts (G53_COPY), both verified by the trunk: the same tokens.
- N-rank exchange: per-peer send threads, a stall diagnostic (G53_STALL_S) and fenced
  pieces for large partials (G53_XCHUNK; MCDMA Endpoint.flushPeer), because the
  Thunderbolt link dropped an overflowing partial without an error.
- Exact speed switches: concurrent encoder (G53_CONC), the wait inside the sum launch
  (G53_FWAIT), shared weight reads for bf16 row matvecs (G53_GROWS), key-split decode
  indexer (G53_KSPLIT), own-row prompt indexer (G53_OWN_FRONT), KV residency and
  touch after a snapshot load (G53_KV_RESIDENT, G53_TOUCH).
- Layer-split latent cache (G53_LSPLIT, _OWNER, _FROM): past a chosen position each
  layer's latent cache and attention live on one rank, so a 512 GB owner beside three
  256 GB Macs takes the cap from about 2.0M to 3.1M positions with the same replies.
- Serve mode (JSON lines over TCP, cancel/stop_at, KV snapshots), oracle mode against
  an mlx-lm dump, tf-glm53-ixbench, and tools: the MLA absorb pack, the MTP head
  converters, a synthetic checkpoint. The copy index's unit tests join zig build test.

Every switch is off by default and leaves replies character-identical when on.
Measured on four M3 Ultra Mac Studios (256/512/256/256 GB) over Thunderbolt 5; not
measured on M5.

Built on Ash Hart's TensorFold and MCDMA (kernel conventions, the exchange, the copy
rounds' acceptance rule). The own-row prompt indexer follows MiaAI-Lab's prompt
sequence-parallel select and drowzeys' TF_GLM53_SP_SELECT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @chadhurley25075-png. Running the full GLM-5.3 across four Macs with replies identical whatever switches are on is a big piece of work, and the layer-split latent cache is a neat way past one Mac's memory.

We can't land it in this form, and the reasons are about how it fits the engine, not the results:

  • It brings its own server (JSON lines over TCP, zig/src/families/glm53/main.zig:35 and :316). Every native model serves through the shared server and lane host, so drafts, concurrency, prompt reuse and the API come from one place.
  • zig/src/families/glm53/copy_index.zig is a copy of zig/src/core/copy_index.zig; the family should import the core module.
  • forward.zig (1,425 lines), kernels.metal (2,283) and main.zig (783) are past our 600-line limit, there are about 70 comments that run over several lines, and the G53_* switches would each need to become the one default path or go.
  • Several comments and the commit message name a person. We keep personal names out of the tree and its history, so a GitHub handle or the project name works instead.

We also don't have four Macs with that much memory to gate it on. If you'd like to take it forward, a smaller first step would help: GLM-5.3's indexer and sparse latent attention as a family on the lane host, checked on one Mac with a layer subset. We'd be glad to review that.

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