Context parallelism is the technique that lets a language model train on sequences too long for any single chip’s memory by splitting one sequence across many chips. Google added four context-parallel strategies to MaxText, its open-source JAX training framework, in version 0.2.4, and reports training Llama 3.1 8B at up to 14 million tokens per sequence on Cloud TPUs, with 70% model FLOPs utilization (MFU) up to 4 million tokens on TPU 5p. This explainer walks through how the four strategies work, using Google’s published results as a worked example.
Why long-context training hits a wall
Context windows have grown from roughly 128,000–200,000 tokens to 1–2 million in three years, Google notes, and models trained toward 10 million tokens are arriving. Serving a long context is one problem; training on it is harder, for two reasons.
- Attention compute grows quadratically. Every token attends to every earlier token, so doubling the sequence roughly quadruples attention work. At multi-million-token lengths, attention dominates the training step.
- Activations grow linearly. The keys and values for every token, the same data that forms the KV cache at inference time, must be held during training along with other activations. Copying all of them onto every chip quickly exhausts high-bandwidth memory (HBM).
Other forms of parallelism do not solve this. Data parallelism splits the batch, and tensor parallelism splits weight matrices, but both still require each chip to process a full sequence. Memory-saving schemes such as ZeRO shard optimizer state and parameters, not the activations of a single long sequence. Context parallelism splits the sequence itself.
The core problem: attention is global
Most of a transformer’s work is local to each token: the feed-forward layers process tokens independently, so splitting the sequence across chips is easy. Attention is the exception. Each token’s query must meet the keys and values of all preceding tokens, which now live on other chips. Every context-parallel strategy is a different answer to one question: how do you bring those keys and values together without running out of memory or waiting on the network?
Google frames the trade-off along three axes: how much key-value (KV) data each chip must hold, how much data moves per layer and whether that movement can overlap with computation, and how many attention heads the model has to split.
Strategy 1: All-gather
Each chip keeps its chunk of the sequence and, at every layer, collects the keys and values from all other chips. It is the simplest approach and, when it fits, often the fastest. The drawback is memory: every chip ends up holding the KV for the whole sequence, so it is the first strategy to run out of HBM as sequences grow.
There is also a load-balancing issue. With causal attention, later tokens attend to longer prefixes than earlier ones, so a chip holding the end of the sequence does more work. MaxText reorders chunks to balance this. Google recommends All-gather, with load balancing on, whenever the gathered KV fits in memory; it can be cheap for models using grouped-query attention, whose KV is small.
Strategy 2: All-to-All (DeepSpeed Ulysses)
Ulysses, introduced by Microsoft’s DeepSpeed team in 2023, changes what each chip owns. Attention is independent across heads, so before attention an all-to-all exchange converts “a slice of tokens for all heads” into “all tokens for a few heads”. Each chip then runs ordinary attention with standard kernels, and a second exchange converts the result back.
KV memory per chip shrinks with the number of chips, and no token load balancing is needed. But there are two limits. You cannot split across more chips than the model has heads, and under grouped-query attention the cap is the number of KV heads, which is eight for Llama 3 8B. And the exchange cannot overlap with compute, because attention cannot start until every chip has its full sequence.
Strategy 3: Ring attention (P2P)
Ring attention, described by Hao Liu and colleagues at UC Berkeley in 2023, never gathers the full sequence. Chips form a ring; each holds its own queries and passes KV chunks to its neighbor one hop at a time. While a chip computes attention against the chunk it currently holds, the next chunk is already in transit, and partial results are merged as they arrive.
Each chip only ever holds its own chunk plus one visiting chunk, and communication overlaps compute. There is no head-count ceiling. The costs are that smaller chunks can make the attention kernel less efficient, and that, unlike Ulysses, explicit load balancing is required. Google calls ring attention “the primary workhorse for very long-context training.”
Strategy 4: Unified Sequence Parallelism (USP)
USP combines the previous two on a two-dimensional grid of chips: an all-to-all along one axis, sized at or below the KV-head count, and a ring along the other. Because the all-to-all groups have already pooled their tokens, each ring step carries a bigger chunk and the ring is shorter, which means more compute per hop to hide transfers behind and fewer hops overall.
A worked example: what Google measured
Google benchmarked Llama 3.1 8B with all strategies running on Splash Attention, a block-sparse flash-attention kernel from its open-source Tokamax library that skips fully masked blocks and handles packed sequences without padding. Its reported results:
| Setup | Result reported by Google |
|---|---|
| TPU 5p, sequences up to 4M tokens | 70% MFU |
| TPU 7 (Ironwood), sequences below 6M tokens | about 50% MFU throughout |
| 14M tokens, ring attention, 64 chips | 48.7% MFU on TPU 7 vs 37.1% on TPU 5p |
| Fixed 64-chip TPU 5p slice, 64K–14M tokens | ring attention beat All-gather at almost every length |
Google attributes the TPU 7 advantage partly to its doubled HBM per chip, and says ring attention outperformed Ulysses and USP on TPU 7. These are vendor benchmarks on one 8-billion-parameter model; results on other models, chips and interconnects will differ.
MFU measures how much of a chip’s theoretical peak arithmetic the training run actually uses; the rest is lost to communication, memory traffic and idle time. Utilization usually falls as sequences grow and more data has to move between chips, so the notable part of the result is that it stays around 50% at multi-million-token lengths rather than collapsing.
How to choose a strategy
Google’s guidance boils down to a short decision path. If the gathered KV fits in HBM, use All-gather with load balancing. If it does not, and the model has enough KV heads for the number of chips you need, Ulysses is simple and needs no balancing. Beyond that, use ring attention, or USP to combine both when the head count limits Ulysses. In every case, the smallest context-parallel size that fits your sequence is usually best, with the remaining chips used for data or tensor parallelism.
The same ideas appear outside TPUs: DeepSpeed and other GPU frameworks implement Ulysses-style and ring-style sequence parallelism, so the concepts carry across hardware even if the numbers do not.
What to watch next
- Support for hybrid architectures that mix sliding-window and global attention, which Google lists as a next step.
- Context parallelism for linear-attention layers such as Gated DeltaNet and Kimi Delta Attention.
- Published “recipes” by model size and context length for different TPU generations.
- Whether open models trained natively at multi-million-token lengths start to appear.
Key takeaways
- Context parallelism splits a single long sequence across chips so no chip holds all of its activations.
- All-gather is simplest but memory-hungry; Ulysses is limited by the number of KV heads; ring attention scales furthest.
- USP combines Ulysses and ring attention on a two-dimensional grid of chips.
- Google reports 70% MFU up to 4M tokens on TPU 5p and training at up to 14M tokens with MaxText 0.2.4.
- The figures are Google’s own benchmarks on Llama 3.1 8B and will vary on other setups.
Frequently asked questions
What is context parallelism in LLM training?
It is a way of splitting one long input sequence across several chips during training, so that memory for activations and keys and values is shared rather than duplicated on every chip.
What is the difference between ring attention and Ulysses?
Ulysses swaps sequence slices for attention-head slices with an all-to-all exchange, so it is limited by the number of heads. Ring attention passes key-value chunks around a ring of chips, overlapping communication with compute and avoiding that limit.
Is MaxText free to use?
Yes. MaxText is Google’s open-source JAX training framework, and version 0.2.4 with context parallelism is available through PyPI, Docker Hub and GitHub.




