Skip to main content
QUICK REVIEW

[Paper Review] A Length-Extrapolatable Transformer

Yutao Sun, Dong Li|arXiv (Cornell University)|Dec 20, 2022
Natural Language Processing TechniquesComputer Science5 citations
TL;DR

This paper proposes the LeX Transformer, a length-extrapolatable attention mechanism that enhances long-context modeling through a novel relative position embedding (xPos) and blockwise causal attention. By maximizing attention resolution and enabling stable performance on sequences longer than seen during training, the model achieves strong results in both interpolation and extrapolation, outperforming existing methods on long-context language modeling tasks.

ABSTRACT

Position modeling plays a critical role in Transformers. In this paper, we focus on length extrapolation, i.e., training on short texts while evaluating longer sequences. We define attention resolution as an indicator of extrapolation. Then we propose two designs to improve the above metric of Transformers. Specifically, we introduce a relative position embedding to explicitly maximize attention resolution. Moreover, we use blockwise causal attention during inference for better resolution. We evaluate different Transformer variants with language modeling. Experimental results show that our model achieves strong performance in both interpolation and extrapolation settings. The code will be available at https://aka.ms/LeX-Transformer.

Motivation & Objective

  • To address the critical limitation of Transformers in generalizing to sequence lengths longer than those seen during training.
  • To define and optimize a metric—attention resolution—that quantifies a model's ability to extrapolate to longer sequences.
  • To design a relative position embedding (xPos) that maintains high resolution and stability across long contexts, improving upon RoPE and Alibi.
  • To enable strong performance on long sequences without sacrificing short-context performance or requiring retraining.
  • To demonstrate that blockwise causal attention enhances resolution and supports extrapolation in autoregressive language modeling.

Proposed method

  • Proposes xPos, a relative position embedding derived from RoPE but generalized with an exponential decay in the rotation matrix to improve attention resolution.
  • Defines attention resolution as a quantitative metric to measure how well a model preserves positional distinctions across long sequences.
  • Introduces blockwise causal attention (BCA) during inference to improve resolution by limiting attention to local blocks while maintaining long-range dependency modeling.
  • Uses a modified self-attention mechanism where query-key interactions are adjusted by xPos embeddings to encode relative position with high fidelity.
  • Employs a universal design principle that ensures order variance and translation invariance, enabling robustness across input length variations.
  • Trains models from scratch using standard dense attention during pre-training, preserving efficiency and performance on standard-length inputs.

Experimental results

Research questions

  • RQ1Can a relative position embedding be designed to maintain high attention resolution across extremely long sequences, enabling extrapolation beyond the training length?
  • RQ2How does blockwise causal attention affect attention resolution and performance in long-context language modeling?
  • RQ3Does the proposed xPos embedding outperform RoPE and Alibi in both short-context and long-context settings?
  • RQ4Can a model trained on short sequences generalize effectively to very long sequences without retraining or architectural changes?
  • RQ5What is the trade-off between improved extrapolation and inference cost in the proposed method?

Key findings

  • The LeX Transformer achieves minimal perplexity on the validation set during pre-training, indicating strong in-distribution performance.
  • On the arXiv dataset (average length >6k), LeX Transformer continues to reduce perplexity as sequence length increases, while other models either plateau or increase perplexity.
  • xPos reduces perplexity by approximately 1 at 2048 tokens and by 8 at 4096 tokens compared to the same model without blockwise causal attention.
  • Blockwise causal attention is essential for RoPE-based models to avoid perplexity explosion at long lengths, but is less critical for Alibi due to its inherent soft attention window.
  • The model maintains strong performance on standard-length sequences, showing no trade-off between short- and long-context capabilities.
  • xPos introduces only about 6% additional inference cost compared to absolute position embeddings, with faster training convergence.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.