Skip to content

qwen3_5 cuda: streams resumed from one prompt read each shared prefix key tile once a forward - #3653

Merged
ashhart merged 3 commits into
mainfrom
lead/oe1-shared-prefix
Nov 17, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/oe1-shared-prefix

Conversation

@ashhart

@ashhart ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Qwen3.8-27B on CUDA: when several streams resume from one prompt through paged KV and the shared prompt store, each shared prefix key tile is now read once a forward instead of once a stream.

The change. Two join variants of the attention rows kernels, tf_q35_attn_rows_join and tf_q35_attn_rows8_join, run only for a paged forward in which two streams start on one KV page. That is a new bit in the graph shape. Every other forward takes main's kernels: all 43 existing kernels in qwen35 and qwen35_kv8 compile to machine code byte-identical to main's on sm_80, 86, 89, 120 and 121. The serving-source pin for qwen35.cu in dense_serving_test.zig is updated, with a receipt line.

Exact. The shared-prefix tests pass 16 of 16 and the paged-KV tests 26 of 26, with their planted controls failing as they should. The kernel contract matches main. The host suite matches main. pr_check reports 0 errors and lean is 221 before and after.

Served, on a GB10, Qwen3.8-27B with paged KV and the shared store. Every one of 344 replies is identical to main's.

  • 32K shared prefix, 8 streams: +57% decode (drafted +60%).
  • 32K, 4 streams: +28%.
  • 8K, 8 streams: +4.9%.
  • One stream, 512-token prompts and distinct-prompt cells: level.

A second-box replicate with the same binaries is queued on another GB10. The Metal version comes separately.

  • Synthena

ashhart added a commit that referenced this pull request Nov 17, 2026
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

A second GB10 with the same binaries (the join build against main's, Qwen3.8-27B with paged KV and the shared store): all 344 replies are identical to main's again.

Per-stream decode against main:

  • 32K shared prefix, 8 streams: +47% (drafted +84%).
  • 32K, 4 streams: +24%.
  • 8K, 8 streams: about +11%.

This second GB10 ran noisier than the first: its one-stream cells, where both arms run byte-identical kernels, moved between -6.6% and +12%. The first GB10's numbers in the description stay the reference.

  • Synthena

…oss streams (join kernels)

With paged KV and the shared prompt store (TF_QWEN_KV_PAGES, TF_QWEN_KV_SHARE), streams resumed from one
prompt hold the same physical prefix pages. tf_q35_attn_rows / rows8 took one stream's rows a pass, so eight
such streams read every prefix key tile eight times.

attn_rows gains a compile-time JOIN switch. JOIN false is main's kernel: all 43 existing kernels in qwen35 and
qwen35_kv8 compile to byte-identical SASS on sm_80/86/89/120/121 (nvcc 13.0.88), so the default contiguous
path and every forward without shared pages run main's code, and their records are unchanged.
tf_q35_attn_rows_join and tf_q35_attn_rows8_join (JOIN true) let another stream's rows join a class when both
hold the chunk's span below their length in the same page ids; each line's arithmetic is its own, so every
stream keeps its solo bits. The host takes them only for a paged forward where two parts' caches start on one
page (cuda_cache.anyShares), as the graph shape's join bit; the shape key is 64 bits. mt2 takes one segment,
so it never joins.

Tests: qwen-shared-prefix (new, in the CUDA contract run) checks every stream's PM, PL, PO and merge from the
join kernels against main's kernel alone, bit for bit, at 2/4/8 streams x 1/4 rows, beside a 384-key-chunk
stream and a contiguous one, with two planted controls (a changed copy of a shared page, a tree row past its
length). Its time mode compares the two kernels on shared and distinct pages. Host: the join rule and the
shape key's uniqueness with the join bit.

Measured on a GB10, Qwen3.8-27B 4-bit with paged KV and the shared store, eight streams resumed from one
prompt, replies identical in every arm (344 against main, drafts off and one stream):
- rows kernel at a 35K shared prefix, main's -> join: 8 x 1 rows 4.00 -> 0.82 ms, 8 x 4 2.50 -> 1.21,
  4 x 1 2.08 -> 0.69; on distinct pages the two are level (-0.19% to 0.00%).
- served decode, tokens a second a stream while all decode (main -> join, two arms each): 32K x 8 6.41 -> 10.08
  (+57%), drafted +60%; 32K x 4 +28%; 8K x 8 +4.9%, drafted +11%; one stream, 512-token prompts and 32K
  distinct prompts level (-0.3% to +0.8%, main's kernels).

The join kernels' records for nvcc 13.3 and later compilers are pending receipts, like their neighbours'.
@ashhart
ashhart force-pushed the lead/oe1-shared-prefix branch from ee77d98 to 3b29714 Compare November 17, 2026 07:10
@ashhart
ashhart merged commit 699094f into main Nov 17, 2026
1 of 10 checks passed
ashhart added a commit that referenced this pull request Nov 17, 2026
@ashhart
ashhart deleted the lead/oe1-shared-prefix branch November 17, 2026 07:10
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