vllm.models.kimi_k3.nvidia.specialized_decode.cutedsl.mla.dcp
¶
MLA decode under decode context parallelism (DCP = TP, rank d owns head block d) without collectives, three kernels per layer. Each rank's KV cache holds 1 / DCP of every context.
MlaQuery FP8 query rows [B, H, 576] (+ the KV insert where this rank owns the slot); each CTA multicasts its bytes into every rank's Lamport q mailbox [B, DCPH, 576], then polls its share until all landed tokenspeed all DCPH heads over the local KV shard -> BF16 rows + LSE (log2) DcpValue re-arms the q mailbox; rows pushed to their head owner's Lamport mailbox (peer stores; BF16 latent rows, or "proj": BF16 value rows through W_UV); the owner LSE-merges its H heads over the DCP sources, then W_UV and the gate (padding from the global lengths). A source with nothing to merge (an empty local shard) sends only its LSE.
Classes:
-
DcpBox–Model-owned DCP state over
group, Lamport mailboxes (sentinel-filled, -
DcpMailbox–One partials format's peer-store mailboxes: partial rows [2, DCP, CAP, H, 512]
-
DcpValue–The DCP tail of one MLA layer, one 512-thread CTA per (head, 16 requests).
Functions:
-
compile_value–DcpValue of one batch (
qrows per request);uv: the (shape, stride, -
fill_splits–Splits filling the SMs (one CTA pair each); tokenspeed caps itself at 32.
-
local_max–Longest local shard of a
max_contextsequence (block-interleaved). -
partials_for–The partials format of a
batchof rows under thespecpolicy: a format -
reserve_workspace–The split-KV workspace of one stock_decode shape (one per (device, heads),
-
resolve_partials–The DcpBox policy of a
spec("default": PARTIALS_DEFAULT of the layer -
split_plan–tokenspeed_mla_decode's FP8 schedule of
batchrequests ofq_lenrows: -
stock_decode–tokenspeed_mla_decode's FP8 path with caller-owned
outandlse(log2)
DcpBox
¶
Model-owned DCP state over group, Lamport mailboxes (sentinel-filled,
re-armed by their reader): q [2, CAP, DCP*H, 576] FP8 bytes (multicast stores),
one DcpMailbox of partial rows and LSE (peer stores) per partials format the
partials policy uses (see partials_for: "bf16" latent rows; "proj": value
rows), and the local tokenspeed rows / LSE.
Parity alternates by layer. interleave: the KV cache's DCP interleave (global
masking of spec verify rows).
Methods:
-
gather_heads–Every rank's W_UV [H, 512, 128] (latent-contiguous) -> [DCP * H, 512, 128]
-
mailbox–The DcpMailbox a
batchof rows exchanges its partials through. -
mc–The q mailbox multicast address of
parity. -
value_weights–The gathered W_UV (gather_heads) a layer's "proj" batches read, with its
Attributes:
-
projected–Whether some batch exchanges W_UV-projected rows ("proj").
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
121 122 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 | |
projected
property
¶
Whether some batch exchanges W_UV-projected rows ("proj").
gather_heads(w_uv)
¶
Every rank's W_UV [H, 512, 128] (latent-contiguous) -> [DCP * H, 512, 128] in the same layout, gathered head block d = rank d's heads ("proj" sources project the rows of every gathered head). Collective: call on every rank.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
mailbox(batch)
¶
The DcpMailbox a batch of rows exchanges its partials through.
mc(parity)
¶
value_weights(w_uv)
¶
The gathered W_UV (gather_heads) a layer's "proj" batches read, with its CuTe view, or None when the policy never exchanges "proj" rows. A copy of every rank's W_UV per layer: DCP x the local one (BF16 DCP * H * 512 * 128: 12 MiB per Kimi K3 / K3.1 attention layer of 96 heads), taken once. Collective: the layer providers call it from their constructors, which build_providers runs on every rank over the same layers in the same order, after the weights are loaded and before the KV cache is profiled.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
DcpMailbox
¶
One partials format's peer-store mailboxes: partial rows [2, DCP, CAP, H, 512] BF16 ("proj": BF16 value rows [..., 128]) and LSE [2, DCP, CAP, H] FP32, sentinel-filled, and their peers' addresses.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
DcpValue
¶
The DCP tail of one MLA layer, one 512-thread CTA per (head, 16 requests).
Every rank re-arms this parity's q mailbox (tokenspeed has read it) and pushes its
local tokenspeed rows (+ LSE) to their head owner's Lamport mailbox; a row of an
empty local shard (or an invalid LSE) sends only the LSE EMPTY_LSE, and the owner
neither polls nor re-arms its partial. Warp r then LSE-weights request t0 + r of
this head over the DCP sources (exp2(lse - max) / sum in FP32), the CTA merges the
polled rows in FP32 (one BF16 rounding, re-arming what it read) into shared
memory, and W_UV (BF16 MMA, FP32 accumulation) and the sigmoid gate follow as in
MlaValue: warp w owns outputs 32 (w // 4) + 8 (w % 4) .. + 7. Rows are tokens,
q per request. Above 64 rows a merging CTA owns every grid[1]-th 16-row
tile: at most one CTA per SM, so every CTA's pushes land while the merging CTAs
poll.
per_row: the emptiness test reads lens per row (a sparse decode's valid
counts of the local shard), else per request (the local lengths).
partials "proj" (w_uv: the gathered [DCP * H, 512, 128] W_UV, see
DcpBox.gather_heads): CTA (h, d < DCP) projects the local rows of gathered head
d * H + h through its W_UV (steps of up to PROJ_ROWS rows staged in shared
memory, the BF16 MMAs of the merge; the next step's latents and LSEs load while
one projects) and pushes BF16 [rows, 128] value rows; CTA (h, DCP + m) merges
request tiles m, m + M, .. of head h over the DCP sources (FP32, one BF16
rounding: the merge is linear, sum_s w_s (O_s W) = (sum_s w_s O_s) W, so only
the rounding points differ from the latent merge) and applies the gate.
No CTA waits on a CTA that may not be dispatched: projecting CTAs wait on
nothing but the sparse decode before them (griddepcontrol_wait); merging CTAs
poll only values and LSEs the projecting CTAs of every rank push. Those have
the lowest linear block indices, so the scheduler dispatches them before any
merging CTA, and independently the grid is at most one CTA per SM, while
everything else that can hold SMs during DcpValue (the PDL-overlapped sparse
decode, the prefetch stream) finishes without waiting on it, and the next
kernel only launches once every CTA here passed its PDL trigger, which the
projecting CTAs reach after their projections. M fills the SMs left by the
DCP * H projecting CTAs.
Methods:
-
__init__–q_chunks: 16 B chunks per q mailbox head row (36 FP8, 72 BF16); -
kernel_projected–partials"proj": the projecting CTAs (y < DCP) and the merging CTAs -
load_tile–This thread's 16 B chunks of the BF16 latent rows t0.. t0 + prows - 1 of
-
merge–The owner's merge of request rows t0.. of this head, then W_UV + gate.
-
merge_projected–The owner's merge of the value rows of request rows t0.. of this head over
-
poll_pair–Polls a BF16 partial chunk (8 values) until published, re-arms it and adds
-
project–Rows t0.. t0 + prows - 1 of gathered head
gh(tile: this -
push_rows–Every rank's local rows (+ LSE) to their head owner's mailbox, then the
-
push_values–preprojected: push gathered headgh's value rows (the W_UV -
rearm–Re-arm this parity's q mailbox (the sparse decode has read it): thread
-
sent_lse–The base-2 LSE row (b, gh) sends: EMPTY_LSE for an empty local shard or a
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
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 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 723 724 725 726 727 | |
__init__(heads, size, batch, sms=148, q=1, q_chunks=36, q_heads=0, lse_scale=1.0, per_row=False, partials='bf16', preprojected=False, pushed=False)
¶
q_chunks: 16 B chunks per q mailbox head row (36 FP8, 72 BF16);
q_heads: q mailbox rows per token (default DCP * H); lse_scale: to
base 2 (LOG2E for a natural-log LSE). preprojected ("proj" only): the
W_UV argument holds the value rows [DCP * H, B, 128] BF16 a batched GEMM
already projected (the stock W_UV bmm over the gathered heads), so the
projecting CTAs only push them. pushed ("bf16" only): the sparse
decode before pushed every rank's rows and LSEs and re-armed the q mailbox
(dsa.attn_sparse), so DcpValue only merges.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
kernel_projected(args)
¶
partials "proj": the projecting CTAs (y < DCP) and the merging CTAs
(y >= DCP). The projecting CTAs come first in launch order and never wait
on another CTA (only griddepcontrol_wait on the sparse decode before them),
so every rank's projections finish however many merging CTAs are
resident; see the class docstring.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
load_tile(args, gh, t0, tid)
¶
This thread's 16 B chunks of the BF16 latent rows t0.. t0 + prows - 1 of
gathered head gh (chunk tid + 512 j: row // 64, 8 (chunk % 64)); zeros
beyond the batch), led by the LSEs of the rows it pushes ((tid + 512 j)
// 16; sent_lse, EMPTY_LSE beyond the batch).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
merge(args, latent, scales, wb, tid, tile)
¶
The owner's merge of request rows t0.. of this head, then W_UV + gate.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
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 | |
merge_projected(args, scales, tid, tile)
¶
The owner's merge of the value rows of request rows t0.. of this head over the DCP sources (FP32, polled 8 at a time, re-armed as read), rounded to BF16 as the latent merge's W_UV output, then the gate.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
poll_pair(source, words, w, merged)
¶
Polls a BF16 partial chunk (8 values) until published, re-arms it and adds
it, weighted by w, to merged.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
project(args, latent, values, wb, gh, t0, tid, tile)
¶
Rows t0.. t0 + prows - 1 of gathered head gh (tile: this
thread's latent chunks and LSE of them, load_tile): stage the BF16 latents,
issue the next step's loads, W_UV (BF16 MMA, FP32 accumulation, rounded to
BF16; one 16-row block per accumulator set) and push the [prows, 128] value
rows (and every row's LSE; a row with nothing to merge sends only its LSE).
Returns the next step's load_tile.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
push_rows(args, head, tile, pusher, tid)
¶
Every rank's local rows (+ LSE) to their head owner's mailbox, then the q mailbox re-arm (see the class docstring).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
push_values(args, gh, tid)
¶
preprojected: push gathered head gh's value rows (the W_UV
argument, [DCP * H, B, 128] BF16) and every row's LSE to the head's owner,
a row with nothing to merge only its LSE (as project). Thread tid
takes 16 B chunk tid % 16 of rows tid // 16, + 32, ..: four rows' loads in
flight per thread.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
rearm(mailbox, me, threads)
¶
Re-arm this parity's q mailbox (the sparse decode has read it): thread
me of threads stores the sentinel into every threads-th 16 B chunk of
the published rows.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
sent_lse(rows_lse, lens, b, gh)
¶
The base-2 LSE row (b, gh) sends: EMPTY_LSE for an empty local shard or a NaN / infinite LSE (then its partial row is not sent).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
compile_value(heads, size, batch, cap, uv, pitch, device, sms=148, q=1, dsa_heads=0, dsa_bf16=True, lse_base_e=True, partials='bf16', preprojected=False, pushed=False)
cached
¶
DcpValue of one batch (q rows per request); uv: the (shape, stride,
dtype) of W_UV, pitch: the projected rows' (the gate follows the 2112 query /
KV columns). dsa_heads: DSA layout, its padded head count: q mailbox rows
(BF16 for FlashMLA sparse, else FP8), rows / LSE as the sparse decode returns
them (lse_base_e: natural-log, else base 2) and lens the sparse decode's
per-row valid counts. partials: the format of its DcpMailbox.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
fill_splits(batch, device)
¶
Splits filling the SMs (one CTA pair each); tokenspeed caps itself at 32.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
local_max(max_context, size)
¶
Longest local shard of a max_context sequence (block-interleaved).
partials_for(spec, batch)
¶
The partials format of a batch of rows under the spec policy: a format
("bf16", "proj") or a batch table of formats.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
reserve_workspace(batch, q_len, heads, device, max_seq, min_split, pack=False)
¶
The split-KV workspace of one stock_decode shape (one per (device, heads), shared by every MLA layer: the calls are stream ordered), grown to fit it. PreparedMla reserves every prepared shape's at construction, before vLLM profiles its memory for the KV cache, so prepare_cache and the steps allocate nothing; growing it during a capture would leave the graphs captured before with the freed buffer.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
resolve_partials(spec, kind)
¶
The DcpBox policy of a spec ("default": PARTIALS_DEFAULT of the layer
kind, "mla" or "dsa"; anything else as given).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
split_plan(batch, q_len, heads, device, max_seq, min_split, pack)
¶
tokenspeed_mla_decode's FP8 schedule of batch requests of q_len rows:
(tiler, pack, fold, SMs, split count, workspace bytes).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/mla/dcp.py
stock_decode(query, cache, block_table, lengths, max_seq, scales, out, lse=None, min_split=1, pdl=True, cp=(1, 0, 1), totals=None, pack=False)
¶
tokenspeed_mla_decode's FP8 path with caller-owned out and lse (log2)
buffers and no per-call allocation: the split count follows from (B, max_seq,
min_split); lengths bound the work, empty splits are skipped by its reducer.
The q rows of a request mask causally; under DCP in global positions (cp:
world, rank, interleave; totals: the global lengths). pack: M128 tiles hold
consecutive (query row, head) rows across the q rows.