End-to-End Long Document Summarization using Gradient Caching

Rohit Saxena, Hao Tang, Frank KellerarXiv 2025

TL;DR

Training Transformers on long documents is notoriously bottlenecked by quadratic memory consumption, usually forcing researchers to truncate inputs during training. This paper introduces CachED, a parameter-free gradient caching technique for encoder-decoder models that eliminates truncation entirely. It enables end-to-end training on texts over 500K tokens long while scaling memory usage linearly instead of quadratically.

What Problem Does This Paper Address?

Standard self-attention mechanisms suffer from an $O(L^2)$ memory complexity relative to the input sequence length $L$. When dealing with long-form texts like books, movie scripts, or financial reports, this quadratic growth quickly leads to Out-Of-Memory (OOM) errors on modern GPUs.

To circumvent this, the standard practice has been to truncate documents during training (often capping them at 16K tokens). However, truncation creates a severe training-test mismatch and throws away critical context necessary for generating high-quality summaries. While previous works have tried chunking inputs or using efficient sparse attention mechanisms, they still resort to truncation during training because they fail to free up intermediate encoder activations from GPU memory.

Methods

The authors propose CachED (Gradient Caching for Encoder-Decoder models), a simple yet highly effective strategy that adapts the concept of gradient checkpointing to chunk-based processing across the encoder-decoder boundary.

Instead of holding the entire document's activation graph in memory, CachED breaks the input into $K$ non-overlapping chunks and processes them in three distinct steps:

  1. Sequential Chunk Encoding: Each chunk is passed through the encoder one by one. Crucially, intermediate activations are discarded immediately using PyTorch's .detach(), and only the final layer's hidden vectors ($H_k$) are retained.
  2. Decoder Backpropagation & Caching: The final hidden vectors from all chunks are concatenated and passed to the decoder. The loss is computed, and standard backpropagation runs through the decoder. The gradients at the encoder-decoder boundary ($\partial J / \partial H_k$) are captured and cached using .retain_grad().
  3. Encoder Re-computation: The encoder is run a second time on each chunk sequentially to re-generate the intermediate activations. The cached gradients from Step 2 are then used to complete the backward pass through the encoder layers, accumulating the final parameter gradients ($\partial J / \partial \Theta$).

This approach requires zero additional parameters and acts as a plug-and-play wrapper around any existing pretrained encoder-decoder model (like BART or T5).

Figure 1: An overview of a CachED approach to long document summarization. The model is trained end- to-end by splitting and encoding the input into chunks (Step 1), then passing the concatenated hidden vectors to the decoder. Gradients are cached for the encoded tokens (Step 2) and passed back to the chunks individually (Step 3).

Datasets

The authors evaluated CachED across two categories of long-text benchmarks:

  • Long Documents (<16K average tokens):
  • GovReport: Executive summaries of US Government Accountability Office reports (~9.6K tokens).
  • SummScreenFD: Recaps of television show transcripts (~8.4K tokens).
  • QMSum: Query-based meeting summaries (~13.3K tokens).
  • Extremely Long Documents (>16K average tokens):
  • ScriptBase: Full-length movie scripts paired with Wikipedia summaries (~36K tokens).
  • BookSum: Entire books paired with book-level summaries (averaging ~139K tokens, with the longest document reaching over 642K tokens).
Distribution of document lengths across the evaluated datasets.

Key Insights and Ideas

  • Linear Memory Scaling: By discarding intermediate encoder activations and recomputing them on the fly, CachED shifts memory consumption from quadratic to linear with respect to document length. This allows a standard BART-large model to process up to 1 million tokens on a single 80GB A100 GPU, whereas baseline methods hit memory limits at around 20,000 tokens.
  • Uniform Document Utilization: Position bias is a well-known issue in long-context models (e.g., the "lost in the middle" phenomenon). By mapping summary sentences back to their source segments, the authors proved that CachED utilizes the entire document uniformly without ignoring the middle or end of long books.
Figure 3: Percentage of generated summary sen- tences aligned with different segments (bins) of a book in the BookSum test set. CachED BARTlarge model uses the entire document, with the align- ment evenly distributed across segments.
  • The Illusion of LLM Long-Context Superiority: When comparing against massive models like GPT-4o and Llama 3.1 8B, the authors discovered a fascinating quirk: prompting these LLMs with only the title and year of a book often yielded higher ROUGE scores than providing the full text. This indicates that large language models frequently rely on memorized training data rather than actually processing ultra-long contexts effectively. CachED BART, by contrast, genuinely synthesizes the provided text.

Key Results

  • State-of-the-Art Summarization: CachED BART-large achieved superior performance on extremely long datasets. On BookSum, it outperformed the previous best chunking method (SLED) by 3.9 points in ROUGE-1 and 3.0 points in ROUGE-2.
  • Factual Consistency: Summaries generated by CachED were significantly more factually accurate. On BookSum, CachED BART-large scored 41.33 on AlignScore and 52.90 on FActScore, substantially beating Unlimiformer (35.00 / 39.30) and SLED (36.92 / 37.70).
  • Minimal Time Overhead: While CachED requires a double forward pass through the encoder, the actual wall-clock time overhead is minimal because encoder computation represents a small fraction of the total training loop time compared to the autoregressive decoder.

Limitations and Future Work

  • Architecture Constraints: The current implementation is strictly tailored to encoder-decoder models. While the authors outline a theoretical framework for extending this to decoder-only models (like modern LLMs) using KV-cache chunking, they leave the empirical validation to future work.
  • Independent Chunk Encoding: Because chunks are encoded independently, the encoder's self-attention mechanism cannot capture cross-chunk dependencies. All global context fusion is deferred entirely to the cross-attention layers in the decoder. The authors suggest exploring overlapping windows or adding lightweight global attention layers over chunk representations to mitigate this limitation.

Summary updated

BibTeX
@misc{saxena2025end,
  author = {Rohit Saxena and Hao Tang and Frank Keller},
  title = {{End-to-End Long Document Summarization using Gradient Caching}},
  year = {2025},
  eprint = {2501.01805},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.01805},
}
Figure