Context parallelism splits a long training sequence across several accelerator chips, so no single chip must hold the entire sequence. Google added four such...
How Google MaxText Trains LLMs with Contexts up to 14 Million Tokens
Context parallelism splits a long training sequence across several accelerator chips, so no single chip must hold the entire sequence. Google added four such strategies to MaxText, its open-source JAX framework, and reports training Llama 3.1 8B with contexts reaching 14 million tokens on Cloud TPUs.
Key Takeaways- MaxText supports All-Gather, All-to-All (Ulysses), P2P (Ring Attention), and a hybrid A2A + P2P approach called USP.
- Ring Attention is the main choice for very long contexts when memory is the limiting factor; All-Gather is a practical baseline when the key-value data fits.
- Google reports up to 70% Model FLOPs Utilization for sequences up to four million tokens on TPU v5p, and support for contexts up to 14 million tokens on TPU v5p and TPU v7.
- Those results are tied to particular models, hardware, and configurations. They are not a promise of identical speed on every workload.
I’m Ermenildo Castro, and I’ve spent enough time around distributed systems to distrust a single impressive benchmark number. It can show what a system achieved, but it does not tell you what it cost, how hard it was to reproduce, or whether the same setup suits your model. With long-context training, those details matter. A training run can hit a memory ceiling before its accelerators reach their compute limit, and throwing more chips at the job does not automatically fix the problem. The chips must share sequence data efficiently, while the software avoids copying more of that data than the task requires.
The practical question is not simply, Can this model accept fourteen million tokens? It is whether the chosen parallel strategy, attention pattern, hardware topology, and training recipe can handle the context at a useful speed. MaxText’s four options give engineers more ways to answer that question. Here is what each one does, where the reported results fit, and what to check before treating a huge context window as a production plan.
What Is Context Parallelism in MaxText?
Context parallelism (CP) divides the sequence dimension of a training example among multiple devices. One chip works on one portion of the tokens, while other chips work on different portions. The training step still needs attention across the full sequence, so the devices must exchange key and value data, or otherwise arrange the data so each query can see the relevant tokens.
That exchange is the central design choice. A simple implementation can gather keys and values from every sequence shard onto each device. It is easy to understand, but the gathered tensors can consume a great deal of high-bandwidth memory (HBM). Other approaches send data between devices in stages, or rearrange it across attention heads. Each method trades memory use, communication volume, compute overlap, and scaling limits differently.
Long sequences are expensive for two separate reasons. Full attention compute grows roughly with the square of sequence length: doubling the tokens can mean about four times the attention work. Meanwhile, many activations and key/value tensors grow roughly in proportion to sequence length. At millions of tokens, both pressures bite. Flash-style attention kernels can avoid storing the full attention matrix, but they cannot make the underlying attention calculation free.
One terminology wrinkle is worth clearing up. A KV cache usually refers to data kept during inference so a model can generate tokens without recomputing past keys and values. During training, engineers more often discuss key/value activations and saved intermediate tensors. The memory problem is related, but it is not quite the same cache used by a serving system.
MaxText is Google’s open-source training framework built with JAX, and its MaxText repository documents the project and its implementation. The four strategies are All-Gather, All-to-All (Ulysses), P2P (Ring Attention), and A2A + P2P (USP). Nathan Beach, a Google director, has pointed out that on TPUs with multi-million-token contexts, attention memory is often the first wall a training team hits—not raw compute. That observation is a useful reminder: a fast chip cannot process data that does not fit or arrive in time.
Core Benefits and Why Context Parallelism Matters
The first benefit is straightforward: context parallelism lets a training job divide a sequence that would overwhelm one device. Instead of asking every chip to store the complete token sequence, the system assigns each chip a slice. With the right communication pattern, the model can still compute attention across the full context.
- Lower per-device memory pressure. Keeping only a portion of the sequence on each device can make longer training examples possible. Ring-style methods are especially useful when gathering every key and value onto every chip would exceed HBM. This does not erase model weights, optimizer states, or other memory costs, but it targets a major sequence-related pressure point.
- More room for useful training examples. A large context can let a model learn from a complete code repository, a long technical document, or a video transcript spanning hours. The point is not to stuff every example with tokens; it is to make long, connected material available when the task needs it.
- A choice of communication patterns. All-Gather can be a sensible baseline when its memory use is acceptable. Ulysses can suit configurations with enough attention heads to distribute. Ring Attention can stream blocks around a device group. USP combines approaches to address limits that arise when a single method does not fit the hardware or model.
- A way to use multiple accelerators for one sequence. In ordinary data parallelism, devices often process separate examples. Context parallelism adds another axis: devices cooperate on different parts of the same example. Real training setups combine parallelism methods, but the distinction helps explain why a massive example can be divided across a TPU pod.
I have seen teams treat memory as a simple capacity question: if the tensor does not fit, add devices. Here’s the kicker: adding devices also adds communication. A strategy that saves memory but spends too much time moving data can produce a slower training run, even when every chip has spare compute. The useful metric is the balance between memory use and time spent on work that advances the model.
Google reports strong results using Llama 3.1 8B on Cloud TPU systems. Its reported figures include 70% Model FLOPs Utilization (MFU) for sequence lengths up to four million tokens on TPU v5p, around 50% MFU for sequence lengths below six million tokens, and support for contexts up to fourteen million tokens on TPU v5p and TPU v7. MFU estimates how much of a system’s theoretical floating-point capability is being used for model work; it is a useful signal, not a complete measure of cost or training quality.
The reported P2P MFU was 48.7% on TPU v7 and 37.1% on TPU v5p. Do not read that as a controlled head-to-head test of chip generations unless the full setup says so. Hardware, device count, sequence length, batch size, and kernel choices all affect the result. Still, the numbers show that long-context training does not have to mean abysmal utilization. Good engineering here is also a kind of stewardship: expensive compute should do useful work, not sit idle while data crawls between chips.
Step-by-Step: How to Choose and Implement a Strategy
A good implementation starts with the workload, not a favorite algorithm. These steps give a practical way to approach context parallelism in MaxText.
- Describe the actual training task. Write down the model architecture, target context length, attention pattern, global batch size, and training objective. Include whether the model uses full attention, sliding-window attention, or a mix. I have watched teams tune kernels for a target length before confirming that their training examples actually need that much context. That is an expensive way to discover a requirements problem.
- Estimate memory before launching a large run. Account for model parameters, optimizer state, gradients, activations, attention intermediates, and communication buffers. Use the framework’s supported configuration and profiling tools where available. Treat a first estimate as a floor, not a promise: temporary buffers, padding, and framework behavior can add pressure. For background on JAX’s distributed data model, consult its guide to distributed arrays and automatic parallelization.
- Start with All-Gather if the data fits. It is a useful baseline because its behavior is comparatively direct. If the gathered keys and values fit comfortably in HBM, test it before reaching for a more complicated strategy. Record tokens per second, MFU, peak memory, and the time spent in communication. A baseline is not glamorous, but it tells you what the other methods must beat.
- Test P2P for very long sequences. Ring Attention passes key and value blocks from device to device in rounds, allowing each query shard to accumulate attention results as blocks arrive. This can keep memory use lower than materializing the full set of keys and values on every chip. The Ring Attention paper describes the method and its goal of overlapping blockwise attention with communication. In practice, check whether the TPU links and kernels overlap those operations effectively; a paper’s algorithm does not guarantee a particular cluster’s performance.
- Check whether Ulysses fits the head layout. All-to-All (Ulysses) rearranges sequence and attention dimensions so devices can work across the sequence with a different communication pattern. Its scaling can be constrained by the number of attention heads or key/value heads available to distribute. The DeepSpeed Ulysses paper explains sequence parallelism through all-to-all communication. Test it against the model’s actual head structure, especially if it uses grouped-query or multi-query attention.
- Try USP when a hybrid is warranted. A2A + P2P combines all-to-all and point-to-point communication so a setup can use each method where it fits. This is not a magic fourth option that always wins; its value depends on topology, head count, context size, and implementation. Compare it with a simpler approach before accepting extra configuration and debugging work.
- Benchmark the complete training step. Measure steady-state throughput after compilation and warm-up, not just a kernel in isolation. Record peak HBM, MFU, tokens per second, scaling as devices are added, and whether the run stays stable. Google’s Cloud TPU documentation covers TPU hardware and platform details, but your own benchmark is still the final word for your recipe.
Keep the first test small. Then increase sequence length and device count in stages, changing one major variable at a time. That makes failures easier to explain. If a run crashes at four million tokens, you want to know whether the cause was memory, a communication timeout, an unsupported attention path, or a configuration mismatch—not guess based on a log full of unrelated changes.
Comparison Table: All-Gather vs. Ring Attention and Other Strategies
There is no single winner. The right option depends on whether the workload is constrained by HBM, device-to-device communication, attention-head layout, or engineering complexity. The table compares the four MaxText approaches at a practical level; exact costs depend on the implementation and TPU configuration.
| Strategy | Main idea | HBM pressure | Communication and overlap | Useful when |
|---|
| All-Gather | Gather key/value data across context shards so each device can use it | Higher; gathered data can be replicated | Collective communication; straightforward baseline | KV data fits and a simple reference is valuable |
| All-to-All (Ulysses) | Rearrange sequence and attention dimensions across devices | Can be lower than full replication, depending on layout | All-to-all exchange; scaling depends on head structure | Attention heads can be distributed across the chosen device group |
| P2P (Ring Attention) | Pass key/value blocks around a ring and accumulate attention in stages | Lower extra memory; streams blocks | Point-to-point traffic can overlap with attention compute | Very long contexts make gathered KV data too large |
| A2A + P2P (USP) | Combine all-to-all and point-to-point communication | Depends on the hybrid configuration | Uses multiple communication patterns | A single method’s limits make a hybrid worth testing |
All-Gather is the baseline; P2P is the long-context workhorse. That is the practical guidance Google highlights. A baseline is helpful when the relevant key and value tensors fit. Ring Attention is a stronger candidate when memory pressure dominates and streaming blocks can keep the chips busy. The original Ring Attention research is useful background, while the Ulysses research paper helps explain the all-to-all alternative.
What does the table leave out? Device topology, kernel maturity, and the exact attention implementation. A communication-heavy method can look good on paper and disappoint if the system cannot overlap transfers with useful compute. Conversely, a method that uses more memory may be faster when the model is small enough and the communication path is the real bottleneck.
Frankly, choosing by the strategy name alone is like choosing a car by its engine label. Measure the actual training configuration. Compare like with like: same model, sequence length, global batch, precision, and device count where possible. If the configuration differs, report the differences instead of pretending the MFU figures settle the question.
Common Mistakes to Avoid
Mistake 1: Treating the maximum context as a throughput target. A system that can train at fourteen million tokens has demonstrated capacity under a specific setup. It has not proved that every run should use fourteen million tokens, or that such a run will be cheap. Keep the context as short as the task permits. Use a longer span when it adds needed information, not because the maximum sounds impressive.
Mistake 2: Assuming the memory bottleneck disappears. Context parallelism spreads sequence data, but it does not remove model weights, optimizer states, gradients, or all activations. Nor does it turn quadratic attention compute into linear work. I once saw a training estimate built around sequence memory alone; the rest of the training state made the plan fail before the first serious run. Count the entire working set.
Mistake 3: Ignoring communication time. Adding more chips can reduce each chip’s local slice and still make a step slower if communication grows or overlaps poorly. Track communication and compute separately where the tooling allows it. A high utilization number is useful, but pair it with tokens per second and total run time. The model has to finish, not merely produce a tidy dashboard.
Mistake 4: Assuming every architecture works with every strategy. The current work identifies future support for architectures that mix sliding-window and global attention, as well as linear-attention mechanisms such as Gated Delta Net (GDN) and Kimi Delta Attention (KDA). Those plans matter because an attention strategy suited to full attention may not map cleanly onto a different pattern. Check what the current MaxText version actually supports before planning a large run.
Mistake 5: Comparing hardware results as if nothing else changed. Google reports P2P MFU of 48.7% on TPU v7 and 37.1% on TPU v5p. Those values show results on the two systems, but alone they do not isolate why the results differ. Model configuration, device count, sequence length, software version, and kernel path can all matter. State the test conditions, or the comparison is mostly noise.
Mistake 6: Making a complicated strategy the default too soon. Teams sometimes jump past a simple baseline because a hybrid sounds more advanced. More moving parts mean more tuning and more places for a configuration to go wrong. Start with All-Gather where it fits; test P2P when memory becomes the wall; try Ulysses or USP when the architecture and measurements justify them. Good engineering respects people’s time as well as machine time.
Google lists several areas for future work: broader architecture support, optimization of Tokamax kernels, improvements to the P2P backward pass, and recipes tailored to model, context length, and TPU architecture. That list is a useful caution. A headline result shows what the team has measured; it does not mean every workload already has a polished recipe.
Frequently Asked Questions
What is context parallelism in LLM training?
Context parallelism splits a sequence across multiple accelerator devices. Each device handles part of the tokens, while communication lets the model compute attention across the larger sequence. It can lower per-device sequence memory, but it adds communication and does not remove the quadratic compute cost of full attention.
Which context-parallel strategy should I use in MaxText?
Use All-Gather as a baseline when the gathered key and value data fits comfortably in memory. For very long contexts where memory is the first constraint, test P2P (Ring Attention). Ulysses and USP can suit other head layouts or communication needs. Benchmark the real model and hardware; no strategy wins every case.
Can MaxText train a model with a 14-million-token context?
Google reports support for context lengths up to fourteen million tokens on TPU v5p and TPU v7, with results using Llama 3.1 8B. That is a reported capability for particular configurations, not a guarantee that every model, architecture, or training recipe will run at that length. Check current MaxText support and run staged tests.
What does MFU mean, and is higher always better?
Model FLOPs Utilization estimates the share of theoretical accelerator floating-point capacity used for model computation. Higher MFU can indicate efficient hardware use, but it does not by itself tell you cost per training run, tokens per second, convergence, or whether the workload meets its goal. Read it alongside throughput, memory use, and total time.
Final Thought
MaxText’s context-parallel options address a real engineering problem: training examples can outgrow the memory and communication patterns that worked at shorter lengths. The four strategies give teams practical choices instead of forcing one design onto every model. All-Gather offers a clear starting point. P2P streams data for workloads where memory is tight. Ulysses and USP offer different ways to distribute attention work when the model and device layout make them suitable.
The reported fourteen-million-token result is striking, but the lesson is not to chase the biggest number. Ask what information the model needs, estimate the full training footprint, and measure the end-to-end step on the hardware you will actually use. If a shorter context answers the task, it may be the better engineering choice. If the long context is essential, then communication design, kernel quality, and careful benchmarking deserve the same attention as raw accelerator count.
MaxText 0.2.4 is available through PyPI, Docker Hub, and GitHub. That gives engineers a concrete place to start, but a repository is not a substitute for a workload-specific test. I prefer a modest benchmark with honest measurements over a grand promise. The useful outcome is a model that trains reliably, uses resources responsibly, and can handle the information its users genuinely need.