MMInference: Accelerating Pre-filling for Long-Context Visual Language Models via Modality-Aware Permutation Sparse Attention

Yucheng Li, Huiqiang Jiang, Chengruidong Zhang, Qianhui Wu, Xufang Luo, Surin Ahn, Amir H. Abdi, Dongsheng Li, Jianfeng Gao, Yuqing Yang, Lili Qiu

TL;DR

MMInference is a novel dynamic sparse attention method designed to solve the "pre-filling bottleneck" in long-context Vision Language Models (VLMs). By identifying a unique "Grid pattern" in video attention and using modality-aware permutations to handle text-vision boundaries, it achieves up to an 8.3× speedup at 1 million tokens while maintaining the accuracy of full-attention models.

The Pre-filling Bottleneck in VLMs

As Vision Language Models (VLMs) scale to handle hours of video or thousands of images, they hit a massive computational wall: the pre-filling stage. Before a model can start generating text (decoding), it must process the entire input context. Because the standard attention mechanism has quadratic complexity ($O(n^2)$), processing a 1-million-token multi-modal input can take minutes, leading to unacceptable "Time-to-First-Token" latency.

Cost and Sparsity in VLMs

Existing sparse attention methods—like those used for text-only Large Language Models (LLMs)—often fail here because they do not account for the unique spatial and temporal locality of video data. Furthermore, multi-modal inputs create "modality boundaries." These are sharp transitions where the model's attention behavior shifts abruptly between text and vision, which disrupts traditional sparse indexing.

How MMInference Works

The authors introduce MMInference, which optimizes the pre-filling stage through a specialized pipeline tailored for multi-modal data.

MMInference Architecture

The system relies on three main components to achieve its speedups:

  1. The Grid Pattern: The researchers discovered that video attention often forms a "Grid" (evenly spaced vertical and horizontal lines) due to the way frames are sampled and processed. They developed a permutation-based method to "gather" these sparse grid points into dense blocks that GPUs can compute much faster.
  2. Hybrid Modality Handling: To deal with interleaved text and video, MMInference classifies attention heads into four types based on their boundary behavior: No-Boundary, K-Boundary, Q-Boundary, and 2D-Boundary. It uses row- and column-wise permutations to isolate intra-modality regions, ensuring that sparse computations don't "leak" across boundaries in a way that hurts performance.
  3. Modality-Aware Sparse Attention Search: Since different attention heads focus on different things, the authors use an offline search algorithm to find the optimal sparse pattern (e.g., A-shape, Vertical-Slash, or Grid) for every single head in the model.
  4. Optimized GPU Kernels: They implemented custom Triton-based kernels that perform "sparse loading with dense computation," leveraging hardware-efficient Block-sparse Tensor Cores.

Key Insights

  • Vision is not Text: Sparse patterns that work for LLMs (like focusing on the first few "sink" tokens) are insufficient for VLMs. Video requires capturing periodic temporal and spatial relationships, hence the "Grid" discovery.
  • Permutation is the Secret Sauce: GPUs struggle with irregular sparsity. By permuting the Query ($Q$), Key ($K$), and Value ($V$) tensors to group relevant tokens together, the authors transform a "messy" sparse problem into a "clean" block-diagonal problem that hardware can accelerate.
  • Global Extrapolation: A key insight was realizing that a sparse index built from a small segment of a modality (e.g., the last few tokens of a video) can effectively extrapolate to the rest of that modality, even if it's interrupted by text.

Datasets and Key Results

The authors evaluated MMInference across a wide range of benchmarks using state-of-the-art VLMs like LongVila, Llava-Video, VideoChat-Flash, and Qwen2.5-VL. They tested on Video Understanding (VideoDC, ActNet-QA, EgoSchema, Next-QA, VideoMME) and Retrieval tasks (Video-NIAH).

They also introduced Mixed-Modality-NIAH (MM-NIAH), a new benchmark where 25% of the input consists of text segments interleaved with video frames, specifically to test how models handle complex, multi-modal contexts.

Performance Highlights: * Massive Speedups: MMInference achieves an end-to-end speedup of 8.3× compared to FlashAttention-2 and 1.7× over MInference (a previous state-of-the-art sparse method) at 1M tokens. * Efficiency: At 1M tokens, the latency for the Grid kernel is only 358ms on a single A100 GPU. * Accuracy Preservation: Across Video QA and Captioning tasks, MMInference maintains nearly identical performance to full attention. In the grueling NIAH tests, it achieved 97.7% recall at 1M tokens, significantly outperforming static sparse baselines. * Zero-Shot Integration: The method requires no fine-tuning or model modifications, making it a "plug-and-play" upgrade for existing VLM pipelines.

Limitations and Future Work

While highly effective, the paper notes a few areas for further exploration:

  • Offline Search: The method relies on an offline search to identify head patterns. While this only takes ~15 minutes per model, a fully online, zero-overhead discovery mechanism would be even more flexible.
  • Beyond Pre-filling: The current work focuses on the pre-filling stage. Optimizing the auto-regressive decoding stage for multi-modal inputs remains a separate challenge.
  • Diffusion Transformers (DiT): The authors suggest that their permutation-based approach could be extended to accelerate video generation models (DiTs), which also suffer from quadratic attention costs.

Summary updated

BibTeX
@inproceedings{li2025mminference,
  author = {Yucheng Li and Huiqiang Jiang and Chengruidong Zhang and Qianhui Wu and Xufang Luo and Surin Ahn and Amir H. Abdi and Dongsheng Li and Jianfeng Gao and Yuqing Yang and Lili Qiu},
  title = {{MMInference: Accelerating Pre-filling for Long-Context Visual Language Models via Modality-Aware Permutation Sparse Attention}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=me6PfbATWM},
}
Figure