█

AI/TLDR

Buy me a coffee
Buy me a coffee

MaxText

Google's pure-JAX LLM library for pre-training and post-training on Cloud TPUs and GPUs

Efficient TrainingOpen source
Language
Python
License
Apache-2.0
IN SHORT

What is MaxText?

MaxText is an open-source LLM library and reference implementation from Google's AI Hypercomputer team, written in pure Python and JAX and aimed at training on Google Cloud TPUs and on GPUs. It sits in the Efficient Training category of the Training & Fine-Tuning tools and is open-source, written in Python and licensed Apache-2.0.

Overview

MaxText is an open-source LLM library and reference implementation from Google's AI Hypercomputer team, written in pure Python and JAX and aimed at training on Google Cloud TPUs and on GPUs. It aims for high Model FLOPs Utilization and tokens per second from a single host up to very large clusters, while staying simple and largely "optimization-free": instead of hand-tuned kernels everywhere, it leans on JAX and the XLA compiler to do the heavy lifting. The project describes itself as a launching point — run it out of the box, then fork and modify it for your own model.

At its core is a library of model implementations you pick by name: Gemma, Llama, DeepSeek, Qwen, Mistral/Mixtral, Kimi, GPT-OSS and others, dense and mixture-of-experts, plus multimodal training for Gemma 3, Gemma 4 and Llama 4 vision-language models. Every run is driven by a YAML config (`configs/base.yml` describes a roughly 1B-parameter decoder-only model) whose options you can override on the command line, so switching model, batch size, sequence length or dataset is a matter of changing `key=value` arguments rather than code.

MaxText covers both halves of the training lifecycle. For pre-training it provides opinionated implementations of sharding, quantization and checkpointing, and reads data through HuggingFace, Grain or TFDS input pipelines. For post-training it uses Google's Tunix library for supervised fine-tuning and reinforcement learning (GRPO and GSPO), with vLLM doing the sampling. The same vLLM adapter lets you decode or serve MaxText checkpoints, and HuggingFace checkpoints can be converted into MaxText's format to start from an existing model.

It is built on the JAX AI stack — Flax for the networks, Optax for optimization, Orbax for checkpointing and Grain for data loading — and is distributed on PyPI and as pre-built container images. A decoupled mode runs MaxText without any Google Cloud dependencies, and Google Kubernetes Engine is the documented route for multi-host jobs. The code is Apache-2.0.

What it does

  • Model library of JAX implementations — Gemma, Llama, DeepSeek, Qwen, Mistral/Mixtral, Kimi and GPT-OSS families among them — selected with a single `model_name=` flag
  • Pre-training that scales from one host to tens of thousands of chips, with built-in sharding, quantization and checkpointing strategies
  • Post-training through Tunix: supervised fine-tuning plus GRPO and GSPO reinforcement learning, on single-host or multi-host TPUs, with vLLM as the sampler
Diagram of MaxText's GRPO reinforcement-learning loop inside a single Pathways cluster: an RL trainer holding the models and the GRPO/GSPO algorithm sends updated weights every K steps to vLLM samplers on TPUs, which read prompts from an input pipeline and return samples to the trainer, with Pathways orchestration on CPU coordinating both sides
Reinforcement learning in MaxText: the trainer (MaxText models, Tunix algorithms) and vLLM samplers on TPU exchange samples and weights under Pathways orchestration.MaxText docs ↗
  • Three data input pipelines — HuggingFace (streamed from the Hub), Grain (ArrayRecord or Parquet) and TFDS — with optional evaluation steps during training
  • Inference on vLLM through an out-of-tree model plugin, for offline decoding with `vllm_decode` or an online `vllm serve` endpoint
  • YAML configs overridable from the command line, checkpoint conversion from HuggingFace, and a decoupled mode that drops the Google Cloud dependencies

Getting started

MaxText is tested on Linux and recommends Python 3.12 inside a virtual environment managed by `uv`. For production work the maintainers recommend the PyPI release or the pre-built images; the steps below follow the documented from-source path, which is the one to take if you intend to fork and modify the code.

Prepare a bucket for outputs

On Google Cloud, create a Cloud Storage bucket for logs and checkpoints and make sure your TPU or GPU VM's service account can read and write it. Every run writes to it through `base_output_directory`.

Clone the repository and create a virtual environment

bashbash
git clone https://github.com/AI-Hypercomputer/maxtext.git
cd maxtext
uv venv --python 3.12 --seed <VENV_NAME>
source <VENV_NAME>/bin/activate

Install the variant for your hardware

Pick one option per environment: `tpu` for pre-training and decoding on TPUs, `cuda12` for GPUs. Post-training (and vLLM decoding on TPU) uses the separate `tpu-post-train` option — start from a fresh virtual environment when switching.

bashbash
# TPU
uv pip install -e .[tpu] --resolution=lowest
install_tpu_pre_train_extra_deps

# or NVIDIA GPU
uv pip install -e .[cuda12] --resolution=lowest
install_cuda12_pre_train_extra_deps

Run a short pre-training job

This streams the C4 dataset from the HuggingFace Hub and trains DeepSeek-V2-Lite for ten steps. The log reports step time, TFLOP/s per device, tokens per second per device and loss for every step.

bashbash
python3 -m maxtext.trainers.pre_train.train \
base_output_directory=gs://<GCS_BUCKET> run_name=demo \
model_name=deepseek2-16b per_device_batch_size=1 steps=10 max_target_length=2048 enable_checkpointing=false \
dataset_type=hf hf_path=allenai/c4 hf_data_dir=en train_split=train \
tokenizer_type=huggingface tokenizer_path=deepseek-ai/DeepSeek-V2-Lite

Move on to post-training or inference

Add `eval_interval=5 eval_steps=10 hf_eval_split=validation` to evaluate during training. For SFT or RL, and for decoding a converted checkpoint with vLLM, follow the post-training and inference tutorials in the MaxText docs; on multiple hosts, run MaxText on Google Kubernetes Engine.

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Reach for it when you are pre-training an LLM on Cloud TPUs and want a high-MFU JAX codebase you can fork rather than write from scratch
  • Reach for it to fine-tune or run GRPO/GSPO reinforcement learning on an open model such as Qwen, Llama or DeepSeek on TPU hardware
  • Reach for it when you are experimenting with model design at scale — dense versus MoE, sharding layouts, sequence lengths — and want every knob exposed as a config override
  • Reach for it when your team works in JAX and wants the Flax, Optax, Orbax and Grain stack wired together for LLM training

How MaxText compares

MaxText alongside other open-source efficient training tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
DeepSpeed★ 43.4kA deep learning optimization library whose ZeRO memory partitioning and offloading let you train very large models across many GPUs.
Megatron-LM★ 18.6kNVIDIA's library for training large transformer models at scale using tensor, pipeline, and sequence parallelism.
Accelerate★ 10kA library that runs the same PyTorch training code across CPUs, multiple GPUs, and TPUs while handling mixed precision, FSDP, and DeepSpeed.
DeepSpec★ 7.3kDeepSeek's codebase for training and evaluating draft models for speculative decoding, bundling data preparation, the DSpark, DFlash and Eagle3 drafters, training code and benchmarks.
TorchTitan★ 6kA PyTorch-native platform for pre-training large models that combines FSDP, tensor, pipeline, and context parallelism in one codebase.
LightlySSL★ 3.8kA modular PyTorch framework for self-supervised computer vision: losses, model heads and multi-view transforms for 20+ methods from MoCo and SimCLR to DINOv2, CAPI and LeJEPA.
Nanotron★ 2.9kHugging Face's minimal library for pre-training LLMs with 3D parallelism, designed to be readable and easy to modify.
MaxText★ 2.5kGoogle's pure-JAX LLM library for pre-training and post-training on Cloud TPUs and GPUs