Skip to content

qwen3.5 cuda dflash2: opt-in batched drafter absorb across a round's streams - #4648

Merged
ashhart merged 3 commits into
mainfrom
lead/q35-absorb-batch
Nov 22, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/q35-absorb-batch

Conversation

@ashhart

@ashhart ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What this changes

On CUDA, a shared Qwen3.5/3.8 DFlash2 round absorbs each stream's target taps into the drafter one stream at a time: for every stream it re-reads the drafter's fc weight, the hidden norm and every layer's K/V projection weights. TF_Q35_DFLASH_ABSORB_BATCH=1 (default off) absorbs the round's live streams in one pass, so those weights are read once a round.

The batched path runs only when there are two or more items, each a distinct live stream on device bf16. Prompt absorbs of more than 16 rows stay per stream, because they switch to the prompt GEMM whose bits differ from the verify path.

Exactness

Absorb fills the drafter's own cache. Each row keeps its arithmetic: the norms, rope, gathers and ring writes work row by row, and the affine-4 projections reduce along K inside a row. The target verifies every proposed row as before, so replies stay token-equal to main. With the switch off nothing changes.

Measured

GB10, Qwen3.8-27B MLX 4-bit with its DFlash2 drafter; base = this branch with the switch off, new = on via a local flip-default commit; order warm base new new base; aggregate tok/s, two boxes:

prompt, temperature 2 streams 4 streams
chat, 0 +0.6%, +0.5% +1.1%, +1.3%
chat, 1 +0.4%, +0.5% +2.3%, +1.8%
code, 0 +0.4%, +0.6% +4.7%, +1.5%
code, 1 +0.6%, +0.3% +1.2%, +0.7%

Every cell gains on both boxes, more at 4 streams, where more streams share each weight read.

Tests

New host tests cover which rounds take the batched path and the window bookkeeping moved into cuda_draft_absorb.zig; zig fmt, ast-check and the lean check pass. compile-cuda-tests builds; the full test-cuda-host run is left to this PR's CI (our build box was too loaded for a clean run).

TF_Q35_DFLASH_ABSORB_BATCH=1 (default off) absorbs a shared round's live
kept rows, two or more streams, in one pass: each stream's gather into its
own rows, one fc, norm and k/v projection over all of them (one weight read),
then each stream's rope at its own positions and its own ring write. Prompt
absorbs, a repeated stream or host features keep the per-stream call. No
kernel on the path reduces across rows, and verify keeps decode's bits a row;
the contract command absorb-batch compares fc, k and v rows batched and alone
byte for byte at 1, 4, 8 and 16 streams, with NaN/Inf and a planted control.
@ashhart
ashhart force-pushed the lead/q35-absorb-batch branch from 94deebc to 0e91337 Compare November 22, 2026 18:08
@ashhart
ashhart merged commit 073d020 into main Nov 22, 2026
10 of 11 checks passed
@ashhart
ashhart deleted the lead/q35-absorb-batch branch November 22, 2026 18:08
ashhart added a commit that referenced this pull request Nov 22, 2026
ashhart added a commit that referenced this pull request Nov 22, 2026
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