Skip to main content
QUICK REVIEW

[Paper Review] The Hedgehog & the Porcupine: Expressive Linear Attentions with Softmax Mimicry

M Zhang, K. Bhatia|arXiv (Cornell University)|Feb 6, 2024
Cognitive and developmental aspects of mathematical skillsMathematics3 citations
TL;DR

Hedgehog proposes a learnable linear attention mechanism that mimics the low-entropy, spiky attention weights and dot-product monotonicity of standard softmax attention, using trainable MLPs to produce expressive, efficient attention patterns. It achieves over 99% of standard Transformer performance in training-from-scratch and fine-tuned settings, sets a new SOTA of 16.7 perplexity on WikiText-103 for 125M models, and enables high-performance linear conversion of Llama-2 7B with 28.1 ROUGE-1 gain over standard attention.

ABSTRACT

Linear attentions have shown potential for improving Transformer efficiency, reducing attention's quadratic complexity to linear in sequence length. This holds exciting promise for (1) training linear Transformers from scratch, (2) "finetuned-conversion" of task-specific Transformers into linear versions that recover task performance, and (3) "pretrained-conversion" of Transformers such as large language models into linear versions finetunable on downstream tasks. However, linear attentions often underperform standard softmax attention in quality. To close this performance gap, we find prior linear attentions lack key properties of softmax attention tied to good performance: low-entropy (or "spiky") weights and dot-product monotonicity. We further observe surprisingly simple feature maps that retain these properties and match softmax performance, but are inefficient to compute in linear attention. We thus propose Hedgehog, a learnable linear attention that retains the spiky and monotonic properties of softmax attention while maintaining linear complexity. Hedgehog uses simple trainable MLPs to produce attention weights mimicking softmax attention. Experiments show Hedgehog recovers over 99% of standard Transformer quality in train-from-scratch and finetuned-conversion settings, outperforming prior linear attentions up to 6 perplexity points on WikiText-103 with causal GPTs, and up to 8.7 GLUE score points on finetuned bidirectional BERTs. Hedgehog also enables pretrained-conversion. Converting a pretrained GPT-2 into a linear attention variant achieves state-of-the-art 16.7 perplexity on WikiText-103 for 125M subquadratic decoder models. We finally turn a pretrained Llama-2 7B into a viable linear attention Llama. With low-rank adaptation, Hedgehog-Llama2 7B achieves 28.1 higher ROUGE-1 points over the base standard attention model, where prior linear attentions lead to 16.5 point drops.

Motivation & Objective

  • To close the performance gap between linear attention and standard softmax attention in Transformers.
  • To identify key properties—low-entropy spikiness and dot-product monotonicity—that underlie softmax attention's success but are missing in prior linear methods.
  • To design a linear attention mechanism that preserves these properties while maintaining linear complexity.
  • To enable high-quality conversion of pretrained models like GPT-2 and Llama-2 into efficient linear variants without performance drop.
  • To demonstrate state-of-the-art results in training-from-scratch, fine-tuned conversion, and pretrained conversion regimes.

Proposed method

  • Hedgehog uses a learnable, multi-layer perceptron (MLP) to map query-key dot products into attention weights, emulating the behavior of softmax attention.
  • The MLP is trained to produce attention weights with low entropy (spiky distributions) and monotonic increase with dot product values.
  • This approach retains linear time and space complexity O(ndd') while capturing the inductive biases of softmax attention.
  • The method is applied across three regimes: training from scratch, fine-tuned conversion, and pretrained conversion of large models.
  • For large model conversion, low-rank adaptation (LoRA) is used to fine-tune the linearized models efficiently.
  • The model is evaluated on standard benchmarks including WikiText-103, GLUE, and SAMSum, with ablation and visualization studies on attention patterns.

Experimental results

Research questions

  • RQ1Why do prior linear attention mechanisms underperform standard softmax attention despite linear complexity?
  • RQ2Which inductive biases of softmax attention are missing in existing linear methods and contribute to performance degradation?
  • RQ3Can a learnable, linear-time attention mechanism recover the spiky, monotonic attention patterns of softmax attention?
  • RQ4To what extent can such a mechanism match or exceed standard Transformer performance across training, fine-tuning, and pretrained conversion?
  • RQ5Can high-quality linear attention be achieved in large language models like Llama-2 through efficient adaptation?

Key findings

  • Hedgehog recovers over 99% of standard Transformer performance in both training-from-scratch and fine-tuned conversion settings.
  • On WikiText-103, Hedgehog achieves 16.7 perplexity for 125M causal GPTs, setting a new SOTA among subquadratic models.
  • In fine-tuned BERT models, Hedgehog improves GLUE scores by up to 8.7 points over prior linear attention methods.
  • For Llama-2 7B, Hedgehog with LoRA achieves 28.1 higher ROUGE-1 points than the standard attention model, while prior linear methods caused a 16.5-point drop.
  • Attention visualization confirms Hedgehog produces low-entropy, spiky attention weights and maintains dot-product monotonicity, closely mimicking softmax behavior.
  • The method enables efficient, high-performance conversion of large pretrained models into linear variants without significant accuracy loss.

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.