Skip to content

serve, qwen38: a long prompt yields to busy slots on the positions' quantum grid, which the Qwen3.8 seat names as its checkpoint grid - #1069

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-prompt-yield
Nov 1, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-prompt-yield

Conversation

@juliankang4

@juliankang4 juliankang4 commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8 서버에서 긴 prompt가 들어와도 다른 slot에서 돌던 요청이 멈추는 시간을 6.3초에서 1.7초로 줄입니다.

Part of #565.

What and why

With --parallel 2, a long prompt arriving beside a decoding stream blocks that stream for the whole prefill. For a 16,385 id prompt the stream's longest gap between two tokens is 6,308.9 ms. The serve loop already cuts a prompt into calls of Engine::prompt_quantum ids so a busy slot can decode between the calls, but only the mock engine named a quantum and the cuts counted from each call's start, which put them off the checkpoint marks.

This change makes the quantum a grid of positions and makes the Qwen3.8 seat name its checkpoint grid (4,096) as the quantum. A prompt longer than the quantum is cut at the next multiple of 4,096 positions. Those places are marks that one uncut call also writes (runtime::seqstate::marks), so the cut prompt leaves the same checkpoints as one call, and a later request reuses the same cache_n whatever the load.

On the 16,385 id prompt the stream's longest gap falls from 6,308.9 ms to 1,719.7 ms, and the long prompt's first token comes 2.4% later. The numbers and commands are under "What I ran".

  • Grid contract (crates/serve/src/engine.rs, genloop.rs, worker.rs, mock.rs): Engine::prompt_quantum is a grid of positions. quantum_end picks the next cut for a prompt (quantum_ends) and for a constrained-decoding run of fixed ids (Gen::fill). A cut never falls inside an image span.
  • Seat plumbing (crates/gpu-gates/src/bind.rs): Seat::prompt_quantum, None by default, read once at load by SeatEngine.
  • Qwen3.8 seat (serve_seats/qwen38.rs): the quantum is CHECKPOINT_EVERY. It is None when the MTP draft serves two or more slots and when --mmproj loads an image encoder, so those keep one call per prompt.
  • Path rule (crates/gpu/src/arch/qwen3moe/body38.rs, resolve_prompt): in Auto, a call that starts or ends at a non-zero multiple of CHECKPOINT_EVERY runs as an ubatch walk whatever its length, because one uncut call also cuts its units at that mark and walks. Without this rule the short first or last piece of a cut prompt would take the short-prompt path and its bits would differ from the uncut call. The same rule applies to a short call at such a position when the request runs alone.
  • A prompt alone, with no other slot busy, still runs as one call.
  • Gate: hw_quantum_cuts is added to just gate-gpu-qwen4exp-mtp-input. Docs: docs/serving.md.

Release notes: Changed: on Qwen3.8, a long prompt now yields to decoding slots every 4,096 positions, which shortens the pause of an already running stream.

Code shape

  • No second copy. The cut rule has one owner, quantum_end, which replaced the two earlier loops in quantum_ends and Gen::fill. The grid spacing reuses CHECKPOINT_EVERY, and the marks stay owned by seqstate::marks.
  • Model code holds only architecture facts. The Qwen3.8 seat names its checkpoint grid. The serve crate gained no model branch.
  • Dead code is gone. The span-end snap in the old cut loop is removed.
  • No silent failure. quantum_end has no failure path, and no Result is ignored.
  • Comments state what is true now. Comments in the touched files describe the grid rule.
  • 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.

Duplication found or removed (path:line): the cut loop in quantum_ends and the fed + q cut in Gen::fill are now one function, quantum_end in crates/serve/src/genloop.rs.

What I ran

Measurement on bloomery-serve, base 6791d577b09c6054d6293b9f6b6a1e2fb54f9970 (main) against head da88f00398e420cd93a916df6335b6ad3c5e18be, both built in the same session and served in turn on the card below. Model nvidia__Qwen3.8-Flash-Next-FP4-Local@b9ce18a6887e18c089fdea8509a33e63429a3300.

cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve
BLOOMERY_DRAFT=off bloomery-serve --host 127.0.0.1 --port 18741 --parallel 2 --ctx-size 40960 --cache-ram 0 --slot-save-path <dir>

Each round erases both slots (/slots/N?action=erase), starts request A (a 64 id prompt, a streamed 400 token answer), and once A has produced 20 tokens sends request B (a 16,385 id prompt, no cache, 8 tokens) to /completion. One warm-up and three measured rounds, medians with ranges. "A longest gap" is the longest time between two tokens of A from the moment B is sent to B's first token.

Metric Base Head Difference Ranges overlap
A longest gap (ms) 6308.9 (6304.5..6358.4) 1719.7 (1715.9..3083.5) -72.7% no
A tokens while B prefills 1 (1..1) 4 (4..4) +3 no
B first token (ms) 6288.4 (6284.1..6294.5) 6438.5 (6429.1..6449.4) +2.4% no
A gap median outside B (ms) 33.14 (32.31..33.14) 32.74 (32.73..33.43) -1.2% yes

On the head, B runs as calls of 4,096, 4,096, 4,096, 4,096 and 1 ids and A emits a token between the calls. One head round had a longest gap of 3,083.5 ms; the other three were 1,715.9 to 1,723.0 ms.

The same run checks the output of both builds:

base CHECK B-ids PASS [1, 198, 248045, 487, 198, 262, 328, 9215] = [1, 198, 248045, 487, 198, 262, 328, 9215]
base CHECK C-cache_n PASS beside 4096 alone 4096 want 4096
base CHECK A-ids PASS 400 ids
head CHECK B-ids PASS [1, 198, 248045, 487, 198, 262, 328, 9215] = [1, 198, 248045, 487, 198, 262, 328, 9215]
head CHECK C-cache_n PASS beside 4096 alone 4096 want 4096
head CHECK A-ids PASS 400 ids

B-ids compares B's 8 ids when B runs alone and beside A. C-cache_n sends a request C that shares B's first 5,146 ids and checks that its cache_n is 4096 alone and beside A. A-ids compares A's 400 ids with and without B.

GPU gate (just gate-gpu-qwen4exp-mtp-input, head 98afe38f93ef6e052b8a8adfe7bf60a791d1d329), run as BLOOMERY_BOX_LOCAL=1 BLOOMERY_QWEN38_FOLDER=<the model above> just gate-gpu-qwen4exp-mtp-input. With Body38::resolve_prompt treating position 0 as a grid position (its p > 0 check removed), the new clause and hw_close_fold report FAIL:

(qc) 3 ids from 0 and 1 run as passes, from 4093 and 4096 as ubatches: [(0, false), (1, true), (4093, true), (4096, true)] FAIL
(cl) the last id rides the ubatch walk at 21, 32 and 5 ids from a reset (the seat steps it otherwise): [true, true, true] FAIL
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 1 filtered out; finished in 107.09s

With the rule in place:

(qc) 3 ids from 0 and 1 run as passes, from 4093 and 4096 as ubatches: [(0, true), (1, true), (4093, true), (4096, true)] PASS
(qc) 8213 ids after 0: the calls [4096, 4096, 21] cut at [4096, 8192] against the one call: argmax 220 = 220, logits true, steps' ids [248046, 198, 248045] = [248046, 198, 248045] and bits true; the last call folds true (one call true); points [4096, 8192, 8212] = [4096, 8192, 8212] PASS
(qc) 8197 ids after 4093: the calls [3, 4096, 5] cut at [4096, 8192] against the one call: argmax 329 = 329, logits true, steps' ids [61608, 248046, 198] = [61608, 248046, 198] and bits true; the last call folds true (one call true); points [4093, 4096, 8192, 8196] = [4093, 4096, 8192, 8196] PASS
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 86.01s

Host tests for the serve crate (cargo test -p bloomery-serve --lib and cargo test -p bloomery-serve --test serve -- --include-ignored yields), head 0b5c6d81d5e96baf8ee6c21a2c354e78a6f510db. With the run's cut put back to every q ids from its start, hw_a_run_of_fixed_ids_is_a_call_a_round_beside_a_decoding_stream fails (calls end off the quantum's grid at [13, 17, 21, 25, 29, 33, 37, 41]). With the change:

test result: ok. 475 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 26.13s
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 100 filtered out; finished in 1.25s

Hardware (if the change is for a machine)

Card Driver
NVIDIA GB10 595.84

nvidia-smi --query-gpu=name,driver_version --format=csv,noheader in the gate run:

NVIDIA GB10, 595.84

AI help

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

…uantum grid, which the Qwen3.8 seat names as its checkpoint grid

Engine::prompt_quantum names a grid of positions: a prompt call of more than one quantum is cut at the multiples of q
inside it (and at the engine's message cuts), not every q ids from each call's start. An engine that keeps checkpoints
on a grid of its own (runtime::seqstate::marks) names a multiple of it, so the cut calls take the checkpoints the one
call takes and a later request keeps the same prefix whatever the load. A multiple inside an image span is not cut. A
constrained run fed beside busy slots is cut on the same grid.

The Qwen3.8 seat names CHECKPOINT_EVERY (not under the MTP draft on more than one slot). Body38::resolve_prompt runs a
call that starts or ends on that grid as the ubatch walk at any length, as the one call's units cut there run, so a cut
prompt's short first or last call keeps the one call's bits. gate_qwen4exp_mtp's hw_quantum_cuts holds the cut calls to
the one call: argmax, logits' bits, three steps and checkpoints.
@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 serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 1, 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 remaining finding asks for corrected test evidence.

Non-blocking

⚠ Correct the FAIL-first evidence: crates/gpu/src/arch/qwen3moe/body38.rs:4648.
Removing this arm on the gate's whole-card load makes the four checks in gate_qwen4exp_mtp.rs:3214 return [true, true, false, false]. The PR reports [false, true, true, true], which does not match this mutation. Rerun with this arm removed and attach the output to establish recurrence prevention.

Checked

Duplicates: the cut rule serves both prompt and fixed-id paths; the GPU gate reuses closed_run. Dryer reported 0 qualifying pairs in serve/levers; GPU crates were outside its scan.
Complexity: crapper flagged no function. resolve_prompt adds one guarded match arm.
Silent failure: quantum_end's unwrap_or(end) selects the final call when no eligible grid position remains; callers feed the remaining ids.
Tests: static inspection confirms that removing grid routing fails the last two path checks in hw_quantum_cuts. The prompt-grid, fixed-id and image tests assert the changed cut behavior. Builds and hardware gates were not run during validation.
Gates: no tolerance or threshold relaxed. The new GPU test is ignored and returns an error when its checks fail.
Escape catalog: no C1–C4 pattern matched. No ledger lessons apply.

Notes

GPU evidence is incomplete: the PR supplies a card/driver table and gate output, but no raw nvidia-smi line required by CONTRIBUTING.md. gpu.json records evidence: false.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs, crates/gpu-gates/src/bin/generate_qwen3moe.rs, crates/gpu-gates/src/bin/shared/serve_seats/qwen38.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 52bd46b into midagedev:main Nov 1, 2026
7 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 serve The HTTP server: crates/serve 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