Repository navigation
buffer arena: three GLM-5 per-pass buffers sized for what they hold (KV pool +11% at TP=2, stacked on #338) - #348
Conversation
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]>
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]>
GLM-5 keeps its mHC highway BF16 under ATLAS_GLM_HC_BF16=1 (hc_bf16_for, both canonical target lanes) and serves the _bf16 twins of the hyper-connection kernels on it, but the arena still sized hc_streams for FP32: [rows, hc_mult, hidden] * 4. Half of it was never touched. On the TP2/EP2 pair that is 32,768 bytes a row: 256 MiB of an 8196-row arena, 512 MiB of a 16384-row one, taken before the KV pool is sized. The arena cannot see the model's policy, so the launcher's topology step copies it into ModelConfig::hc_highway_bf16 (environment only, and on the long-context lane resolved before the reserve preflight). Left false the arena keeps the FP32 size, which is never too small. The model build refuses an arena whose highway is smaller than hc_elem_bytes says the kernels read, so a config and a policy that disagree stop the launch. One consumer read the highway as FP32 scratch, not as the highway: the mHC TF32 prewarm (ATLAS_GLM_HC_TF32_PREWARM=1, on in the serving profile) warms cuBLASLt with an FP32 [rows, hc_mult*hidden] activation there. Over a BF16 highway it now borrows that activation from the arena's per-pass span, past the members zero_all never zeroes (its scratch stays in gate_logits_f32, one of them): BufferArena::lend_tail / return_lent_tail. It still zeroes the highway, as it always left it. With an FP32 highway the prewarm is unchanged. ATLAS_DUMP_HYPER_RMS reads the highway as FP32; it now refuses a BF16 one instead of reading past it. No computed value changes: the highway's bytes and every kernel that reads them are the same. Co-Authored-By: Claude Fable 5.2 <[email protected]>
moe_router_in_f32 is the FP32 [rows, hidden] MoE-input norm that ATLAS_FP32_ROUTING feeds the gate GEMM. MoeLayer::fp32_routing_active needs that switch and a router without a correction bias, so GLM-5's noaux_tc router never reads or writes a router input there. What it does keep in the buffer is the MoE's tile worklists and the K128W row-tile prefix (prequant_fp4, decode_m16, route_fuse, gate_up_btile_grouped), each of which checks the buffer's capacity before it writes. For a correction-bias router without ATLAS_FP32_ROUTING=1 and without per-layer expert shapes the buffer is now sized for exactly that: a tile count and one 8-byte item per row, routed expert and 128-wide tile of the expert intermediate (router_worklist_bytes, the widest of those worklists over every arena row), no less than the one FP32 row a one-row arena always had or the K128W prefix. On the GLM pair that is 1,024 bytes a row in place of 16,384: 120 MiB of an 8196-row arena, 240 MiB of a 16384-row one. Every other router keeps the FP32 size. The FP32 gate GEMM now checks that the buffer holds the rows it reads, so a router input can never be read from a worklist-sized buffer. No computed value changes: the worklists are the same bytes at the same offsets of a shorter buffer. Co-Authored-By: Claude Fable 5.2 <[email protected]>
ssm_conv_out_f32 is the GDN's FP32 conv output, [rows, q|k|v|z] * 4. GLM-5 has no GDN: its linear-attention layers are KDA (Glm5KdaLayer), whose convolution kernels write BF16 q|k|v rows ([rows, 3p], or the same bytes as three planes), and its MLA has neither a RoPE partition nor a low-rank O projection, the other two users that scale this buffer with the rows. On the TP2/EP2 pair a row held 65,536 bytes and the convolution wrote 24,576 of them. For glm5_next (KDA heads, qk_rope_head_dim 0, o_lora_rank 0) the buffer is now [rows, 3p] BF16, and no less than the FP32 width over one attention piece (GLM_ATTENTION_PIECE_ROWS, 4100 rows): what a piece borrows of the buffer, the native sparse attention's padded queries, fits as it always did. A 16384-row pair arena gives back 640 MiB, an 8196-row one 256 MiB. What keeps a wrong claim loud: - every KDA path takes the buffer through convolved_rows(), which checks the rows it is about to convolve against the buffer; - the native sparse startup check asked the arena for its operands at the arena's rows. The kernel path only ever takes a piece (plan::admit, 2048..=4100 rows), so the check now asks for the widest piece; each Plan::new still checks the operands of its own call; - the indexed KDA core and the K3/verify stage plans already carry the buffer's size with its pointer. zero_dirty (ATLAS_GLM_ZERO_ROWS, not served) shares a buffer out by rows. The conv scratch now holds fewer rows than the arena at the FP32 width a pass may reach, so it is shared out by those rows (conv_wide_rows): a pass of n rows has the same bytes zeroed as before. sizes_glm_tests.rs pins the pair's arena after this and the two commits before it: 390,740 bytes a row (was 479,828), 3189.6 MiB at 8196 rows (was 3821.8, the figure the server logs) and 6176.6 MiB at 16384, each trim's condition, and unchanged sizes for other models. No computed value changes: the convolution and its readers use the same rows and strides in a shorter buffer. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Review: use_routing_bias is also set by other models, which have not run with the worklist-sized buffer. Every writer checks capacity, so the cost would have been a refusal, not an overrun; they keep the full size. Co-Authored-By: Claude Fable 5.2 <[email protected]>
cargo doc --workspace --no-deps fails under rustdoc::private_intra_doc_links: UNZEROED is pub(super). Same treatment b31250e gave the tower's attach. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
3339cf9 to
0ff16c8
Compare
|
Restacked: the four GLM PRs are now one linear stack on main
Pre-push checks on the stack top: fmt, 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 |
|
@data-angel pair gate for #348: passed. Merging after this comment; this closes the GLM stack. Setup: 2× GB10. Fresh builds at exact commits: parent = #347 GLM-5.3-Flash
Our pool is set by reiner's rank 0, which has about 3–4 GB of KV headroom at 0.91. The 632 MB therefore shows up as about +24% blocks here, against your +11% on a much larger pool. The absolute numbers aren't comparable to yours. Qwen3.8-Flash-Next FP4-Local, regression check (the arena is shared). Pair default rc16 serve, base =
Generated with Devin |
Three per-pass buffers in the prefill arena were sized for cases GLM-5 does not use. The arena is allocated before the KV pool, so every byte comes out of the prompt cache.
Change
hc_streams)hc_bf16_for, environment only)moe_router_in_f32[rows, hidden]FP32ATLAS_FP32_ROUTINGssm_conv_out_f32Per row at 8,196 rows: 479,828 → 390,740 bytes. Other models keep their sizes; every writer of the router scratch checks capacity before writing.
Result (2x DGX Spark, GLM-5.3-Flash, 4 x 1M profile)
Tests
cargo test -p spark-runtime --lib bufferspasses, with new size tests for GLM-5 and for a non-GLM correction-bias model.Stacked on #338 (it touches the lend span that PR adds); the last four commits are this change.
🤖 Generated with Claude Code