Skip to content

placement: an unset context takes the largest step under the model's limit that the machine holds - #906

Merged
juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-ctx-largest-fit
Oct 28, 2026
Merged

juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-ctx-largest-fit

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

--ctx-size를 주지 않으면 모델이 학습한 context에서 시작해, 머신이 담는 가장 큰 1,024 단위 context를 고르도록 바꾸고, 서버 시작 때 plan을 덜 반복하게 합니다.

What and why

Without --ctx-size, a slot is planned at the model's limit. When that plan does not fit, the old default halved the context until a plan held, so a machine that could hold 116,736 tokens a slot got 65,536. Now an unset context takes the largest multiple of 1,024, down to a 4,096 floor, whose plan holds. A set --ctx-size is unchanged: it holds, or it is refused with the largest share that holds.

The search keeps one bisection owner (placement::ctx::largest) and asks fewer plans by trying the step under the first short plan next. The MTP draft is turned off for the context only when the plain load holds at least twice the drafted context, so a few 1,024 steps do not cost the draft. The setup line names the rule that set the context (set, target or fitted) and why a rule turned the draft off. Two start-time costs are removed: a checkpoint folder's least part reads are planned once for plans that hold the same card tensors, and a context probe reads the plan of the machine it already made instead of planning it again. The docs that described the halving default (docs/serving.md, docs/BUILD.md, docs/contrib/dgx-spark.md, docs/contrib/qwen35-dense-validation.md) and the gate comments now describe the new default.

Release notes: Changed: with no --ctx-size, the server picks the largest context the machine holds instead of halving from the model's limit, and the setup line names the rule that chose it.

Code shape

  • No second copy. The context search stays in ctx::largest; the line's fit is computed in one place (fit_of); the least-reads memo lives in PlacedSource::host_bytes; plan reuse lives in widen_card_route.
  • Model code holds only architecture facts. The common owners gained no per-model branch, flag or trait method.
  • Dead code is gone. DEFAULT_TARGET and the halving rule are removed, and the tests and docs that named them are updated.
  • No silent failure. A poisoned memo lock is a named refusal, and a hint outside the open search range falls back to the midpoint.
  • Comments state what is true now. No dates or history in code comments besides the PIN lines.
  • No relaxed gate. Renamed and changed tests carry PIN(2026-10-27) or PIN(2026-10-28) with the reason. dense_shortage_fits_the_default_context probes [16384, 10240, 9216, 8192] and chooses the same 8,192 context as before.
  • cargo fmt is clean on what I touched. I did not run cargo clippy on this branch.

Duplication found or removed (path:line), or "none": none.

What I ran

Start time, measured with bloomery-serve -m <Qwen3.8 FP4-Local folder> --parallel N --plan, N = 1, 2, 4. The model is nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6. Both arms ran in one sitting in the order base, head, head, base, twice, so each arm has four wall-clock runs per N. The base arm is the upstream commit this change builds on.

Metric Base (median, range) Head (median, range) Difference Ranges overlap
plan time at 1 slot, s 4.49 (4.44..4.75) 4.445 (4.21..4.50) -0.045 yes
plan time at 2 slots, s 4.705 (4.54..4.75) 4.30 (4.15..4.46) -0.405 no
plan time at 4 slots, s 5.62 (5.55..5.94) 5.415 (5.39..5.52) -0.205 no

At 4 slots the head prints ctx rule=fitted ctx=116736 slots=4 total=466944 and the base prints ctx rule=halved ctx=65536 slots=4 total=262144. At 1 and 2 slots both arms keep ctx rule=target ctx=262144, so the change there is only the plan reuse.

Checks on the code of this branch, before its last rebase onto upstream efa54f26a. The rebase changed only context lines in two test files that upstream had moved, and the lines this PR adds are the same.

  • cargo fmt -p bloomery-placement --check: exit 0. cargo test -p bloomery-placement: 209 passed, 0 failed.
  • Three mutants of the context search each fail the tests that pin it (a_short_card_fits_only_the_default, a_steered_search_ends_on_the_largest_step_whatever_the_shortfalls): exit 101 each.
  • just check: exit 0. cargo fmt --all --check: exit 0.
  • the_card_route_runs_the_whole_ubatch_where_nothing_moves_for_it: 1 passed. A mutant that returns the widened machine with the first plan's read fails it, exit 101.
  • just gate-qwen3-plan: exit 0, 7 passed, 0 failed, including dense_shortage_fits_the_default_context.

Not run: gate_qwen3_serve, gate_qwen38_serve, gate_mimo2_serve, gate_glm5next_serve, gate_ds41_serve and gate_nemotron_serve, whose models were not available, and the bloomery-gpu part-load tests (parts::). Their sources compile in just check. The gate runs on the rebased head did not finish, so the checks above are not repeated on it. The change touches crates/gpu, so a maintainer needs to run those gates on a card.

Hardware

Machine Card Driver CUDA Conditions
DGX Spark NVIDIA GB10 595.84 13.3 start-time runs
RTX 5090 host GeForce RTX 5090 595.99.02 13.2 400 W power limit; just check, just gate-qwen3-plan, widen test

nvidia-smi on each machine:

  • NVIDIA GB10, 595.84, CUDA 13.3
  • NVIDIA GeForce RTX 5090, 595.99.02, CUDA 13.2

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: the host_room_halves_the_default clause no longer pins the largest context, and its change carries no dated PIN.

Must fix

1. mimo2 host-room clause accepts any context from the half up to the default

crates/gpu-gates/src/bin/gate_mimo2_serve.rs:971 The old clause required ctx == below. The new one requires below <= c < ctx_max and need(c) <= between. Mutant: an off-by-one in largest_held that returns one step under the largest context that holds. The line still says rule=fitted, host-short, planned == fitted_to and need(c) <= between hold, so the clause stays green. The gate cannot tell "largest" from "some context that holds". The same happens for the reshaped default_load_is_its_whole_fit clause in gate_qwen3_serve.rs: it now has no dated reason. This is a moved gate without a PIN(YYYY-MM-DD): line.
Cost: a gate that passes on the bug is cheaper to fix now than after the next search change.
Fix: add // PIN(2026-10-28): the default is fitted, not halved; the clause pins the largest context the room holds, not one context. above let fitted_to, and replace the need_fitted and fitted lines with:

        let need_fitted = fitted_to
            .map(|c| default_plan_need(file, levers, (c, cards)))
            .transpose()?;
        let need_above = fitted_to
            .map(|c| default_plan_need(file, levers, (c + STEP, cards)))
            .transpose()?;
        let fitted = status.is_some_and(|s| s.success())
            && fitted_to.is_some()
            && planned == fitted_to
            && need_fitted.is_some_and(|n| n <= between)
            && need_above.is_some_and(|n| n > between);

Non-blocking

⚠ Memo test misses its key's card-tensor term: crates/gpu/src/parts.rs:1055. Mutant: key (card, room) without OnCard. Both plans (4096, 8192) hold the same tensors, so the test stays green, and a plan that moves a tensor off the card gets the stale host_bytes. Add a case where the second plan changes the card's tensors and the count rises.

⚠ Library expect on a caller contract: crates/model/src/arch/qwen35moe/place.rs:1352. R10 allows expect in a library only where the type cannot allow the failure. A plan closure that returns Ok without calling on panics here. The panic is named, so it is not silent. Direction: refuse with a PlaceError or state the contract in the type.

⚠ also 2 minor: stale PIN(2026-10-14): the default is the seats' ladder at gate_qwen38_serve.rs:3591 (now misleading); old names kept (host_room_halves_the_default, ctx_default_is_the_highest_rung_held).

Checked

  • Duplicates: 9 new items checked (Below, fit_of, Rule::word, reading, machine_read, Plans::read, fits, floor_of, step_above), none duplicated. dryer pair levers/src/tests.rs:1583-1624 ~ 1630-1660: two tests over different reserves, shape only, not a finding.
  • Complexity: largest_held 5 → 18 is a new function complex on its own (the steering state in the closure); fit_of is already split out, left. choose 16 → 17 is even growth. served and host_room_halves_the_default are gate bodies, read for correctness only.
  • Silent failure: 6 sites followed (poisoned memo lock is a named refusal; out-of-range hint falls to the midpoint, and the seen assert cannot fire because an open-range hint is never a probed point; RungCost::of with with == 0 yields; Below::Nothing for a limit under the floor gives FloorShort; widen_card_route read follows the returned machine; rule=fitted string match in glm.rs agrees with Rule::word).
  • Search: I checked the bisection invariants (largest held k, step above is short or is ctx, floor planned only when all above are short); the above short plan is shorts[0].
  • Tests: the ctx_ask and largest_rows mutants turn red; the memo test misses the key mutant above.
  • Gates: moved without PIN: mimo2 host-room, qwen3 whole-fit (item 1). Renamed tests carry PINs.
  • Escape catalog: none matched (no shell changes).
  • Performance: load and plan path, not a hot path. No headroom items.

Notes

  • gpu.json evidence is false: no commit hashes, the gate runs were before the rebase, and the six gate_*_serve gates and parts:: tests did not run. The PR body says so; a maintainer needs to run them on a card.
  • The PR body says cargo clippy was not run.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/bloomery_serve_qwen38.rs, crates/gpu-gates/src/bin/gate_ds41_serve.rs, crates/gpu-gates/src/bin/gate_glm5next_serve.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-ctx-largest-fit branch from 3cec665 to 4cc2ff3 Compare October 28, 2026 05:11
github-actions[bot]
github-actions Bot previously approved these changes Oct 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: the earlier must-fix is fixed for mimo2, and the qwen3 clause still pins the largest context, so only non-blocking items remain.

Since the last review:

  • Must-fix 1 (mimo2 host_room_halves_the_default): fixed. gate_mimo2_serve.rs:971 has the dated PIN, and need_above > between at line 990 turns an off-by-one low mutant of largest_held red.
  • qwen3 default_load_is_its_whole_fit: no PIN, now a ⚠. Mutant: the search loads one step low. The clause fails when the step above fits and was probed.
  • The other ⚠ items are still open, unchanged.

Non-blocking

⚠ Reshaped clause has no dated reason: gate_qwen3_serve.rs:3152. The old clause required the last verdict at the loaded context; the new one drops that order. Add above check(: // PIN(2026-10-28): the default is fitted, not halved; the clause pins that no larger probed context fits.

⚠ Memo test misses its key's card-tensor term: parts.rs:1055. Mutant: key (card, room) without OnCard. Both test plans hold the same tensors, so it stays green. Add a case where the second plan moves a tensor off the card.

⚠ Library expect on a caller contract: place.rs:1352. A plan closure that returns Ok without calling on panics (R10). Direction: return a PlaceError.

⚠ also 2 minor: stale PIN(2026-10-14): the default is the seats' ladder in gate_qwen38_serve.rs; old names kept (host_room_halves_the_default, ctx_default_is_the_highest_rung_held).

Checked

  • Duplicates: need_above is the only new item in this round, one use.
  • Complexity: largest_held 5 → 18 and choose 16 → 17 unchanged; host_room_halves_the_default 30 → 34 is a gate body, read for correctness only.
  • Silent failure: need_above with c + STEP past ctx_max: the need only grows, so > between holds.
  • Gates: mimo2 PIN present; qwen3 PIN missing (⚠). Escape catalog: none matched.

Notes

  • gpu.json evidence is false: no commit hashes, and the six gate_*_serve gates and parts:: tests did not run. A maintainer needs to run them on a card.
  • The PR body says cargo clippy was not run.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/bloomery_serve_qwen38.rs, crates/gpu-gates/src/bin/gate_ds41_serve.rs, crates/gpu-gates/src/bin/gate_glm5next_serve.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: the rebase edits are three mechanical changes with no behavior change, and the earlier items are all non-blocking.

Since the last review: the four non-blocking items below are still open, none answered by the author.

Non-blocking

⚠ Reshaped qwen3 clause has no dated reason: gate_qwen3_serve.rs:3152, the default_load_is_its_whole_fit clause. The old clause required the last verdict at the loaded context; the new one drops that order. No PIN(2026-10-28) is in the file. Add above check(: // PIN(2026-10-28): the default is fitted, not halved; the clause pins that no larger probed context fits.

⚠ Memo test misses its key's card-tensor term: parts.rs:108. Mutant: key (card, room) without OnCard. Both test plans hold the same tensors, so it stays green. Add a case where the second plan moves a tensor off the card.

⚠ Library expect on a caller contract: place.rs:1352. A plan closure that returns Ok without calling on panics (R10). Direction: return a PlaceError.

⚠ also 2 minor: stale PIN(2026-10-14): the default is the seats' ladder at gate_qwen38_serve.rs:3591; old names kept (host_room_halves_the_default, ctx_default_is_the_highest_rung_held).

Checked

  • Interdiff: ctx.is_multiple_of(STEP) at ctx_ladder.rs:35 equals ctx % STEP == 0 on an unsigned type, and the method is already used across the tree. The MemoKey alias at parts.rs:108 names the same tuple. The removed test import tensor_places has no use left in the test module. The Name alias in the ctx_ask test is test-only.
  • Duplicates: 1 new item (MemoKey), one owner. Complexity: largest_held and choose unchanged. Silent failure: no new site. Gates: no pin moved in this round. Escape catalog: none matched.

Notes

  • gpu.json evidence is false: no commit hashes, and the six gate_*_serve gates and parts:: tests did not run. A maintainer needs to run them on a card.
  • The PR body says cargo clippy was not run.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/bloomery_serve_qwen38.rs, crates/gpu-gates/src/bin/gate_ds41_serve.rs, crates/gpu-gates/src/bin/gate_glm5next_serve.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 8d10299 into midagedev:main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant