vllm.models.minimax_m3.common.ops.index_topk
¶
Triton kernels for MiniMax M3 lightning-indexer block scoring + top-k.
Index queries score each 128-token block of index keys (max over the block), then the top-k blocks (plus forced init/local blocks) are selected per query token. Adapted to vLLM's paged KV cache: the KV page size is forced to equal the sparse block size (128), so one sparse block maps to exactly one page.
Index-K cache layout (vLLM): (num_blocks, 128, idx_head_dim) (single head).
Only the paths MiniMax M3 uses are implemented: score_type="max", index value
disabled (score-only indexer), single shared index head. The selected block ids
feed the block-sparse attention kernels in sparse_attn.
Functions:
-
minimax_m3_index_decode–Decode index block-score + top-k, both split-K (cudagraph-safe).
-
minimax_m3_index_decode_score–Decode index block-score (split-K, cudagraph-safe); no top-k.
-
minimax_m3_index_score–Compute per-token index scores for each visible sparse block.
-
minimax_m3_index_topk–Select index top-k from a precomputed score tensor.
minimax_m3_index_decode(idx_q, index_kv_cache, block_table, seq_lens, max_seq_len, topk, init_blocks, local_blocks, num_kv_heads, decode_query_len, max_decode_query_len, out=None, score_out=None)
¶
Decode index block-score + top-k, both split-K (cudagraph-safe).
Returns topk_idx [num_kv_heads, total_q, topk] (0-indexed block ids, -1 pad).
When out ([num_kv_heads, >=total_q, topk]) is given, writes into
out[:, :total_q, :] (stable address for cudagraph) instead of allocating.
When score_out ([num_kv_heads, total_q, >=max_block]) is given, the block
scores are written into it (read back by the top-k) instead of a fresh
tensor -- used to share a unified score buffer with the prefill side. Reads
via strides, so a transposed view of a block-major buffer is accepted.
Source code in vllm/models/minimax_m3/common/ops/index_topk.py
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | |
minimax_m3_index_decode_score(idx_q, index_kv_cache, block_table, seq_lens, max_seq_len, init_blocks, local_blocks, num_kv_heads, decode_query_len, max_decode_query_len, score_out=None)
¶
Decode index block-score (split-K, cudagraph-safe); no top-k.
Returns score [num_kv_heads, total_q, >=max_block] (fp32; init/local blocks
forced to 1e30/1e29). When score_out is given the scores are written into
it (read/written by strides, so a transposed view of a unified buffer is
accepted) instead of a fresh tensor -- used to share a unified score buffer
with the prefill side and run a single top-k over both.
Source code in vllm/models/minimax_m3/common/ops/index_topk.py
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 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
minimax_m3_index_score(idx_q, index_kv_cache, block_table, cu_seqlens_q, seq_lens, prefix_lens, max_query_len, max_seq_len, num_kv_heads)
¶
Compute per-token index scores for each visible sparse block.
Returns score [num_kv_heads, total_q, max_block], where each score is the max over a 128-token index-K block. M3 has num_idx_heads == num_kv_heads.
Source code in vllm/models/minimax_m3/common/ops/index_topk.py
minimax_m3_index_topk(score, cu_seqlens_q, prefix_lens, max_query_len, topk, init_blocks, local_blocks, out=None)
¶
Select index top-k from a precomputed score tensor.
When out is provided (a [num_idx_heads, >=total_q, topk] buffer), the
result is written into out[:, :total_q, :] instead of a fresh tensor --
used to keep the top-k output at a stable address for cudagraph capture.