xFormers
Hackable and optimized Transformers building blocks
...One of its key goals is efficient attention: it supports dense, sparse, low-rank, and approximate attention mechanisms (e.g. FlashAttention, Linformer, Performer) via interchangeable modules. The library includes memory-efficient operator implementations in both Python and optimized C++/CUDA, ensuring that performance isn’t sacrificed for modularity. It also integrates with PyTorch seamlessly so you can drop in its blocks to existing models, replace default attention layers, or build new architectures from scratch. xformers includes training, deployment, and memory profiling tools.