Skip to content

glm sp: quantized MoE and MLA gathers on the pair (cold prefill +3.1%, exact) - #347

Merged
AzeezIsh merged 8 commits into
Atlas-Inf:mainfrom
Enntity:glm/pair-quant-gather
Nov 15, 2026
Merged

AzeezIsh merged 8 commits into
Atlas-Inf:mainfrom
Enntity:glm/pair-quant-gather

Conversation

@data-angel

Copy link
Copy Markdown
Contributor

During sequence-parallel prefill the four-rank chain gathers each layer's MoE and MLA inputs in the packed form the receiving rank would compute anyway (NVFP4 rows + routes, FP8 block rows + scales) instead of BF16 rows. The pair was held to BF16 by sp.ranks > 2 checks.

Change

ATLAS_GLM_SP_QUANT_GATHER_PAIR (default 0, in the startup parity table):

  • 1: the pair gathers MoE and MLA inputs quantized on its own chunks. KDA layers keep the BF16 gather.
  • 2: the pair's chunks are also cut to 128 rows a rank, as the chain's are, and KDA layers gather quantized too.

Unset, every topology takes the paths it took: the chain's conditions are the same expressions and the pair's stay false.

Result (2x DGX Spark, GLM-5.3-Flash, mode 1)

  • RigMark cold 16K prefill: 2,753 → 2,837 tok/s (+3.1%); about 20% fewer bytes between the Sparks.
  • Output is bit-identical: greedy text on 8 prompts and prompt log-probabilities (1K, 4.4K and 15K-token prompts) match the build without the switch.
  • Mode 2 measured no further gain on the pair (3,038 against 3,035 with 16K chunks) and has not been through the output comparison.

Tests

Host tests cover the switch, gating, row multiple, parity table and both mock ranks through a seam. GPU tests cover the pair's halves and seam blocks. cargo test -p spark-model --lib glm_sp and startup_parity pass.

Note: this adds one environment switch, so the env budget check may need a maintainer's call.

🤖 Generated with Claude Code

@data-angel
data-angel requested a review from AzeezIsh as a code owner November 11, 2026 15:51
data-angel and others added 8 commits November 14, 2026 15:58
In multi-rank worlds the GLM vision tower sizes its scratch for the
processor's whole budget (GlmCapacity::budgets: 120,000 patches, one video
temporal group). That is 1.25 GiB held for the life of the process on the
encoding rank, and since the KV pool is the minimum across ranks it costs
every rank the same number of blocks.

The tower only runs between prefill passes, so the scratch now comes from
the BufferArena instead. The arena's 15 per-pass members (FP8 activations,
router and gate logits, QKV/attention/norm/MoE outputs, SSM and expert
intermediates) are carved from one allocation (buffers/lend.rs), and the
encoding rank lends that span to the tower:

- lend(): device-wide sync, then hand out the span's base.
- return_lent(): zero only the borrowed bytes that overlap members decode
  expects zeroed, then wait on the encode stream. The four members the
  arena never zeroes sit first in the span, so the borrow's first bytes
  need no memset.

Every encode call site (prefill and the vision cache head) goes through
vision_forward_items(). When the span is smaller than the tower's scratch,
the factory falls back to a private allocation, which is the old behaviour.
total_bytes() accounts for the aligned span.

GLM-5.3-Flash FP4-Local, TP=2 on two GB10s, 4x1M profile, util 0.91: the
KV pool goes from 116,958-122,639 to 142,988-144,780 blocks (+19%). Vision
output is identical to the owned-scratch build (images and a 19K-token
video, alone and mixed with text decodes, every token logprob), greedy text
and prompt logprobs are identical, and text decode is level. Image TTFT is
about 20 ms (0.7%) higher from the sync and memset around each encode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
norm_output is now carved from the arena's per-pass span, which is freed
once through its base, so the teardown-order check looks for the span.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The confidence width rule never verified one draft on the pair, because a
lone owner's 2-row verify was priced 10.3 ms over its 3-row one. That was the
2026-09-28 sweep of the fused two-row path, which expert TP retired. On
SparkGLM 0.3.2 (TP2, prose, ATLAS_DFLASH_FIXED_WIDTH=1, 2026-11-11) a 2-row
verify takes 42.0 ms against 47.4 for 3 rows, and 46% of prose steps accept
no draft. The pair now prices 2 rows on the same 5.68 ms line, so an unsure
block verifies one draft. The chain has not been re-measured and keeps the
charge. Verification stays exact at any width.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…line

Review: the non-chain branch also serves a single GPU and a pair without
expert TP, which still run the fused two-row path the 10.3 ms charge was
measured on. The row-line price now needs the pair under expert TP
(set at startup with the topology); everything else keeps the charge, and
the width tests keep their expectations.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…_PAIR

The four-rank chain gathers a sequence-parallel layer's MoE input as NVFP4
rows + routes (2368 B a row), its KDA input cast and side-projected (4864)
and its MLA input as FP8 block rows + scales (4224) instead of 8192 B of
BF16. The pair was held to BF16 by `sp.ranks > 2` in each of the three, by
the MLA's chain-only `supports_gather_async` check, by b_proj_full being
loaded at TP4 only, and by its 8196-row chunks (4098 rows a part, off the
KDA cast's 128-row scale tile grid). The gathers themselves are
`SpRows::all_gather{,_block}`, which already swap the two parts over the
pair's exchange.

ATLAS_GLM_SP_QUANT_GATHER_PAIR (default 0, in the startup parity table):
  1  MoE and MLA gather quantized on the pair; KDA too where a part is
     whole 128-row tiles (not on the pair's own 8196-row chunks).
  2  also cuts the pair's chunks to 128 rows a rank (8192), as the chain's
     are, so KDA layers gather quantized.

Unset, every topology takes the paths it took: the chain's conditions are
the same expressions, and the pair's stay false.

Tests: the switch and gating, the row multiple, the parity table, and both
mock ranks through a seam that gathers staged tensors of other widths in
place of the normed rows (whole, and per block group).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The row-local steps of the three quantized gathers were checked on the
chain's quarters and sixteenths. Add the pair's parts: halves, a half's
four seam blocks (1025/1023 rows of a 4098-row half for the MoE), eighths
for the KDA cast on the tile grid, and the MLA indexer GEMM with one of
two parts set.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Review: under mode 1 a KDA layer gathered quantized whenever a chunk's
parts fell on the 128-row tile grid (a 4096- or 8192-row tail), a path the
pair's own 8196-row chunks never run. Mode 1 is now MoE and MLA only, and
b_proj_full is loaded for the pair only in mode 2.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor

Restacked: the four GLM PRs are now one linear stack on main cb59c7663, in order: #338 → #346 → #347 → #348. This PR sits on #346. Its own commits: e05c7af, a001034, b55c317.

git range-diff against the previous heads shows every original commit unchanged (=). All cherry-picks applied without conflicts.

Pre-push checks on the stack top: fmt, clippy --workspace --tests, cargo test --workspace --locked, the ≤500-line cap, typos, SPDX, mdBook and cargo doc all pass. While the PRs below are open, GitHub shows their commits in this PR's diff as well.

Pair gate on 2× GB10 is running now: GLM-5.3-Flash FP4-Local, the SparkGLM 0.3.2 4x1m spark launch with KV shard at 0.91, each PR's binary against its parent's. Results will follow here.

Generated with Devin

@AzeezIsh

Copy link
Copy Markdown
Contributor

@data-angel pair gate for #347: passed. Merging after this comment.

Setup: 2× GB10. Fresh builds at exact commits: parent = #346 7ea9aecbf (22efc028…), PR = b55c31745 (557758d5…). Three arms: parent, PR with the switch unset, and PR with ATLAS_GLM_SP_QUANT_GATHER_PAIR=1 on both ranks. Boots alternate, 2 per arm. Launch is the same as #338/#346: SparkGLM 0.3.2 4x1m spark, KV shard, 0.91, GLM-5.3-Flash FP4-Local 76348ddb. In the mode-1 arm, rank 0 logs the switch, MLA attention input gathered as FP8 block rows + scales and MoE input gathered as NVFP4 rows + routes, so the path was exercised.

Check switch unset mode 1
Teacher-forced top-20 text, 27,169 positions × 2 boots KL 0, exact KL 0, exact
Vision top-20 (29,488 positions) KL 0 KL 0
Vision under 2 live decodes 5/5 identical 5/5 identical
Greedy 8 prompts C1 / C8 8/8 / 8/8 8/8 / 8/8
Tools 21/21 21/21
Cold TTFT 16K (s, median of 4) 5.05 → 5.09 5.05 [5.02–5.08] → 4.90 [4.88–4.93] (−3.0%)
Cold TTFT 28K 8.44 → 8.49 8.44 [8.43–8.46] → 8.18 [8.17–8.37] (−3.1%)
Cold TTFT 2K / 8K level level (8K is one chunk at --max-prefill-tokens=8192)
Decode prose/code/json, C1–C4 aggregate level level

Mode 1 matches your +3.1% cold prefill and bit-identical output. With the switch unset, 28K TTFT read 8.49 against 8.44 (ranges just disjoint at n=4); 2K/8K/16K and decode are level, and the default path's code is unchanged. We read that as boot noise, recorded here in case it shows up again. Mode 2 wasn't run.

On the env-budget ratchet: this adds one switch, so the count goes 1134 → 1135 (budget 1091; main already fails). If mode 1 should become the pair's default, folding it into the profile or a MODEL.toml field would retire the knob. That would be a follow-up PR.

Qwen: the 11-11 pair receipt on this patch covers it (KL 0 / 34,245 positions, bench level), so we didn't re-run it.

Generated with Devin

@AzeezIsh
AzeezIsh merged commit 548de46 into Atlas-Inf:main Nov 15, 2026
24 of 27 checks passed
AzeezIsh pushed a commit that referenced this pull request Nov 16, 2026
…_GLM_SP_QUANT_GATHER_PAIR

PR #347's mode 1 measured bit-exact against mode 0 on the two-rank pair
and ~3% faster on cold prefill, so the pair now always takes it; mode 2
was never output-validated and gained nothing, so it is deleted. One
fewer env var on the budget.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

3 participants