Skip to content

serve seats, generate_qwen3moe: the n-gram lookup draft on Qwen3.8 through the seats' one lookup owner - #546

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-lookup-every-seat
Oct 20, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-lookup-every-seat

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

가중치 없는 n-gram lookup 초안(BLOOMERY_DRAFT=lookup)을 V4.1 전용에서 공용 경로로 옮기고, Qwen3.8 서버와 generate_qwen3moe에서도 쓸 수 있게 하는 작업입니다.

Part of #495 (lookup draft on every seat), one DGX Spark (TP=1, #493).

What and why

runtime::Lookup proposes the token that followed the most recent earlier match of the last 3, 2 or 1 tokens. It needs no weights, and its Draft impl takes any Verify target. Until now only the V4.1 seat and generate_ds41 served it, because the seat rebuilt the lookup's tables from the V4.1 body's token history (Body::history), which no other body keeps. This PR gives the lookup one owner that every seat can hold, and serves it on Qwen3.8.

  • runtime::Lookup gains truncate and stand. stand(pos, last) makes the context what a target standing at pos before last holds, keeping what the context already holds of the positions before pos. A context that already stands at pos with another token (a sampled id where the argmax was pushed) takes last in its place without a rebuild, because the last token is in no indexed n-gram yet. A cut back needs no call of its own: the next call truncates. A prompt call that continues a cached prefix puts its first id in with stand instead of rebuilding the tables. A new test drives a context through a prompt call, steps, passes keeping one or two rows, a replaced last token and cuts back, and checks it against a context rebuilt from the history each time, tables and proposal both.
  • drafted::Lookups (crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs) is the seats' one owner of the lookup draft: a window, a context and a width chooser for each resident slot, all verified by the session's two-row pass. A slot's context follows the slot by position, and a pass's cost is read when the pass ends (Choosing::finish_pass), so slots that take turns under --parallel 2 each finish their warm-up and keep their own acceptance record. A seat can hand it the body's token history; then a context that falls behind the target (a round of plain steps the draft did not see, a state put back) is rebuilt from it. A seat without one parks the context with the saved state and puts it back with it.
  • SlotDrafts (the Qwen3.8 and GLM seats' draft table) and served::ServedDraft (the V4.1 and qwen3 seats') both hold a Lookups, so the seats keep one call per event and the table picks the draft.
  • The MTP draft and the lookup share one pass-end helper, drafted::pass_in_turn. Each pass's cost is read when that pass ends, so under --parallel with BLOOMERY_MTP_WIDTH=cost a pass another slot runs in between never counts toward this slot's cost. The default multi-slot MTP round (one_pass) and DSpark do not go through this helper and are unchanged.
  • The lookup refuses a prompt call that carries no id, by name, before it touches the slot's width chooser.
  • tools/gpu-gate.sh admits the drafted arm of gate_qwen38_serve on a local card, as it already did for lookup, because that arm runs no card-specific paged clause. The plain arm keeps its 3090 pin, and the exception carries a dated PIN(2026-10-20) comment that says why the two arms are admitted.
  • Metadata and gate wiring for the new tests. tools/defaults-twins.tsv gains two rows for the pins BLOOMERY_DRAFT=draft and BLOOMERY_DRAFT=lookup in gate_qwen38_serve; both point at slots_default_residency, which runs the seat with the draft lever unset. tools/model-tax.tsv loses the glm and qwen rows for drafted.rs, whose count of 1 is gone. 14 new tests now run in a gate recipe: three serve_client tests in gate-q38-serve-rules, ten tests of the shared draft in the new gate-serve-draft-rules (the other two serve bins that include it), and the TP plan test of generate_glm5next in gate-ds41-place. tools/recipes.py adds the new gate to two expected selector sets, each with a dated PIN(2026-10-20) comment.
  • The V4.1 seat drops its own lookup arm (Served41) and serves the lookup through ServedDraft, passing Body::history as the history. Its contexts rebuild from that history at the same points as before, and each slot keeps its own width chooser.
  • bloomery-serve --model qwen38 and bloomery-serve-qwen38 take BLOOMERY_DRAFT=lookup: the plain load, the two-row verify pass captured at load (capture verify rows=2), a load draft=lookup line, a context per slot, the prompt cache parking each slot's context with its state, and /props naming the draft. BLOOMERY_MTP_HEAD_ROWS and BLOOMERY_MTP_DRAFT beside it are refused by name, as are BLOOMERY_ROUTE_TRACE and BLOOMERY_PREFILL=steps.
  • generate_qwen3moe takes BLOOMERY_DRAFT=lookup on a qwen4exp file: the plain load, then the same drafted arm the MTP draft runs (run_arm38, now generic over the draft), each pass's time pass record kind=lookup, and a draft summary record at the arm's end. drive38_lookup and drive38_mtp walk their arms through Session::arms, as the other drivers do, and the draft summary record comes from one function, record::draft_summary, which generate_ds41 calls too.
  • The lookup reports no probabilities, so the width chooser rates it by its calibrated gain alone. Under Rule::DEFAULT that gain starts at 1 (every id kept) and moves 5 % of the way a verify, which keeps the gate open for tens of verifies on a prompt where the lookup keeps one proposal in five. runtime::width::Rule gains prior: a position's gain is the running mean of what its tests kept, with the start counted prior times, until the step falls to calibrate. Rule::DEFAULT has no prior, so the MTP and DSpark choosers are unchanged. Lookup::RULE counts the start once, and every lookup chooser (the seats' Lookups, generate_qwen3moe and generate_ds41) is built with it. A new test runs a draft of one id with no probabilities that keeps 0.18 of its proposals, its pair pass at 1.35 of the step: the gate closes by pass 12 under Lookup::RULE and after pass 40 under the fixed step, and a draft that keeps 0.7 stays open.
  • Bodies whose load verifies no rows refuse lookup by name with the reason: the qwen3moe body (no pass of several rows), qwen35moe and dense qwen35 (they verify only on a load with a lane of delta state a row, which neither binary opens), and glm5next (a load holds two KDA lanes only with its NextN layer). The mimo2 and nemotron seats do not act on BLOOMERY_DRAFT, so the levers parse refuses it set.
  • generate_glm5next --place tp plans its N ranks in one private function, tp_ranks: rank 0 is this card, then one rank per address in BLOOMERY_TP_NODES, in order. One test checks N = 1 (refused by name), N = 2 and N = 4 (three addresses), and the levers test reads three addresses in order. N is data (nodes.len() + 1), not a constant. This commit is in the PR because the first commit already changes generate_glm5next.rs, and this closes that file's postponed item, a test of the plan beyond two ranks. The step that reads each node's card census over TCP needs live tier servers, so it is outside the tests.

Release notes: Added: BLOOMERY_DRAFT=lookup serves the n-gram lookup draft on Qwen3.8 in bloomery-serve and generate_qwen3moe. Fixed: under BLOOMERY_MTP_WIDTH=cost with several slots, the MTP draft no longer adds the time other slots ran to a slot's cost. Fixed: generate_qwen3moe refuses -n 1 with a drafted arm instead of printing a NaN rate.

Code shape

  • No second copy. The lookup's slot bookkeeping lives in Lookups alone; SlotDrafts and ServedDraft dispatch to it, and the V4.1 seat's own arm is gone. A pass's draft counts come from one function, drafted::drafted (moved from served.rs), and the Qwen3.8 seat's MTP-only levers are one list (mtp_only_lever), read by both the lookup refusal and the drafts-nothing refusal.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. ServedDraft::refuse_media became ServedDraft::prefill_media, which also feeds the lookup.
  • No silent failure. A slot past the table, a state saved under one draft put back under the other, and the MTP-only levers under lookup are refused by name. generate_qwen3moe refuses -n 1 with a drafted arm (BLOOMERY_DRAFT=mtp or lookup) before it opens the model, because the prompt call already yields the first token and no pass is left for the draft to verify. Before this, the lookup run printed tok/s(positions)=NaN and exited 0. A --warm that leaves no counted pass (a drafted pass keeps several positions, so -n past --warm can still end inside it) is refused by name too; one function, counted_passes, decides that for the SMOKE record, the lookup's draft summary and the MTP summary.
  • Comments state what is true now.
  • No relaxed gate.

Duplication found or removed (path:line), or "none": the V4.1 seat's Served41::Lookup arm and its lookup_follows rebuild (crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs) are gone; the V4.1 seat and the Qwen3.8 seat now share Lookups.

What I ran

Checks ran on the heads named below. The GPU gates and the MTP serve A/B ran on 4fa0a12b, rebased over #535 (which changed the serve files) onto upstream 71ca4de9. The final head 62ae0592 is that branch rebased onto upstream 654f1b0e. Two upstream changes came in between: #526 (accepts.rs and tools/model-tax.tsv) and #537, which moves the hub code into bloomery-model-hf. The #537 rebase needed two edits: the gate recipes this PR adds now list the hf feature as #537's recipes do, and generate_glm5next.rs calls #537's read_tp. Neither touches the runtime, the kernels, the serve seats or the draft code the gates and the A/B exercise, so those results carry to the final head. The unit tests, the mutants, the -n 1 run and the decode A/B ran earlier, on the heads named in each section. The third commit changes only generate_glm5next.rs, a levers test and one gate recipe, which no gate here reaches.

Lint and recipe checks

just contrib-check --tier t0 passed on 77ce4285, which carries the same three patches over an earlier upstream main: DONE tier=t0 total=94 red=0.

Unit tests

On e9cb5764 on the DGX Spark (cargo oxide test --arch sm_121, features deepseek41,gemma-embedding2):

  • bloomery-gpu-gates lib: 210 passed; 0 failed; 3 ignored.
  • bloomery-serve-qwen38 bin: 15 passed; 0 failed.
  • generate_qwen3moe bin: 2 passed; 0 failed.

On the final head 72876485 on one RTX 5090 (--arch sm_86; these tests launch no kernel), with the glm5next feature added: the lib passed 210 tests, bloomery-serve-qwen38 15, generate_qwen3moe 2 and generate_glm5next 1, with 0 failed.

The runtime and app crates last ran on 5692f83a (cargo test):

  • bloomery-runtime lib (width, lookup, DSpark, speculative): 252 passed; 0 failed.
  • bloomery-app lib (MTP policy, DSpark): 24 passed; 0 failed.

A drafted run with -n 1

The command, on a qwen4exp file with the lookup draft:

BLOOMERY_DRAFT=lookup bash tools/gpu-gate.sh generate_qwen3moe --place gate --tokens "$I" -n 1

With the earlier code (generate_qwen3moe.rs as of 5429b65e) it exited 0 and printed draft summary proposals=0 accepts=0 positions=0 passes=0 tok/s(positions)=NaN. On this branch it exits 1 after 1 s, before the model opens, with the message drafting needs -n 2 or more. The same run with -n 8 exits 0 and reports passes=6.

Mutants that must fail

Five mutants each made a new test fail, and the tests pass without them. On the DGX Spark: Lookup::stand replaced by a push (lookup_prompt_discards_the_prior_last_token failed), the refusal of a prompt call with no id removed (a_lookup_prompt_call_of_no_id_is_refused failed), and the counted_passes guard narrowed to warm > 0 && (a_rate_over_no_counted_pass_is_refused failed). On the RTX 5090: the empty-nodes refusal in tp_ranks removed (N = 1 then planned one rank), and the node order reversed (rank 1 of N = 4 then took the first address instead of the second). Both failed tp_ranks_are_this_card_then_each_node_in_order.

Cost read at the end of a pass

drafted::tests::turns_land_each_slots_cost_before_the_other_slots_expensive_pass sends two slots through the production helper 12 turns each on a fake clock: a 10 ms step, a 13.5 ms verify for slot 0 and a 400 ms verify for slot 1. With the finish_pass call removed, the test failed: slot 0's second cost read 413.5 ms instead of 13.5 ms, because the other slot's 400 ms landed in it. With the call in place the drafted tests passed 3 of 3 in each serve binary. The fake clock shows the ordering only; it is not a GPU cost measurement.

Runner admission of the MTP arm

bash tools/gpu-gate.sh has a self-test. With the drafted exception removed, it failed 2 cases (129 of 131 ok), where the arm exited 64 on a local card. With the exception it passes 131 of 131, including the plain arm's 3090 pin.

Qwen3.8 MTP serve gate

gate_qwen38_serve --arm drafted passed 28 of 28 clauses on 4fa0a12b (the draft-off ids as reference, greedy and top-k 1 ids equal, draft counts, continuation, cache switch and break-even clauses). The gate printed gate-gpu-qwen38-serve: PASS. It is a function gate, not a speed measurement. The MTP file is MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf from the same model revision below.

Qwen3.8 lookup dispatch

The gate_qwen38_serve --arm lookup arm starts bloomery-serve-qwen38 with the draft off, then with lookup (BLOOMERY_MTP_WIDTH=fixed for lookup only, BLOOMERY_RESIDENCY=off, --parallel 2). It compares both servers' greedy ids and sampled ids requested with n_probs, checks the two-row capture's node count, and requires both rejected and accepted lookup proposals. It erases the resident slots, restores the code and prose conversations in reverse order, and checks that each keeps its cached prefix and ids on a different slot. A third server (BLOOMERY_MTP_WIDTH=cost, --parallel 2, two requests at once) checks that every round takes the two slots' passes in turn and that both slots finish their cost warm-up.

bash tools/gpu-gate.sh gate_qwen38_serve --arm lookup \
  --gen "$D/gen.log" --prompt "$T" --ids "$I" --dir "$D/lookup"

D, T and I are the output directory, prompt and token ids from just gate-gpu-qwen38-serve; that recipe runs the lookup arm after its plain and MTP arms.

On 4fa0a12b the arm passed 41 of 41 clauses in 226 s and printed gate-gpu-qwen38-serve: PASS. The two-row capture had nodes=1475, the lookup made 140 proposals and 82 were accepted, all 51 of 51 rounds of the cost server took both slots' passes in turn, and both slots finished their cost warm-up.

The prompt-boundary regression runs with cargo oxide test --arch sm_121 -- -p bloomery-gpu-gates --features deepseek41,gemma-embedding2 --release --bin bloomery-serve-qwen38 lookup_prompt_discards.

MTP serve A/B on one DGX Spark

The change adds one clock read per pass under BLOOMERY_MTP_WIDTH=cost with --parallel 1, so I compared bloomery-serve-qwen38 built from upstream main 71ca4de9 with the one built from 4fa0a12b. Each server started fresh, with the model's MTP file:

BLOOMERY_DRAFT=mtp BLOOMERY_MTP_DRAFT="$MTP" BLOOMERY_MTP_WIDTH=cost BLOOMERY_RESIDENCY=off \
  bloomery-serve-qwen38 --host 127.0.0.1 --port 0 --ctx-size 4096 --parallel 1

Then one /completion request (prompt The capital of France is, n_predict 128, temperature 0, cache_prompt false, ignore_eos true) and the predicted_per_second from its timings. Main and the branch alternated for 3 rounds each, after the load average read 0.76 with 6 quiet polls 5 s apart:

Arm tok/s runs Median
main 24.309, 28.243, 28.15 28.15
head 28.758, 28.747, 28.163 28.747

Delta (head against main, medians): +2.1% tok/s; main's first run (24.309) is a cold start.

I read main's first run as a cold start and did not confirm it. The branch is not slower than main. This shows that the extra clock read has no visible cost. It is not a speed claim, and I did not measure the card's read bandwidth in this sitting.

Decode A/B on one DGX Spark

generate_qwen3moe on four 4096 id prompts, -n 128, graph mode, one lease, measured on e6562f72 against upstream main c900efac before the later commits (its table is comparison-r7.json, not the A/B table above). Draft off on this branch equals main within 0.3 %, the lookup ids equal the draft-off ids in every bundle, and the lookup gains where the prompt repeats itself:

  • code-fn: main 29.78 tok/s, branch with the draft off 29.84 tok/s, lookup 35.83 tok/s (20.3 % over main).
  • code-js: main 29.74 tok/s, draft off 29.8 tok/s, lookup 35.28 tok/s (18.6 % over main).
  • prose-en: main 29.75 tok/s, draft off 29.84 tok/s, lookup 29.75 tok/s (0.0 % over main).
  • prose-ko: main 29.7 tok/s, draft off 29.7 tok/s, lookup 29.71 tok/s (0.0 % over main).

I carry this A/B to the later heads instead of measuring again. generate_qwen3moe drives the draft directly and never calls finish_pass or pass_in_turn. Its token loop and Lookup::propose, accept and stepped did not change after the measured head, and width.rs gained only the finish_pass method and a doc sentence. The default one-pass MTP path did not change either. I measured no new MTP speed.

Hardware

One DGX Spark. The GPU gates and the A/B above ran on it at 4fa0a12b; the binaries were built in the CUDA 13.3.1 devel container and ran on the host.

GPU name, driver and CUDA version, from nvidia-smi --query-gpu=name,driver_version --format=csv,noheader and the container banner of the same job:

NVIDIA GB10, 595.84, CUDA 13.3.1

The gate recipe, whose lookup and MTP arms ran in that job, and the output summary of each arm:

just gate-gpu-qwen38-serve
lookup PASS 41 FAIL 0
gate-gpu-qwen38-serve: PASS
mtp PASS 28 FAIL 0
gate-gpu-qwen38-serve: PASS

Model: unsloth/Qwen3.8-Flash-Next-GGUF at revision 766911a6b7369840a91dbcd95f9f997acaab6cd6, UD-Q4_K_XL.

What I ran into

None of this blocks the PR.

  • The final head 62ae0592 was not run through the GPU gates or the A/B, for the reason given above; its recipe checks and the runtime and gate host tests passed on it. The unit tests ran on e9cb5764 and 72876485 as listed, and the runner self-test (131 of 131 ok) ran on 44a35e24; none of them was repeated after the serve: schemajump R2 feeds a run of fixed ids as one prefill call (BLOOMERY_SCHEMAJUMP, on by default) #535 rebase.
  • The cost figures in the lookup gate come from --place gate (a step near 100 ms), so they show warm-up and slot separation only, not speed.
  • With BLOOMERY_MTP_WIDTH=cost, the MTP pass-end read also changes --parallel 1: host work after a pass no longer counts in the cost. In fixed mode finish_pass does nothing.

AI help

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

…test (Rule::prior)

The lookup reports no probabilities, so the width chooser rates it by its
calibrated gain alone. Under Rule::DEFAULT that gain starts at 1 and moves
5 % of the way a verify: on Qwen3.8 at 4096 on GB10, a prose prompt whose
proposals keep one in five holds the gate open for about 38 verifies of a
128-token decode. Rule::prior makes a position's gain the running mean of
what its tests kept, the start counted as that many tests, until the step
reaches Rule::calibrate. Rule::DEFAULT has no prior and is unchanged;
Lookup::RULE counts the start once, and every lookup chooser (the seats'
Lookups, generate_qwen3moe and generate_ds41) is built by it.
@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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 20, 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 was found in the changed code.

Non-blocking

⚠ Verify the V4.1 lookup consumer: crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs:1171. This seat now uses incremental contexts and the history callback. The reported GPU runs cover Qwen3.8. Attach a V4.1 lookup serve run covering continuation, rollback, slot switching and saved-state restore.

Checked

Duplicates: 106 new or renamed declarations checked; no duplicate owner found. Dryer reported zero pairs in runtime/levers; gate code was checked manually.

Complexity: new lookup_main (39) combines server/request/cache stages; new lookup_cost_turns (27) combines concurrent requests and record checks. run_arm38 (25) generalizes the existing prompt/decode/report pipeline. Generator run 185→193 adds lookup branches; Q38 open 65→68 adds draft dispatch; Q38 run 130→132 adds refusals; gate run 15→17 adds arm dispatch.

Silent failure: 5 sites followed. Invalid capture nodes fail the gate; empty counted passes error; body() is infallible; a completed step has positive position; the discarded tally is not a Result.

Tests: static mutation audit covered context replacement/cuts, pass-end timing, calibration prior, input refusals, reply validation and TP node order. Assertions reject the corresponding dropped update/guard or reordered nodes. An independent in-memory lookup model matched rebuilt tables over 20,000 cut/replacement cases; Rust tests and GPU gates were not rerun.

Gates: no numeric band relaxed. Card-admission and selector-set changes carry dated PIN reasons. No new unsafe block or kernel reduction change.

Escape catalog: C1–C4 did not match added code.

Notes

Dryer did not search gpu-gates; manual searches covered its changed code. GPU evidence is supplied by the author for the NVIDIA GB10.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/bloomery_serve_qwen38.rs, crates/gpu-gates/src/bin/gate_qwen38_serve.rs, crates/gpu-gates/src/bin/generate_ds41.rs … and carries a gate run on the author's card, which counts as verified.

🔨 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 added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 20, 2026
@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 64acd37 into midagedev:main Oct 20, 2026
6 checks passed
@midagedev

Copy link
Copy Markdown
Owner

감사합니다!

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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants