vllm.models.deepseek_v41.nvidia.specialized_decode.attention.candidate_topk
¶
Candidate-block selection with cooperative_topk for decode rows.
select_candidate_blocks scores every block of the padded logits row and
runs torch.topk over all of them. At long context most of a decode row is
padding, so here the score kernel also writes each row's valid block count and
cooperative_topk scans only that prefix.
The selected set of non-negative ids matches select_candidate_blocks except
for which blocks whose fp32 scores tie exactly at the selection boundary are
kept. cooperative_topk keeps at most k (rows of up to 16384 blocks) or
1024 per cluster CTA (longer rows) candidates of its fp16 boundary bin, so a
more crowded boundary bin is selected approximately. The pinned newest block is
kept unless at least k blocks of the row score NaN or overflow fp16. Rows
are not sorted and -1 padding may sit anywhere; every consumer of the candidate
buffer treats a row as a set.
Functions:
-
select_candidate_blocks_cooperative–select_candidate_blocksfor decode rows, oncooperative_topk. -
supports_cooperative_candidates–Whether
select_candidate_blocks_cooperativetakesnum_rowsrows of
select_candidate_blocks_cooperative(logits, row_ends, block_size, out)
¶
select_candidate_blocks for decode rows, on cooperative_topk.
Parameters:
-
(logits¶Tensor) –[rows, width] fp32 logits; row
iis valid belowrow_ends[i]. -
(row_ends¶Tensor) –Contiguous [rows] int32 row lengths in logits columns.
-
(block_size¶int) –Columns per candidate block.
-
(out¶Tensor) –Contiguous [rows, k] int32 candidate block ids, -1 padded; see
supports_cooperative_candidatesfor the supported shapes.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/attention/candidate_topk.py
supports_cooperative_candidates(num_rows, num_blocks, k)
¶
Whether select_candidate_blocks_cooperative takes num_rows rows of
num_blocks blocks and k candidates.