Adjoint sharding for very long context training of state space models

Xingzi Xu, Amir Tavanaei, Kavosh Asadi, Karim BouyarmanearXiv 2025 · DOI

Abstract

Training State Space Models (SSMs) on extremely long sequences is often limited by the memory overhead of backpropagation. Researchers from Amazon and Duke University have introduced Adjoint Sharding, a technique that replaces standard backpropagation with a parallelizable adjoint method. This approach reduces memory usage by up to 3x, enabling a 1.27B parameter model to train on contexts exceeding 100,000 tokens on modest hardware without sacrificing gradient accuracy.

The Challenge of Long-Context Training

While Large Language Models (LLMs) are increasingly capable of processing long contexts during inference, training them on such sequences remains a massive bottleneck. Standard training relies on Backpropagation Through Time (BPTT), which requires storing every intermediate activation to calculate gradients. For long sequences, these activations quickly exceed available GPU memory. Even with activation checkpointing, training on 100k+ tokens often requires specialized, high-end infrastructure. This paper specifically targets State Space Models (like Mamba), which have linear scaling during inference but still struggle with memory-heavy gradient calculations during training.

Methodology: Adjoint Sharding

The authors propose Adjoint Sharding to shift the gradient computation paradigm from sequential storage to parallelizable reconstruction.

The Adjoint Method

Instead of saving all intermediate states during the forward pass, the adjoint method uses a backward "adjoint process" to compute gradients. Traditionally used for optimizing dynamical systems, this method allows for significant memory savings by trading redundant computation for reduced storage requirements.

Sharding the Gradient via VJPs

The core innovation lies in "disassembling" the model's gradient computation into independent Vector-Jacobian Products (VJPs). Because these VJPs are independent, they can be computed in parallel across different GPUs or instances, effectively sharding the entire training process.

Computational graph of the Adjoint Sharding method, illustrating the decomposition of gradient calculations into independent Vector-Jacobian Products (VJPs).

Truncated Adjoint Sharding

To address the $O(T^2)$ time complexity of full adjoint computation, the authors introduced a truncated version. By focusing on the gradients of the last $\bar{T}$ states, the computation time grows linearly ($O(T)$) while maintaining model performance.

Experimental Setup and Datasets

The method was evaluated using a 1.27B parameter SSM-ResNet model across three primary long-context benchmarks:

  • PG19: Books from Project Gutenberg for long-range language modeling.
  • Proof-Pile: Mathematical LaTeX documents.
  • CodeParrot: Large-scale Python code repository.

Key Results: Memory and Scaling

The empirical results highlight a significant breakthrough in memory efficiency. Adjoint Sharding allows for much larger training contexts on the same hardware compared to standard backpropagation.

GPU memory usage comparison between standard backpropagation and Adjoint Sharding across various model sizes and training context lengths.
  • 3X Memory Reduction: For a 1.27B parameter model training on a 1M context length, the algorithm reduced memory usage by up to 3x.
  • Context Length Boost: On a setup of five AWS P4 instances, the maximum trainable context length for a 1.27B model increased from 35,000 tokens to over 100,000 tokens.
  • Gradient Equivalence: The authors analytically proved that Adjoint Sharding produces gradients mathematically equivalent to those from standard backpropagation.
  • Parallel Speedup: Using parallel computing (MIG instances), they achieved up to a 56x speedup in gradient evaluation on a single AWS P4 instance compared to a non-parallelized version.

Conclusion and Future Work

Adjoint Sharding demonstrates that memory, rather than raw compute, is often the primary bottleneck in modern AI training. By treating neural networks as physical dynamical systems, the authors provide a path toward training massive models on extremely long sequences with accessible hardware.

Future work includes developing custom CUDA kernels to minimize implementation overhead and conducting deeper convergence analysis for the truncated version on specific long-range reasoning tasks.

Summary updated

BibTeX
@misc{xu2025adjoint,
  author = {Xingzi Xu and Amir Tavanaei and Kavosh Asadi and Karim Bouyarmane},
  title = {{Adjoint sharding for very long context training of state space models}},
  year = {2025},
  eprint = {2501.00692},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.00692},
}
Figure