Skip to content

width: the MTP width gate rates recent windows, and a width it left comes back once it pays - #846

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-mtp-width-lockin
Oct 26, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-mtp-width-lockin

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

MTP 폭 선택기가 느린 구간 한 번 때문에 좁은 폭에 머무르던 문제와, 짧은 요청마다 폭을 잘못 줄이던 문제를 고칩니다.

What and why

The cost chooser for MTP draft widths (BLOOMERY_MTP_WIDTH=cost) could hold a narrower gate for a server's whole life after one slow stretch of the wider width's readings, and a draft on code moved between widths 3 and 2 from one run of the same requests to the next. This PR changes crates/runtime/src/width.rs in two commits.

The first commit lets a width the gate left come back. An open probe's reading now starts its width's readings over when, put in place of the width's median, it would move the gate. Opening or closing the gate starts the probe period over and sends its first probe to the width it left. A chain draft's width past the gate's starts over at every probe, together with the means of the positions the gate does not reach.

The second commit rates the gate over the last 1 / calibrate windows that filled their room, instead of over the mean profile. A draft's windows are not alike: a sure window is likely at every position and an unsure one unlikely at every one. The mean of their products exceeds the product of their means, so the mean profile rated the wider widths low. Each window's own cut still rates each width at that width's own cost, because the ids a chain draft walked past a width are spent whatever the verify step checks, and charging them to every width would rate the wider widths up. A chain draft's gate whose windows mostly cut below it gives its seat to a narrower gate that rates as high.

Rated over the recent windows, the gate can move between open widths faster than a probe period. Such a move keeps the probe period and every width's reading age. Restarting the period at each move let requests that alternate quickly hold every probe off, and pointing each probe at the width just left could keep the other costs stale.

The gate keeps those recent windows in buffers sized from the calibration step. A step too small for its windows to be held is refused with a named WidthError::Rule when the chooser is built.

Release notes: Fixed: The MTP width chooser no longer stays at a narrower width after a slow stretch, and it holds the width that pays on short requests.

Code shape

  • No second copy. The change is in the one owner of width choice. gate_rate computes a window's wall once, and the two single-call helpers it used are gone.
  • Model code holds only architecture facts. No model file changed; the shared chooser gained no per-model branch.
  • Dead code is gone. The walked argument of rate and best and the two single-call helpers are removed.
  • No silent failure. A calibration step too small to hold its windows is a named WidthError::Rule.
  • Comments state what is true now. The docs that described the gate as rated by the mean profile now describe the recent windows.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. cargo clippy -p bloomery-runtime --all-targets -- -D warnings is clean on that commit.

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

What I ran

Head 60d87fce435fc945dfc9c48b1771a31f5db11a5d on main 5b8619efc3066c720f7528c0401c2c4c648df9b5. The end-to-end runs below measured 3126f6a79bcb0471f3c902364b49661ce52354ca on main c343a6292046c4e1575bb2632fde17f4b9e4844b. The pushed head differs from the measured one only in crates/runtime/src/width.rs: the construction guard, the single gate_rate wall computation, the probe period kept across moves between open widths, and comments. I did not repeat the end-to-end runs on the pushed head, so the probe timing after a move between open widths is not measured end to end.

Unit tests and clippy ran on bff5b22d873377d57e1d331d490add9748fef94d, which differs from the pushed head only in the wording of one test doc comment (crates/runtime/src/width.rs, three lines):

  • cargo test -p bloomery-runtime --lib width::: test result: ok. 33 passed; 0 failed.
  • cargo clippy -p bloomery-runtime --all-targets -- -D warnings: finished with no warnings.

FAIL-first, with the new tests on the code they guard:

  • short_requests_hold_the_gate_and_cut_what_does_not_pay (24 requests of 128 positions each, repeated with begin) fails when the walk is charged to every width alike: 0.9860 of the rate of the run that pays, test result: FAILED. 0 passed; 1 failed. With the fix it passes.
  • undefined_input_is_a_named_error, with the added tiny-calibration cases, fails without the guard: attempt to multiply with overflow at crates/runtime/src/width.rs:982, test result: FAILED. 0 passed; 1 failed. With the fix it passes.
  • alternating_requests_still_reread_every_cost fails when every move between open widths restarts the probe period: the plain step re-read at pass None, width 3 at pass None: the bound is pass 196, test result: FAILED. 32 passed; 1 failed. With the fix it passes.

End to end, fp4l-mtp and fp4l-off on the FP4-Local checkpoint, main against the measured head, greedy output of 128 tokens equal in both runs, decode tok/s @ 4096-id prompt, n=128, one concurrent request, three rounds after one discarded lead-in round, eight windows:

Metric Base Head Difference Ranges
fp4l-off code-fn decode tok/s 30.2993 30.2425 -0.188% overlap
fp4l-mtp code-fn decode tok/s 55.9633 55.4204 -0.970% overlap
fp4l-mtp prose-en decode tok/s 40.1014 39.6767 -1.059% separate

The medians are the middle of three rounds. In the fp4l-mtp prose-en arm the three head rounds all lie below the three base rounds (the highest head round is 39.89 and the lowest base round is 39.97), so I am not claiming that arm is unchanged. Prefill tok/s and TTFT p95 moved by 0.492% or less in every arm.

This change is host code only (crates/runtime), so there is no PTX or device-path comparison.

Hardware

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |

One DGX Spark. Model: nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, with the MTP draft MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf from unsloth/Qwen3.8-Flash-Next-GGUF at revision 766911a6b7369840a91dbcd95f9f997acaab6cd6. The prompts come from two token files, code-fn (SHA-256 7520b471436fb307e91ee22640ad8100701d48e63e3da7de9160b705b92915d1) and prose-en (SHA-256 d10c7044df8884fdd200304604772d81a4b56a228f802d5f05db724b245ef77a).

Reproduction, per arm and per window (the offsets are 0, 50000, 100000, 150000, 200000, 250000, 300000 and 350000, after warm-up requests at 400000 and 404096; the base and head servers alternate, each restarted for its own round):

git -C base checkout c343a6292046c4e1575bb2632fde17f4b9e4844b
git -C head checkout 3126f6a79bcb0471f3c902364b49661ce52354ca  # the measured head
env BLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G BLOOMERY_MTP_DRAFT="<mtp-folder>" BLOOMERY_MTP_WIDTH=cost ./head/target/release/bloomery-serve -m "<folder>" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

Send one request per window: a 4096-token prompt, 128 generated tokens, temperature 0, one request at a time.

For fp4l-off the server runs with BLOOMERY_DRAFT=off and without the MTP variables.

AI help

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

The cost chooser could hold a narrower gate for a server's life after a
slow stretch of the wider width's readings. Three things kept it there:
an open probe's reading only joined its width's median of eight, so one
reading a probe could not move it; the probes took the widths in turn,
so the width the gate left came after the plain step and the narrower
width; and a chain draft held at the narrower width never reached the
wider width's last positions, whose means kept what they last heard.

A probe whose reading, put in place of its width's median, would move
the gate now starts that width's readings over while open as it already
did while closed, and the gate decides on `min_timings` readings taken
since. A move of the gate starts the probe period over, and its first
probe re-reads the width it left. A chain draft's width past an open
gate's starts over at every probe, together with the means of the
positions the gate's width does not reach.
The gate rated each width by `E(k)` over the mean profile, the product of
each position's mean `p_i`. A draft's windows are not alike: a sure
window is likely at every position and an unsure one unlikely at every
one, so the mean of the products is above the product of the means, and
each unsure window is cut to fewer rows than the gate's width. The mean
profile missed both and rated the wider widths low; an MTP draft on
code moved between widths 3 and 2 from one run of the same requests to
the next, decoding slower on the runs that took 2.

The gate now rates a width over the last `1 / calibrate` windows that
filled their room: the rows they keep over the walls they cost, a chain
draft's windows each verifying the width it cuts to with the walk of the
gate's width paid. A window past the positions it reached is rated by
the mean conditional on the ids before it. A chain draft's walk of one
id is read off the passes a window cut below its walk. A window's own
cut still rates each width at its own cost: the walk past a width is
spent whatever the pass verifies, and charged to every width alike it
would rate the wider widths up and keep windows wide that pay cut. A
chain draft's gate whose windows mostly cut below it gives its seat to a
narrower gate that rates as high, since those windows walk its width for
nothing; otherwise a move still needs the margin.

Rated over the recent windows, the gate can move between open widths
faster than a probe period. Such a move now keeps the period and every
width's reading age; only an open or a close starts the period over and
sends its first probe to the side it left. Restarting the period at each
move let alternating requests hold every probe off, and pointing each
probe at the width just left could keep the other costs stale.

A calibration step too small for its windows to be held is refused by
name when the chooser is built.
@github-actions github-actions Bot added the host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset label Oct 26, 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: I built failure paths for the chooser's new state transitions and found each one blocked; the open points are questions about evidence.

Non-blocking

⚠ The pushed head was not measured end to end: the PR body says the runs used 3126f6a, and width.rs changed after it (probe period kept across moves, gate_rate, the guard). The fp4l-mtp prose-en arm already reads -1.059% with separate ranges. Please re-run that arm on 60d87fc, or say why the later edits cannot move it.

⚠ A chain draft's probe of a width past the gate now costs more than one pass: width.rs:1611 calls start_over(k), so min_timings (4) consecutive passes are forced to the wider width and the gate is frozen, once per probe_every (64) passes. Term [derived]: 3 extra forced wide passes per 64, plus 4 passes with no gate decision, against 1 pass before. A timed A/B on a chain draft (BLOOMERY_MTP_WIDTH=cost against fixed) is the proof the change class asks for.

⚠ The PR body leaves two checks unrun: just contrib-check and the lint-count ratchet. Run both before merge.

Checked

  • Duplicates: 9 new items checked (recent, cut_of, gate_rate, decided, moves_on, start_over, walk, before/upto, test helpers), none duplicated. cut_of replaces the body of cut; start_over replaces Timings::restart and the warm.push_back pair. dryer: 0 pairs.
  • Complexity: decided is new at 18 (one loop, one decision match). propose rose 29 to 32 by one branch (the chain probe at 1611); I found no better owner.
  • Silent failure: 5 sites followed, each guarded: walk.median().unwrap_or(0.0) by len >= min_timings; (f.walked - f.width) by Kind::Cut needing k < walked; learn writes by n <= WIDTH; cut keeps its old fallback; a step too small gets a named WidthError::Rule.
  • Failure scenarios built and blocked: a window shorter than the gate; walk_ms still 0 early; a gate frozen by warm; a probe that moves the gate while open.
  • Hot path: the decode step. decision allocates nothing. The loop is about W × R × W² flops per filled proposal [derived, default calibrate 0.05], microseconds against a pass of milliseconds.
  • Tests, mutation: a_chain_gate_inside_the_margin_holds_against_noise turns red if 2 * cut > recent_len is dropped. short_requests_hold_the_gate… and alternating_requests_still_reread_every_cost turn red on their mutants (the PR shows both).
  • Gates: no band, tolerance or lint moved. Escape catalog: none matched; no shell file changed.

Notes

  • No just gate-* output is in the PR body, so I mark GPU evidence as absent; the change is host code only.

🔨 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 741005f into midagedev:main Oct 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant