flashinfer-ai/flashinfer
FlashInfer: Kernel Library for LLM Serving
FlashInfer – High‑Performance GPU Kernels for LLM Inference
What it is
- A C++/CUDA library (with a Python package) that ships a collection of highly‑optimized GPU kernels for the core operations needed when serving large language models (LLMs). It focuses on attention, matrix‑multiply (GEMM), mixture‑of‑experts (MoE) routing, sampling, and a few supporting ops.
Why it matters
- LLM inference is often bottlenecked by the speed of attention and GEMM kernels, especially when serving many concurrent requests (prefill + decode) or when using low‑precision formats (FP8/FP4). FlashInfer bundles multiple backend implementations (FlashAttention‑2/3, cuDNN, CUTLASS, TensorRT‑LLM) and automatically picks the fastest one for the GPU you have, delivering "state‑of‑the‑art" throughput on everything from Turing GPUs (RTX 20) up to the newest Blackwell chips.
Key capabilities
| Area | What FlashInfer provides |
|---|---|
| Attention | • Paged/ragged KV‑cache for dynamic batching • Separate kernels for pre‑fill, decode, and mixed (POD) workloads • Support for DeepSeek MLA, cascade (hierarchical) attention, block‑sparse patterns, and custom JIT‑able variants |
| GEMM / Linear | BF16, FP8, FP4 matrix multiplication; grouped GEMM for LoRA/MoE; Blackwell‑specific NVFP4/MXFP4 kernels |
| Mixture‑of‑Experts | Fused MoE kernels with several routing algorithms (DeepSeek‑V3, Llama‑4, top‑k) and quantized expert weights |
| Sampling / Decoding | Sorting‑free top‑k / top‑p / min‑p sampling; speculative decoding support |
| Communication | Custom AllReduce, multi‑node NVLink (MNNVL) and NVSHMEM integration for distributed inference |
| Other ops | RoPE (including LLaMA 3.1), fused RMSNorm/LayerNorm, fused SiLU/GELU activations |
Hardware coverage
- Works on any NVIDIA GPU from Turing (SM 7.5) onward. Specific kernels are tuned for Ampere, Ada Lovelace, Hopper, and the newest Blackwell architectures, with low‑precision (FP8/FP4) paths only on the latter.
How you use it
- Install the Python wheel:
pip install flashinfer-python(optional extra wheels give pre‑compiled kernels or JIT‑cache shims). - Call the high‑level API, e.g.
flashinfer.single_decode_with_kv_cache(q, k, v)for a single‑decode attention step, or use the richer batch APIs for prefill. - The library integrates with PyTorch’s
torch.compileand CUDA Graphs, so you can embed it in low‑latency serving stacks.
Ecosystem adoption
- Integrated into major open‑source inference servers such as vLLM, TensorRT‑LLM, HuggingFace Text Generation Inference, SGLang, MLC‑LLM, LightLLM, Lorax, and ScaleLLM.
Documentation & community
- Full docs at https://docs.flashinfer.ai, a Slack community, and a GitHub discussion forum. CI badges show continuous testing across CUDA versions (12.9, 13.0, 13.4).
When to pick FlashInfer
- You need the fastest possible attention/GEMM kernels on NVIDIA GPUs, especially if you serve mixed prefill‑decode workloads, want low‑precision (FP8/FP4) inference, or run on newer Blackwell hardware. It is a drop‑in replacement for the attention kernels used by existing PyTorch‑based servers.
All details above are taken directly from the repository’s README.
Related
- Project
- Project
- Project
- Project
- Project