vllm.models.minimax_m3.nvidia.specialized_decode.kernels.sparse_decode
¶
sparse_decode stage: FP8-KV sparse decode over the 16 pages page_topk
selected, one cluster of CL CTAs per (row, KV head), MXFP8 output for the
o_proj GEMV.
CuTe DSL kernel (sparse_decode_kernel.py, fp16-P online softmax). One kernel is
compiled per (cluster width,
Q heads per KV head, pre-wait order, min blocks, PDL) at build.
Residency: the kernel only waits inside its own cluster (DSMEM mbarrier), so
correctness needs one cluster to be schedulable. build() probes
cuOccupancyMaxActiveClusters of the compiled kernel for every cluster
width (16, 8) and picks the width per row count
(geometry.sparse_cluster_size, recorded in cluster_sizes): up to
one_wave_rows rows (the decode chain was tuned for 8) the grid must be
co-resident (one wave), 16 CTAs per (row, KV head) narrowed to 8 when 16 does
not fit, else build() fails closed; larger grids (up to max_rows, 64)
only need to be schedulable and take the width with the fewest waves
(multi_wave_rows lists those that still need more than one).
strict_one_wave=False drops the one-wave requirement.
The kernel itself takes up to 128 rows (one MXFP8 scale tile).
Classes:
-
ClusterSparseDecodeStage–__call__(q_fp8, k, v, tables, lens, out, q8, sf, sfp)
Functions:
-
cluster_size–The preferred width before the occupancy probe: 16 CTAs per (row, KV
-
launch–One launch of the (cl, min_blocks, prewait) build; prewait 0 at min blocks 1
-
max_clusters–Clusters of width
clof the (min blocksminb, pre-wait) build that -
sparse_lens–int32 tokens covered by the selected pages (graph-safe torch ops):
-
split_kv–(k, v) uint8 views [pages, Hkv, 128, 128] of an fp8 KV cache whose
ClusterSparseDecodeStage
¶
__call__(q_fp8, k, v, tables, lens, out, q8, sf, sfp)
q_fp8 e4m3 [T, Hq, 128] (Hq = heads_per_kv * Hkv per rank: 16 at TP4, 8 at TP8)
k, v e4m3/uint8 [P, Hkv, 128, 128] views (split_kv)
tables int32 [Hkv, T, >= 16] page_topk output (physical pages)
lens int32 [Hkv, T] sparse_lens of each row
out bf16 [T, Hq * 128]
q8 uint8 [T, Hq * 128] MXFP8 values for the o_proj GEMV
sf uint8 [128 * Hq * 4] UE8M0, 128x4 swizzled, rows padded to 128
sfp uint8 [T, Hq * 4] UE8M0, row-major copy
Methods:
-
__call__–q_prewait: q was not written by the kernel launched right before
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
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 | |
__call__(q_fp8, k, v, tables, lens, out, q8, sf, sfp, *, done_cnt=None, q_prewait=False)
¶
q_prewait: q was not written by the kernel launched right before
this one (e.g. the front, with the index scorer and page top-k in
between), so the kernel may read it before its PDL grid wait. From
PREWAIT_MIN_ROWS rows the lens (written at the start of the step,
sparse_lens) are read before the wait, and q with them when
q_prewait; below, every input is read after it.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
_compile(cl, hq, pre, minb, pdl, cap=0)
¶
The compiled kernel of one build (cached per process); outside capture. cap >
0 pads the shared memory
so that at most cap CTAs are resident per SM.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
_dump_dir()
¶
Where the DSL writes the kept cubins (read back for the occupancy probe): a per-process temp dir.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
_ext()
¶
Load-time check (the kernel registry calls it before building): the CuTe
DSL kernel module imports. Kernels compile in build().
_kernel()
¶
The CuTe DSL kernel module (imports cutlass).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
_kernel_function(key)
¶
(CUfunction, dynamic smem bytes) of a compiled build, loaded from its cubin on the current device (the DSL launches through its own runtime and exposes no handle; the occupancy probe needs one).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
cluster_size(rows, num_kv_heads)
¶
The preferred width before the occupancy probe: 16 CTAs per (row, KV
head) unless that makes the grid 32 clusters or wider (then 8). The stage
launches with the width build() chose (cluster_sizes).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
launch(q_fp8, k, v, tables, lens, out, q8, sf, sfp, *, done_cnt=None, qk_scale_log2, v_scale, cl, min_blocks, prewait, heads_per_kv=HEADS_PER_KV, pdl=True, cap=0)
¶
One launch of the (cl, min_blocks, prewait) build; prewait 0 at min blocks 1 reads every input after the wait. q_fp8 e4m3 [T, Hq, 128]; k, v e4m3 [pages, Hkv, 128, 128] views; tables int32 [Hkv,
= T, >= 16]; lens int32 [Hkv, >= T]; out bf16 [T, Hq * 128]; q8 [T, Hq * 128]; sf [128 * Hq * 4] (128x4 swizzle); sfp [T, Hq * 4]; done_cnt optional int64 [1] completion counter.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
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 | |
max_clusters(cl, minb=1, hq=HEADS_PER_KV, cap=0)
¶
Clusters of width cl of the (min blocks minb, pre-wait) build that
can be resident at once (cuOccupancyMaxActiveClusters); negative = -CUresult.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
num_regs(cl, minb=1, hq=HEADS_PER_KV, pre=True)
¶
Registers per thread of one build (for the port's resource comparison).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
sparse_lens(seq_lens, *, page=PAGE, topk=TOPK)
¶
int32 tokens covered by the selected pages (graph-safe torch ops): L if ceil(L / page) <= topk else (topk - 1) * page + tokens of the last page. Assumes page_topk always keeps the last (partial) page (local_blocks >= 1).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/sparse_decode.py
split_kv(kv_cache)
¶
(k, v) uint8 views [pages, Hkv, 128, 128] of an fp8 KV cache whose last dim is K|V (256 bytes per token per head). The cache must be laid out (page, head, token, 256) up to strides; pass a permuted view if the allocator's dim order differs.