--- id: x-transformers version: "2.25.5" 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) license_treatment: permissive maintenance: active --- # x-transformers — X-Transformers License: permissive · Maintenance: active · Downloads: 1.4M/mo ## 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 above — 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 pip install x-transformers uv add x-transformers 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_current - Install friction: low - Maintenance: active - Downloads: 1.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags transformer architecture library, encoder decoder implementation, attention mechanism pytorch, flash attention support, vision transformer vit, language model building blocks, multimodal transformer, transformer-architecture, vision-language, attention-mechanism [View on SkillFed](https://skillfed.io/packages/x-transformers) · [View on PyPI](https://pypi.org/project/x-transformers/)