GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
MLSys 2025

FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving

The attention library inside SGLang, vLLM and MLC-Engine: every KV layout as one block-sparse format, custom variants compiled on demand, uneven batches balanced. 29-69% lower latency in SGLang.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2025
AUTHORS
Ye, Chen, Lai, Lin, et al.
FROM
University of Washington, NVIDIA, Perplexity AI, Carnegie Mellon University
PUBLISHED
Jan 2025 · MLSys 2025
CITED BY
376Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 21% of this breakdown.

01

The paper in one minute

Training mostly runs dense attention on fixed-size batches. Serving doesn't. The KV cache lives in pages (vLLM) or a radix tree (SGLang); a batch mixes new prompts and single-token decodes; many requests share a system prompt; speculative decoding verifies trees of guesses; and models keep adding attention variants (sliding windows, logit soft-capping, fused rotary embeddings). Each engine had been writing its own kernels for its own subset.

FlashInfer is an attention library built for that mix, with three ideas.

One format for every KV layout. A page table or a prefix tree is a block-sparse row (BSR) matrix: rows are queries, columns are KV blocks, and a non-zero block means "this query attends to this page". FlashInfer's kernels accept any block size, gathering scattered pages into contiguous shared memory before using tensor cores. Composable formats split one cache into two views: a shared prefix stored with a large row block (many queries together), so its KV is loaded once into fast on-chip memory for the whole group; and each request's own tokens with single-row blocks. No data moves; only the index arrays differ.

Customizable attention, compiled just in time. A variant is specified as small functions (query and key transforms such as RoPE, a logits transform such as soft-capping, a mask), and FlashInfer generates CUDA from FlashAttention-2 or -3 templates, picking a query tile size (1 to 128) to match the batch's average query length.

Load balancing that survives CUDA graphs. Each step, a CPU-side plan splits long KV sequences into equal chunks across the GPU's processors and records where partial results go; persistent kernels with fixed grid sizes then run inside a captured graph and merge partial results with the log-sum-exp composition.

Integrated into SGLang, vLLM and MLC-Engine, it cut SGLang's median inter-token latency 29-69% against Triton kernels, StreamingLLM latency 28-30% with a fused kernel, and parallel-generation inter-token latency 13.7-17.4% with composable formats.

THE IDEA, VISUALLY
EVERY KV LAYOUT AS A BLOCK-SPARSE MATRIX (SECTION 3.1) rows = queries (requests), columns = KV pages r0 r1 r2 r3 shared prefix (pages 0-1) for r0-r2: one block with 3 query rows, read once into shared memory; own pages: 1-row blocks Composable formats: same page table, two block sizes, no data moved CUSTOM ATTENTION, COMPILED JUST IN TIME (3.2) write the variant as small functors: query/key transform (e.g. RoPE), logits transform (soft-cap, sigmoid), mask; FlashInfer generates CUDA from FA2/FA3 templates query tile 1/16/32/64/128 picked from the average query length BALANCE EVERY STEP, KEEP CUDA GRAPHS (3.3) plan() on the CPU: split long KV into equal chunks per SM, map partial outputs to final ones (deterministic order) run() inside a captured CUDA graph: persistent kernels merge partials with the log-sum-exp composition Integrated in SGLang, vLLM and MLC-Engine END-TO-END RESULTS (SECTION 4) SGLang: median inter-token latency -29% to -69% vs Triton backend; Llama 3.1 8B and 70B StreamingLLM with fused RoPE -28% to -30% latency vs unfused FlashAttention fused RoPE kernel bandwidth 1.6-3.7x vs RoPE kernel + attention kernel parallel generation, n = 4 -13.7% / -17.4% ITL, 8B / 70B, composable formats WHY KERNELS LOSE: SKEWED BATCHES (FIG. 8) batch 16 with Zipf lengths (mean 1,024): one unit of work per request leaves most SMs idle while the longest finishes; FlashInfer's balanced split beat FlashAttention on uniform and skewed lengths for decode and prefill MEASURED ON A100 40GB and H100 80GB, fp16, CUDA 12.4; SGLang v0.3.4, P99 TTFT held under 200 ms; ShareGPT and 512-2,048-token synthetic requests
FlashInfer sees paged caches, prefix trees and speculative trees as one block-sparse matrix of queries against KV blocks, so one kernel family serves them all and shared prefixes are read once per group.
Research notes: the problem, approach and results
29-69%

lower median inter-token latency in SGLang with FlashInfer than with its Triton attention backend

1.6-3.7x

more memory bandwidth used by a fused RoPE-plus-attention kernel than separate RoPE and attention kernels

3

major serving engines integrating it: SGLang, vLLM and MLC-Engine

THE PROBLEM

Serving engines need attention kernels for many shapes at once: paged or tree-structured KV caches, prefill and decode mixed in one batch, shared prefixes, speculative trees, and new attention variants. Batches have very uneven lengths that leave GPU cores idle, and CUDA graphs, which serving relies on to cut launch overhead, require fixed launch configurations.

THE IDEA

Represent any KV layout as a block-sparse row matrix (queries by KV blocks) with arbitrary block sizes, and combine formats so shared prefixes use bigger blocks read once into shared memory. Provide an attention template whose variants (masks, logit transforms, RoPE) are compiled just in time. Plan work on the CPU each step to split long KV evenly across processors with persistent kernels that stay CUDA-graph compatible.

THE RESULT

Inside SGLang, median inter-token latency fell 29-69% against the Triton backend on Llama 3.1 8B and 70B. A fused RoPE kernel cut StreamingLLM latency 28-30%, and composable formats cut inter-token latency 13.7-17.4% for parallel generation.

02

Why it matters to an FDE

Most engineers never call FlashInfer directly; it sits under the serving engine. It still shows up in deployments in three ways.

It's a setting. SGLang and vLLM let you choose the attention backend. On the same model and GPU, the choice changed inter-token latency by up to 69% in the paper's SGLang tests, so check which backend a slow deployment uses before tuning anything else.

New model features need kernel support. A model with soft-capped logits, an unusual mask or a new positional scheme runs slowly, or not at all, until the attention kernels support it. JIT templates are what let engines support new variants quickly.

Batch shape matters. Mixed lengths, shared prompts and parallel sampling all change which kernel path is fastest. If a customer's traffic is highly skewed (a few very long contexts among many short ones), load-balanced kernels are what keep the GPU busy.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 149 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    Block-sparse KV, composable formats, tile selection, plan/run scheduling and three misreadings

    Free account
  2. 04How it works

    The BSR format, data loading, JIT variants, the planner and the API

    Premium
  3. 05The numbers that matter

    Serving results, kernel utilization, long-context and parallel generation

    Premium
  4. 06Try it yourself

    Run attention through a BSR page table, count prefix reads, balance skewed batches and size tiles

    Premium
  5. 07Where it breaks

    NVIDIA-only kernels, CPU planning cost, benchmark scope and slips

    Premium
  6. 08Using it on a deployment

    Choosing the attention backend, checking variant support, and testing on real batch shapes

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →