---
title: "Hugging Face Reads, Feb. 2021 - Long-range Transformers"
description: "Long-range attention methods attack the quadratic memory and time cost of self-attention in sequence length, and four papers illustrate the main families."
url: "https://swe.quest/articles/hugging-face-reads-feb-2021-long-range-transformers-59eb38f5969384a8"
canonical: "https://huggingface.co/blog/long-range-transformers"
source: "Hugging Face"
published: "2021-03-09"
difficulty: "hard"
kind: "Research"
reading_minutes: 8
tags: ["llms","machine-learning","model-training"]
---

# Hugging Face Reads, Feb. 2021 - Long-range Transformers

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2021-03-09, 8 min read, Research. Original: [https://huggingface.co/blog/long-range-transformers](https://huggingface.co/blog/long-range-transformers)

## Summary

Long-range attention methods attack the quadratic memory and time cost of self-attention in sequence length, and four papers illustrate the main families. Longformer combines dilated windowed and global attention to reach linear cost and serves as a drop-in replacement, so pretrained checkpoints can be adapted to long inputs. Compressive Transformer extends Transformer-XL with a compressed memory of past activations, using pooling or convolution, to model longer dependencies. Linformer exploits the low rank of attention matrices to project the sequence dimension and get linear complexity. Each paper comes with complexity analysis, main findings and open questions, such as TPU indexing costs, hyperparameter brittleness and long-target seq2seq tasks.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)

## Prerequisites

- Transformer self-attention
- Big-O complexity
- Low-rank matrix approximation

## Keywords

Longformer, Compressive Transformer, Linformer, Performer, Transformer-XL, Johnson-Lindenstrauss lemma, PG19

## Related posts

- [Mastering Long Contexts in LLMs with KVPress](https://swe.quest/articles/mastering-long-contexts-in-llms-with-kvpress-778c6dc9287ed60d.md): Hugging Face · 2025-01-23 · Medium · 7 min read · Inference & serving, LLMs, Python, Performance engineering
  KV cache memory grows linearly with context length: Llama 3-70B at 1M tokens in bfloat16 needs about 330GB of KV cache, roughly 70% of total memory.
- [A failed experiment: Infini-Attention, and why we should keep trying?](https://swe.quest/articles/a-failed-experiment-infini-attention-and-why-we-should-keep-trying-49bb19744a04d6da.md): Hugging Face · 2024-08-14 · Hard · 16 min read · LLMs, Model training, Evaluation
  A Hugging Face reproduction of Google's Infini-attention found that retrieval quality degrades as memory is compressed more times.
- [Supercharging transformer residual connections](https://swe.quest/articles/supercharging-transformer-residual-connections-cfa196a28b957618.md): Google Research · 2026-11-23 · Hard · 7 min read · LLMs, Model training, Machine learning
  DeepCrossAttention (DCA) replaces the fixed point-wise summation of transformer residual connections with learned, per-token routing over all preceding layer outputs.
- [Nyströmformer: Approximating self-attention in linear time and memory via the Nyström method](https://swe.quest/articles/nystromformer-approximating-self-attention-in-linear-time-and-memory-via-the-fd6613fb9ac42d67.md): Hugging Face · 2022-08-02 · Hard · 6 min read · LLMs, Machine learning, Algorithms, Python
  Nyströmformer replaces quadratic softmax self-attention with an O(n) approximation built on the Nyström method, which reconstructs a matrix from a sampled subset of its rows and columns via a Moore-Penrose pseudoinverse.
- [​Sequential Attention: Making AI models leaner and faster without sacrificing accuracy](https://swe.quest/articles/sequential-attention-making-ai-models-leaner-and-faster-without-sacrificing-65f934b916a51bd2.md): Google Research · 2026-02-04 · Hard · 7 min read · Machine learning, Algorithms, Inference & serving, Recommendations & ranking
  Sequential Attention is a greedy subset-selection algorithm that runs inside a single training run.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
