Skip to content

glm5next: a split NextN plan's host headroom keeps the draft's routed experts, as an unsplit one's does, so the residency rule and the load take them out once - #93

Merged
midagedev merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-glm-residency
Oct 13, 2026

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

What and why

Part of #13. With MTP on, GLM-5.3-Flash UD-Q4_K_XL on a plan the NVMe expert tier split leaves residency off on a DGX
Spark, because the seat's unset rule reads a negative host headroom. The NextN layer's routed experts were taken out of
that headroom twice. With this change they are taken out once, and the seat with MTP on resolves residency the way it
does with MTP off at the same budget.

plan_nextn_slots (crates/model/src/arch/glm5next/place.rs) runs the trunk's split at the host room less the NextN
layer's routed experts (draft_host), and expert_nvme_tier sets the split plan's host.headroom_bytes from that
room. A split plan's headroom has therefore already lost draft_host. An unsplit plan's headroom comes from
Plan::plan_at or the machine's figure and still holds it. Three readers take the NextN layer's host bytes
(NextnPlan::host_runs, the same bytes) out of plan.host.headroom_bytes themselves:

  • PlanRoom::headroom, crates/gpu-gates/src/residency.rs:43 (the unset residency rule the GLM seat runs)
  • residency_host_beside, crates/gpu-gates/src/record.rs:4003 (the record's headroom_after)
  • ChurnPool::check_beside, crates/placement/src/placement/churn.rs:121 (the load's own check)

On a split plan each of them took the bytes out a second time. NextnPlan::host_headroom_bytes handled both kinds of
plan correctly, which is why the plan's own HostOver check never showed it. The split path came in with c05b502c,
and the bug with it.

On a DGX Spark with BLOOMERY_CARD_BUDGET=100691449484 and --plan, 8fb237f2 (its crates/ tree is the same as
dc76bbb8's) printed:

residency unset residency=off why=unset: the churn pool needs 0 B at the highest P the card slots hold, the plan leaves -4378278012 B and MemAvailable 333064068 B, and this load hosts its pool

The split plan's headroom was 575364 B: the plan_room of 124455665664 B less the cache line's need of 124455090300 B,
which counts the NextN bytes once [derived]. The rule printed 575364 - 4378853376 = -4378278012 B. 4378853376 B is this
file's blk.45.ffn_{gate,up,down}_exps [derived from the tensor sizes]. With the change:

residency unset residency=mid-p0-s1 why=unset: --place a or bp
residency host residency=mid-p0-s1 hosted=hosted pinned=0 churn_experts=0 churn_bytes=0 headroom=4386183044 headroom_after=7329668

headroom less headroom_after is 4378853376 B, the NextN bytes taken out once. headroom_after equals that run's
plan_room of 124101840896 B less its need of 124094511228 B.

With MTP off at the same budget the seat already planned mid-p0-s1 with an empty pool (churn_experts=0 churn_bytes=0, headroom=2680980). With MTP on it now gets the same word. The pool stays empty on this plan because
ChurnPool::of skips a stack with a segment on the NVMe tier. So the change moves the residency word and the residency
records. I did not measure decode with and without it; with an empty pool I expect no difference [inferred]. The prompt
cache is 0 on this plan with and without the change: the default budget is under one saved state (cache ram=0 ... why=the default budget 153385922 B is under one saved state's 358962176 B).

I fixed it on the plan side. The docs of ChurnPool::check_beside and PlanRoom already say that the bytes beside are
bytes the plan does not count, and an unsplit NextN plan keeps that contract. The three readers are shared with the
Qwen3.8, V4.1 and MiMo seats, so fixing them would put a GLM case into common code. Right after the split, the split
plan's headroom now gets draft_host back. host_headroom_bytes takes it out on both paths and keeps its value, so the
HostOver check does not move. One assumption: the fix adds draft.host.expert_bytes and the readers subtract
host_runs().1; they are equal because plan_host_routed puts every routed stack of the NextN layer on the host as
file bytes.

MTP off (plan_slots), V4.1, MiMo2 and the Qwen plans do not go through this function. An unsplit NextN plan takes no
new path, and its headroom and host_headroom_bytes are as before.

On main at serving defaults the GLM plan is refused before residency is read (HostRoomFloor; my next PR, the unified pool floor, fixes that case), so
this bug shows only under a card budget. With that change applied (commit 51541b79 on my fork's dgx-spark-unified-floor, serving defaults, no lever set), the
defaults reach it: the plan leaves -4376524924 B. Please take this PR first. Both change the same lines of
plan_nextn_slots, and I will open that PR on top of this one, where the correction moves into its plan_in_pool closure,
right after the split.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. The fix is one statement in the GLM NextN plan, where the room is shortened; the shared
    readers are untouched.
  • Model code holds only architecture facts. The NextN layer's routed experts hosted beside the trunk are a GLM
    plan fact; no common owner gained a branch.
  • Dead code is gone. The two-way host_headroom expression became one line.
  • No silent failure. No new path; a plan the host cannot hold is still refused by HostOver and by the load's
    check.
  • Comments state what is true now. tools/check-comments.sh is green.
  • No relaxed gate.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none. The test fixture routed() is the one the unified pool floor
change's test uses too; it is added here once.

What I ran

The test slots::a_nextn_plan_leaves_the_draft_experts_in_its_host_headroom plans a synthetic four-layer file with Q4_K
routed stacks twice: at an ample room, where the trunk's host experts fit, and at one byte under that plan's host need,
where they split through the NVMe tier. For each plan it checks that it split or not as expected, and that
host_headroom_bytes and ChurnPool::check_beside (a pool of 0 B, the NextN bytes beside) both equal the room less
HostNeed::of(plan, beside).bytes(), a figure that does not read the headroom.

On one DGX Spark in the dev container, cargo test -p bloomery-model --lib a_nextn_plan_leaves_the_draft_experts_in_its_host_headroom, each mutant applied alone:

original                                    test result: ok. 1 passed
correction removed                          FAILED (the split plan is refused: "the plan breaks its invariants")
correction added twice                      FAILED (split plan: headroom 2573991935 B, expected 7077887 B)
correction added without the split check    FAILED (unsplit plan: headroom 2566914048 B over, the draft's bytes)

With the unified pool floor change stacked on this commit, both plan tests pass, and cargo test -p bloomery-model --lib glm5next passes 38 of 38.

On the Mac (each step's line cut after its time; the lint step counts 41 warnings, the ratchet's 41; the combos step ran
19 shapes, 0 red):

$ just mac-static upstream/main
mac-static: fmt-check rc 0 in 42 s
mac-static: lint rc 0 in 73 s
mac-static: combos rc 0 in 51 s
mac-static: check-arch, check-comments, check-defaults, check-levers, check-loads, check-ptx-names, check-records,
            check-recipes, check-rustflags, check-unsafe, check-waits: rc 0 each
mac-static: ok
$ just mac-test
mac-check: test rc 0; 12 crates (crate=rc): ...; 1105 passed, 0 failed, 177 ignored in 45 test binaries

bloomery-model is not one of the Mac's pure crates, so the new test runs on Linux only (above).

On the DGX Spark, bloomery-serve -m GLM-5.3-Flash-UD-Q4_K_XL-00001-of-00006.gguf --plan with BLOOMERY_CARD_BUDGET
set and nothing else, base 8fb237f2 and the change. The numbers above are from commit a2c329f6, which has the same
code as this commit outside the comments and the test. Each line reads MemAvailable, so the headroom moves a little
from run to run.

Budget 8fb237f2 change
100691449484 residency=off, the plan leaves -4378278012 B mid-p0-s1, headroom_after=7329668
99500000000 (both arms back to back) residency=off, the plan leaves -4366862460 B mid-p0-s1, headroom_after=5416836
100691449484, MTP off mid-p0-s1, headroom=12232852 mid-p0-s1, headroom=2680980

The load with the change at BLOOMERY_CARD_BUDGET=99500000000 (at 100691449484 the session's own plan is refused
by the NVMe tier's floor, the case the unified pool floor change fixes): residency=mid-p0-s1, draft=mtp layer=45, loaded in 48.2 s, and one chat
request answered "Paris" (40 tokens, the draft's 5 of 5 accepted).

GPU gates:

On the DGX Spark in local mode (BLOOMERY_BOX_LOCAL=1), base 79e5afbe and the change (a2c329f6; gate-glm5next-meta also at
96ebc823, this commit before its rebase onto the latest main, which changed only the review bot). The GLM shards were mounted read-only at the path glm5next_meta.rs names.

  • gate-glm5next-meta: green on both. The library runs 31 tests on base and 32 with the change (the new test);
    hw_glm5next_spec passes.
  • gate-gpu-glm5next-residency: its first 10 clauses pass on both, line for line the same. The NextN clauses stop on
    both at the missing glm5next/corpus-prose.ids, which the published refsets do not carry.
  • gate-gpu-glm5next-mtp, -nvtier, -e2e and -stagger stop on the same missing file on both; -media-seat needs the
    GLM mmproj file, which is not on this machine.
  • Not run: gate-gpu-glm5next-twocard, gate-gpu-glm5next-serve and serve-start-glm (local mode refuses
    BLOOMERY_CARD=both), the GLM fixture variants (not in the published fixtures) and weekly-gpu-glm5next-e2e-long
    (the same corpus file).

So the gates that ran show no change, but none of them reaches a split NextN plan. gate-gpu-glm5next-nvtier@q6kdown
is the one that plans this path, and it needs the box's fixture variants and corpus.

Hardware (if the change is for a machine)

Machine --version Card, driver CPU, RAM What ran
DGX Spark bloomery-serve 0.3.1 (commit 8fb237f2), (commit a2c329f6), (commit 96ebc823) NVIDIA GB10, driver 595.84 (CUDA 13.2 in nvidia-smi), Ubuntu 24.04.5, kernel 6.17.0-1032-nvidia 20 Arm cores (Cortex-X925 and Cortex-A725), 128 GB unified --plan, one load, the gates and the unit tests above; built in a CUDA 13.3.1 container with cargo-oxide 87bc9518
Mac Apple silicon just mac-static, just mac-test

… experts, as an unsplit one's does, so the residency rule and the load take them out once

plan_nextn_slots splits the trunk through the NVMe tier at the host room less the NextN layer's routed experts, and
expert_nvme_tier sets the split plan's host headroom from that room, so the headroom had already lost them. The readers
that host them beside the plan take them out again: the residency rule's PlanRoom, the residency record's headroom_after
and the load's ChurnPool::check_beside. An unsplit plan's headroom never took them out, so only a split plan read short,
by the draft's routed experts. The split plan's headroom now gets them back: both plans' headroom means the same, every
reader takes them out once, and host_headroom_bytes keeps its value on both paths.

On a DGX Spark, GLM-5.3-Flash UD-Q4_K_XL with MTP on under a card budget printed "the plan leaves -4378278012 B" and
left residency off; with the fix it plans mid-p0-s1, as MTP off does at the same budget.
@midagedev

Copy link
Copy Markdown
Owner

Thank you. The cause and the mutant table are clear.

This goes into today's last train before the 0.3.2 cut. I merge it after the train now on the box lands, then run the GLM gates on the box, gate-gpu-glm5next-nvtier@q6kdown among them, since it plans the split path.

The review bot failed on this PR because a workflow setting refuses fork checkouts. That is ours to fix, not yours.

@midagedev
midagedev merged commit 7a7a282 into midagedev:main Oct 13, 2026
3 of 5 checks passed
@midagedev

Copy link
Copy Markdown
Owner

Merged. The commit on main is 7a7a282, with the same patch as your head. The GLM gates run on the box in today's last train before the 0.3.2 cut. I will write here if one goes red.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants