Overview of MSA (MiniMax Sparse Attention) in TokenSpeed
mainThe msa directory contains a vendored copy of the MiniMax MSA sparse-attention Python package (originally fmha_sm100). It provides the CuTe-DSL sparse-attention stack for block-sparse prefill attention, as well as nvcc-JIT dense FMHA used for score-only modes in the prefill indexer.
Key Components
- Public API Surface: Found in
__init__.pyandsparse.py. It re-exports functions likesparse_atten_funcandbuild_k2q_csr. - CuTe-DSL Stack: Located in
cute/. This includes the interface, quantization logic, and sparse index utilities. - Dense FMHA / Indexer Path: Located in
api.py,jit.py, andcsrc/. This path providesfmha_sm100,fmha_sm100_plan, andsparse_topk_select, which are used bytokenspeed_kernel/ops/attention/msa_score.pyfor OnlyScore scoring and top-k selection.
Important Note on CUTLASS
This package does not vendor the full CUTLASS repository. Instead, jit.py uses a local patch (_find_cutlass_dir) to resolve headers from the following locations in order:
- The
TOKENSPEED_MSA_CUTLASS_DIRenvironment variable. - A package-local
cutlass/checkout. - The CUTLASS tree bundled within the
flashinferwheel.