NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving

Zihao Ye, Lequn Chen, Ruihang Lai, Wuwei Lin, Yineng Zhang, Stephanie Wang, Tianqi Chen, Baris Kasikci, Vinod Grover, Arvind Krishnamurthy, Luis Ceze

TL;DR

FlashInfer is an open-source, highly efficient, and customizable attention engine designed specifically for Large Language Model (LLM) inference serving. By introducing a unified block-sparse KV-cache format, a JIT-compiled attention template, and a dynamic load-balanced scheduler, it slashes inter-token latency by up to 69% and seamlessly adapts to diverse, evolving LLM application patterns.

What Problem Does This Paper Address?

Deploying LLMs in production environments requires maximizing throughput while minimizing latency. At the heart of this challenge lies the attention mechanism, which must constantly read from and write to the KV-cache (the memory storing historical context).

However, standard attention kernels (like FlashAttention) designed for model training fall short in inference serving due to two major challenges:

  1. Workload Dynamism: Inference requests arrive unpredictably with highly variable sequence lengths. Advanced serving techniques like prefix-sharing, speculative decoding, and multi-token parallel generation introduce complex, irregular attention patterns.
  2. Storage Heterogeneity: To prevent memory fragmentation, modern serving frameworks use non-contiguous storage layouts like paged attention or radix trees.

Existing solutions typically hardcode optimizations for a narrow subset of these patterns, leading to high maintenance overhead and an inability to easily support new attention variants (e.g., specialized masking or logit soft-capping).

Methods

FlashInfer tackles these challenges through a decoupled system architecture that separates hardware-specific compute optimizations from runtime scheduling.

Figure 1. Overview of the FlashInfer system design: Attention variant specifications, task information and KV-cache layout specifics are provided at compile time for JIT compilation, while sequence length information is input at runtime for dynamic scheduling.
  • Unified Block-Sparse Format: FlashInfer unifies fragmented memory layouts (paged attention, radix trees, sparse masks) under a single Block Compressed Sparse Row (BSR) matrix abstraction.
  • Composable Formats: Inspired by sparse compilers, FlashInfer allows developers to decompose the KV-cache. For instance, a shared system prompt (prefix) can be processed using a kernel optimized for large block sizes to maximize shared memory reuse, while the unique user query uses a fine-grained block size.
Figure 3. Composable formats for shared-prefix decomposition in attention computation. The queries corresponding to the first 6 rows have a shared prefix, as do the queries in the last 6 rows. We store the KV cache corresponding to the shared prefix in a block sparse matrix with a block size of (3, 1), while storing the remaining unique KV cache in another block sparse matrix with a block size of (1, 1). For block size (3, 1), 3 queries can share the same KV cache in high-bandwidth shared memory, while for block size (1, 1), each query access KV-Cache within its own threadblock, which can only go through low-bandwidth global memory or L2 cache.
  • JIT Compiler for Attention Variants: Instead of hand-writing CUDA kernels for every new model variant, users define mathematical modifications (like LogitsTransform) in Python/CUDA code strings. FlashInfer’s Just-In-Time (JIT) compiler automatically injects these into highly optimized templates.
  • Dynamic Load-Balanced Scheduling: To handle variable sequence lengths without sacrificing GPU utilization, FlashInfer introduces a runtime scheduler that splits long KV-caches into deterministic chunks. Crucially, it pre-allocates a fixed-size workspace buffer, making it fully compatible with the static execution requirements of CUDAGraph.

Datasets

The authors evaluated FlashInfer using both synthetic and real-world workloads:

  • ShareGPT: A widely used dataset of real user-chatbot conversations to simulate production traffic.
  • Variable Synthetic Workloads: Workloads with sequence lengths uniformly distributed between 512–2,048 tokens and 4,096–16,384 tokens to rigorously test input dynamism.
  • MT-Bench: Used to evaluate end-to-end multi-turn conversation performance within the Streaming-LLM framework.

Key Insights and Ideas

  • System Layouts as Sparse Matrices: The core conceptual leap is realizing that complex system-level memory management structures (like page tables) are mathematically equivalent to sparse matrices. This allows hardware-level tensor core optimizations to be applied directly to memory management.
  • Decoupling Scheduling from Compute: Traditional kernels bake the scheduling logic directly into the GPU code. By moving scheduling to a lightweight CPU runtime plan, FlashInfer can dynamically rebalance workloads per generation step without needing to recompile or re-capture the GPU execution graph.

Key Results

FlashInfer was integrated into leading frameworks like SGLang, vLLM, and MLC-Engine, demonstrating substantial performance gains on NVIDIA A100 and H100 GPUs:

  • End-to-End Serving: Integrated with SGLang, FlashInfer achieved a 29% to 69% reduction in inter-token latency (ITL) compared to SGLang's highly optimized, closed-source Triton backend.
  • Long-Context Acceleration: For Streaming-LLM (million-token inference), FlashInfer's fused RoPE-attention kernel delivered a 28% to 30% end-to-end latency reduction and improved memory bandwidth utilization by up to 3.7x.
  • Parallel Generation: When generating multiple tokens simultaneously in MLC-Engine, composable formats yielded up to a 17.4% speedup in ITL and a 22.8% speedup in Time-To-First-Token (TTFT).
  • Fine-Grained Sparsity: On the Quest algorithm (which prunes KV-caches at a fine granularity), FlashInfer outperformed PyTorch SDPA and FlexAttention by up to 20x.

Limitations and Future Work

  • Forward Pass Only: FlashInfer currently only supports the forward pass for inference. Extending its customizable template design to support the backward pass for training and fine-tuning is left for future work.
  • Hardware-Specific Constraints: Hopper’s Tensor Memory Accelerator (TMA) does not natively support non-affine sparse gathering, forcing FlashInfer to fall back to Ampere-style asynchronous copies for sparse layouts.
  • Host-Side Overhead: In frameworks like vLLM, heavy Python-side array operations during integration caused minor regressions in certain dense workloads. The authors plan to port the runtime scheduler entirely to C++ to eliminate this bottleneck.

Summary updated

BibTeX
@misc{ye2025flashinfer,
  author = {Zihao Ye and Lequn Chen and Ruihang Lai and Wuwei Lin and Yineng Zhang and Stephanie Wang and Tianqi Chen and Baris Kasikci and Vinod Grover and Arvind Krishnamurthy and Luis Ceze},
  title = {{FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving}},
  year = {2025},
  eprint = {2501.01005},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.01005},
}
Figure