vllm.models.kimi_k3.amd.ops.flydsl_sparse_mla_gfx950
¶
FlyDSL sparse MLA forward over fp8_ds_mla records, gfx950.
Serves the DeepSeek-V3.2 / Kimi-K3 fp8_ds_mla path of sparse_mla_fwd
(kv_lora_rank 512, rope 64, bf16 q, <= 16 heads, CSR index stream). The host
wrapper and its support predicate live in flydsl_sparse_mla.py.
Record (656 B): 512 e4m3 latent | 4 f32 per-128 pow2 scales | 64 bf16 rope.
One 4-wave workgroup per query row (rows issued in reverse order, so the long
causal tail starts first), 128-token tiles over the row's CSR slice
indices[indptr[q] : indptr[q + 1]]:
- QK: wave w computes S for tokens [32w, 32w + 32) of the tile, all heads, from the raw fp8 latent: a scaled MFMA 16x16x128 with the record's pow2 scale as the E8M0 scale_a, and Q quantized per (head, 128) to an fp8 hi plus an fp8 lo residual. The rope part is a bf16 MFMA.
- Softmax: the per-wave tile max is exchanged through LDS; P = exp2(s - m + 8).
- PV: wave w owns output dims [128w, 128w + 128), which is exactly one KV scale block, so the V scale folds into P (P' = P * scale_v, fp16) and V stays raw fp8 in LDS (ds_read_b64_tr_b8, exact fp8 -> f16, f16 MFMA).
- Tiles: nt = ceil(len / 128), or with has_invalid ceil(last_valid / 128),
where a scan of the row finds the last entry >= 0. Positions >= len and,
with has_invalid, entries < 0 are masked; their latent DMA reads row 0.
Index reads go through a buffer descriptor sized to
indices, so a tail tile never reads past the end of the index buffer. - KV rows are addressed in 64 bits (global_load ... lds for the latent DMA, plain global loads for the scale and rope words), so the cache may span more than 4 GiB: vLLM hands the non-DCP path its whole packed block-row space, which does. Nothing bounds those reads; see the last precondition.
Preconditions the host cannot check
- Every per-128 KV scale is a power of two, as vLLM's fp8_ds_mla writer (concat_and_cache_ds_mla) stores it: QK takes the scale's exponent as the MFMA E8M0 scale, so a mantissa would be dropped.
- Every per-128 KV scale is <= 2^7: P' = P * scale has to fit fp16 and P <= 2^8. vLLM's writer uses scale = pow2ceil(max(amax, 1e-4) / 448), so this holds iff |latent| <= 57344. A larger scale is clamped to 2^7 in-kernel, which keeps the output finite but makes it inexact.
- Every consumed index i satisfies 0 <= i < kv rows (as for the Gluon path).
Functions:
-
build_sparse_mla_fp8ds_module–JIT launcher for one (heads, has_invalid, return_lse) configuration.
_BoundedI32
¶
Bases: GTensor
GTensor whose buffer descriptor carries the real byte size, so an out-of-range read returns 0 instead of touching memory past the end.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_cvt_v8(x)
¶
8 raw e4m3 (2 i32 from tr8) -> 8 f16 (4 i32), exact.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_e8m0_for(amax)
¶
E8M0 byte s with amax / 2^(s - 127) in [128, 256), and f32 2^(127 - s).
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_global_i32(addr, words)
¶
words i32 (1 or 4) at the 64-bit global address addr: a cache
past 4 GiB is out of a buffer descriptor's 32-bit offset reach.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_guarded(pred, fn)
¶
Run fn() under a runtime predicate (an scf.if around its body).
_pack_fp8x4(vals)
¶
4 f32 -> one i32 of e4m3 (byte i = vals[i]).
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_pv_mfma(d0, v_a, pp, o)
¶
O^T[d0 .. d0 + 3] += V^T P'^T for 4 output column chunks, in place.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_q_prologue(q_t, q_row, g, h_ok)
¶
Quantize this lane's q row to fp8 hi/lo MFMA operands.
MFMA scale group kb (lanes 16kb.. supply its E8M0) is K bytes 32kb..32kb + 31, so lane d's bytes 0-15 belong to group d // 2 and bytes 16-31 to group 2 + d // 2. Lane g therefore holds, for MFMA j, chunk 2j + g % 2 of record block g // 2 (first 16 B) and of block 2 + g // 2 (second 16 B), and supplies the scale of block g.
Returns (q8 hi operands, hi E8M0, q8 lo operands, lo E8M0).
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_quant(vals, inv)
¶
Vals * inv -> fp8 words (hi), and the residual * 32 as fp8 words (lo, whose E8M0 scale is the hi one minus 5).
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
_xmax(x)
¶
Max over the 4 lane groups (xor 16, 32) via permlane swaps.
_xsum(x)
¶
Sum over the 4 lane groups (xor 16, 32) via permlane swaps.
build_sparse_mla_fp8ds_module(num_heads, has_invalid, return_lse)
¶
JIT launcher for one (heads, has_invalid, return_lse) configuration.
The latent tile lives in LDS as 4 column blocks (bytes 128b..128b + 128 of the record), filled directly by global_load ... lds (DMA) from 64-bit per-lane row addresses. Wave w streams the next tile's column block w right after its own PV tr8 reads; only wave w reads block w in PV.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla_gfx950.py
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 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 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 | |