Skip to content

perf(cbv2-mtp): single-forward Qwen draft rounds (1.13x vs MTP-off); env-gated draft-head shortlist - #108

Merged
Gajesh2007 merged 1 commit into
mainfrom
perf/qwen36-mtp-draft-trim
Aug 13, 2026
Merged

Gajesh2007 merged 1 commit into
mainfrom
perf/qwen36-mtp-draft-trim

Conversation

@Gajesh2007

Copy link
Copy Markdown
Member

Problem

Capture-verify MTP (#106) reached 1.08x vs MTP-off, but each round still ran the MTP draft head twice (staging double-forward) — re-reading the 286 MB quantized lm_head and blocking the engine thread with a mid-graph eval — ~0.72 GB of draft traffic per round against ~1.79 committed tokens.

Change

  1. Single draft forward per round: the draft pair is deferred in request state and appended by the next round's one [1,1+p] forward, only after target confirmation. No KV trim on any path; removes the second lm_head read and one blocking eval per round. Legacy double-forward stays as an env-pinned oracle (DARKBLOOM_QWEN_MTP_DOUBLE_FORWARD=1).
  2. Draft-head shortlist: implemented but default-OFF (DARKBLOOM_QWEN_MTP_SHORTLIST=<K>): scoring the draft against the target's top-K rows regresses at practical K because the top-K source is one position behind the draft (acceptance 0.79→0.58 at K=256 → net 0.91x); at K=16384 coverage recovers but argPartition+gather outweigh the ~1.3 ms full-head read. Kept for k≥2 chains where the math changes. Negative result documented, guarded by tests.

Measured (M4 Max, release, prod artifact, B=1 greedy 256 tok, paired sessions, drift bracket ~2%)

Config tok/s Acceptance
MTP off 103.1–105.0 —
Capture-verify, double forward (parent) 111.8 0.790
Single forward (this PR default) 116.5 0.778
temp 0.7 via target_prefix 110.3 0.70–0.77

1.11–1.13x vs MTP-off (+4.2% over parent).

Behavior

flowchart LR
  subgraph Before
    A1[round] --> B1["draft: 2x MTP-head forwards<br/>2x 286MB lm_head + mid-graph eval"] --> C1["1.08x vs off"]
  end
  subgraph After
    A2[round] --> B2["draft pair deferred in request state<br/>one [1,1+p] forward post-confirmation"] --> C2["1.11–1.13x vs off"]
  end
Loading

Code

flowchart LR
  subgraph Before
    D1[Qwen35MTP.draftStep] --> E1[staging forward + confirm forward]
  end
  subgraph After
    D2[Qwen35MTP.draftStep] --> E2[pending-pair carry in request state<br/>append on next round forward]
    D2 -.env opt-in.-> F2[shortlist head K rows<br/>default off — acceptance guard]
  end
Loading

Tests

6 new Qwen35MTPDraftTrimTests: single-vs-double-forward oracle parity across accept/reject chains, rollback/discard pending semantics, float+quantized shortlist parity via the production load path; +3 integration tests (carry plumbing, opt-in, coverage math). Release suites green.

…d shortlist

Draft-step trim on top of capture-verify (c020624):

1. SINGLE DRAFT FORWARD (shipped, default): Qwen35InlineMTPAssistant.draftStep
   no longer runs the MTP head twice per round (proposal + staging
   re-forward). The proposed draft pair (assistant hidden, draft token) is
   DEFERRED in request state and enters assistant KV as part of the NEXT
   round's one [1, 1+p] forward, only after the target confirmed it
   (finalizeRound confirmed==2). Rejection simply drops the pair — no KV
   trim on any path, and the blocking mid-graph eval() between the two
   forwards is gone. Per round this halves draft weight traffic
   (~0.72 GB -> ~0.36 GB; the second full 286 MB 4-bit lm_head read was
   computed and discarded). Content is bit-compatible with the legacy
   staging forward (same fused inputs; only batch geometry differs, per the
   documented NUMERICS POLICY). Legacy path pinned via
   DARKBLOOM_QWEN_MTP_DOUBLE_FORWARD=1 as the A/B oracle.

2. DRAFT-HEAD SHORTLIST (implemented, measured, DEFAULT OFF):
   CBv2MTPRequestStatefulDrafter.draftShortlistSize opts verify rounds into
   surfacing each position's target top-K ids + probability mass
   (EngineLoopV2.mtpDraftShortlist; mass rides the acceptance packet as ppm,
   coverage-gated >= 0.90 at finalize into the carry); the drafter scores K
   gathered quantized lm_head rows (quantizedMM over weight[ids]/
   scales[ids]/biases[ids]) instead of streaming the full 248,320-row head.
   Measured net-negative on M4 Max because the shortlist source is one
   position behind the draft: K=256 acceptance 0.79->0.58 (95.5 vs 116.5
   tok/s), K=2048 0.68 (110.3), K=16384 0.77 (115.2) — coverage recovers
   but verify-side top-K + gather outweigh the ~1.3 ms full head read.
   Env-gated via DARKBLOOM_QWEN_MTP_SHORTLIST=<K> for future k>=2 chains.

Paired same-session ladder (release, B=1 greedy, 256 tok, median of 5):
  MTP-off 103.0/105.0 | double-forward control 111.75 (accept 0.79) |
  single-forward 116.45 (accept 0.78) = 1.11-1.13x vs off, +4.2% vs
  control | temp-0.7 target-prefix 110.25 (multi-token deltas, accept
  0.65-0.86).

Tests: new Qwen35MTPDraftTrimTests (6) — single vs double-forward oracle
parity across accept/reject chains, rejection/discard pending-pair
semantics, float + quantized gathered-row shortlist parity (real assistant
via production load path). CBv2QwenMTPIntegrationTests +3 — shortlist
carry plumbing (coverage-gated ids contain the committed carry token),
opt-in gating, ppm coverage math. Suites: 111 tests / 15 suites green.
@Gajesh2007
Gajesh2007 merged commit 7e3f185 into main Aug 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant