WhoBuilt

Road to 5 Million Tokens: Breaking Barriers in Long Context Training

Jun 8, 2026· 16 min· 6.1K views·Watch on YouTube

Speaker

Max Ryabinin, VP of Research and Development at Together AI, explains how his team combined context parallelism and memory-saving techniques to train models on up to 5 million tokens, speaking at AI Engineer.

Why long context matters

Ryabinin points to agent applications that need to use large amounts of context and video applications that must track many frames over time. Training models to handle long sequences well can help those uses, and understanding memory demands can also help teams improve training efficiency at shorter lengths.

Where memory goes

Standard transformers face quadratic attention computation and memory use that grows linearly with sequence length. In his example, a Llama 3B model with a 3 million token context does not fit on an 8× H100 node, even after sharding model parameters, because attention activations consume too much memory.

Stacking memory-saving techniques

DeepSpeed Ulysses context parallelism distributes attention heads across GPUs while each GPU still processes the full sequence, and it can use FlashAttention. Ryabinin then describes activation checkpointing, CPU offloading of transformer block inputs, and tiling element-wise work such as loss calculations and MLPs. Together, these techniques make 3 million tokens possible in his example.

Reusing buffers to reach 5 million tokens

Ryabinin’s team developed an approach he calls Untitled Ulysses: divide heads into chunks, compute attention for each chunk in turn, and reuse buffers instead of allocating one large buffer. He says this saves activation memory without significantly reducing throughput at small scales. Their results at 8B and 32B model scales match memory-optimized training implementations while reaching 5 million tokens.

Balancing memory and throughput

Larger head chunks use more memory but can run the model faster. Ryabinin says stacking the techniques and adding U-Pipe can free memory for other training stages, including when training across three 5-million-token contexts. He recommends profiling to find bottlenecks that may be unexpected.

Takeaways

  • Profile memory use before assuming attention is the only bottleneck.
  • Combine sharding, context parallelism, checkpointing, offloading, and tiling to reduce memory pressure.
  • Chunk attention heads and reuse buffers when a single allocation is too large.
  • Tune chunk size against available memory and desired throughput.
  • Consider U-Pipe when memory needs to be shared across training stages or long contexts.

Mentioned in this talk

Search inside this talk

What was claimed 7

  • works at
    Distinguished Research Scientist (AI Engineer speaker profile lists 'Vice president of model shaping')
    “I’m VP of Research and Development at Together AI.”
    YouTube
    Verified2 sources· Talk, Web· archived
  • feature
    Together AI: Provides an AI-native cloud with services and infrastructure for AI developers and builders
    “Together AI is an AI-native cloud that provides services and infrastructure for AI developers and builders”
    YouTube
    Unverified1 source· Talk
  • metric
    Together AI: More than 200 models in its portfolio
    “We have more than 200 models in our portfolio”
    YouTube
    Unverified1 source· Talk
  • feature
    DeepSpeed Ulysses: Distributes attention computation across GPUs by communicating activations as required
    “you can compute the attention for different heads at different points in time, or on different GPUs”
    YouTube
    Unverified1 source· Talk
  • feature
    Untitled Ulysses: Chunks attention heads and reuses allocated buffers across iterations to save activation memory
    “you can divide them into chunks and iterate through those chunks over time”
    YouTube
    Unverified1 source· Talk
  • metric
    Untitled Ulysses: Scales to 5 million tokens at both 8-billion and 32-billion model scales
    “at both the 8-billion and 32-billion scales, we closely match the most memory-optimized implementations of transformer training while scaling to 5 million tokens”
    YouTube
    Unverified1 source· Talk
  • feature
    PyTorch: Provides a profiler that can help identify training bottlenecks
    “Tooling like the PyTorch profiler”
    YouTube
    Unverified1 source· Talk

Related talks