xFormers
Meta's toolbox of optimized transformer building blocks, best known for memory-efficient attention kernels.
About
Memory-efficient attention was popularized by xFormers, Meta's toolbox of optimized, composable transformer building blocks that predates and still complements PyTorch's built-in scaled dot product attention. The library provides exact attention kernels the maintainers measure at up to 10x faster than naive implementations, block-sparse and sparse attention variants, and fused operations for softmax, linear layers, layer norm, SwiGLU, and dropout-activation chains, all exposed as independent components that slot into existing PyTorch models. It remains a default acceleration dependency across the ecosystem: Stable Diffusion tooling, LLM fine-tuning stacks, and inference servers list it for its attention speed and memory savings. Prebuilt wheels install via pip alongside recent PyTorch on Linux and Windows with CUDA 12.6 through 13.0, experimental ROCm 7.1 wheels cover AMD hardware on Linux, and building from source needs a full CUDA toolchain. The code is BSD-3-Clause licensed and holds about 10,500 GitHub stars, and research teams use its components to prototype new attention mechanisms without writing Triton or CUDA from scratch.
Should you use xFormers?
Pick it when
Use it when your diffusion or transformer stack lists it for memory-efficient attention, or you are prototyping new attention variants and fused ops in PyTorch without writing Triton or CUDA yourself.
Look elsewhere when
Recent PyTorch ships built-in scaled dot product attention, so check whether your project still needs the extra dependency. Wheels must match your PyTorch and CUDA versions, and AMD support is still experimental.
Alternatives to xFormers
- FlashAttention
Dedicated exact attention kernels with Hopper and Blackwell versions, but narrower: no general fused layer components.
- Liger Kernel
Fuses norms, RoPE, SwiGLU, and loss for Hugging Face LLMs with a one-line patch; targets training memory, not attention.
- PyTorch
Built-in scaled dot product attention covers memory-efficient attention with no extra install or wheel version matching.
- Triton (OpenAI)
Lets you write your own GPU kernels in Python when xFormers' components do not cover your attention variant.
Reviews (0)
Leave a Review
No reviews yet. Be the first to review!
Details
- Category
- Model Training & Fine-Tuning
- Price
- Free
- Platform
- Local/Desktop
- Difficulty
- Intermediate (3/5)
- License
- BSD-3-Clause
- Added
- Jul 29, 2026