x-transformers
X-Transformers
What it is and what it does
x-transformers is a PyTorch library that provides composable transformer components—Encoder, Decoder, and full encoder-decoder (XTransformer)—along with experimental architectural improvements from recent papers. It supports standard use cases like GPT-style language modeling, BERT-style encoding, vision transformers (ViT), and multimodal tasks like image captioning and vision-language models. The library integrates Flash Attention for memory-efficient training, memory tokens for improved attention dynamics, and persistent memory key-values as alternatives to feedforward layers.
The package is designed for researchers and practitioners building custom transformer models. Dependencies include torch for the core computation, einops and einx for tensor operations, loguru for logging, and packaging for version handling. It requires Python 3.9+ and is actively maintained, with recent releases indicating ongoing development.
Use it for:
- Build a GPT-like decoder-only language model with configurable depth, heads, and sequence length
- Implement a BERT-style encoder for text classification or token-level tasks
- Create a vision transformer (ViT) for image classification on custom datasets
- Combine a vision encoder with a text decoder for image-to-caption generation
- Experiment with Flash Attention or memory tokens to reduce training memory footprint
- Prototype multimodal models like PaLI that fuse vision and language encoders
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
x-transformers provides modular transformer building blocks—encoder, decoder, and encoder-decoder architectures—with experimental features like Flash Attention, memory tokens, and persistent memory for research and production use.
Yes. x-transformers is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and offers a well-designed API for building transformer variants. It is worth installing if you need modular transformer components with experimental features like Flash Attention or memory tokens. Install friction is low. The main constraint is the torch dependency and GPU requirement for practical training.
Install
x-transformers on PyPI
pip
pip install x-transformersuv
uv add x-transformerspoetry
poetry add x-transformersInstalling x-transformers
Before you install
Low friction: pure Python wheel with six runtime dependencies (torch, einops, einx, loguru, packaging, torch-einops-utils). Active maintenance with a release 5 days ago.
License in practice
MIT License permits unrestricted use, modification, and distribution in both open and proprietary projects, with only the requirement to include the original copyright notice and license text.
Quickstart
pip install x-transformers
import torch
from x_transformers import TransformerWrapper, Decoder
model = TransformerWrapper(
num_tokens=20000,
max_seq_len=1024,
attn_layers=Decoder(dim=512, depth=12, heads=8)
).cuda()
x = torch.randint(0, 256, (1, 1024)).cuda()
output = model(x)
Requires PyTorch and CUDA-capable GPU for practical use; torch dependency must be installed separately.
Verify before relying
- Whether Flash Attention integration requires PyTorch 2.0+ or works with earlier versions
- Memory and compute requirements for training models at scale
- Performance benchmarks against other transformer libraries
Package facts
| License | MIT License Copyright (c) 2020 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — einops, einx, loguru, packaging, torch-einops-utils, torch |
| Maintenance | actively maintained — 5 days since the last release |
| First released | |
| Downloads | 1,401,439/month — #3,951 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: x_transformers-2.25.5-py3-none-any.whl
Keywords: artificial intelligence, attention mechanism, transformers
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
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
xformersXFormers provides reusable, composable building…
permissive · top 5,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI
local-attentionImplements local windowed attention for…
permissive · top 15,000 on PyPI
axial-positional-embeddingProvides axial positional embeddings for…
permissive · top 15,000 on PyPI
rotary-embedding-torchImplements rotary positional embeddings for…
permissive · top 15,000 on PyPI
vector-quantize-pytorchImplements vector quantization layers for…
permissive · top 5,000 on PyPI
fla-coreProvides hardware-efficient implementations of…
permissive · top 15,000 on PyPI