skillfed

x-transformers

X-Transformers

x-transformers v2.25.5 1.4M downloads/30d#3,951 on PyPI
Permissive 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) Active released

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-transformers

uv

uv add x-transformers

poetry

poetry add x-transformers

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.6Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

transformer architecture libraryencoder decoder implementationattention mechanism pytorchflash attention supportvision transformer vitlanguage model building blocksmultimodal transformer
transformer-architecturevision-languageattention-mechanism

More Artificial Intelligence packages

Further reading