vllm.models.minimax_m3.common.ops.sparse_attn ¶
Triton kernels for MiniMax M3 block-sparse GQA attention.
The main heads attend only to the blocks selected by the lightning indexer (see index_topk). Adapted to vLLM's paged KV cache: the KV page size is forced to equal the sparse block size (128), so one selected block maps to exactly one page.
Main K/V cache layout (vLLM): (num_blocks, 2, 128, num_kv_heads, head_dim) K=[:,0] V=[:,1]
Only the paths MiniMax M3 uses are implemented: no attention sink, base-2 (exp2/log2) softmax. The decode kernels use split-K (flash-decoding) over the selected blocks with a separate merge step, since one query token per request leaves the prefill kernels (which parallelize over the query dim) idle.
Functions:
-
minimax_m3_sparse_attn–GQA block-sparse attention over the selected blocks. block_size_q == 1.
-
minimax_m3_sparse_attn_decode–GQA block-sparse attention for decode (split-K over the top-k blocks).
_sparse_attn_num_stages_kwarg() ¶
Triton num_stages override for the sparse-attn GEMM kernels.
Forced only where required: CDNA3 (gfx942) caps LDS at 64 KB, and the default 2-stage pipeline double-buffers the 128x128 K/V tiles to ~66 KB ("out of resource: shared memory"), so pin gfx942 to a single stage (~32 KB, which fits). Everywhere else (NVIDIA, CDNA4 gfx950) return an empty kwarg and let Triton keep its own default -- don't second-guess it. Cached: the arch is fixed per process.
Source code in vllm/models/minimax_m3/common/ops/sparse_attn.py
minimax_m3_sparse_attn(q, kv_cache, topk_idx, block_table, cu_seqlens_q, seq_lens, prefix_lens, max_query_len, num_kv_heads, sm_scale, output) ¶
GQA block-sparse attention over the selected blocks. block_size_q == 1.
Source code in vllm/models/minimax_m3/common/ops/sparse_attn.py
minimax_m3_sparse_attn_decode(q, kv_cache, topk_idx, block_table, seq_lens, num_kv_heads, sm_scale, output, decode_query_len) ¶
GQA block-sparse attention for decode (split-K over the top-k blocks).
Source code in vllm/models/minimax_m3/common/ops/sparse_attn.py
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 | |