GoogleMichael Tran, Nuojin Cheng, Deepak PatilAnnouncement
Announcing Long-Context Training on TPUs with MaxText Context Parallelism
Summary
MaxText v0.2.4, Google Cloud’s open-source JAX training framework, now supports long-context training on Cloud TPUs through four context-parallel strategies: All-gather, A2A (DeepSpeed Ulysses), P2P (Ring Attention), and the A2A + P2P hybrid (Unified Sequence Parallelism, or USP). These strategies split a long sequence across chips to avoid exhausting high-bandwidth memory, and all use the Tokamax Splash Attention kernel. In benchmarks with Llama 3.1 8B on TPU 5p, P2P achieved 70% Model FLOPs Utilization (MFU) for sequences up to 4 million tokens. Context can be extended to 14 million tokens on both TPU 5p and TPU 7, with TPU 7 maintaining 50% MFU below 6 million tokens. The choice of strategy depends on whether gathered KV fits in HBM and on the number of KV heads, with offloading recommended before recomputation when memory is low.
Context
Long-context training, including pretraining and post-training, has become a foundation of frontier AI models. Longer native sequence lengths give LLMs the working memory to read a whole code repository or ingest hours of video, and reason through multi-step agentic tasks. In three years, context windows have grown from 128K–200K tokens to 1M–2M, and models trained toward 10M tokens are arriving. Efficient training at multi-million-token sequence lengths runs into bottlenecks: attention FLOPs grow quadratically with sequence length, and activations including keys and values for every token grow with sequence length, exhausting HBM and triggering out-of-memory failures.
Approach / What changed
MaxText v0.2.4 supports four context-parallel strategies on Cloud TPU: All-gather, A2A (DeepSpeed Ulysses), P2P (Ring Attention), and the A2A + P2P hybrid (Unified Sequence Parallelism, or USP), all using the Tokamax Splash Attention kernel. The choice depends on whether gathered KV fits in HBM and on the number of KV heads. When gathered KV fits, All-gather with load balancing is simplest and often fastest. When it does not, the ring family is recommended, with USP preferred when KV heads allow an A2A factor of 2 or more, and P2P alone for MLA models or when head count does not divide.
Takeaways
MaxText v0.2.4 supports four context-parallel strategies on Cloud TPU: All-gather, A2A (Ulysses), P2P (Ring Attention), and the A2A + P2P hybrid (USP), all using the Tokamax Splash Attention kernel.
P2P (Ring Attention) is the primary workhorse for very long-context training, outperforming All-gather at almost every context length from 64K to 14M tokens on a 64-chip TPU 5p slice with Llama 3.1 8B.
When memory is low, offload saved activations, optimizer states, and parameters to host memory before recomputing; at long context lengths, these transfers are hidden behind compute, making offloading effectively free.
FAQ
What is context parallelism in MaxText?
Context parallelism splits a long sequence across chips so no chip holds the activations of the whole sequence. It can be combined with data and tensor parallelism, and the smallest context-parallel size that fits your sequence in HBM is usually the right one.
How do I choose a context parallelism strategy?
The choice depends on whether the gathered KV fits in HBM and on the number of KV heads. When gathered KV fits, use All-gather with load balancing. When it does not, use the ring family: USP when KV heads allow an A2A factor of 2 or more, and P2P alone for MLA models or when head count does not divide.
What performance does P2P achieve at long context?
In benchmarks with Llama 3.1 8B on a 64-chip TPU 5p slice, P2P outperformed All-gather at almost every context length from 64K to 14M tokens. On 64 TPU 7 chips, P2P training of 14M tokens reached 48.7% MFU compared to 37.1% on TPU 5p.
Source and freshness
- Source
- developers.googleblog.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.