Skip to content

GLM-5.3-Flash on one Mac: the streams share one MLA cache pool, so --parallel 3 serves the full 1M window - #639

Merged
ashhart merged 1 commit into
ashhart:mainfrom
BobClawblaw:glm-shared-pool
Oct 11, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
BobClawblaw:glm-shared-pool

Conversation

@BobClawblaw

Copy link
Copy Markdown
Contributor

What changes

Every slot past the first allocates its own MLA caches for the whole window at load. At --context 1048576 that is about 20 GB a stream, so three streams need ~65 GB of caches beside 180.6 GB of weights: more than a 256 GB Mac has under any load limit. The slots now share the engine's own MLA caches:

  • families/glm/pool.zig: a request takes a contiguous region of the engine's caches, in 256-token blocks, for its prompt plus max_tokens (plus a last window) when it begins, and gives it back when it leaves. One request alone can use the whole window; several split it. The kernels see a region as a cache of its size: its Refs are offsets into the engine's buffers, no kernel changes.
  • Slots past the first are made with KDA states only (initState(..., 0, ...)), ~0.3 GB each; glm_host.fit counts that.
  • api.Info.admit: the lane host asks whether the queue's head fits beside the running streams, and when it does not, the request waits in the queue, in order, until enough streams leave. With no stream running it is always admitted (a request larger than the window is still refused at prefill, as now).
  • Resident prompt states (428affe) keep their MLA prefix in their slot. In the pool a finished stream's region goes back to the pool, so its kept states now hold just the blocks under their prefixes (Snap.held). A request that needs those blocks takes them: the oldest held state gives its blocks up and goes stale, and its next turn reads the prompt again. Admission does not wait for held blocks.
  • Off on a pair (e.ep or followsPeer(): the ranks mirror slot commands) and with GLM_POOL=0, where each slot keeps its own window as before.
  • GLM sets no prefill_step, so its prompt pass, and so its region, is taken inside admission: the next request's fits already sees it (feat(lanes): a prompt pass a chunk a round, between the other streams' rounds #623's chunked pass doesn't apply here).
  • GLM: a new stream takes the free slot whose cache holds no kept prefix it would overwrite #622's pick is unchanged: in the pool a free slot holds no resident state of its own (its states moved to held blocks), so it picks the first free slot.

Checks

  • zig build test passes. New: pool.zig's block arithmetic, and a lane host test where a request that fits no pool waits with a lane free, then runs once the other stream leaves.
  • zig fmt --check zig/src clean. Every file stays under 600 lines (slots.zig 597, pool.zig 162).

On this branch before its rebase onto 56150e6 (main 38de96b + this PR; the rebase changed no GLM file, and zig build test passes after it), one M5 Ultra, GLM_LAYERS=8, --context 1048576 --parallel 3, greedy. Eight layers write nonsense, so these are exactness checks, not quality:

check result
the suite's 12 snapshot prompts, pooled vs GLM_POOL=0 (quality.suite --compare) 12/12 identical
four streams together vs each alone (concurrent), pooled and GLM_POOL=0 12/12, 12/12
drafted vs "draft": false (drafts), pooled and GLM_POOL=0 12/12, 12/12
9,553 and 7,231-token prompts at offsets in the pool beside a 23,825-token one, vs each alone; and pooled vs GLM_POOL=0 identical; byte-identical output
A streams with max_tokens 1,048,000 (all but 2 blocks): B1 (16 tokens, 1 block) answers beside it in 0.3 s; B2 (600 tokens, 3 blocks) waits with a lane free (running 1, waiting 1) until A's client leaves at 5.3 s, then answers at 7.9 s; a request past the window gets a 400 as described
a 6,376-token system prompt's second question, asked while another stream holds a slot: resumed at 6,362 from the blocks its finished stream left held (0.40 s, 0.94 s read whole); a request for nearly the whole pool is admitted at once (first token in 0.03 s); the question then reads its prompt whole again with an identical reply as described
memory after load, 8 layers 196.1 GiB free pooled, 161.6 GiB with GLM_POOL=0

The full model, 1M window, three streams, measured downstream on 1.0.5 with the same pool (plus residency wiring, #581, which this PR does not include): 200-201 GiB wired, 31-40 GiB free, one user 92 / 105 / 99 / 96 tok/s (prose / code / structured / list, the ruler), 106-124 tok/s aggregate at three users, the Spark recipe's suite with replies of four streams together equal to each alone 12/12 and drafted equal to undrafted 12/12; a 6.4k-token system prompt's second question resumed at 6,362 of 6,376 tokens from another slot in 0.55 s (6.05 s read whole).

…ion a request

Every slot past the first allocated its own MLA caches for the whole window at load, so --parallel 3 at
--context 1048576 needed ~65 GB of caches beside 180.6 GB of weights. The slots now share the engine's own MLA
caches (pool.zig): a request takes a contiguous region for its prompt plus max_tokens when it begins and gives it
back when it leaves. One request alone can use the whole window; several split it. The kernels see a region as a
cache of its size (Ref offsets, no kernel change). Info.admit lets the lane host keep a request that does not fit
beside the running streams in the queue, in order, until enough of them leave. A kept prompt state whose prefix
sits in a region holds those blocks after its stream leaves, until a stream needs the room; the state then goes
stale and its prompt is read again. Off on a pair (its ranks mirror slot commands) and with GLM_POOL=0.
@ashhart
ashhart merged commit 88ab992 into ashhart:main Oct 11, 2026
2 checks passed
@ashhart

ashhart commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw. This is in 1.0.6 (21ca64cd4, plus our commit e09b78e72 that makes four new doc comments one line each). Our gate was on one M5 Ultra with GLM_LAYERS=8, --context 1048576 --parallel 3, comparing the candidate without this PR, this PR pooled, and this PR with GLM_POOL=0:

  • Solo greedy replies were identical in all three builds. Drafted equalled "draft": false, and three streams at once equalled solo.
  • A 10,160-token prompt beside a 25,339-token one equalled each alone. A burst of six 25k-token requests all finished, all equal.
  • Waiting path: A asked for 1,048,000 tokens and dropped its stream at 6.0 s. B1 (short) answered beside it at 1.7 s. B2 (~600 tokens) waited and answered at 6.2 s, right after A left. Both equalled their solo replies.
  • Footprint once ready: 48 GB pooled against 85 GB with GLM_POOL=0 and 85 GB for the candidate.
  • On the two-Mac pair, where the pool is off, all six prose replies equalled the candidate's.

We didn't load the whole model on one Mac (past our 70% load rule there), so the full-window claim for three streams is from your run.

jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 11, 2026
…A cache pool, so --parallel 3 serves the full 1M window

Thanks @BobClawblaw.
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 11, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 11, 2026
@BobClawblaw
BobClawblaw deleted the glm-shared-pool branch October 11, 2026 20:35
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
The change landed rebased over ashhart#639 as 3e02e29d4 with its author kept; this keeps the PR's head in the history with no change to the tree.
sethforprivacy added a commit to sethforprivacy/TensorFold that referenced this pull request Oct 13, 2026
…XTS, and a stream that outgrows its session moves

Every session held the whole window, so few fit beside the model (three 262K sessions in 15.4 GiB on a 256 GB Mac).

- FLASHNEXT_SLOT_CONTEXTS lists the sessions past the engine's own (token counts, CONTEXTxN for N alike, e.g.
  "65536,32768x3,16384x11": 16 streams in 11.6 GiB); unset, nothing changes.
- A new stream takes the smallest free session that holds its prompt and its reply's next FLASHNEXT_SLOT_GROW tokens
  (default 8192); LaneHost's admit hook (as on main since ashhart#639) holds a request until one is free.
- Before a round, a stream left too little room moves to the smallest free larger session that holds its next
  FLASHNEXT_SLOT_GROW tokens (Session.moveTo: its cache rows, DeltaNet states, n-gram tail, head rows and pooled
  blocks copied on the GPU at a round's end, states settled first), or pauses (Stream.paused) until one frees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…A cache pool, so --parallel 3 serves the full 1M window

Thanks @BobClawblaw.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The author rebased ashhart#639 onto main after our merge; this keeps the PR's current head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The change landed rebased over ashhart#639 as 3e02e29d4 with its author kept; this keeps the PR's head in the history with no change to the tree.
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