NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Blockwise Parallel Transformers for Large Context Models

Hao Liu, Pieter Abbeel

TL;DR

Blockwise Parallel Transformers (BPT) significantly extend the context window of Transformer models by fusing blockwise self-attention with feedforward network (FFN) computation. This approach allows for training sequences up to 32 times longer than vanilla Transformers and 2-4 times longer than previous state-of-the-art memory-efficient methods like FlashAttention, all while maintaining exact (non-approximated) mathematical outputs.

The Context Window Bottleneck

The "context window"—the amount of text or data a model can consider at once—is a major bottleneck in modern AI. Standard Transformers suffer from two main memory drains as sequences get longer:

  1. Self-Attention: The memory required grows quadratically ($O(s^2)$) with sequence length because the model compares every token to every other token.
  2. Feedforward Networks (FFN): While FFNs only grow linearly ($O(s)$) with sequence length, they produce massive intermediate activations. In large models, these activations can actually become a larger memory burden than optimized attention mechanisms.

Existing solutions like FlashAttention solve the quadratic attention problem but leave the FFN bottleneck untouched. As a result, even if you optimize attention, the model eventually runs out of memory (OOM) because it tries to process the FFN for the entire long sequence at once.

Methods: Blockwise Parallel Transformers (BPT)

The authors introduce Blockwise Parallel Transformers (BPT). The core innovation is a "fused" blockwise computation strategy that addresses both the attention and FFN bottlenecks simultaneously.

Blockwise Parallel Transformer Architecture
  • Nested Loops: Instead of processing the whole sequence at once, BPT uses two nested loops. The outer loop iterates over blocks of "queries," and the inner loop iterates over blocks of "keys" and "values."
  • FFN Fusion: Crucially, BPT doesn't wait for the attention step to finish for the whole sequence. As soon as the blockwise attention for a specific query block is computed, the model immediately runs the FFN and the residual connection for that specific block.
  • Memory Efficiency: By processing the FFN block-by-block, the model only needs to store intermediate FFN activations for a small chunk of data at a time. This reduces the FFN memory overhead from being proportional to the total sequence length ($s$) to being proportional to the much smaller block size ($c$).
  • Exact Computation: Unlike "Sparse" or "Low-rank" Transformers that take shortcuts to save memory, BPT computes the exact same mathematical output as a standard Transformer.

Key Insights

  • The FFN is the New Bottleneck: The most important insight is that once you've optimized self-attention, the Feedforward Network becomes the primary limiting factor for context length.
  • Fusion is Key: By merging the attention and FFN steps into a single blockwise operation, BPT minimizes "data movement"—the expensive process of moving data between fast SRAM and slower HBM (High Bandwidth Memory) on a GPU/TPU.
  • Context Length = Performance in RL: In reinforcement learning experiments, the authors found that simply being able to process more history (32 trajectories instead of 4) led to a massive jump in performance without changing the underlying RL algorithm. This suggests that for many tasks, "more memory" is a direct path to "more intelligence."

Key Results

BPT demonstrates remarkable improvements in context scaling across various hardware setups, including single GPUs, multi-GPU nodes, and TPU clusters.

Maximum Context Length Comparison
  • Massive Context Scaling: On a single NVIDIA A100 (80GB), BPT enabled a 1B parameter model to handle a context length of 131K tokens, compared to just 16K for a vanilla Transformer and 65K for memory-efficient attention baselines.
  • Memory Savings: BPT achieved up to a 4x memory reduction compared to other memory-efficient Transformers, preventing OOM errors at sequence lengths that crash standard models.
  • RL Breakthrough: Evaluated on the ExoRL benchmark, BPT-based agents achieved a total average return of 111.13, significantly outperforming the baseline average of 83.02. This was possible because BPT allowed the agent to condition its behavior on 8x more historical data.
  • Throughput: Despite the complex looping, BPT maintains competitive (and sometimes superior) processing speeds because it reduces the need for memory-intensive "checkpointing" (recomputing values during the backward pass).

Limitations and Future Work

  • Implementation Overhead: The current version is implemented in JAX using high-level operations. While efficient, writing custom low-level kernels (e.g., in CUDA or OpenAI Triton) would likely unlock even higher speeds and better hardware utilization.
  • Inference Speed: The paper focuses primarily on the training bottleneck. While BPT helps with training long-context models, managing the "KV cache" remains a challenge for fast inference on extremely long sequences.
  • Hardware Specifics: The benefits of blockwise parallelization are most pronounced when the block size fits perfectly into the hardware's fastest memory (SRAM), meaning the "optimal" configuration varies between different GPUs and TPUs.

Summary updated

BibTeX
@inproceedings{liu2023blockwise,
  author = {Hao Liu and Pieter Abbeel},
  title = {{Blockwise Parallel Transformers for Large Context Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=KbqQMoqfLQ},
}
Figure