Skip to content

runtime: learn batch acceptance from the current request - #690

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-mtp-batch-width
Oct 22, 2026
Merged

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-mtp-batch-width

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

여러 요청이 동시에 MTP draft를 쓸 때 verify 폭을 요청 하나가 아니라 batch 전체의 비용으로 고르게 해서, 동시 요청 네 건의 처리량을 높입니다.

Part of #565.

What and why

With MTP drafting, each verify step checks a proposal of several draft ids per request. When four requests draft at once, the verify rows of all four requests share one step, but the width of each proposal was chosen as if its request ran alone. A deep proposal that looks cheap for one request costs more once the rows of every active request share the step.

This PR makes the width rule see the whole batch.

  1. runtime::width::Batch in crates/runtime/src/width.rs owns the rule. It weighs the conditional acceptance of each proposal position against the measured wall time of the whole round, indexed by the total rows the round selects, and prices the active round before the serving owner packs its verify calls. Batch::choose takes the active slots and nothing about prompt rows, because a round's cost is read by its verify rows alone. Qwen supplies the supported widths 0..=WIDTH and GLM supplies 1..=WIDTH, which keeps the current two-row restriction of its NextN window. The rule has no model branch and no rank special case.
  2. The serving path keeps the existing single-request width path and uses batch selection when more than one draft is active.
  3. Batch acceptance is learned from the current request and is independent of the single-proposal calibration. Early conditional samples use their empirical mean, followed by the existing calibration floor. The prompt and begin lifecycle entries share one reset owner. A request that starts with a step alone, without a prompt or begin call, also learns its batch acceptance again from that request.
  4. A window of zero depth runs the existing before_step and recording path, so the draft state stays valid without inventing optional proposal probabilities.
  5. Exploration is shorter and cheaper. At depth three with zero allowed, endpoint exploration needs eight rounds instead of sixteen, and the profiles are borrowed and the width scratch is kept, which removes two temporary vectors per round (counted in the source).

The BLOOMERY_MTP_WIDTH lever description now separates the single-sequence prefix cut from the batch proposal-depth selection. Its default, cost, is unchanged.

The GLM serve gate reads its draft counts through the shared draft_counts helper, which returns a named failure when a count is missing or malformed instead of reading it as zero.

Release notes: Changed: batched MTP drafting picks each request's proposal width from the cost of the whole batch.

Code shape

  • No second copy. One width owner in runtime::width serves Qwen and GLM, and both lifecycle entries call one reset helper. A removal test exists for each caller.
  • Model code holds only architecture facts. The models supply supported width ranges. The rule has no per-model branch, flag or trait method.
  • Dead code is gone. The new public items have the shared serving caller, and the old single-request path stays in use for one active draft.
  • No silent failure. A bad profile shape, an unsupported width, a non-finite probability, row arithmetic and cost readings return named WidthError failures that selection and observation propagate.
  • Comments state what is true now. The touched comments describe the current contract.
  • No relaxed gate. No band, tolerance or pin moved. The new batch assertion and the extended calibration and lifecycle assertions each fail first under a production mutant.
  • cargo fmt is clean on what I touched.

Duplication found or removed (path:line), or "none": none. The five draft-count reads in the GLM serve gate now use the one draft_counts owner.

What I ran

Head c6724e76f, on top of main.

GPU Evidence

On an NVIDIA GB10:

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

The width rule is host code, and its owning gate runs on the host:

BLOOMERY_BOX_LOCAL=1 just gate-runtime
test result: ok. 282 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.09s

The width tests alone:

cargo test -p bloomery-runtime --lib width::
test result: ok. 23 passed; 0 failed; 0 ignored; 0 measured; 259 filtered out; finished in 0.11s

The new batch assertion fails first when the interpolated cost is replaced by the lower endpoint:

  left: (10.0, 10.0)
 right: (13.0, 19.0)
FAIL-FIRST-OK interpolation

The contribution check at the first tier finished clean:

DONE tier=t0 total=38 red=0 wall=228s

Throughput

The checkpoint is nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, served directly from its folder with an external shared-head Q8_0 MTP draft file (SHA256 5ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6). The base arm is main, the head arm adds this PR's width commits, and a draft-off arm runs the head binary with BLOOMERY_DRAFT=off. Both draft arms use the same environment and arguments:

BLOOMERY_DRAFT=mtp BLOOMERY_MTP_DRAFT=<draft file> BLOOMERY_MTP_WIDTH=cost \
  bloomery-serve -m <checkpoint folder> --host 127.0.0.1 --port <port> --parallel 4 --ctx-size 16896

Each arm loads its server once and runs one group per concurrency. A request sends a 4096-id window of a code corpus and generates 128 ids at temperature 0, with no RAM cache. Concurrency is 1, 2 and 4, and each request at a concurrency takes the next window. Throughput is all generated ids divided by the group makespan, from the first request sent to the last token received, so it includes prompt time and excludes model load. Release binaries are built with cargo oxide build --arch sm_121, and the GPU is idle apart from the server for each arm.

Measurement Base Head Draft off Head vs base
C@1 group tok/s 12.1949 12.1834 10.3152 -0.09%
C@2 group tok/s 12.8597 12.7323 11.7907 -0.99%
C@4 group tok/s 12.3425 12.6280 12.6863 +2.31%

C@4 group throughput changed by +2.31% against baseline and -0.46% against draft off. It rose from 12.3425 to 12.6280 tok/s, and draft off reaches 12.6863 tok/s.

At one request, throughput is effectively unchanged (-0.09%). At two requests it fell from 12.8597 to 12.7323 tok/s (-0.99%).

At four concurrent requests, the four requests proposed 292 draft ids with the head against 523 with the base (-44.17%).

All 1792 greedy token ids of the base and head arms equal the ids of the draft-off arm.

This is a single observation without a confidence interval, so the changes are point estimates and no significance is claimed.

What I ran into

This does not block the PR. At four concurrent requests the head is still 0.46% below draft off, and at two requests it is 0.99% below the base. A window of zero depth still refreshes the MTP state through before_step, which a draft that is truly off does not do. That work is a possible contributor to the remaining gap, and I did not time it by itself. No GLM hardware run covers the batch rule or the changed reads in the GLM serve gate, and the host cases cover one, two and four active slots and the supported width bounds.

Hardware

One NVIDIA DGX Spark (GB10), driver 595.84, CUDA 13.3, with CUDA 13.3.1 in the build image.

AI help

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

@github-actions github-actions Bot added 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 needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 22, 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: No must-fix defect found in the changed code.

Non-blocking

⚠ Complete the GPU dispatch evidence: crates/gpu-gates/src/bin/shared/serve_seats/rounds.rs:309.
For S active slots at depth d, the old pack used ceil(S / floor(MAX_ROWS / (1 + d))) verifies. The new pack uses 1 + width rows per window, changing pass count and row geometry. Supply the owning Qwen and GLM GPU gate outputs and an interleaved timed A/B with both commit hashes and command output. The reported host gate does not exercise this dispatch.

⚠ Force the zero-depth state transition: crates/app/src/mtp.rs:649.
Removing the new zero-depth refresh record leaves every added host test unchanged. Extend the existing MTP gate to force depth zero followed by positive depth on each slot, then compare tokens and draft-store state with the reference path. This catches lost refresh state before it reaches serving requests.

Checked

Duplicates: 8 new items and 2 API edits checked by Grep; no duplicate owner. Dryer reported 0 pairs; gpu-gates was excluded and checked manually.

Complexity: Batch::choose is new at 25, with validation, endpoint exploration and greedy pricing as split boundaries. pass_rows_one_pass rose 15→23 through selection and packing; app::mtp::pass_slots rose 15→19 through zero-depth branches. GLM slots_skipping 32→36, slots_flow_together 40→43 and slots_sampled 28→30 add count-error propagation.

Silent failure: 7 sites followed. Five draft-count reads return named errors for malformed counts; absent pairs mean no proposals. The maximum-width fallback is unreachable after the nonempty guard. The existing cache-count sentinel reaches explicit expected-count assertions.

Tests: static inspection ties assertions to width.rs line 536 (interpolation), line 952 (acceptance update), and reset calls at lines 852/1265/1402. Dropping those operations contradicts the assertions. The added host tests do not call app::mtp::pass_slots or its zero-depth hooks.

Gates: no tolerance or pin relaxed in the diff.

Adversarial checks: empty/invalid profiles are refused; endpoint readings bracket interpolation; packing makes progress within MAX_ROWS; singleton verifies retain the Pass arena; request entries reset acceptance.

Escape catalog: no matching pattern. No new unsafe block.

Notes

Tests were not rerun during validation. The PR supplies no GPU gate output or explicit base hash for its timing arms.

Card check: needs-gpu. This pull request changes crates/app/src/mtp.rs, crates/gpu-gates/src/bin/gate_glm5next_serve.rs, crates/gpu-gates/src/bin/gate_qwen38_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 92908c5 into midagedev:main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant