Blockwise Self-Attention for Long Document Understanding

Jiezhong Qiu, Hao Ma, Omer Levy, Wen-tau Yih, Sinong Wang, Jie Tang

Presented at EMNLP 2020, BlockBERT introduces a variant of the BERT architecture specifically engineered to process long documents efficiently. By replacing standard dense self-attention with a sparse, blockwise masking strategy, the authors significantly mitigate the memory and computational overhead that typically restricts Transformers to short text sequences.

The Quadratic Bottleneck in Transformers

The primary obstacle in scaling standard Transformers is the "quadratic bottleneck." In traditional self-attention, every token in a sequence attends to every other token, resulting in a computational and memory complexity of $O(N^2)$, where $N$ is the sequence length. While manageable for 512 tokens, the memory required for sequences exceeding 1,000 tokens often surpasses the capacity of modern GPUs.

The authors identify that activation memory—the intermediate tensors stored for backpropagation—accounts for nearly 88% of total GPU memory usage during training. This makes it the critical target for optimization to enable long-document processing without sacrificing contextual information through truncation or sliding windows.

Methods: Blockwise Self-Attention

The core innovation of this work is the Blockwise Self-Attention mechanism. Instead of computing a single $N \times N$ attention matrix, the sequence is divided into $n$ blocks, and attention is restricted through structured masking.

Architecture of Blockwise Attention and examples of masking matrices for different block counts.
  1. Sparse Block Masking: The model utilizes a masking matrix $M$ based on permutations. For instance, an "identity" permutation allows tokens within a block to attend only to themselves, creating a block-diagonal structure.
  2. Permutation Shifting: To maintain long-range dependencies, different attention heads are assigned different permutations. While most heads focus on local context (identity), a subset is assigned "shifted" permutations, allowing them to attend to distant blocks.
  3. Hardware Efficiency: Unlike many sparse Transformers that require custom CUDA kernels, BlockBERT’s block-diagonal structure utilizes standard, highly optimized dense matrix multiplication libraries, ensuring it remains "hardware-friendly."

Key Results: Efficiency and Performance

Empirical evaluations show that BlockBERT achieves substantial gains in both memory efficiency and speed without compromising accuracy.

Comparison of activation memory usage between standard BERT and BlockBERT variants across sequence lengths.
  • Memory & Speed: For a sequence length of 1024, BlockBERT (with $n=3$ blocks) reduced activation memory usage by 36.1% and training time by 25.1% compared to RoBERTa.
  • Inference: The model achieved a 27.8% speedup during inference.
  • Accuracy: On long-document tasks like SearchQA, BlockBERT trained on 1024 tokens significantly outperformed models limited to 512 tokens. On standard benchmarks like SQuAD, it performed comparably to RoBERTa-1seq, proving that sparsity does not necessarily degrade performance.

Insights on Head Distribution

A key finding of the paper is the "Vital Few" principle. Ablation studies revealed that assigning the majority of heads to the identity permutation (local context) is crucial. If too many heads are dedicated to long-range permutations, the model loses its grasp on local syntax, leading to a drop in performance. A balanced mix of local and global blocks is sufficient to capture necessary document semantics.

Conclusion

BlockBERT demonstrates that sparse, block-structured attention is a viable path toward processing long sequences on standard hardware. By targeting activation memory, the authors provide a scalable solution for tasks requiring deep contextual understanding across thousands of tokens, such as document-level question answering and long-form text analysis.

Summary updated

BibTeX
@inproceedings{qiu2020blockwise,
  author = {Jiezhong Qiu and Hao Ma and Omer Levy and Wen-tau Yih and Sinong Wang and Jie Tang},
  title = {{Blockwise Self-Attention for Long Document Understanding}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.findings-emnlp.232},
}
Figure