xformers
XFormers: A collection of composable Transformer building blocks.
What it is and what it does
XFormers is a library of modular, reusable components for building Transformer neural networks. Rather than implementing entire architectures as monolithic models, it provides composable building blocks—attention mechanisms, layer variants, and other Transformer primitives—that can be combined to reproduce state-of-the-art model designs. The library targets researchers and practitioners who want flexibility in assembling custom Transformer architectures without reinventing core components.
It depends on torch for computation and numpy for numerical operations. Installation requires Python 3.9 or later and involves platform-specific compiled wheels, which adds moderate setup friction but ensures optimized performance on supported systems (Linux x86_64 and Windows x86_64).
Use it for:
- Build custom Transformer architectures by combining xformers blocks instead of implementing layers from scratch.
- Experiment with different attention mechanisms and layer configurations for research or model optimization.
- Integrate efficient attention implementations into existing PyTorch models to reduce memory usage or improve speed.
- Reproduce published Transformer variants by assembling their documented building-block combinations.
- Prototype novel Transformer designs by swapping and reconfiguring composable components.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
XFormers provides reusable, composable building blocks for constructing Transformer neural network architectures, enabling flexible assembly of state-of-the-art model variants without monolithic implementations.
Yes, if you are building or experimenting with Transformer architectures in PyTorch. XFormers is actively maintained, has no known vulnerabilities, uses a permissive BSD license, and ranks in the top 5000 PyPI packages by download volume. The medium install friction (platform-specific wheels) is a minor trade-off for the modularity and performance benefits it provides. Not necessary if you only use pre-built, monolithic Transformer models.
Install
xformers on PyPI
pip
pip install xformersuv
uv add xformerspoetry
poetry add xformersInstalling xformers
Before you install
Medium install friction due to compiled wheel dependencies (xformers ships platform-specific wheels for Python 3.9+ on Linux and Windows). Active maintenance with a recent release as of 2026-02-20. Requires torch and numpy as runtime dependencies.
License in practice
BSD License (permissive) means you can use, modify, and distribute xformers with minimal restrictions, provided you include the license notice.
Quickstart
pip install xformers torch numpy
import xformers
from xformers.ops import memory_efficient_attention
# Use composable transformer blocks in your model
Requires Python 3.9 or later; torch and numpy must be installed. Platform-specific wheels available for Linux (manylinux_2_28_x86_64) and Windows (win_amd64).
Verify before relying
- Whether xformers provides performance improvements over standard PyTorch transformer implementations in typical use cases.
- Compatibility with other transformer frameworks or whether it is PyTorch-specific.
- Availability of pre-built wheels for ARM64 or other architectures beyond x86_64.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 2 — torch, numpy |
| Maintenance | actively maintained — 175 days since the last release |
| First released | |
| Downloads | 2,196,828/month — #3,220 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: xformers-0.0.35-py39-none-manylinux_2_28_x86_64.whl; xformers-0.0.35-py39-none-win_amd64.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
curated-transformersCurated Transformers provides PyTorch…
permissive · top 5,000 on PyPI
x-transformersx-transformers provides modular transformer…
permissive · top 5,000 on PyPI
spacy-transformersIntegrates pretrained transformer models (BERT,…
permissive · top 15,000 on PyPI
fla-coreProvides hardware-efficient implementations of…
permissive · top 15,000 on PyPI
adaptersAdapters adds parameter-efficient fine-tuning…
permissive · top 15,000 on PyPI
megatron-coreMegatron Core provides GPU-optimized building…
permissive · top 15,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
XBlockXBlock is a Python component architecture for…
permissive · top 15,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI
spandrel-extra-archesRegisters additional PyTorch model…
permissive · top 15,000 on PyPI