Repository navigation
glm vision: borrow the tower's scratch from the prefill arena (~+15% KV pool at TP=2, image/video unchanged) - #338
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]>
b31250e to
1897b47
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 |
Pair gate: passed (2× GB10, reiner + spark2)Each arm is a binary built from a fresh checkout at an exact commit. Only the binary differs: base = main GLM-5.3-Flash FP4-Local. Checkpoint
About the KV numbers: on this pair the pool is set by reiner's rank 0, which has 119.6 GB visible against spark2's 121.6 GB and carries the vision tower. Only 2–3 GB is left for KV at 0.91, so absolute pools are far below your 136K–145K. Rank 0's pre-KV also moves about ±0.35 GB between boots. Read the gain as observed on this pair with n=2 boots per arm, in the direction your change predicts (rank 0 frees the 1.25 GiB scratch). It isn't a re-measurement of your +15%. Qwen3.8-Flash-Next FP4-Local regression check. The arena layout is shared by every model, so this ran on the pair's default rc16 TP2 serve (Spark config), same interleave, base =
CI: the workspace jobs pass. The remaining reds (env-budget ratchet, PR benchmark gate, cargo deny RUSTSEC-2026-0441) fail on main as well. Generated with Devin |
|
@data-angel this is merged as e50e619 after the pair gate above: GLM and Qwen are both bit-exact, and rank 0's KV pool grew on our pair. #346, #347 and #348 are restacked on it and gating now. I'll tag you on each with its receipts. Note that I force-pushed the rebased stack to your four Generated with Devin |
Summary
On the rank that encodes images and video, the GLM vision tower holds 1.25 GiB of scratch for the life of the process. That's because, in multi-rank worlds,
GlmCapacity::budgetssizes it for the processor's whole budget: 120,000 patches, one video temporal group. The KV pool is the minimum across ranks, so that one allocation costs every rank the same number of KV blocks.The tower only runs between prefill passes. So this PR has it borrow its scratch from the
BufferArena's per-pass members instead of owning it:crates/spark-runtime/src/buffers/lend.rs). The tower binds its 10 scratch buffers inside that span (GlmVisionEncoder::new_lent,attach_lent_scratch).BufferArena::lenddoes a device-wide sync, so no pass is still using the members, then hands out the span.BufferArena::return_lentzeroes only the borrowed bytes that overlap members decode expects zeroed (zero_all/zero_dirty), then waits on the encode stream. The four members the arena never zeroes are placed first, so that part of the borrow needs no memset.vision_forward_items(). The span is returned even if the encode fails.BufferSizes::total_bytes()counts the aligned span instead of the 15 members.return_lentstill waits on the encode stream and marks the arena's dirty extent unknown, so the nextzero_dirtyzeroes every member whole. A lent tower that was never attached refuses to encode, so it can't launch on null scratch.Results
GLM-5.3-Flash FP4-Local, TP=2 on two GB10s, 4x1M profile, KV shard on,
--gpu-memory-utilization 0.91. The A/B uses the same product image with only this commit changed (on top of our Spark branch,5f79b46b), freshly booted.The pool's range covers 8 boots of this change: 4 of the test build and 4 of the product release image built from this branch's commits. Rank 0's measured pre-KV footprint varies by about ±0.3 GB from boot to boot. Against the adjacent boots of the build without this commit, the gain was +12% to +18%.
Exactness against the build without this commit:
lent_scratch_is_bit_exact_with_owned_scratchfills the span with0xffbytes, which read as NaN, and checks that two passes produce rows identical to a tower with its own scratch.Cost: the sync before lending and the memset on return. On the test build, image TTFT was about 20 ms (0.7%) higher than adjacent base rounds. On the release image, image and video TTFT were level with adjacent base rounds (two pairs).
Checks
cargo fmt --checkcargo clippy -D warningson spark-runtime and spark-modelspark-runtime unit tests pass, including updated arena allocation counts and
total_bytesaccountingthe vision encoder's GPU tests, on a GB10
new unit test
a_failed_return_of_the_lent_span_leaves_everything_to_zero(mock memset failure injection); it fails without the fixWe didn't run the PR-gate benchmark suites.
Notes for review
ncclCommRegisterofnorm_output/moe_outputnow registers sub-ranges of the span. Registration failure is non-fatal, and decode speed is level in our A/B.VisionTower::forward_batchedandVisionEncoder::forward/forward_batchedstay public and skip the lend. Nothing in production calls them, but a future caller on a lent tower would have to go throughvision_forward_items.🤖 Generated with Claude Code