Repository navigation
attention: shared-scan BF16 paged decode (ATLAS_ATTN_SHARED_SCAN) - #20
Merged
Merged
Conversation
`paged_decode_attn` runs one CTA per (query head, row) and each walks its KV head's whole K and V in scalar FP32. On Qwen3.8-27B (24 query heads over 4 KV heads) an 8-row speculative verify fetches every cached key and value 48 times a layer; at 210K tokens that scan is about 270 ms of a 365 ms decode step. `attn_shared_scan` reads each KV head once for the rows that share its blocks and scores every query on tensor cores; `attn_shared_scan_reduce` folds the per-superblock partials. Rows that share blocks are found on the device from the block tables, so no caller changes. Positions are cut by the row's own length and every sum is per query, so a row's bytes do not depend on the rows launched beside it, which is what ATLAS_EXACT_VERIFY needs. Value weights enter the V product as two BF16 terms (16 mantissa bits). Off by default. With ATLAS_ATTN_SHARED_SCAN=1 the BF16 decode arm takes the shared scan for serial decode and every verify width (qwen3.6-27b kernel tree: head dim 256, block size 16..=256). `examples/attn_shared_scan_check.rs` gates it on the GPU: each row of a batched launch byte-identical to that position run alone with every later slot NaN, across step, superblock and size-class boundaries; 0.18% of output elements differ from the scalar kernel, each by one BF16 step. Measured on one DGX Spark, Qwen3.8-27B with DFlash2 and exact verify: - one layer at 210K tokens, 8 rows: 16.9 ms -> 5.1 ms (168 GB/s of K+V) - real agentic turns at 210K, greedy: 18.5 / 15.4 / 9.5 tok/s -> 38.2 / 32.9 / 19.8 tok/s; serial decode 3.2 -> 6.8 tok/s - short prompts: step 87.2 ms either way (code), 86.4 -> 86.8 ms (thinking) - speculative and 8-way concurrent output identical to serial on 16/16 short cells, and serial equals speculative over 250 tokens at 211K Not covered end to end: tree verify with the switch on, sampled decoding. Co-Authored-By: Claude <[email protected]>
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A second BF16 paged decode attention path for the qwen3.6-27b kernel tree (so Qwen3.6-27B and Qwen3.8-27B), behind
ATLAS_ATTN_SHARED_SCAN=1. Off by default; with it off nothing changes.Why
paged_decode_attnruns one CTA per (query head, row), and each one walks its KV head's whole K and V in scalar FP32. On Qwen3.8-27B (24 query heads over 4 KV heads) an 8-row speculative verify fetches every cached key and value 48 times a layer. At 210K tokens that scan is about 270 ms of a 365 ms decode step, at roughly 50 GB/s on a machine that streams weights at about 200 GB/s.How
attn_shared_scan(kernels/gb10/qwen3.6-27b/nvfp4/attn_shared_scan.cu): a CTA owns one KV head over one superblock of positions, reads those keys and values once, and scores every query that attends them (the KV head's query heads, for every row that shares the blocks) withm16n8k16.attn_shared_scan_reducefolds a row's superblock partials in order.ATLAS_EXACT_VERIFY: superblocks and 16-position steps are cut by the row's own length at absolute alignment, every sum is per query, masked positions are masked by select, and slots past the group's longest row are staged as zeros. The kernel header has the full argument.ops/shared_scan.rsholds the switch, the shape test and the launch pair; the hook is one arm inrun_paged_decode.rs.Checks
examples/attn_shared_scan_check.rs(GPU): each row of a batched launch byte-identical to that position run alone with every later slot NaN, for 16 rows, 8 rows, a 3-row window, rows interleaved with another sequence and reversed order, at chain starts around step, superblock and size-class boundaries; a changed value at an attended position changes exactly the rows that attend it. Against the scalar kernel 0.18% of output elements differ, each by one BF16 step.Measured on one DGX Spark, Qwen3.8-27B NVFP4 with DFlash2 and exact verify:
With the switch on: speculative and 8-way concurrent output identical to serial on 16/16 short cells each, and serial equal to speculative over 250 tokens at 211K from the same starting state.
The end-to-end numbers were taken on this change over 4594757; the branch is rebased onto 7fbbd2b (prefill checkpoint cadence, no decode change), rebuilt, and the GPU check rerun there.
Local gates:
cargo clippy --workspace --testsand the example withcuda,gpu-examplesclean, the two new unit tests pass, license headers and typos clean.cargo fmt --checkreports ten files that are already unformatted onq27/conc; none are in this change.Not covered
ATLAS_DFLASH_TREE) with the switch on, end to end.🤖 Generated with Claude Code