Repository navigation
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
Conversation
There was a problem hiding this comment.
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_projlaunch 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)
|
|
||
| /// [`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> { |
There was a problem hiding this comment.
R13: both callers are inside bloomery_gpu, so keep this accessor crate-visible.
| pub fn normed(&self) -> &DeviceBuffer<f32> { | |
| pub(crate) fn normed(&self) -> &DeviceBuffer<f32> { |
| /// `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( |
There was a problem hiding this comment.
R13: the only caller is mtp35::walk_rows inside bloomery_gpu, so keep this accessor crate-visible.
| pub fn body_parts_normed( | |
| pub(crate) fn body_parts_normed( |
…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.
…st token and end-to-end
8c28ab3 to
f73ac2e
Compare
There was a problem hiding this comment.
Since the last review:
- Fixed: both normed-row accessors are crate-private: crates/gpu/src/head.rs:759 and crates/gpu/src/model.rs:1859.
- Fixed: restoration compares every logit: crates/gpu-gates/src/bin/gate_qwen35moe_mtp.rs:517.
- Fixed: the new regression covers width-one reopening with probability one and retained gains: crates/runtime/src/width.rs:3043.
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)
|
The review is done and the contribution check passed, so I'm merging this. |
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_Mwith its own MTP draft, 4,096-id prompts, 128 greedy tokens, one request at a time, main6791d577bagainst this head3ebdff767: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:
walk::storeto 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 withoutattn_appendrefuses by name.dispatch::attn_appendthe one owner of the gemv arm's append (NeoX-128, gated-256, head-128 norm).attn_corecalls it first, and the store walk calls it alone.Mtp35'sWalkMode::Storethroughwalk::storewith 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.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 useChoosing::forget_pass. This chooser is shared by every MTP draft.gate_qwen35moe_mtpandgate_qwen35moe_verifyread 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 fromBLOOMERY_REF_MODELand, for the MTP file,BLOOMERY_MTP_MODEL(still pinned bygeneral.nameand size) instead of fixed paths. The clauses and bounds are unchanged.docs/numbers.mdand 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
dispatch::attn_append) forattn_coreand the store walk. The gates read prompts throughprose_idsand files throughopen_split.mtp35.rsonly picks the walk byWalkMode.attn_coreused is inlined; every new function has a caller.attn_append, a missingBLOOMERY_MTP_MODELand a load without the head's rows are refused by name.cargo fmtandcargo clippyare 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_mtpclause (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_MODELthe plainQ4_K_Mfile andBLOOMERY_MTP_MODELunsloth'sUD-Q4_K_M. The output below is from head467b5a81c; the MTP and verify gates passed again unchanged at2effb0681:just canon-check 6791d577bat2effb0681: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:
NVIDIA GeForce RTX 5090, 595.99.02), power limit 400 W (default 600 W,400.00 W, 600.00 W, 3090 MHzread before the run): the timings above.NVIDIA GB10, 595.84: the Qwen3.6 gates, the GLM fixture gate and the Qwen3.8 check.FAIL-first
(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-runtimepasses 301 tests.Speed
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-serveand started fresh each round asBLOOMERY_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
6791d577bagainst3ebdff767, median of three rounds (8 windows each):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 초안 리뷰는 제가 직접 했습니다.