vllm.models.kimi_k3.nvidia.specialized_decode.cutedsl.dsa.prepared
¶
Prepared DSA core (Kimi K3.1 sparse MLA layers): the orchestration of one layer's stages over the packed MLA cache and the indexer cache (64-entry pages):
query stage MlaQuery (dsa) -> wq_b -> DsaIndex (query_stage.py) indexer stage TP on FlashInfer: the fused decode indexer (indexer.py: scores, exact top-k and the physical rows in two PDL-chained kernels); DCP with the #63 merge: its scorer and local top-N select feed the merge (indexer_stage.py); else the stock decode scoring and top-k (indexer_stage.py) sparse core FlashInfer sparse MLA on a per-tensor FP8 cache (attn_fi.py: trtllm-gen or prims_ts per batch, called directly into the value stage's rows), else FlashMLA sparse on fp8_ds_mla (attn_ds.py) MlaValue W_UV and the sigmoid gate of the BF16 latent
Query overlap (overlap.py, per batch of rows): the indexer path needs only q_c, so QueryNorm writes it (or IndexFront fuses it with wq_b and DsaIndex, front.py) on the main stream while MlaQuery (and, under DCP, the q mailbox poll) runs on a side stream that the main stream joins before the sparse core; or (TP, "late") MlaQuery runs on the main stream right after the fused indexer's select, beside it.
Under DCP (= TP, dcp_stage.py) each rank's cache holds 1 / DCP of every context: the query and DsaIndex insert only the owned slots, the query publishes its heads into every rank's q mailbox, the indexer merges the ranks' local top-k into global token ids, which are filtered to this rank's slots (on FlashInfer with the #63 merge: into this rank's slots directly) for the sparse decode of every rank's gathered heads, and DcpValue merges this rank's heads by LSE.
The packed projection row is [q_a 1536 | kv_a 576 | gate H*128 | wk 128 | wv 32].
Classes:
-
PreparedDsa–One K3.1 DSA layer.
attention: the KimiK3DSAAttention;pitches: the
Functions:
-
compile_core–CuTe kernels (query, index, value) of one batch of rows (
qper request). -
dsa_on_flashinfer–Whether a KimiK3DSAAttention runs FLASHINFER_MLA_SPARSE (per-tensor FP8 query;
PreparedDsa
¶
One K3.1 DSA layer. attention: the KimiK3DSAAttention; pitches: the
packed projection pitch per batch; queries: the query lengths q (1 + the
draft length under DSpark verify) prepared for every batch divisible by q;
kernels: the FlashInfer sparse MLA kernels to pick from per batch (default:
attn_fi.fi_kernels); prims_ts_rows: the prims_ts plans' row capacities
(default: every batch on its own plan);
overlap: a query overlap mode or "rows:mode" table (overlap.QUERY_OVERLAP).
Methods:
-
compile_overlap–The overlap kernels of a batch: (front, wait, norm).
front: the fused -
dcp_core–Sparse decode of every rank's query heads (the gathered q mailbox) over the
-
fused_core–TP on FlashInfer: the fused decode indexer's physical rows, then the
-
held–The shapes on a FlashInfer kernel (HELD_KERNELS) whose overlap mode is
-
indexer_core–Top-k of the current rows into the shared buffer (stock decode scoring).
-
pushes–Whether the sparse decode of (batch, q) pushes its rows into DcpValue's
-
run–projected: the packed projection rows;out[B, H * 128] gets the -
run_dcp–rununder DCP: the query publishes into the q mailbox and DcpValue -
run_index–The indexer inputs: wq_b and DsaIndex (
kernel), or the fused index -
run_query–MlaQuery and the q_c rows per the overlap mode. Returns what makes the
-
sparse_core–Sparse decode of the query rows -> the latent ([B, 64, 512]-strided on
-
sparse_decode–The specialized sparse decode (attn_sparse) of every rank's gathered query
Attributes:
-
query–This layer's query rows (FlashInfer: FP8 [B, H, 576] bytes).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | |
query
property
¶
This layer's query rows (FlashInfer: FP8 [B, H, 576] bytes).
compile_overlap(batch, q, index_spec)
¶
The overlap kernels of a batch: (front, wait, norm). front: the fused
index front (IndexFront / IndexFrontMma from the packed rows under front /
late_front, IndexFrontMma from q_c under serial up to FUSED_INDEX
rows) or None; wait: QueryWait under DCP (else None); norm:
QueryNorm under fork / late (else None). Each kernel is compiled once per
key and shared by every DSA layer (query_stage memoizes them).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
dcp_core(cache, topk, metadata, batch, projected=None, join=None, q=1)
¶
Sparse decode of every rank's query heads (the gathered q mailbox) over the
local shard into the DcpValue rows, LSE and per-row valid counts: on a
per-tensor FP8 cache FlashInfer over this rank's flat rows, on fp8_ds_mla
FlashMLA as the stock decode. topk: the global ids, or None with
projected: on FlashInfer the indexer stage's DCP merge (#63) gives this
rank's rows directly, else the stock op's global ids are filtered to them.
join: what makes the sparse decode wait for the query (run_query).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
fused_core(cache, metadata, batch, q, join=None)
¶
TP on FlashInfer: the fused decode indexer's physical rows, then the
sparse decode -> the [B, H, 512] latent. join: what makes the sparse
decode wait for the query (run_query).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
held(modes)
¶
The shapes on a FlashInfer kernel (HELD_KERNELS) whose overlap mode is
one of modes: the kernel right before their sparse decode (TP: the
fused indexer's select, or the late query) must not launch it early.
prims_ts' split-KV decode launches with PDL but reads its query and rows
before its PDL wait, so it would read the previous layer's; trtllm-gen
reads its per-row counts early too (a CUDA graph with only the counts
poisoned before each layer hangs at 60 rows).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
indexer_core(projected, batch)
¶
Top-k of the current rows into the shared buffer (stock decode scoring).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
pushes(batch, q)
¶
Whether the sparse decode of (batch, q) pushes its rows into DcpValue's
"bf16" mailbox itself (DcpValue pushed).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
run(projected, out, *, cache, slots, index_slots, metadata, q=1)
¶
projected: the packed projection rows; out [B, H * 128] gets the
gated attention output; slots / index_slots: the MLA and indexer
cache slots. Rows beyond the requests run as empty requests.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
run_dcp(projected, out, cache, slots, index_slots, metadata, q)
¶
run under DCP: the query publishes into the q mailbox and DcpValue
merges every rank's partial rows of this rank's heads (global lengths).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
run_index(kernel, projected, index_slots, q)
¶
The indexer inputs: wq_b and DsaIndex (kernel), or the fused index
front (from the packed rows, or under serial from q_c).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
run_query(projected, cache, slots, q, publish=())
¶
MlaQuery and the q_c rows per the overlap mode. Returns what makes the sparse core wait for the query (None: it is already in stream order).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
sparse_core(cache, topk, metadata, batch, q)
¶
Sparse decode of the query rows -> the latent ([B, 64, 512]-strided on fp8_ds_mla, [B, H, 512] on FlashInfer).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
sparse_decode(kv, rows, valid, batch, q)
¶
The specialized sparse decode (attn_sparse) of every rank's gathered query
heads over this rank's flat kv rows rows / valid: into the
owners' DcpValue mailbox where it pushes (pushes), else into the
FlashInfer core's latent [B, Q, 512] and natural-log LSE [B, Q] buffers.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
compile_core(batch, heads, pitch, specs, device, q=1, dcp=0, q_heads=0, sms=148, fp8=False, lse_base_e=True, nvfp4=False, overlap='serial', partials='bf16', cap=64, release=True, pushed=False)
cached
¶
CuTe kernels (query, index, value) of one batch of rows (q per request).
specs: the layouts of the weights, the MLA cache and the indexer cache.
Under DCP (dcp: its size, q_heads: the gathered query's padded heads,
cap: the DcpBox rows) the query also publishes into the q mailbox and the
value is DcpValue. fp8: a per-tensor FP8 query [B, H, 576] and cache, and
the value reads FlashInfer's [B, H, 512] latent (under DCP: an FP8 q mailbox,
and an LSE in base e if
lse_base_e, else base 2). nvfp4: that FP8 query over an nvfp4_ds_mla
cache (FlashInfer prims_ts). overlap: the query overlap mode (overlap.py).
partials: the DcpBox's partial rows. release: the query launches the
next kernel early (PDL). pushed: DcpValue only merges (the sparse decode
pushes the rows, attn_sparse).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
dsa_on_flashinfer(attention)
¶
Whether a KimiK3DSAAttention runs FLASHINFER_MLA_SPARSE (per-tensor FP8 query; per-tensor FP8 or nvfp4_ds_mla cache).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/attn_fi.py
kv_cache_blocks()
¶
The 64-token blocks the KV cache holds, if known before it is allocated (a num_gpu_blocks override, or a cache already sized): a request's context fits in it, so it bounds the fused indexer's logits with the longest context. None if unknown (the KV cache is sized after the specialized decode is built).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/dsa/prepared.py
value_rows(device, rows, heads)
cached
¶
The W_UV bmm's value rows [H * rows * 128] BF16 of the wide TP / TP1 value projection (mla.value.value_bmm), shared by every DSA layer of a device.