vllm.models.kimi_k3.nvidia.ops.dcp_topk_merge
¶
One-round DCP decode top-k merge for the DSA indexer.
The kernels live in kernels.py (imports CuTe DSL); this module only holds
the configuration helpers so model construction stays import-light.
Packed candidate rows (the "B'" layout), int32 [T, N + N/32] per rank,
N a multiple of 32, local index l = the token's position in this rank's
shard (global id l * W + rank, interleave 1), l < 2**17:
- word
j < N:(ord16(s) << 16) | (0xFFFF - (l & 0xFFFF))as uint32, wheresis the bf16 score bits andord16(s) = s | 0x8000fors >= 0(sign bit clear),~s & 0xFFFFotherwise (order-preserving: a larger score gives a largerord16).0marks an empty slot; slots may be in any order and empty ones anywhere. - word
N + j // 32, bitj % 32: bit 16 oflfor candidatej.
Modules:
-
kernels–One-round DCP decode top-k merge for the DSA indexer (CuTe DSL).
Functions:
-
dcp_merge_local_topk–Per-rank candidate count N: 1.5x the fair share
topk / world_size, -
dcp_topk_merge_fits–Whether a decode step of
num_rowsrows can take the one-round merge -
dcp_topk_merge_local_topk–N for the one-round DCP decode top-k merge, or 0 when it is unavailable
-
dcp_topk_merge_max_rows–Rows one merge call may hold (0 when the merge was not initialized).
-
init_dcp_topk_merge–Set up the exact one-round DCP decode top-k merge at model construction
-
packed_row_words–int32 words per packed row: N candidate words + N/32 bit-plane words.
-
rescue_slots–Upper bound on the saturated ranks of one row in the exact merge.
dcp_merge_local_topk(topk, world_size)
¶
Per-rank candidate count N: 1.5x the fair share topk / world_size,
warp-aligned. 0 when it would not be smaller than topk.
Source code in vllm/models/kimi_k3/nvidia/ops/dcp_topk_merge/__init__.py
dcp_topk_merge_fits(num_rows, topk, local_topk)
¶
Whether a decode step of num_rows rows can take the one-round merge
(identical on every DCP rank): it was initialized and its rescue
workspace holds the rows. Otherwise the generic merge runs.
Source code in vllm/models/kimi_k3/nvidia/ops/dcp_topk_merge/__init__.py
dcp_topk_merge_local_topk(vllm_config, topk)
¶
N for the one-round DCP decode top-k merge, or 0 when it is unavailable
(no DCP, more than MAX_WORLD_SIZE DCP ranks, PCP, a top-k backend
other than auto / deep_select, not SM100, no CuTe DSL / DeepSelect, or
local token indices that do not fit LOCAL_INDEX_BITS).
Source code in vllm/models/kimi_k3/nvidia/ops/dcp_topk_merge/__init__.py
dcp_topk_merge_max_rows(topk, local_topk)
¶
Rows one merge call may hold (0 when the merge was not initialized).
init_dcp_topk_merge(vllm_config, topk)
¶
Set up the exact one-round DCP decode top-k merge at model construction and return its N, or 0 to keep the generic (fp32 all-gather) merge.
Collective: every DCP rank must call it, in the same order, outside CUDA
graph capture (only the first call per topk runs collectives). The
merge is exact only with its rescue workspace (symmetric memory over the
DCP group, sized by the decode rows of a step); without one the merge is
disabled here (fail closed) rather than run lossy. The ranks agree on
that before allocating; a failure of the (collective) allocation itself
is fatal. Also registers the merge kernels for JIT warmup.
Source code in vllm/models/kimi_k3/nvidia/ops/dcp_topk_merge/__init__.py
packed_row_words(local_topk)
¶
int32 words per packed row: N candidate words + N/32 bit-plane words.
rescue_slots(topk, local_topk)
¶
Upper bound on the saturated ranks of one row in the exact merge.
A saturated rank sent N words, all strictly above the K-th selected key,
so they are among the K - 1 keys above it: at most (K - 1) // N.