14 million tokens per sequence: MaxText v0.2.4 adds context parallelism for long-context training on TPUs
Google Cloud's open-source JAX framework MaxText now offers four context-parallel strategies, training Llama 3.1 8B at up to 14M tokens on TPU 5p and TPU 7.

TL;DR
- MaxText v0.2.4 adds four context-parallel strategies: All-gather, All-to-All (Ulysses), P2P ring attention and the USP hybrid [1].
- Google reports 70% MFU for Llama 3.1 8B on TPU 5p up to 4M tokens, and runs up to 14M tokens on TPU 5p and TPU 7 [1].
- Users pick a strategy with context_parallel_strategy (ring, ulysses or usp) and set the context-parallel size [1].
Google has added long-context training support to MaxText, Google Cloud’s open-source JAX training framework, through four context-parallel strategies on Cloud TPU [1]. The feature ships in MaxText v0.2.4, which is on PyPI, in the matching Docker images and on the GitHub main branch [1]. MaxText itself is published as an open-source project on GitHub [2].
Why it matters
Google notes that context windows have grown from 128K-200K tokens to 1M-2M in three years, and that training at those lengths, not just serving them, is where system limits appear [1]. At multi-million-token lengths, attention compute grows quadratically with sequence length, and replicating keys and values on every chip exhausts high-bandwidth memory (HBM) [1]. Context parallelism splits one long sequence across chips so that no chip holds the activations of the whole sequence [1]. For supported models, users choose the strategy and context-parallel size through MaxText configuration [1].
The four strategies
- All-gather: each chip gathers keys and values from every other chip at every layer; it is the simplest option but needs load balancing because of causal masking [1].
- All-to-All (Ulysses): swaps sequence sharding for head sharding, so it cannot split across more chips than the model has heads; tensor parallelism times context parallelism is capped by the KV-head count [1].
- P2P (ring attention): key/value chunks travel around a ring of chips while each chip computes, so communication overlaps compute [1].
- A2A + P2P (USP): combines All-to-All on one mesh axis with a ring on the other to scale past the head limit [1].
All four use the Splash Attention kernel from Tokamax, Google’s open-source library of TPU kernels [1].
Benchmarks
With Llama 3.1 8B, Google reports 70% Model FLOPs Utilization (MFU) on TPU 5p for sequence lengths up to 4 million tokens, and context lengths up to 14 million tokens on both TPU 5p and TPU 7 [1]. Training 14M tokens with P2P on 64 TPU 7 chips reached 48.7% MFU, compared with 37.1% on TPU 5p, which Google attributes in part to TPU 7 having twice the HBM per chip [1].
How to choose and use it
Google recommends All-gather when the gathered keys and values fit in HBM, All-to-All alone on a few chips up to the number of KV heads, and the ring family once they no longer fit, with USP preferred when the KV heads allow it and P2P for MLA models such as DeepSeek [1]. When memory runs short, the guidance is to offload activations, optimizer states and parameters to host memory before falling back to rematerialisation [1]. To turn it on, users set context_parallel_strategy to ring, ulysses or usp, set the context-parallel size, and keep the rest of the run unchanged [1]. The support is for Cloud TPU; Google lists models that mix sliding-window and global attention, such as Gemma, and linear attention variants as planned next steps [1].
Sources
Written and checked by AI from the sources below
Fact-checked by gpt-6.1-sol on · Editorial policy



