T5X: High-Performance Sequence Model Training Framework for JAX

Jul 6, 2025

Introduction

Training large-scale language models often involves a grueling battle against distributed compute bottlenecks, data infeeding issues, and the sheer complexity of managing TPU clusters. T5X, developed by Google Research, is a modular, composable framework designed to eliminate these frictions, enabling researchers to train sequence models at massive scales with high performance. By transitioning the original T5 codebase from Mesh TensorFlow to JAX and Flax, T5X provides a research-friendly environment for the training, evaluation, and inference of models with hundreds of billions of parameters on multi-terabyte datasets.

What Is T5X?

T5X is a modular, composable, research-friendly framework for high-performance, configurable, self-service training, evaluation, and inference of sequence models, starting with language models. It is essentially a new and improved implementation of the T5 codebase (originally based on Mesh TensorFlow) rewritten in JAX and Flax. Maintained by Google Research and released under the Apache-2.0 license, T5X allows developers to define model architectures and training pipelines through a flexible configuration system, making it a primary tool for scaling up Transformer-based architectures.

Why T5X Matters

Before T5X, training models at the scale of the original T5 required specialized knowledge of Mesh TensorFlow, which was often cumbersome for researchers to modify or extend. The shift to JAX and Flax provides a more intuitive, functional programming approach to model definition and parallelism. This allows for faster iteration cycles and more efficient use of hardware, particularly Google Cloud TPUs.

T5X fills a critical gap by providing a standardized way to handle model and data partitioning across multiple TPU hosts. It integrates deeply with SeqIO, a companion library for reproducible input and evaluation pipelines, ensuring that the data feeding process does not become a bottleneck for the compute. This combination makes T5X one of the few open-source frameworks capable of training models with hundreds of billions of parameters while maintaining a research-friendly API.

Key Features

  • JAX and Flax Integration: T5X is built on JAX and Flax, leveraging the XLA (Accelerated Linear Algebra) compiler for high-performance execution on TPUs and GPUs.
  • Modular Model Architecture: The framework uses a BaseModel abstract class, allowing researchers to easily subclass it to define custom architectures (e.g., Encoder-Decoder or Decoder-only) without worrying about parallelism logic.
  • Scalable Partitioning: T5X includes a sophisticated partitioning system that handles the distribution of model weights and activations across TPU pods, separating the model definition from the hardware configuration.
  • SeqIO Integration: By utilizing SeqIO, T5X ensures that training and evaluation pipelines are reproducible and that data is preprocessed and mixed according to a high-level task-based API.
  • XManager Support: T5X is designed to work with XManager on Vertex AI, which automates the creation and shutdown of TPU instances, simplifying the deployment of large-scale experiments.
  • Comprehensive Checkpointing: The framework provides robust tools for saving and restoring model states, including support for importing checkpoints from the original TensorFlow-based T5 models.
  • Flexible Configuration via Gin: T5X uses Gin-config to allow users to define hyperparameters, model architectures, and dataset mixtures without changing the underlying Python code.
  • Multi-Hardware Support: While optimized for TPUs, T5X can be run on GPUs in single-node or multi-node configurations using SLURM+pyxis clusters.

How T5X Compares

Feature T5X Original T5 (MeshTF) Hugging Face Transformers
Backend Framework JAX / Flax Mesh TensorFlow PyTorch / TensorFlow
Primary Target Large-scale Research Original T5 Paper General Purpose / Deployment
Scaling Capability Hundreds of Billions of Params High (but complex) Moderate to High
Configuration Gin-config Python/Config files JSON / Python API
Data Pipeline SeqIO TF Data Datasets Library

T5X represents a significant evolution over the original T5 implementation. While the original T5 was a breakthrough in the text-to-text framework, its reliance on Mesh TensorFlow made it difficult for the broader research community to extend. T5X solves this by using JAX, which is far more flexible and allows for a more functional approach to model parallelism. Compared to Hugging Face Transformers, T5X is less about “plug-and-play” deployment and more about the infrastructure required to train a state-of-the-art model from scratch at a massive scale.

The primary tradeoff is the learning curve. T5X requires a deep understanding of JAX and the Gin configuration system. However, for researchers who need to train models with billions of parameters across TPU pods, the performance and scalability provided by T5X are unmatched by most general-purpose libraries.

Getting Started: Installation

T5X is primarily designed for use on Google Cloud Platform (GCP) TPU VMs. The following steps outline the installation process for a TPU VM environment.

Prerequisites

A Google Cloud Platform account with TPU quota (Vertex AI API enabled) and a TPU VM instance.

TPU VM Installation

# SSH into your TPU VM
gcloud compute tpus tpu-vm ssh ${TPUVMNAME} --zone=${TPUVMZONE} -- -L 8888:localhost:8888

# Update and install Python 3.9
sudo apt update
sudo apt install -y python3.9 python3.9-venv

# Create a virtual environment
python3.9 -m venv t5_venv
source t5_venv/bin/activate

# Install core dependencies
python3 -m pip install -U pip setuptools wheel ipython
pip install flax

# Clone and install T5X
git clone https://github.com/google-research/t5x
cd t5x
python3 -m pip install -e '.[tpu]' -f https://storage.googleapis.com/jax-releases/libtpu_releases.html

# Verify TPU access
python3 -c "import jax; print(jax.local_devices())"

Vertex AI / XManager Installation

For those using Vertex AI, T5X integrates with XManager to automate TPU instance management. Follow the pre-requisites in the T5X documentation to install XManager and launch scripts via t5x/scripts/xm_launch.py.

How to Use T5X

The T5X workflow revolves around the interaction between a Gin configuration file, a model architecture, and a SeqIO task. The basic process for running an experiment is as follows:

  1. Define the Model: Choose a model architecture (e.g., EncoderDecoderModel) and define its parameters in a Gin config file.
  2. Define the Data: Use SeqIO to define the dataset mixture and the preprocessing steps.
  3. Launch the Job: Use the t5x.main binary or an XManager script to launch the training or evaluation job on the TPU cluster.
  4. Monitor: Use TensorBoard to monitor the loss and metrics provided by the T5X trainer.

For a simple “Hello World” scenario, researchers typically start with the provided Colab notebooks, which use an InteractiveModel to run inference or small-scale training on natural text inputs without needing a full TPU pod.

Code Examples

The following examples demonstrate how T5X components are instantiated and used. These are simplified versions of the patterns found in the official T5X introductory Colabs.

Example 1: Running Inference with InteractiveModel

The InteractiveModel is a high-level wrapper that simplifies the process of restoring a checkpoint and running inference on a few examples.

from t5x.interactive_model import InteractiveModel
from t5x.examples.t5 import network

# Define the model and its configuration
model = InteractiveModel(
    model_config=network.T5Model,
    checkpoint_path="gs://t5-data/pretrained_models/t5x/t5_1_1_small.ckpt",
    # Other config options like vocab and optimizer
)

# Run inference on a natural text input
predictions = model.infer_with_preprocessors(
    ["translate English to German: Hello, how are you?"]
)
print(predictions)

Example 2: Launching a Training Job via XManager

This example shows the command-line pattern used to launch a large-scale training run using a Gin config file.

export GOOGLE_CLOUD_BUCKET_NAME=my-t5x-bucket
export TFDS_DATA_DIR=gs://$GOOGLE_CLOUD_BUCKET_NAME/t5x/data
export MODEL_DIR=gs://$GOOGLE_CLOUD_BUCKET_NAME/t5x/$(date +%Y%m%d)

python3 ./t5x/scripts/xm_launch.py \
  --gin_file=t5x/examples/t5/t5_1_1/examples/base_wmt_from_scratch.gin \
  --model_dir=$MODEL_DIR \
  --tfds_data_dir=$TFDS_DATA_DIR

Advanced Configuration

T5X relies heavily on Gin-config for its flexibility. Instead of passing arguments to Python constructors, you define the configuration in a .gin file. This allows you to change the model size, optimizer settings, or dataset mixtures without modifying the code.

Example of a typical Gin configuration for a T5 model:

# Model Architecture
network.T5Model.num_layers = 12
network.T5Model.num_heads = 8
network.T5Model.d_model = 512

# Optimizer Settings
t5x.train_state.Optimizer.learning_rate = 1e-4

# Dataset Mixture
seqio.Task.dataset_name = "c4"
seqio.Task.preprocessor = @my_preprocessor

# Partitioning
partitioning.T5Partitioning.model_parallelism = 8

Real-World Use Cases

T5X is specifically designed for scenarios where standard deep learning libraries fail to scale. It shines in the following concrete scenarios:

  • Pre-training Massive Language Models: A researcher at a large lab can use T5X to pre-train a model with 100B+ parameters on a multi-terabyte corpus (like C4) across a TPU pod, ensuring the model weights are partitioned correctly across hosts.
  • Fine-tuning for Domain-Specific Tasks: An NLP engineer can take a pre-trained T5X checkpoint and fine-tune it for a specialized domain (e.g., medical or legal text) using SeqIO to define a custom task mixture for the same scale.
  • Developing New Transformer Architectures: A researcher can subclass BaseModel to implement a new variant of the Transformer (e.g., a new attention mechanism) and immediately test its scaling laws by running it on a single TPU host and then scaling to a pod.
  • T5X Retrieval: Using the T5X Retrieval extension, developers can build high-performance dense retrieval and ranking models (like SentenceT5) that are optimized for search applications.

Contributing to T5X

T5X is a research-oriented project maintained by Google Research. While it is open-source, contributions are primarily handled through the standard GitHub flow. Users can report bugs via the GitHub Issues tab and suggest improvements through Pull Requests. Because the framework is tightly coupled with Google’s internal infrastructure (like XManager and TPU pods), many contributions focus on improving the documentation, adding new model examples, and fixing bugs in the JAX/Flax implementation.

[/et_pb_column]

Community and Support

T5X is widely used in the research community, particularly those with access to TPU clusters. Support is primarily provided through GitHub Discussions and the official T5X ReadTheDocs documentation. The project is highly active in terms of commits, as it is the primary framework for many of Google’s latest sequence model research papers. For those new to the framework, the introductory Colab notebooks are the recommended starting point for learning the T5X API.

Conclusion

T5X is the definitive tool for researchers and engineers who need to train sequence models at the absolute limit of current hardware. By moving to JAX and Flax, Google Research has created a framework that is more modular, more performant, and more flexible than its predecessors. While the learning curve is associated with JAX and Gin-config, the ability to scale to hundreds of billions of parameters is a critical advantage.

If you are training a small-to-medium model for a general application, a library like Hugging Face Transformers may be more suitable. However, if your goal is to push the boundaries of NLP research and train a state-of-the-art model from scratch on TPU pods, T5X is the right choice. Star the repo, try the introductory Colabs, and begin scaling your models.

What is T5X and what problem does it solve?

T5X is a JAX-based framework for training sequence models at scale. It solves the problem of distributed compute bottlenecks and the complexity of managing TPU pods, allowing researchers to train models with hundreds of billions of parameters efficiently.

How do I install T5X?

T5X is best installed on a GCP TPU VM. You can clone the repository, create a Python 3.9 virtual environment, and install the dependencies using pip install -e '.[tpu]'. For automated deployment, use XManager on Vertex AI.

How does T5X compare to the original T5?

T5X is a rewrite of the T5 codebase in JAX and Flax, replacing the original Mesh TensorFlow backend. This makes it more modular, research-friendly, and more performant on TPU hardware.

Can I use T5X for decoder-only models?

Yes, T5X supports both encoder-decoder and decoder-only architectures. While it was created with the T5 architecture in mind, it can be used to train other sequence models, including GPT-like models.

What is the relationship between T5X and SeqIO?

T5X handles the model training and compute distribution, while SeqIO provides the task-based API for reproducible data pipelines and evaluation. They are designed to be used together as a complementary pair of libraries.

Does T5X support GPUs?

T5X can be run on GPUs, though it is highly optimized for TPUs. It can be run in single-node or multi-node configurations using SLURM+pyxis clusters.

Can I use T5X for retrieval applications?

T5X Retrieval is a specialized implementation optimized for neural retrieval and ranking models, such as sentence encoders and dense retrieval models, built on top of the T5X framework.

What license does T5X use?

T5X is released under the Apache-2.0 license, making it open-source and available for both research and academic use.