Skip to content

Living Weights for the full GLM-5.3 (glm53 family) - #575

Closed
chadhurley25075-png wants to merge 4 commits into
ashhart:mainfrom
chadhurley25075-png:glm53-living-weights
Closed

chadhurley25075-png wants to merge 4 commits into
ashhart:mainfrom
chadhurley25075-png:glm53-living-weights

Conversation

@chadhurley25075-png

Copy link
Copy Markdown
Contributor

Living Weights for the full GLM-5.3 (glm53 family)

For your consideration: not a finished feature, but a working starting point that has learned real facts on the full GLM-5.3 across four Macs. We're excited to see what you and the community do with it.

Branch glm53-living-weights, 3 commits stacked on #557 (f90dc25, #557 rebased onto 1.0.3).

What it adds

  • "lw": path serves a learned low-rank change after layer 77's shared-expert down projection on every rank;
    "slide": true also takes {"learn": ...} / {"learn_step": k} lines. Without "lw" the engine is the stock one.
  • Learning runs on N Macs in lockstep: each rank computes its quarter of the head's vocabulary for the loss and W^T g,
    and the parts are summed through the exchange. Captures come from a scratch engine; the KV caches are never touched.
  • Same append-only shard files as the Flash PR (living-NNNN.safetensors + living_weights.index.json, sha256 of the
    site weight per shard, drop the newest to undo). Every rank must load the same change before serving.
  • Reuses the Flash PR's learner files (families/glm/lw_learner.zig, lw_math.zig, lw_sites.zig, identical), so
    whichever lands first, the other drops them.
  • zig build test-glm53-lw: format, shards and rollback, a simulated 4-rank split against one rank, the served apply's
    reference. A section in docs/recipes/glm-5.3.md.

How to use

Add to every rank's settings: "lw": "<folder>/living_weights.index.json" (or a living_weights.safetensors path),
and "slide": true to learn. Then send every rank the same lesson line, for example
{"learn": {"train": [...], "held": [...], "steps": 400, "commit": true, "save": true}}, followed by
{"learn_step": k} lines.

Measured (4 × M3 Ultra)

  • No change loaded: replies equal the build without this branch on the reference prompts (exact), 17×23 = 391,
    53.9 tok/s.
  • "I like blue." on 4 ranks: learn 24 s, commit 20 s; the saved shard is byte-identical on all four ranks. The KV caches
    were unchanged on every step, and replies did not change before the commit.
  • After commit: the trained question and an unseen phrasing both answer blue. Six of seven neighbouring questions are
    bit-identical; the seventh (who wrote Romeo and Juliet) was reworded and still correct.
  • A third-person fact (a person's name and birth date), with the turn-end fix from the Flash PR: kept after 20 steps with
    the strict recalled check true, no repetition, neighbours' facts intact; it answers with the full date (measured on the
    build this branch was cleaned up from).
  • An earlier run found a bug: a capture reused an exchange sequence number and read stale data, so the ranks saved
    different shards. Fixed in this branch; a reused number is now refused.

Known limits

  • For the "I like blue." lesson, one held-out phrasing ("Remind me, what's my favorite colour?") still misses and the
    strict recalled check (every answer token p > 0.5) is false. Recall with thinking on is not there yet: the lessons
    train the no-thinking form, and GLM-5.3 reasons its way past the fact. Thinking-mode lesson copies are the next step.
  • Not tested yet: reload from the saved shard after a restart, thinking-on recall, several facts.
  • macOS build and zig build test pass; zig fmt --check is clean on the changed files.

Thank you for the engine and the learner this is built on; please reshape or decline as you see fit.

🤖 Generated with Claude Code

chadhurley25075-png and others added 4 commits October 9, 2026 19:17
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>
(cherry picked from commit c09e1be)
…ab-split learning step, CPU tests

The change is y += 10 (x a^T) b after layers.77's shared-expert down projection (in 2048, out 6144). Learned rows live
in append-only living-NNNN.safetensors shards listed in living_weights.index.json (a lone living_weights.safetensors
loads as shard 1), each with the site weight's sha256. The step past the site is split by the head's vocabulary rows:
each rank's part of the log-sum-exp and of W^T g, summed across ranks. The learner state machine, Sites and the shared
CPU math are the GLM-5.3-Flash learner's files (families/glm/lw_*.zig), identical to that PR's.

zig build test-glm53-lw: format round trip, shards and rollback, a simulated 4-rank split against one rank, the
served apply's reference; no GPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…acs through the exchange

The committed change is applied at layer 77's shared expert per canonical slice (two kernels in kernels.metal); rank 0
of the change encodes nothing, so a run without "lw" is the stock forward. With "slide", learn lines give every rank
the same lesson; each runs the same learner in lockstep on scratch-engine captures and sums its vocab parts through
the exchange. Learning never touches the KV caches. Every rank must load the same change (its tag is in the start
word), and an exchange number is never reused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. Learning in lockstep across four Macs, with every rank saving a byte-identical shard, is neat work, and catching the reused exchange sequence number was a good find.

This PR starts from #557's code unchanged, so the reasons we gave there still apply: its own server (glm53/main.zig, now 890 lines), glm53/copy_index.zig as a copy of the core module, and forward.zig and kernels.metal at 1,457 and 2,319 lines. It also adds four Python tools, and we're moving the project off Python rather than adding to it. The Living Weights part learns through that server and keeps each change in side files, while Living Weights is moving to changes written into the model's own shards. So we'll close this one.

The path from #557 stands: GLM-5.3's indexer and sparse latent attention as a family on the lane host, checked on one Mac with a layer subset. Learning for glm53 would then follow on the shared learner.

@ashhart ashhart closed this Oct 10, 2026
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