vllm.model_executor.layers.sparse_attn_indexer ¶
Custom Sparse Attention Indexer layers.
Classes:
-
SparseAttnIndexer–Sparse Attention Indexer Custom Op Layer. This layer is extracted as a
Functions:
-
kv_cache_as_quant_view–4D
[num_blocks, block_size, 1, head_width]view expected by
SparseAttnIndexer ¶
Bases: CustomOp
Sparse Attention Indexer Custom Op Layer. This layer is extracted as a separate custom op since it involves heavy custom kernels like mqa_logits, paged_mqa_logits and top_k_per_row, etc. Those kernels maybe requires specific memory layout or implementation for different hardware backends to achieve optimal performance.
For now, the default native path will use CUDA backend path. Other platform may requires add the corresponding Custom Op name sparse_attn_indexer to custom_ops in CompilationConfig to enable the platform specific path.
Source code in vllm/model_executor/layers/sparse_attn_indexer.py
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 821 822 823 824 825 826 | |
_gather_workspace_shapes(total_seq_lens, head_dim, fp8_dtype, use_fp4_cache) ¶
Return ((values_shape, values_dtype), (scales_shape, scales_dtype)) for the K-gather workspace. FP8 path: (T, head_dim) fp8 + (T, 4) uint8 fp32 scales. MXFP4 path: (T, head_dim // 2) uint8 packed mxfp4 + (T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales.
Source code in vllm/model_executor/layers/sparse_attn_indexer.py
_merge_dcp_topk_global(logits, topk_indices, topk_tokens, dcp_rank, dcp_world_size, cp_interleave, row_starts=None) ¶
Merge each DCP rank's local top-K into the global top-K.
topk_indices are this rank's local top-K positions into its 1/N KV shard. A token in the global top-K must also be in its owning rank's local top-K (at most topk_tokens - 1 tokens rank globally above it, hence at most that many on its own rank), so exchanging only the per-rank local candidates is exact -- equivalent to all-gathering the full logit matrix, but it ships dcp_world_size * topk_tokens candidates instead of the whole score row. Overwrites topk_indices with global token ids (-1 for padding); the attention backend localizes them back to physical slots per rank.
Source code in vllm/model_executor/layers/sparse_attn_indexer.py
kv_cache_as_quant_view(kv_cache, head_dim, use_fp4_cache) ¶
4D [num_blocks, block_size, 1, head_width] view expected by DeepGEMM, from the 3D indexer kv-cache allocation.