vllm.models.minimax_m3.amd.indexer_msa
¶
MSA (gfx950/CDNA4) indexer impl for MiniMax M3.
Scores index blocks and selects the top-k with AITER's fp8 MFMA kernels. Prefill
and decode differ only in the scorer -- ragged rows against uniform ones -- and
share one pa_sparse_block_topk, which also emits the attend's page table in
one numbering for both. Under indexer CP, decode instead scores this rank's
stride of the blocks, cuts it to the full top-k, exchanges the candidates and
merges them, over those same kernels at world > 1.
Classes:
-
MiniMaxM3IndexerMSABackend–Indexer side-cache backend selecting the MSA builder.
-
MiniMaxM3IndexerMSAImpl–Fp8 score + top-k for both prefill and decode.
-
MiniMaxM3IndexerMSAMetadata–Adds the per-row shape the ragged top-k needs.
-
MiniMaxM3IndexerMSAMetadataBuilder–The Triton indexer's metadata plus the prefill rows' causal shape.
-
MiniMaxM3MSAIndexer–MiniMaxM3Indexer's surface over the MSA impl.
Functions:
-
msa_indexer_cp_enabled–Whether to run the selected MSA indexer context-parallel.
-
msa_indexer_unsupported_reason–Return why this config cannot use this indexer, or None if it can.
-
select_msa_indexer_impl_cls–The MSA indexer impl if this config can use it, else None.
MiniMaxM3IndexerMSABackend
¶
Bases: MiniMaxM3IndexerBackend
Indexer side-cache backend selecting the MSA builder.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
MiniMaxM3IndexerMSAImpl
¶
Bases: MiniMaxM3IndexerImpl
Fp8 score + top-k for both prefill and decode.
Methods:
-
init_cp–Resolve the CP decode pass and allocate its buffers.
Attributes:
-
num_owned_index_heads(int) –Index heads whose selection this rank ends up holding.
-
pages_per_block(int) –Physical pages one selected block expands into for the attend.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
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 | |
num_owned_index_heads
property
¶
Index heads whose selection this rank ends up holding.
Under CP the scoring pass runs every head on every rank, but the merge
leaves each rank only the run it owns -- so this, not
num_index_heads, is the width of the top-k the attend reads and of
everything downstream of the exchange. It equals this rank's KV head
count, which is what the emitted page table is laid out against.
pages_per_block
property
¶
Physical pages one selected block expands into for the attend.
_decode(index_query, kv, d, decode_topk, decode_page16_block_table, sparse_bt, sparse_ctx)
¶
Score the blocks, take the top-k, emit the attend's page table.
The unsharded pair does both in one rank's worth of work, which is the thing CP exists not to do, so the sharded case takes the fused cross-rank selector instead.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
_decode_cp_aiter(index_query, kv, d, decode_topk, decode_page16_block_table, sparse_bt, sparse_ctx)
¶
Score this rank's block shard, then select across the shards.
Two kernels: the selector nominates, exchanges over the IPC mapping and
merges in one launch, with no collective between the halves. Both bound
the context by cp_max_seq_len so capture cannot specialize a shard
width. Every rank must reach this with the same row count or it hangs.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
_prefill(index_query, kv, p, prefill_topk, prefill_page16_block_table, sparse_bt, sparse_ctx, num_valid_pages, row_req_id, kv_lens)
¶
Score the blocks, take the top-k, emit the attend's page table.
AITER both sides, CP or not: prefill has a whole chunk of query rows to spread over the machine and nothing to gain from sharding the block axis on top of that, so the sharded chain the decode path takes buys it only an exchange it would otherwise not pay for.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
_table_rows(lo, hi)
¶
The page table and context rows covering score rows [lo, hi).
One table row per (token, kv head), head minor, which is the order
pa_decode_gluon reads once it flattens the cache. Slices of the
shared buffers rather than copies, so the attend sees the writes; a
model that reserved no buffers gets throwaway ones, and the attend
rebuilds the table itself in that case.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
init_cp()
¶
Resolve the CP decode pass and allocate its buffers.
Separate from __init__ because the topology is assigned after it,
and persistent because the decode path is captured: a replay reuses the
addresses it recorded, so the chain has to hand back the same ones.
Every shape is taken from max_model_len rather than the batch, for
the same reason. Capture goes through a dummy batch one token long, so a
width derived from that batch's own max_seq_len would bake a
one-block shard into the graph and then replay it at full context. The
per-request causal bound clips the real work at runtime instead.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
MiniMaxM3IndexerMSAMetadata
dataclass
¶
Bases: MiniMaxM3IndexerMetadata
Adds the per-row shape the ragged top-k needs.
The uniform decode rows are recovered inside the kernel from seq_lens and
the shared query length, which also clamps cudagraph padding rows to nothing.
Prefill rows have no such shape, so it is materialized here once per forward
and shared by every layer -- which is also where the emitted page table's
tail block comes from, since a block count alone does not say how many tokens
the last block holds.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
MiniMaxM3IndexerMSAMetadataBuilder
¶
Bases: MiniMaxM3IndexerMetadataBuilder
The Triton indexer's metadata plus the prefill rows' causal shape.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
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 | |
MiniMaxM3MSAIndexer
¶
Bases: Module
MiniMaxM3Indexer's surface over the MSA impl.
Fp8 score + top-k for both prefill and decode.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
_cp_score_buffer(heads, rows, max_seq_len, block_size, device, world)
¶
The CP score buffer, allocated once and shared by every layer.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
_score_buffer(heads, rows, max_seq_len, block_size, device, world=1)
¶
Score buffer for rows query rows, padded as the top-k requires.
Left uninitialized on purpose: the score pass writes every block up to the longest row it covers and the top-k reads only the blocks its own row can see, so nothing downstream observes the padded tail. Filling it would cost a write over what is, at long context, the largest tensor in the indexer.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
_score_width(max_seq_len, block_size, world=1)
¶
Blocks one score row spans, padded as the top-k requires.
Lanes read whole wave-wide strips with no tail guard and each holds a power-of-two count of them, so the block axis is padded past the block count the context actually needs.
world is the block shard the row holds: a context-parallel row covers
only this rank's 1/world of the blocks, so the padding is reached from
that count and not from the context's.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
msa_indexer_cp_enabled(vllm_config, *, msa_indexer_selected)
¶
Whether to run the selected MSA indexer context-parallel.
select_msa_indexer_impl_cls's gate re-asked at the CP world. Call once
per model: the projection layout and head count are decided off one answer.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
msa_indexer_unsupported_reason(*, topk_blocks, sparse_block_size, index_head_dim, indexer_kv_dtype, max_model_len, score_type='max', cp_world=1, num_index_heads=1, num_kv_heads=1, max_query_len=1, dcp_size=1)
¶
Return why this config cannot use this indexer, or None if it can.
Checks platform (ROCm/gfx950), the AITER sparse PA attend, index-cache
dtype, the kernels' shape contract and the max context in blocks. The
default cp_world=1 ignores every argument below it and asks about the
unsharded indexer; above one it adds the checks sharding brings. Callers
fall back on a reason rather than raise.
Source code in vllm/models/minimax_m3/amd/indexer_msa.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | |
select_msa_indexer_impl_cls(*, topk_blocks, sparse_block_size, index_head_dim, indexer_kv_dtype, score_type='max')
¶
The MSA indexer impl if this config can use it, else None.