Files
tokenspeed/python
Nicolas Perrin bd8f0d4f4a perf(dsa): score and select KVP decode index candidates in two CuTe DSL launches (#3660)
## Summary

A KVP decode's local index candidates ran the DeepGEMM leaf's query
quantization, schedule metadata, paged logits, non-finite scrub, ragged
top-k, and gather, then copied the scores into the owned top-k's send
buffer: about 30 microseconds per DSA layer at one request.

- The DeepGEMM leaf writes its candidate scores straight into the send
buffer (`scores_out`) and copies the query only when it is strided.
- `dsa_decode_index_candidates` (`cute_dsl` on SM100 and SM103) runs the
fused decode top-k's scorer and select in a KVP mode: every request is
scored over its compact owned pages to each row's own local length, and
the select writes each row's exact local top-k as logical positions and
FP32 logits, recovered from its order keys. The logits are bit for bit
the DeepGEMM leaf's.
- A row that sees at most `topk` keys over every rank keeps all of them
in the merged selection, so the op takes each row's keys over every rank
(`row_lengths`): the scorer schedules no tiles for a request whose last
row fits, and the select writes such a row's local keys in key order,
scored 0, without reading logits.
- The owned decode top-k takes the op for BF16 decode queries without
mandatory windows, up to 4096 requests; other sizes keep
`dsa_index_candidates`.

## Test Plan

- [x]
`tokenspeed-kernel/test/nvidia/ops/attention/test_dsa_decode_index_candidates.py`:
9 passed on GB300 (positions and logits against the DeepGEMM leaf, rows
that fit the top-k, short and empty rows, verify windows, strided send
buffers, and a batch past the scorer's 4096 requests refused); a
position-offset mutant fails it.
- [x] Every touched test file and every test file importing a touched
module, 44 in all, on GB300, among them `test_dsa_fused_decode_topk.py`
(32), `test_cute_dsl_dsa_owned_selection.py` (12),
`test_flashmla_dsa_dcp.py` (73), `test_dsa_dcp_owned_decode_topk.py` (2
and 4 ranks), `test_kimi_k31_dcp.py` (14), `test_dsa_dcp_k31_indexer.py`
(10), and `test_dsa_dcp_index_reuse.py` (24).
- [x] One KVP8 rank's decode candidates, GB300, CUDA graph, top-k 2048,
microseconds:

  | rows | context tokens | DeepGEMM leaf | this PR |
  |-----:|-----:|-----:|-----:|
  | 8 | 1.5K (fits the top-k) | 32.5 | 5.2 |
  | 128 | 1.5K to 2K | 17.6 | 10.6 |
  | 8 | 16K | 15.0 | 8.7 |
  | 128 | 16K | 21.0 | 12.0 |
  | 8 | 64K | 21.2 | 18.2 |
  | 128 | 64K | 32.5 | 27.8 |
- [x] Kimi-K3.1, TP8 with KVP8 on 2x GB300, DSpark with synthetic
acceptance 8, 1024 output tokens, steady ms per token, two alternating
boots per arm:

  | batch | main | this PR | change |
  |-----:|-----:|-----:|-----:|
  | 1 | 1.294 | 1.223 | -5.5% (boots -9.8% and -1.1%) |
  | 2 | 1.640 | 1.602 | -2.4% |
  | 4 | 2.212 | 2.116 | -4.4% |
  | 8 | 2.942 | 2.859 | -2.9% |
  | 16 | 4.404 | 4.326 | -1.8% |
  | 32 | 5.716 | 5.618 | -1.7% |
  | 64 | 7.925 | 7.786 | -1.8% |
- [x] GSM8K, 1000 questions with real acceptance: 959 with this PR, 961
on main (2 and 4 questions right only in one arm, sign test p = 0.69).

---------

Signed-off-by: Nicolas Perrin <nperrin.ai@gmail.com>
2026-11-20 00:41:41 -08:00
..
2026-05-06 13:27:02 +00:00