lucidrains/x-transformers

A concise but complete full-attention transformer with a set of promising experimental features from various papers

What it solves

This project provides a concise, ready-to-use implementation of the Transformer architecture. It addresses the complexity of building custom models by offering a modular framework that integrates various experimental and state-of-the-art features from academic research, allowing developers to easily experiment with advanced techniques like Flash Attention, specialized normalization, and sparse attention mechanisms.

How it works

The library provides high-level wrappers (TransformerWrapper, XTransformer, ViTransformerWrapper) that allow users to configure encoder, decoder, or vision-transformer architectures with simple Python arguments. Users can toggle advanced features—such as memory tokens, gated linear units (GLU), or specific normalization methods—by setting boolean flags or parameters within the model configuration. It is built on PyTorch, enabling seamless integration into existing deep learning workflows.

Who it’s for

It is designed for researchers and machine learning engineers who want to build or experiment with Transformer-based models without writing the underlying architecture from scratch. It is particularly useful for those looking to test specific architectural improvements or optimizations (like memory efficiency or faster convergence) proposed in recent AI research papers.

Highlights

  • Flash Attention: Built-in support for memory-efficient, high-speed attention kernels.
  • Versatile Architectures: Supports encoder-only (BERT-like), decoder-only (GPT-like), and encoder-decoder configurations.
  • Vision Integration: Includes wrappers for Vision Transformers (ViT) and multimodal tasks like image captioning.
  • Research-Backed Features: Easy access to advanced techniques like RMSNorm, GLU variants, sparse attention, and persistent memory tokens.
  • Training Stability: Offers multiple normalization and initialization options to help stabilize training for large-scale models.

Related

  • Project
  • Project
  • Project
  • Project
  • Project