Registry / llm-agents / flashinfer-python

flashinfer-python

JSON →
library0.6.17pypypi✓ verified 25d ago

FlashInfer is a high-performance kernel library for optimizing Large Language Model (LLM) inference on NVIDIA GPUs. It provides efficient CUDA kernels for operations like paged attention, prefill, and decode. Currently at version 0.6.7.post3, the library is under active development with frequent patch releases and nightly builds, indicating rapid evolution and potential API changes.

pip install flashinfer-python
INSTALL
IMPORT
SIG · FLASHINFER-PYTHON
F
flashinfer-python
llm-agentspythonv0.6.17
Install
81.3s avg
Import
13913ms
Disk
5299MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.17 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 89.3s
py 3.11
✕ build_error
✓ 82.45s
py 3.12
✕ build_error
✓ 78.05s
py 3.13
✕ build_error
✓ 75.25s
py 3.9
✕ build_error
✕ build_error
5299MB installed
● package 5299MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flashinfer
import flashinfer as fi
BatchDecodeWithPagedKVCache
from flashinfer import BatchDecodeWithPagedKVCache
BatchPrefillWithRaggedKVCache
from flashinfer import BatchPrefillWithRaggedKVCache
PagedKVCache
from flashinfer.core import PagedKVCache

This quickstart demonstrates how to set up `PagedKVCache` and use `BatchDecodeWithPagedKVCache` to perform a single-token decode operation. It simulates a sequence already present in the cache and then processes a new query token, highlighting the typical workflow for LLM inference.

import torch import flashinfer as fi # Ensure CUDA is available if not torch.cuda.is_available(): raise RuntimeError("CUDA is not available. FlashInfer requires a CUDA-enabled GPU.") # Device and dtype device = "cuda" dtype = torch.float16 # Model parameters (simplified for example) num_layers = 1 # In real models, usually multiple num_heads = 32 kv_heads = 32 head_dim = 128 page_size = 16 max_total_seq_len = 2048 # Max tokens in KV cache across all sequences # 1. Initialize PagedKVCache # This manages the memory for key/value states on the GPU kv_cache = fi.core.PagedKVCache( num_layers=num_layers, num_kv_heads=kv_heads, head_dim=head_dim, page_size=page_size, max_num_pages=max_total_seq_len // page_size, device=device, data_type=dtype, ) # 2. Create a BatchDecodeWithPagedKVCache wrapper # This object prepares the inputs for the underlying attention kernels decode_wrapper = fi.BatchDecodeWithPagedKVCache( kv_cache=kv_cache, num_heads=num_heads, kv_heads=kv_heads, head_dim=head_dim, sm_scale=1.0 / (head_dim**0.5), # Standard attention scale dtype=dtype, ) # 3. Simulate adding a sequence to the cache (prefill step) # In a real LLM serving scenario, this would populate the cache with initial tokens. batch_size_decode = 1 # Decoding one sequence prefill_len = 50 # Length of the sequence already in cache # Allocate pages for a new sequence of `prefill_len` seq_idx_in_batch = kv_cache.begin_forward(prefill_len) # In a real application, you'd populate kv_cache with actual K/V from a prefill operation. # For this example, we just simulate the cache being 'ready' for decode. kv_cache.end_forward(seq_idx_in_batch, prefill_len) # Commits the pages, making the sequence ready for decode. # 4. Prepare query tensor for decode # Query for the next token, shape (batch_size, 1, num_heads, head_dim) query_decode = torch.randn(batch_size_decode, 1, num_heads, head_dim, dtype=dtype, device=device) # 5. Perform the decode operation for the next token output = decode_wrapper.decode(query_decode) print(f"FlashInfer BatchDecode output shape: {output.shape}") print("FlashInfer decode successful.")
Debug
Known issues
gotchaFlashInfer is a kernel library requiring an NVIDIA GPU with a compatible CUDA runtime. It will not work on CPUs or other accelerators. Using pre-built wheels requires a matching CUDA toolkit version (e.g., cu118 for CUDA 11.8); a mismatch often leads to `RuntimeError` or `ModuleNotFoundError`.
fix
Ensure your system has a compatible NVIDIA GPU. When installing, verify that the `flashinfer-python` wheel's CUDA version tag (+cuXXX) matches your installed CUDA toolkit, or build from source if no matching wheel is available.
affects: All versions
breakingThe library is under active development and not yet at a 1.0 release. Frequent minor and patch releases (including nightly builds) may introduce API changes or breaking modifications to function signatures and class constructors.
fix
Pin `flashinfer-python` to a specific version (`flashinfer-python==x.y.z`) to prevent unexpected breakage. Always refer to the official GitHub repository's README and examples for the latest API usage patterns when upgrading.
affects: All versions prior to 1.0
gotchaFlashInfer's API, particularly for `PagedKVCache` and attention wrappers, is relatively low-level. Incorrect setup of internal metadata, page tables, or buffer management can lead to subtle bugs, incorrect attention calculations, or memory access violations.
fix
Thoroughly review official documentation and examples for `PagedKVCache` and high-level wrappers like `BatchDecodeWithPagedKVCache` to ensure correct initialization, sequence management, and tensor data handling.
affects: All versions
gotchaFlashInfer is tightly coupled with PyTorch for tensor operations and device management. While `torch` is a dependency, ensure your PyTorch version is compatible, especially when using specific CUDA versions or pre-built FlashInfer wheels.
fix
Check FlashInfer's documentation or GitHub issues for recommended PyTorch versions. If encountering issues, try aligning PyTorch with the CUDA version targeted by your FlashInfer installation (e.g., `pip install torch==2.x.x+cuXXX`).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flashinfer'
Users often mistakenly try to install or import a package named `flashinfer` instead of the correct `flashinfer-python` as listed on PyPI, or they try to import a submodule that doesn't exist in their installed version.
fix
Ensure you install the correct package name: `pip install flashinfer-python`. When importing, use `import flashinfer` (the package itself) and then access its functions, or explicitly import the correct submodules if they exist in your version.
AttributeError: module 'setuptools.build_meta' has no attribute 'prepare_metadata_for_build_editable'
This error typically occurs during installation from source or editable installs when `pip` and/or `setuptools` are outdated and do not support newer build meta features.
fix
Upgrade pip and setuptools to their latest versions: `python -m pip install --upgrade pip setuptools`.
RuntimeError: Could not find nvcc
FlashInfer requires `nvcc` (NVIDIA CUDA Compiler) to be accessible in the system's PATH for JIT compilation of its CUDA kernels. This error means `nvcc` could not be located.
fix
Ensure the CUDA Toolkit is installed correctly and that the `bin` directory of your CUDA installation (e.g., `/usr/local/cuda/bin`) is added to your system's PATH environment variable. You might also need to install `build-essential` or `python3-dev` on Linux.
RuntimeError: FlashInfer requires sm75+
This error indicates that FlashInfer's kernels, which rely on Tensor Cores and specific block-interleaving schemes for high performance, require a GPU with a compute capability of SM75 (Turing architecture) or newer. Your GPU might be older or CUDA might not be correctly configured to detect its compute capability.
fix
If your GPU is indeed SM75+ (e.g., RTX 20 series or newer), ensure your CUDA drivers and toolkit are correctly installed and detected. If using vLLM, you can disable FlashInfer or rebuild it for your specific GPU architecture by setting `export TORCH_CUDA_ARCH_LIST='YOUR_GPU_SM_NUMBER'` (e.g., '8.6' for RTX 3090) before reinstalling `flashinfer-python`.
AttributeError: module 'flashinfer' has no attribute 'batch_prefill_with_paged_kv_cache'
This `AttributeError` often arises due to API changes between FlashInfer versions, where a specific function or module has been renamed, moved, or removed. It can also happen if the user's installed version is older than the one expected by the code.
fix
Consult the official FlashInfer documentation for your installed version to verify the correct API usage. If the function is missing, you might need to upgrade FlashInfer to a newer version (`pip install --upgrade flashinfer-python`) or adjust your code to use the currently available equivalent function.
Upgrade
Version history
0.6.17latest on PyPI · released Aug 11, 2026
Audit
Dependencies
torchrequiredFlashInfer kernels integrate with PyTorch tensors; it's a direct dependency for array manipulation and device management.
Agent activity
68 hits · last 30 days
node
62
OpenAI (training)
1
Resources
flashinfer-python — pip install flashinfer-python · libregistry