Skip to content

glm metal: GLM_POOL_TOKENS sizes the shared latent pool apart from the per-stream window (stacked on #3903) - #3906

Merged
ashhart merged 5 commits into
ashhart:mainfrom
gilby:glm-metal-pool-tokens
Nov 24, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
gilby:glm-metal-pool-tokens

Conversation

@gilby

@gilby gilby commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

GLM_POOL_TOKENS sizes GLM-5.3-Flash's shared Metal MLA latent pool on one Mac independently from the per-stream --context window (so --parallel 3 --context 1048576 with GLM_POOL_TOKENS=2000000 shares a 1,999,868-token pool across up to three streams, capping each stream at --context, and cutting a stream's window cleanly when the pool is smaller). Unset, empty, or whitespace-only keeps the pool equal to --context as before; malformed values, pools below 1024 or above 4294967231, pools exceeding the Mac load limit, and combinations with --speed-up or GLM_POOL=0 stop startup before cache allocation naming GLM_POOL_TOKENS.

Checks on this head

  • Head commit: 62b362a575d352be7031dbacb7ef62010b835bfe (stacked on glm metal: shortest-remaining-first prompt order by default on one Mac #3903 813ebef6f6459d9f7ae08624dae11f2bd1d2aef1; 12 files added/changed beyond glm metal: shortest-remaining-first prompt order by default on one Mac #3903, 15 total vs origin/main; #3152 served receipt measured on e95aa3853/533031810, macOS runtime behavior identical)
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 vs 221, 0 new (tools/zig/lean_new.py clean vs origin/main a1781885e9; tools/pr_check.py --base origin/main --pr 3906 exits 0 with 0 error(s), 1 warning(s): the expected advisory CHANGELOG.md Unreleased warning since CHANGELOG.md is omitted to avoid merge conflicts).
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig: passed (0 exit) on 62b362a57.
    • git diff --check origin/main: passed (0 exit) on 62b362a57.
    • Linux x86_64-linux-gnu (-Odebug) cross-link check on zig/src/glm_schedule_tests.zig (--test-filter matching glm_expiry.zig): compiled & linked ELF binary with 0 errors and 0 objc symbols (nm -u clean), fixing the 533031810 test-host-a objc_msgSend/objc_release/sel_registerName link failure.
    • Fail-before / pass-after: without the GLM_POOL_TOKENS rule in zig/src/platform/environment.zig, zig build test-glm-scheduling-host crashed 1/71 and zig build test-environment-host crashed 2/26; after registering it and the state.zig comptime guard:
      • zig build test-glm-scheduling-host test-environment-host test-glm-prefill-widths-host --summary all: passed (7/7 steps succeeded; 71/71 tests passed: 26/26 environment + 71/71 glm scheduling/prefill) on 62b362a57.
      • zig build test test-golden dev-tools native --summary all -Dcpu=apple_m1: passed (1105/1105 steps succeeded; 1748/1791 tests passed, 43 skipped incremental on 62b362a57 after 15080/15204 full pass on e95aa3853).
      • Also verified GLM_DRY=1 GLM_POOL_TOKENS=2000000 under default 70% RAM load limit (GLM_LOAD_LIMIT_GB unset) passes plan/limit checks keeping all 45 + MTP layers (180.58 GB buffers).
  • CI: on 62b362a575d352be7031dbacb7ef62010b835bfe, all 9 active checks were CANCELLED before start as infrastructure when the repo-wide queued PR Actions backlog was cleared (Zig format / fmt; No GPU: benchmark-clients (ubuntu-latest), benchmark-clients (windows-latest), pytest, zig, zig-b, zig-windows, release-paths (ubuntu-24.04), zig-macos-dev-tools), and host-nightly-linux / host-nightly-macos SKIPPED. Prior 533031810 passed Zig format and 7/8 active No GPU checks (failing only zig Linux link due to Objective-C symbols from glm_schedule_tests.zig), fixed in 62b362a57 (verified with x86_64-linux-gnu -Odebug NO_OBJC_SYMBOLS, 71/71 host tests, and 1105/1105 macOS steps above).
  • Not run, and why: CUDA, HIP, Windows, desktop app, full 3-stream 900K needle pass with GLM_LOAD_LIMIT_GB unset (verified GLM_DRY=1 GLM_POOL_TOKENS=2000000 acceptance under default 70% limit 358.4 GB and observed 208.2 GiB kept wired on pr3_pool2m; default limit refusal verified at GLM_POOL_TOKENS=20000000), and M1–M4 hardware checks (only Metal GLM pool sizing and environment.zig rules change; no GPU kernels changed).

Receipt

  • Main against branch: On M5 Ultra (512 GiB RAM) with TensorFold/GLM-5.3-Flash-MLX-4bit-MTP, --parallel 3 --context 1048576 --prompt-cache-gib 0, Nominal thermal (notifyutil -g com.apple.system.thermalpressurelevel == 0) and idle background (mediaanalysisd CPU 0.0) at start and end of every arm. Raw scrubbed artifacts + script: https://gist.github.com/bb001310eb3cf2eb87c015d576c2cc05
    • 6 explicit startup refusals (all exit 1, naming GLM_POOL_TOKENS, before cache allocation):
      • GLM_POOL_TOKENS="abc" -> tensorfold: GLM_POOL_TOKENS="abc": expected a whole number of tokens from 1024 to 4294967231 (unset or blank: the --context window)
      • GLM_POOL_TOKENS="0" -> tensorfold: GLM_POOL_TOKENS="0": expected a whole number of tokens from 1024 to 4294967231 (unset or blank: the --context window)
      • GLM_POOL_TOKENS=20000000 (default 70% limit) -> error: glm: GLM_POOL_TOKENS=20000000 needs 390.3 GB of caches beside 180.6 GB of weights and images, past this Mac's 358.4 GB load limit (70% of RAM); lower GLM_POOL_TOKENS or raise the limit (OverMemoryLimit)
      • GLM_POOL_TOKENS=20000000 (GLM_LOAD_LIMIT_GB=400) -> error: glm: GLM_POOL_TOKENS=20000000 needs 390.3 GB of caches beside 180.6 GB of weights and images, past this Mac's 400.0 GB load limit (GLM_LOAD_LIMIT_GB); lower GLM_POOL_TOKENS or raise the limit (OverMemoryLimit)
      • GLM_POOL_TOKENS=2000000 GLM_POOL=0 -> error: glm: GLM_POOL_TOKENS sizes the shared pool of one Mac: it cannot be used with the two-Mac pair or GLM_POOL=0 (PoolTokensNeedPool)
      • GLM_POOL_TOKENS=2000000 --speed-up -> error: glm: GLM_POOL_TOKENS sizes the shared pool of one Mac: it cannot be used with the two-Mac pair or GLM_POOL=0 (PoolTokensNeedPool)
    • Startup equivalence (main vs unset vs blank vs GLM_POOL_TOKENS=2000000 + GLM_LOAD_LIMIT_GB=400):
      • main, pr3_unset, pr3_blank: all loaded 1048572-token MLA pool, context 1048576 tokens, 3 streams; bench_concurrent.py --alone --serial --tokens 256 --reps 2 --temperatures 0 --levels 1,3 had 0 unequal, 0 failed, and 0 token_sha256 diffs vs main (code 98.8/168.7 vs 99.1/169.2 vs 99.0/169.1; chat 80.8/145.7 vs 81.0/146.2 vs 81.1/145.8 tok/s).
      • pr3_pool2m (GLM_POOL_TOKENS=2000000 GLM_LOAD_LIMIT_GB=400): info: glm: 3 streams share one 1999868-token MLA pool, 208.2 GiB kept wired between requests, context 1048576 tokens a stream in a shared pool of 1999868 tokens (GLM_POOL_TOKENS=2000000), 3 streams; bench_concurrent 0 unequal, 0 failed, 0 diffs vs main (code 99.0/169.5, chat 81.5/146.0 tok/s).
    • 3-stream 900,000-token needle test under GLM_POOL_TOKENS=2000000 (2,700,000 concurrent tokens sharing the 1,999,868-token pool):
      • NEEDLE-ALPHA-74921: solo 587.03s, concurrent 637.19s, found=true, complete=true, token_sha256 719826071f5e715fe3e2296ee74f83b94baf0d7c2c4c12292c14243e897c7c3b exact match (solo == concurrent).
      • NEEDLE-GAMMA-92047: solo 577.99s, concurrent 1205.72s, found=true, complete=true, token_sha256 95fed1bf0550699f843e4124626e15144f45b7418a69df1d4c1b45ab8a4b2f24 exact match (solo == concurrent).
      • NEEDLE-BETA-38514: solo 577.59s, concurrent 1733.38s (queued cleanly until a 900K pool region freed), found=true, complete=true, token_sha256 ac9ffd484beee96dfccb327ea46f484cd2867d1c901e294839fba08c78833273 exact match (solo == concurrent).
  • Boxes it reaches: Apple Silicon Macs running native Metal GLM-5.3-Flash (tensorfold-native, one-Mac shared pool); two-Mac pair and GLM_POOL=0 refuse GLM_POOL_TOKENS; no CUDA/HIP/Windows/app changes.
  • New switch? Default, accepted values, profile row: GLM_POOL_TOKENS (registered in zig/src/platform/environment.zig, scope .metal, kind .u32). Unset, empty, or whitespace-only = --context window as before. Accepted values: whole integers 1024..4294967231 (trimmed spaces/tabs, first char digit; refuses signs, suffixes, out-of-range, GLM_POOL=0, --speed-up, and load-limit overflow naming GLM_POOL_TOKENS). Documented in docs/environment.md. No optimization-ledger profile row needed.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: Base origin/main 2a674b552498739e783a31c2573fc9ccf4d8cc0d (v1.2.10), stacked on glm metal: shortest-remaining-first prompt order by default on one Mac #3903 813ebef6f6459d9f7ae08624dae11f2bd1d2aef1, head 62b362a575d352be7031dbacb7ef62010b835bfe (macOS runtime identical to measured e95aa3853/533031810; adds 62b362a57 non-macOS Arena compile guard); Zig 0.17.0; Apple Metal toolchain 32023.922 (metalfe-32023.922.4) (Metal 4); Apple M5 Ultra (80-core GPU, 512 GiB RAM), macOS 27.2.1 (26B131); checkpoint TensorFold/GLM-5.3-Flash-MLX-4bit-MTP (rev d2b17f5253440224422b150705c1109a9a3a0368).
  • Paths and platforms the change reaches, which I ran and which I could not: Reaches zig/src/families/glm/{pool_size.zig,pool.zig,engine.zig,glm.zig,state.zig}, zig/src/native/glm_host.zig, zig/src/platform/environment.zig, zig/build/glm_expiry.zig, and unit tests. Ran on M5 Ultra (macOS 27.2.1) and cross-linked glm_schedule_tests.zig for x86_64-linux-gnu; M1–M4 hardware not run on-device (host tests built -Dcpu=apple_m1).
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: Across main, pr3_unset, pr3_blank, and pr3_pool2m (GLM_POOL_TOKENS=2000000), bench_concurrent reported unequal_alone = 0, unequal_serial = 0, failed = 0, 0 token_sha256 diffs vs main, and all 3 900K-token needle prompts produced identical token_sha256 between solo and 3-stream concurrent runs.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): Posted above and in the public receipt gist (https://gist.github.com/bb001310eb3cf2eb87c015d576c2cc05).
  • Decode speed before and after, from tools/bench_openai.py: Single-stream and 3-stream greedy decode from tools/bench_concurrent.py --alone --serial: code 98.8 / 168.7 (main) vs 99.1 / 169.2 (unset) vs 99.0 / 169.1 (blank) vs 99.0 / 169.5 tok/s (GLM_POOL_TOKENS=2000000); chat 80.8 / 145.7 (main) vs 81.0 / 146.2 (unset) vs 81.1 / 145.8 (blank) vs 81.5 / 146.0 tok/s (GLM_POOL_TOKENS=2000000); standalone bench_openai.py suite n/a because GLM_POOL_TOKENS only sizes the MLA buffer allocation and pool capacity without changing decode kernels (covered in glm metal: GLM_ROUND_PROF per-round host and GPU summary #3894).
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold on a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: Unset GLM_POOL_TOKENS allocates the identical 1,048,572-token pool as main (exact match in bench_concurrent.py TTFT 0.08s/0.12s); with GLM_POOL_TOKENS=2000000, solo 900,000-token cold prompts completed in 587.03s, 577.59s, and 577.99s (--prompt-cache-gib 0, exact needles found).
  • Licence of any new weights or drafter, or "n/a": n/a (uses existing TensorFold/GLM-5.3-Flash-MLX-4bit-MTP checkpoint, no new weights or drafter).

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.

  • No precision traded for speed. If the bits change, the description says which sums change and why.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled

@krunkosaurus

Copy link
Copy Markdown
Contributor

This is the setting our production serving needed most. Measurements from a second M5 Ultra (512 GB) below, then some feedback. Setup is the same as in my comment on #3903: v1.2.10 built from source as main, 62b362a as the PR, TensorFold/GLM-5.3-Flash-MLX-4bit-MTP @ d2b17f52, the machine serving nothing else during a run.

Why we needed it

70 hours of agent traffic on the 1.2.8 release with the #3545 patch (--parallel 4 --context 1048576 --prompt-cache-gib 64; 12,432 requests, median prompt 111K tokens, p90 182K), read from the server log:

  • 91.5% of prompt tokens were reused. Of the 120.3M tokens that were read, 101.6M (84%) came from 1,225 requests that each read 16K tokens or more.
  • Matching requests by prompt size and resume point, about 795 of them were the next turn of a conversation whose previous turn was at most 80 requests earlier. Those re-read 82.8M tokens, 69% of everything read.
  • By the same matching, 3 to 5 conversations were alive at a time, 0.38M tokens at the median and 1.3M at most.
  • The prompt cache held a median of 10 states and at most 36, never more than 5.0 GiB of its 64 GiB, while evicted reached 13,053.

So the byte budget was never the limit. The 1,048,572-token pool was, although the live conversations would have fitted in it.

The same effect at a quarter of the size

PR build, --context 262144 --parallel 4. Six conversations of 30K tokens behind a 15.8K-token system prompt they share (49K each, 294K in all) are opened two at a time, then each gets one more 400-token turn, twice. Greedy, 16-token replies.

pool = window (262,140) GLM_POOL_TOKENS=1048576
A pass of six return visits 114.8 s, 115.6 s 4.0 s, 4.1 s
Tokens read in such a pass 199,150 of 294,022 2,543 of 294,022
Return visit, first token, p50 37.9 s 0.9 s
evicted at the end 28 0
States kept 9 (1,267 MiB) 25 (3,519 MiB)

All 18 replies have the same token hashes in both arms. In the small-pool arm every return visit resumed at 15,812, the end of the shared system prompt: that prefix survived and each conversation's own rows did not.

3,000,000 tokens on 512 GB

GLM_POOL_TOKENS=3000000 --parallel 4 --context 1048576 --vision, past the 2M in the receipt:

  • Start: 4 streams share one 3000060-token MLA pool, 232.2 GiB kept wired between requests (196.8 GiB at the default), drafts still MTP + copies.
  • Top of the pool: three streams, each a 36-token prompt asking for max_tokens 960000, hold about 2.88M tokens between them. A 105,358-token greedy prompt with a planted answer then takes the room that is left. Its token_sha256 equals the same request alone on a default pool, both cold and resumed (105,356 cached), and it returns the planted answer. A further request that needs 125K tokens waits under pool_room until the holders leave, which bounds the room left to between 105K and 125K.
  • tools/bench_concurrent.py --alone --serial --tokens 256 --reps 2 --temperatures 0 --levels 1,4: 0 unequal, 0 failed; code 99.4 / 163.8 and chat 81.5 / 153.2 tok/s at 1 / 4 streams, against 99.4 / 170.3 and 81.4 / 154.8 at the default pool, inside the spread I saw between arms.

Feedback

  1. Guidance on sizing would help. The docs explain what the setting does but not when to reach for it. What I would have wanted to read: when several agent sessions share a server, size the pool to a few times the tokens alive at once, at about 19.5 GB per million tokens.
  2. The eviction order may be worth a look. As I read placeWith, oldest and first in families/glm/pool.zig, a region that finds no free run gives up the held state with the lowest id, wherever its blocks are, and repeats until a run of the needed length is free. With several conversations of 100K to 200K tokens in a 1M pool, that took live conversations with it. Ordering by last use (the used stamp is already there) or preferring states whose blocks adjoin free room might keep more in the same pool.
  3. /metrics has no figure for how much of the pool the kept prefixes hold, and the eviction counts are only in the prompt cache: log line. A gauge for held blocks over pool blocks would let an operator size the setting without reading the log.
  4. In engine.zig the fallback that leaves the MTP head on disk runs before the new pool check, with the pool-sized cap. A pool that passes the load limit only without the head therefore starts without MTP drafts and says so in one info line, where an operator raising the pool would probably prefer the refusal.

In production

Serving our agent traffic at 3M tokens since 2026-11-19 11:11 UTC, with #3903 and the #3418 to #3458 stack. In the first 33 minutes (100 requests from the same agents, 4 to 5 conversations and about 0.5M tokens alive) no next turn of a live conversation was re-read, where 6.4% of requests and 69% of the tokens read were such re-reads before. Reuse is 93.7% against 91.5%. That is a short window, so take it as a first reading.

My agent (Claude) did the builds, the runs and this write-up. The load script and the raw JSON are available if you want them.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. This is our first review of GLM_POOL_TOKENS, and it is ready.

The setting is opt-in: unset or blank keeps the pool and the output tokens exactly as on main, and your receipt shows zero token differences across main, unset, blank and a 2M-token pool. The refusals for malformed or out-of-range values, the load limit, the two-Mac pair and GLM_POOL=0 are named and covered by tests, and the three-stream 900K-token needle checks keep identical token hashes.

Main has since added cases to environment_test.zig, so we will rebase it on our side, keeping your commits and authorship, and land it. Nothing further is needed from you.

  • Synthena

@ashhart
ashhart force-pushed the glm-metal-pool-tokens branch from 4f17156 to bcce0e8 Compare November 20, 2026 01:18
@AIFlowML

Copy link
Copy Markdown
Contributor

I checked bcce0e8da against main 210e3b0c5. The trial merge found the same docs/api.md conflict as #3903 and a second conflict in environment_test.zig. I kept main's existing invalid-value cases, including the newly added XPU cases, and appended the eight GLM_POOL_TOKENS invalid values. The formatter then laid out the combined table.

zig build test-glm-scheduling-host test-environment-host test-glm-prefill-widths-host -Dcpu=apple_m1 -j5 --summary all passed 99/99 on the resolved trial tree on an M5 Max with Zig 0.17.0. Removing just the GLM_POOL_TOKENS registration made the two environment tests abort at the unregistered-variable check (26/28). This checks the merged host behavior. I did not repeat the production-population or long-context device measurements.

Igor Lessio - AIFLOW LABS

@krunkosaurus

Copy link
Copy Markdown
Contributor

A correction to the "Why we needed it" and "In production" sections of my comment above.

The 70 hours I analysed were two workloads. 50 hours in, we limited our support agent to two background runs at a time; on the day we set it, the agent had averaged 3.5 runs at once and peaked at 8. The same matching, split at that point:

1.2.8, no limit (50.3 h) 1.2.8, two runs at most (20.5 h) new build at 3M, two runs at most (30.0 h)
Requests 9,421 3,011 4,201
Prompt tokens read 102.3M 18.0M 19.1M
Of those, re-reading a live conversation 78.3M (76.5%) in 744 requests 4.5M (24.8%) in 50 requests 0.2M (1.1%) in 15 requests
Conversations alive at once, p50 / p90 / max 3 / 5 / 11 2 / 4 / 6 2 / 3 / 6
Tokens alive at once, p50 / p90 / max 0.42M / 0.73M / 1.31M 0.30M / 0.52M / 0.93M 0.23M / 0.45M / 0.82M

So "69% of the tokens read were re-reads" described mostly the heavier first 50 hours. The like-for-like figure for the default pool is the middle column, where a quarter of the tokens read were re-reads of live conversations. At 3M that is 1.1%. The quarter-scale revisit test and the 3M checks in the comment are not affected.

The middle column also bears on the second feedback point (eviction order): by this estimate the live conversations alone stayed under the 1,048,572-token pool the whole time, 0.93M at most, and a quarter of the reading was still re-reads. The estimate counts conversations at their final size and leaves out what each running stream reserves, so read it as a hint.

We removed the limit today (2026-11-20 17:27 UTC), so the 3M pool now gets the load of the first column, where up to 1.31M tokens were alive at once. I can add those numbers here once there is a day of them.

My agent (Claude) found the mistake and wrote this.

@gilby
gilby marked this pull request as ready for review November 21, 2026 20:44
@ashhart
ashhart force-pushed the glm-metal-pool-tokens branch from bcce0e8 to 0464275 Compare November 22, 2026 00:33
@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the current GLM stack against main 2ce240cf0: profiler #3894 at 2c8435791, scheduling #3903 at 3d2f44dd5, and pool #3906 at 0464275b0. Each merges alone. Merging the three published heads in that order conflicts in four files because #3906 carries an older copy of #3903. Those two scheduling commits have the same stable patch ID.

I replayed only the pool delta (980c1f84f..0464275b0) over the scratch merge of #3894 and #3903. The two remaining conflicts were the environment docs row and positive parser test rows. Keeping the profiler and pool rows in both files was sufficient.

  • Linux x86-64, Zig 0.17.0: zig build test-glm-scheduling-host test-glm-prefill-widths-host test-glm-expiry -Dversion=1.0.0 -j2 --summary all passed all seven steps, with 92 passes and two skips. This exercises the combined pool host tests with the non-Mac Arena change.
  • M5 Max, Zig 0.17.0: zig build test-glm-scheduling-host test-glm-prefill-widths-host test-glm-gathers test-glm-expiry check-glm-restore-host test-environment-host -Dcpu=apple_m1 -j4 --summary all passed 140/141 tests. The one Flash Next switch-count failure also occurs on the same main. The five direct round_prof.zig tests passed separately.

This validates the host integration for taking the three changes in order. Full-checkpoint serving and GPU timings were outside these runs.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the glm-metal-pool-tokens branch from 0464275 to 93552d7 Compare November 23, 2026 11:56
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for the pool-sizing work. Two startup cases still need small fixes.

With MTP enabled, an explicit pool that fits only after dropping the MTP head currently logs that fallback and starts. Could you preserve the documented named refusal for this case, keeping the existing fallback when the pool setting is unset?

Also, when fixed streams do not fit beside an explicit pool, the error recommends lowering --context, which cannot reduce that pool allocation. Please point to GLM_POOL_TOKENS or --parallel instead. Small host regressions for both cases would cover these fixes.

  • Synthena

@gilby

gilby commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Fixed both startup cases in commit a8286197d5:

  1. Extracted pool_size.planFit in zig/src/families/glm/pool_size.zig (called by zig/src/families/glm/engine.zig), gating the MTP-drop fallback strictly on pool_tokens == null so an explicit GLM_POOL_TOKENS that only fits after dropping MTP preserves the named GLM_POOL_TOKENS=... refusal instead of dropping MTP and starting, while keeping the existing fallback when GLM_POOL_TOKENS is unset.
  2. Extracted pool_size.fitProblem and passed pool_tokens into fit() in zig/src/native/glm_host.zig, so fixed-stream exhaustion beside an explicit pool recommends lowering --parallel or GLM_POOL_TOKENS rather than --context.
  3. Added host regressions for both cases in zig/src/families/glm/pool_size_test.zig.

Verified on this commit: zig build test-glm-scheduling-host compile-metal-residency-host --summary all (78/78 tests passed), zig fmt --check build.zig zig, git diff --check origin/main...HEAD, python3 tools/pr_check.py --base origin/main (0 error(s)), and python3 tools/zig/lean_check.py (0 new).

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. Both startup fixes are present. An explicit pool now keeps MTP enabled and gives the named refusal when it cannot fit; the unset setting keeps the existing fallback. Fixed-stream errors now point to the pool setting or parallel count, and the host cases cover both messages.

No further code correction is requested for these fixes. What's left is device evidence for the complete stack, because it changes the default scheduling: generated token IDs equal to main with GLM_POOL_TOKENS unset, then the explicit-pool runs, on the same saved prompts, seeds and stream counts. We don't hold the GLM MLX checkpoint on a Mac large enough for these cells, so those receipts need to come from your side. It merges cleanly with current main.

  • Synthena

@gilby

gilby commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Device evidence for the complete stack (origin/main ef0ecb9a6d cleanly merged with #3906 a8286197d5) on Apple M5 Ultra, 512 GiB:

Checkpoint & Serving Configuration

  • Model: GLM-5.3-Flash-MLX-4bit-MTP, revision d2b17f5253440224422b150705c1109a9a3a0368 (config.json sha256 f80682bcc8ba5fc6ecdc5ce553700b02befe999bc4a6ba6fd47f644df4864adf)
  • Server: tensorfold-native serve ... --parallel 3 --context 1048576 --prompt-cache-gib 0 --profile stable --no-update-check (MTP drafting active)
  • Client: tools/bench_concurrent.py --alone --serial --tokens 256 --reps 3 --temperatures 0,1.0 --levels 1,3 --seed 1234 (8 cells × 48 total measured concurrent runs + --alone solo references + --serial "draft": false checks per server pass)
  • Thermals (pmset -g therm): no thermal or performance warnings recorded before or after any pass.

1. Token Equality (main unset -> #3906 unset -> #3906 GLM_POOL_TOKENS=2000000)

  • main (GLM_POOL_TOKENS unset) vs main + #3906 (GLM_POOL_TOKENS unset): 48/48 concurrent rows (0 diffs) exact token_sha256 match across all 8 cells (code/chat, T=0/T=1.0, N=1/N=3), plus 0 failed, 0 unmeasured, 0 --alone unequal, 0 --serial unequal (plain_drafted = 0).
  • main (GLM_POOL_TOKENS unset) vs main + #3906 (GLM_POOL_TOKENS=2000000): 48/48 concurrent rows (0 diffs) exact token_sha256 match across all 8 cells, plus 0 failed, 0 unmeasured, 0 --alone unequal, 0 --serial unequal.
  • Representative N=1 token_sha256 prefixes identical across all three runs (main unset == #3906 unset == #3906 GLM_POOL_TOKENS=2000000):
    • code T=0: 7cd4ab7084c38db6...
    • chat T=0: 4d09cdba4e48219b...
    • code T=1.0: 267637fa5f63ab18...
    • chat T=1.0: dbe669fd4d402f1f...

2. Pool Sizing, Timings & Peak Memory (/usr/bin/time -l)

Run Pool log Wired Max RSS / Peak footprint
main (GLM_POOL_TOKENS unset) 3 streams share one 1048572-token MLA pool 190.9 GiB 205.26 GB / 205.61 GB
main + #3906 (GLM_POOL_TOKENS unset) 3 streams share one 1048572-token MLA pool 190.9 GiB 205.26 GB / 205.62 GB
main + #3906 (GLM_POOL_TOKENS=2000000) 3 streams share one 1999868-token MLA pool; context 1048576 tokens a stream in a shared pool of 1999868 tokens (GLM_POOL_TOKENS=2000000), 3 streams 208.2 GiB 223.79 GB / 224.16 GB
Cell (N, T) main unset agg (per-stream) #3906 unset agg (per-stream) #3906 GLM_POOL_TOKENS=2000000 agg (per-stream)
code N=1, T=0 108.1 (108.1) 108.2 (108.2) 108.6 (108.6)
code N=3, T=0 181.9 (61.0) 181.7 (61.0) 182.0 (60.7)
chat N=1, T=0 87.8 (87.8) 88.2 (88.2) 87.0 (87.0)
chat N=3, T=0 155.0 (53.1) 154.8 (53.1) 153.8 (52.7)
code N=1, T=1 121.7 (121.7) 121.7 (121.7) 122.0 (122.0)
code N=3, T=1 121.8 (47.4) 124.0 (47.6) 122.0 (47.1)
chat N=1, T=1 81.7 (81.7) 81.8 (81.8) 82.0 (82.0)
chat N=3, T=1 111.2 (43.7) 110.9 (42.7) 111.5 (43.3)

3. Oversized Pool Refusal Check (GLM_POOL_TOKENS=999999999)

Startup stopped cleanly before cache allocation (exit status 1, naming GLM_POOL_TOKENS):

error: glm: GLM_POOL_TOKENS=999999999 needs 19477.3 GB of caches beside 180.6 GB of weights and images, past this Mac's 358.4 GB load limit (70% of RAM); lower GLM_POOL_TOKENS or raise the limit

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The new release-model receipt answers the remaining device request: both the unset and 2M-pool runs report 48 of 48 replies matching main, with no solo or serial differences. Both startup fixes and their focused cases remain present.

Main now contains the scheduling default already. The remaining conflicts with main are additive settings and test entries, which we will merge on our side keeping both. No further source correction or duplicate device run is requested. Exact-tree CI remains before landing.

  • Synthena

ashhart and others added 5 commits November 24, 2026 20:21
…e per-stream window

Unset keeps the pool equal to --context. A set pool is planned with its caches and window scratch, refused by name before cache allocation when the load limit cannot hold it, and refused with the two-Mac pair or GLM_POOL=0. Refs ashhart#3152.
@ashhart
ashhart force-pushed the glm-metal-pool-tokens branch from c71b062 to 42a9343 Compare November 24, 2026 20:21
@ashhart
ashhart merged commit d30325d into ashhart:main Nov 24, 2026
1 check failed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

4 participants