vllm.models.kimi_k3.nvidia.specialized_decode.cutedsl.dsa.attn_sparse
¶
Specialized sparse MLA decode of a DCP K3.1 DSA layer on a per-tensor FP8 cache
(SparseDcpDecode): every rank's gathered query heads (the q mailbox) over this
rank's compacted flat KV rows (the exact top-k merge's rows / valid).
Why: at the latency checkpoint (DCP8, 5 verify rows) each row attends ~256 local keys. FlashInfer's prims_ts decode (split-KV over 80 CTAs plus its reduction, launched only after the merge: it reads its inputs before its PDL wait) and DcpValue's push of its rows hold the chain ~18 us at 3-25% DRAM for ~1 MB of KV. Here a cluster of SPLIT CTAs per (16 heads, row) splits the row's keys, launches early under PDL (reads nothing before its wait), merges its partials over DSMEM and pushes the merged rows straight into the owners' DcpValue mailbox.
Per CTA (row b, heads 16 m .. 16 m + 15, its 1 / SPLIT of the row's keys), per
chunk of up to CHUNK keys:
gather the Q rows (first chunk) and the chunk's KV rows (cp.async.bulk, one
per 576 B row, on one mbarrier); V rows past the count up to a 32-key
step are zeroed
QK warp w < CHUNK / 8: keys 8 w .. 8 w + 7 x the 16 heads, FP8 mma.sync
m16n8k32 (FP32 accumulation) over the 576 bytes
softmax the chunk's row max (shared memory), the running max, P =
exp2(s * scale_log2 - max + log2(448)) quantized to E4M3 (satfinite,
RN), FP32 sums of the unquantized P, the accumulators rescaled when the
running max rises
PV warp w: latent columns 32 w .. 32 w + 31, E4M3 P x E4M3 V (V transposed
in registers with byte permutes), FP32 accumulation
then the cluster merges (FP32): CTA s of the cluster takes columns s / SPLIT of the
16 heads, weights each CTA's partial by exp2(max_c - max), and writes
BF16(sum * k_scale / total) and LSE = max + log2(total / 448) (push: into the
owners' mailbox slot, base 2, as DcpValue's push; else the latent [B, Q, 512] and
natural-log LSE [B, Q] DcpValue reads).
Precision: FlashInfer's sparse MLA decode (E4M3 query and cache, FP32 logits, E4M3 P at 448 of the running row max of its split, FP32 sums of the unquantized P, FP32 accumulation, one BF16 rounding of the output). FlashInfer's split-KV partials are BF16 (merged by its reduction); here they merge in FP32, so only the order of the sums, where the P scale anchors and the partials' rounding differ.
Rows of count 0 (padded rows; a rank owning none of a row's keys) write zeros and LSE -inf (pushed: only the LSE EMPTY_LSE).
Classes:
-
SparseDcpDecode–batchrows,headsgathered query heads (a multiple of 16; the q
Functions:
-
compile_sparse–SparseDcpDecode of
batchrows (the q mailbox ofcaprows;push: -
run_sparse–query[cap, padded, 576] (FP8 bytes),kv[N, 576] (the flat cache -
sparse_for–Whether a DCP batch of
rowsruns SparseDcpDecode (gatheredquery -
store_fp8_pair_shared–E4M3 (satfinite, RN) of
low,highas two bytes of shared memory. -
transpose4–Bytes of four words -> four words of bytes: out[j] = (w0.j, w1.j, w2.j,
SparseDcpDecode
¶
batch rows, heads gathered query heads (a multiple of 16; the q
mailbox and outputs hold padded rows per token), the merge's row width
width (its K). push (owner heads H, DCP, mailbox rows): push the
merged rows and base-2 LSEs into their owners' DcpValue "bf16" mailbox and
re-arm the q mailbox rows read (DcpValue pushed then only merges).
Methods:
-
merge–Columns split * COLS .. + COLS of the 16 heads over the cluster's
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_sparse.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
merge(args, inbox, stats, tile, split, b, tid)
¶
Columns split * COLS .. + COLS of the 16 heads over the cluster's
partials (FP32, in inbox / stats): thread t takes head t // 32, 4
columns.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_sparse.py
compile_sparse(batch, heads, padded, width, cap, device, push=None)
cached
¶
SparseDcpDecode of batch rows (the q mailbox of cap rows; push:
(owner heads, DCP) to push into the DcpValue mailbox).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_sparse.py
run_sparse(kernel, query, kv, rows, valid, latent, lse, scale_log2, out_scale, push=None)
¶
query [cap, padded, 576] (FP8 bytes), kv [N, 576] (the flat cache
rows), rows [>= B, K] / valid: this rank's flat rows and counts ->
latent [B, padded, 512] BF16 and lse [B, padded] FP32 (first heads
heads), or with push (DcpMailbox, parity, rank) into the owners' mailbox.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_sparse.py
sparse_for(rows, gathered, padded)
¶
Whether a DCP batch of rows runs SparseDcpDecode (gathered query
heads of a padded-row q mailbox).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_sparse.py
store_fp8_pair_shared(pointer, low, high)
¶
E4M3 (satfinite, RN) of low, high as two bytes of shared memory.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_sparse.py
transpose4(w)
¶
Bytes of four words -> four words of bytes: out[j] = (w0.j, w1.j, w2.j, w3.j), byte 0 the lowest.