Skip to content

gpu, chain, runtime: Qwen3.6's MTP store walk ends at the cache append, and a closed width gate judges a request on its own shadows - #1073

Merged
juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-mtp35-store
Nov 1, 2026
Merged

juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-mtp35-store

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.6의 in-file MTP draft가 prompt와 닫힌 gate의 plain step에서 아무도 읽지 않는 layer와 head를 건너뛰고 cache append에서 멈추게 하고, 닫힌 width gate가 새 요청을 그 요청의 shadow로 판정하게 하는 작업입니다.

What and why

On one RTX 5090 at a power limit of 400 W (default 600 W), Qwen3.6-35B-A3B UD-Q4_K_M with its own MTP draft, 4,096-id prompts, 128 greedy tokens, one request at a time, main 6791d577b against this head 3ebdff767:

  • Prefill: 2,071.6 to 8,747.2 tok/s (+322.2%)
  • Decode: 267.2 to 268.2 tok/s (+0.4%)
  • Time to first token: 1,979 to 470 ms (-76.3%)
  • End-to-end: 1,718.1 to 4,456.9 tok/s (+159.4%)

Each value is the median of three rounds, each round the median of 16 requests (8 code and 8 English prose windows); the table under Speed gives the rounds' ranges. End-to-end is (prompt ids + generated ids) over the request's whole time.

Decode by corpus: code 281.1 to 282.8 tok/s (+0.6%), English prose 244.5 to 254.3 tok/s (+4.0%). The greedy ids are the same on main and head for all 48 requests. The shared width chooser now re-judges each request on that request's own measurements at its start: code, whose draft keeps most ids, stays open, and prose, where the now cheaper plain step pays more, closes.

Qwen3.6's MTP draft keeps its own key/value store. While a prompt is prefilled, and on every plain step while the width gate is closed, the draft walks the target's rows only to fill that store: a later row reads their keys and values and nothing else. The walk still ran the whole draft layer (attention output, the MoE block, the final norm) and the full-vocabulary head for every row, and the plain step read the target's normed row back to the host to upload it again. On a 4,096-id prompt that cost about three quarters of the time to first token.

This PR:

  • adds walk::store to the shared qwen3moe chain (crates/chain/src/arch/qwen3moe/walk.rs): an attention layer's input side and its cache append (ChainOps::attn_append), then stop. A delta or short-conv layer is refused by name; a backend without attn_append refuses by name.
  • makes dispatch::attn_append the one owner of the gemv arm's append (NeoX-128, gated-256, head-128 norm). attn_core calls it first, and the store walk calls it alone.
  • runs Mtp35's WalkMode::Store through walk::store with no head, and copies the step row from the target head's normed rows on the card (Head::normed, GpuModel::body_parts_normed) instead of a host round trip.
  • fixes the width chooser (crates/runtime/src/width.rs) that the cheaper plain step exposed. A closed gate hears of a request only through one shadow every 16 passes, so it kept the earlier requests' windows until they aged out: after two prose requests that closed it, a code request whose draft keeps 63 of 63 ids stayed on plain steps for its first 81 passes. Now a prompt call (Choosing::prompt_by) on a closed gate drops the earlier windows and runs its first 4 passes (Rule::min_timings) as shadows, and the gate decides on those. The calls that only forgot the pass in flight use Choosing::forget_pass. This chooser is shared by every MTP draft.
  • makes gate_qwen35moe_mtp and gate_qwen35moe_verify read their prompt ids from the shared prose corpus (prose_ids("qwen4exp")) instead of a recorded reference dump that the gates used only for its ids, and their files from BLOOMERY_REF_MODEL and, for the MTP file, BLOOMERY_MTP_MODEL (still pinned by general.name and size) instead of fixed paths. The clauses and bounds are unchanged.
  • adds the Qwen3.6 MTP numbers to docs/numbers.md and the README.

Release notes: Changed: Qwen3.6's MTP draft prefills about four times faster (time to first token down about three quarters on a 4,096-token prompt), and a closed MTP gate re-checks each new request instead of staying closed.

Code shape

  • No second copy. The gemv append has one owner (dispatch::attn_append) for attn_core and the store walk. The gates read prompts through prose_ids and files through open_split.
  • Model code holds only architecture facts. The store walk is in the shared chain and dispatch; the chooser fix is in the shared runtime; mtp35.rs only picks the walk by WalkMode.
  • Dead code is gone. The gemv helper that only attn_core used is inlined; every new function has a caller.
  • No silent failure. A store walk over a delta or short-conv layer, a backend without attn_append, a missing BLOOMERY_MTP_MODEL and a load without the head's rows are refused by name.
  • Comments state what is true now. No dates, issue numbers or how a bug was found.
  • No relaxed gate. No band or tolerance 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): none.

What I ran

Output is unchanged

gate_qwen35moe_mtp clause (w), new: store walks over positions 0 to 62 leave the draft's logits bit for bit, the step after them equals the eager run's last step bit for bit, other rows below the position do move the largest logit (the clause can fail), and the step row read on the card gives the same token and logits as the host copy. In the timed run every request's greedy ids match between main and head.

GPU evidence

The Qwen3.6 gates ran on a DGX Spark (GB10) that holds both Qwen3.6 files, with BLOOMERY_REF_MODEL the plain Q4_K_M file and BLOOMERY_MTP_MODEL unsloth's UD-Q4_K_M. The output below is from head 467b5a81c; the MTP and verify gates passed again unchanged at 2effb0681:

just gate-gpu-qwen35moe-mtp
(s) the draft's token is the target's own next token at 12/16 of the last positions = 75.0 % (26/63 over every position, 0/16 the prompt's next id; floor 30 %) PASS
(w) other rows below position 62 move its largest logit: (2567, 1093476036) against (s)'s (2567, 1095026256) PASS
(w) store walks over positions 0..62 leave the draft's logits bit for bit PASS
(w) the step at position 62 after them: token 2567 (s): 2567, largest logit bit for bit PASS
(w) the step row on the card: token 349 (read back: 349), logits bit for bit PASS
gate_qwen35moe_mtp: PASS
just gate-gpu-qwen35moe-verify
gate_qwen35moe_verify: PASS
BLOOMERY_TIER=fixture just gate-gpu-glm5next-mtp
gpu-gate.sh: gate_glm5next_mtp ran 44 s (exit 0)

just canon-check 6791d577b at 2effb0681: canon-check: 4 bins, 1848 entries: 1848 identical, 0 reordered-only, 0 differs, 0 only-on-one-side, so the dispatch split leaves every PTX entry the same program.

The real binary on the RTX 5090 loads the draft and serves: load draft=mtp layer=40 resident=564520960 scratch=2756208 head=full in 3.9 s. In one profiled request a side, the kernel time fell from 4,820.8 ms in 399,290 launches on main to 1,797.4 ms in 239,399 on head.

Machines:

  • RTX 5090 32 GB (NVIDIA GeForce RTX 5090, 595.99.02), power limit 400 W (default 600 W, 400.00 W, 600.00 W, 3090 MHz read before the run): the timings above.
  • DGX Spark (GB10), NVIDIA GB10, 595.84: the Qwen3.6 gates, the GLM fixture gate and the Qwen3.8 check.

FAIL-first

  • Clause (w) from this head's gate file, run on main's tree, fails exactly on the store clause: (w) store walks over positions 0..62 leave the draft's logits bit for bit FAIL.
  • a_request_on_a_closed_gate_opens_on_its_own_windows (close a losing draft, start a request whose draft keeps 0.95, expect the gate open within 16 passes) fails with the prompt-call rule switched off (the gate stayed closed 16 passes into a request that pays) and passes with it; cargo test -p bloomery-runtime passes 301 tests.

Speed

Metric main head Change
Prefill, tok/s 2,071.6 [2,071.1 to 2,072.0] 8,747.2 [8,743.6 to 8,754.5] +322.2%
Decode, tok/s 267.2 [267.1 to 272.7] 268.2 [268.1 to 268.3] +0.4%
Time to first token, ms 1,979 [1,979 to 1,980] 470 [470 to 471] -76.3%
End-to-end, tok/s 1,718.1 4,456.9 +159.4%

RTX 5090 (numbers at the top): each side built with cargo oxide build --arch sm_120a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve and started fresh each round as BLOOMERY_DRAFT=mtp bloomery-serve -m Qwen3.6-35B-A3B-UD-Q4_K_M.gguf --host 127.0.0.1 --port 18741 --parallel 1 --ctx-size 16896; two warm requests, then 16 requests (/completion, 4,096 ids, 128 greedy tokens), one lead-in round discarded, then three rounds a side in alternating order.

Qwen3.8 shares the width chooser, so its MTP draft was checked for no slowdown on one DGX Spark (GB10), Qwen3.8 FP4-Local, MTP on, main 6791d577b against 3ebdff767, median of three rounds (8 windows each):

Metric (Qwen3.8 FP4-Local, MTP on) main head Change
C=1 decode, code, tok/s 59.90 60.26 +0.6%
C=1 decode, English prose, tok/s 41.37 41.45 +0.2%
C=2 decode, code, tok/s (sampled) 33.51 32.26 -3.7%
C=2 decode, English prose, tok/s (sampled) 26.48 26.71 +0.9%

Every row sits inside the round-to-round spread (the C=2 code rounds spread 6.6% on main alone) and the ranges overlap. Qwen3.8's gate never closed in these runs (no closed pass on either side), so the chooser change does not act on it. Where a gate is closed when a request starts, the request now pays 4 shadow proposals in its first 4 passes instead of 1 in every 16; on the RTX 5090 that is what turned code from 268 to 302 tok/s on its first request after two prose ones.

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 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: MUST_FIX: the new buffer accessors expose unused public APIs contrary to R13.

Must fix

1. Keep both normed-row accessors inside the GPU crate

crates/gpu/src/head.rs:759 and crates/gpu/src/model.rs:1859 export methods whose callers are all inside bloomery_gpu. Head::normed serves its host getter and body_parts_normed; the latter serves only mtp35::walk_rows. R13 permits pub only when another crate calls the item.
Restricting visibility now changes no caller and avoids retaining an unused external API.

    pub(crate) fn normed(&self) -> &DeviceBuffer<f32> {
        match &self.fin {
            Final::Rms { normed } => normed,
            Final::Mixed => &self.x,
        }
    }
    pub(crate) fn body_parts_normed(
        &mut self,
        what: &'static str,
    ) -> Result<(&Gpu, &Weights, &mut B, &DeviceBuffer<f32>), GpuError> {
        self.refuse_one_pass(what)?;
        let head = self.heads.first().ok_or(no_head(what))?;
        Ok((&self.gpu, &self.weights, &mut *self.body, head.normed()))
    }

Non-blocking

⚠ Compare every restored logit: crates/gpu-gates/src/bin/gate_qwen35moe_mtp.rs:518 compares only the winning token and its logit.
A change confined to a non-winning logit passes this restoration check. Retain the eager logits and use bits_equal after restoration; the existing eager run already supplies the reference.

⚠ Cover the Qwen3.6 probability contract: crates/runtime/src/width.rs:3020 changes both acceptance and reported probabilities in a three-id mock.
The real Qwen3.6 draft has width one and reports probability one throughout; its gains survive the prompt reset. Extend this regression with that case, changing only acceptance, to check reopening through the actual calibration path without a card run.

Optimization headroom

  • D. More at once: crates/gpu/src/arch/qwen3moe/mtp35.rs:702 still enqueues each store row separately. Batch the two store rows through the existing multi-row dispatch: one fewer eh_proj launch and one fewer append launch per two stored tokens [derived].

Checked

Duplicates: 15 added function/constant definitions checked; no new duplicate owner. Dryer reported 0 pairs; GPU and gate code checked manually.
Complexity: new store_clause is 22 (cache checks / step-copy checks are its natural split); Mtp35::enqueue 18→19 adds the store branch; Choosing::propose 32→33 adds opening-shadow selection.
Silent failure: 2 fallback candidates followed (hidden-source arm and opening saturation); neither masks an error.
Tests: dropping walk.rs:172's append breaks the op-log assertion. Removing width.rs:1070's reset breaks the reopen bound; ignoring mtp35.rs:443's store branch breaks preserved-logit equality (both FAIL-first runs reported in the PR). Mutations assessed from source.
Gates: no tolerance or pin moved; model paths and prompt source changed.
Escape catalog: no C1–C4 pattern matched.

Notes

Static review only. Builds and hardware gates were not rerun here.

Card check: gpu-evidence. This pull request changes crates/app/src/arch/qwen3moe/mtp35.rs, crates/gpu-gates/src/bin/gate_qwen35moe_mtp.rs, crates/gpu-gates/src/bin/gate_qwen35moe_verify.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)

Comment thread crates/gpu/src/head.rs Outdated

/// [`Head::normed_to_host`]'s rows on the card, for a launch on the
/// engine stream that reads them where they sit.
pub fn normed(&self) -> &DeviceBuffer<f32> {

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.

R13: both callers are inside bloomery_gpu, so keep this accessor crate-visible.

Suggested change
pub fn normed(&self) -> &DeviceBuffer<f32> {
pub(crate) fn normed(&self) -> &DeviceBuffer<f32> {

Comment thread crates/gpu/src/model.rs Outdated
/// `step` or prompt call on the card ([`GpuModel::head_normed`]'s rows,
/// not read back), for a body's launch on the engine stream that reads
/// them where they sit. Refused as `head_normed` is.
pub fn body_parts_normed(

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.

R13: the only caller is mtp35::walk_rows inside bloomery_gpu, so keep this accessor crate-visible.

Suggested change
pub fn body_parts_normed(
pub(crate) fn body_parts_normed(

@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 Nov 1, 2026
…and its step row is read on the card

walk::store runs an attention layer's input side and its append (ChainOps::attn_append, a default
refusal for backends without it). dispatch::attn_append is the gemv arm's append, which attn_core
and the store walk run. Mtp35 in WalkMode::Store stops there and runs no head, and a
MtpArena::Step walk copies the target head's normed row on the card (GpuModel::body_parts_normed,
Head::normed) instead of reading it back. gate_qwen35moe_mtp (w) holds the store's bits to the
eager walk's and the step row to the host copy's.
…he shared prose corpus and their files from levers

Both gates read only prompt ids from the ik dump ref_qwen35moe_d1k. They now take them from
prose_ids("qwen4exp"), the corpus the Qwen3.8 gates read, which carries the same vocabulary, so
the gates need no oracle set. The plain file is open_split's (BLOOMERY_REF_MODEL) and the MTP
gate's file with the next-token layer is BLOOMERY_MTP_MODEL's, still pinned by general.name and
size, instead of fixed paths, so the gates run where the model tool put the files. Their clauses
and bounds are unchanged.
…ation on its own shadows

A closed gate hears of a generation only through a shadow every Rule::shadow_every passes, so it
kept the earlier generations' windows for as long as those took to age out: a request whose draft
pays stayed on plain steps for most of its length after one that did not. Choosing::prompt_by, the
owner of a generation's start, now drops the earlier windows on a closed gate and runs the first
Rule::min_timings passes as shadows; the gate decides once those are in. The calls outside the
chooser's passes that only forgot the pass in flight (a row of a pass of several slots, a closed
lookup window) use Choosing::forget_pass.

@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.

Since the last review:

Verdict: CLEAN: the previous findings are resolved, and the interdiff introduces no merge-blocking defect.

Checked

Duplicates: 1 new function checked; it reuses PairRig and covers a distinct calibration case. Dryer reported 0 pairs; edited GPU and gate code checked manually.
Complexity: store_clause (22) combines cache-restoration and step-copy checks; Mtp35::enqueue (18→19) adds the store branch; Choosing::propose (32→33) adds opening-shadow selection. The interdiff adds no control-flow growth to these functions.
Silent failure: 1 empty-logit initializer followed to its consumers; the fixed 64-id prompt fills it, and a short corpus returns an error.
Tests: mutations assessed from source: omitting walk.rs:172's cache append breaks the store-walk op-log assertion; omitting width.rs:1072's opening assignment breaks the new proposal-count assertion. Restoration now compares every logit's bits.
Gates: no pins or bounds moved; restoration comparison strengthened.
Escape catalog: no C1–C4 pattern matched.

Notes

Static review only. Tests and hardware gates were not rerun here.

Card check: gpu-evidence. This pull request changes crates/app/src/arch/qwen3moe/mtp35.rs, crates/gpu-gates/src/bin/gate_qwen35moe_mtp.rs, crates/gpu-gates/src/bin/gate_qwen35moe_verify.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)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

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

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.

1 participant