Skip to content

Weng: The Transformer Family Version 2.0

optionalextendedfundamentalblogrubric 7/122023 · ~45 min

Lilian Weng

Status

TL;DR. Lilian Weng’s post (27 January 2023) surveys how the 2017 Transformer was changed in the five years after it appeared. It covers position encoding, ways to reach longer context, adaptive computation, cheaper attention, and Transformers for RL. Each idea comes with its equations and a figure from the source paper. The estimated reading time is 45 minutes.

The post is organised by the problem each variant solves. The table maps its sections onto pages on this site.

SectionMethods coveredRead on this site
Transformer basicsScaled dot-product and multi-head attention, encoder-decoderAttention, Illustrated Transformer
Positional encodingSinusoidal, learned, relative (Shaw, Transformer-XL), rotaryRoPE, T5 (relative bias)
Longer context: memoryTransformer-XL, Compressive Transformer, kNN-LM, SPALM, Memorizing TransformerLost in the middle, RULER
Longer context: distance-aware scoresDA-Transformer, ALiBiYaRN for the RoPE-based alternative
Make it recurrent; adaptive modellingUniversal Transformer, adaptive attention span, depth-adaptive Transformer, CALMTest-time compute (spending variable compute per input)
Efficient attention: sparse patternsImage Transformer, Sparse Transformer, ETC, Longformer, Big BirdGemma 3 (sliding windows), native sparse attention
Efficient attention: content-basedReformer (LSH, reversible layers), Routing TransformerColBERT for the retrieval view of keys and queries
Efficient attention: low-rankLinformer, Random Feature Attention, PerformerMamba, Gated DeltaNet
Transformers for RLGated Transformer-XL, Decision TransformerPPO

The post states complexity for several methods. Reformer’s LSH attention goes from O(L2)O(L^2) to O(Llog⁡L)O(L \log L). Routing attention reaches O(L1.5)O(L^{1.5}). Linformer and the random-feature methods are linear in LL.

The post reports results from the papers it covers. ALiBi trained a 1.3B model on 1,024-token inputs and extrapolated to 2,048-token inputs (the post prints 2,046; the original paper gives 2,048). A Memorizing Transformer with 8K tokens of memory matched the perplexity of a vanilla Transformer with five times more trainable parameters. Sparse Transformer trained networks with hundreds of layers on sequences up to 16,384 tokens. Longformer worked better with small windows in lower layers and larger ones in higher layers than with the reverse. Seen from 2026, two of these lines became mainstream. Sliding-window layers are in Gemma 3 and gpt-oss, and gated linear-attention layers are in Qwen3-Next and Kimi Linear. Other lines, such as LSH attention, are rarely seen in today’s open models.

  • Raschka’s architecture comparison is the 2025–26 follow-on. It shows which of these ideas made it into open-weight models.
  • RoPE derives the rotation and the relative-position property properly. Read it alongside the post’s RoPE section.
  • For IR readers, kNN-LM and Memorizing Transformer are retrieval inside the model. Compare them with retrieval-augmented pipelines such as DSP.
  • FlashAttention took the opposite route to most of this post. It keeps exact attention and makes it fast on the hardware.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Using the post's random-feature attention section, show how replacing the softmax kernel with a feature map phi turns causal attention into a computation that is linear in sequence length, and what state a decoder must keep per layer.

    What a strong answer covers
    • Softmax attention weights exp(q · k_i); random features give exp(q · k) ≈ c · phi(q) · phi(k) for unit-norm vectors, following Rahimi and Recht.
    • Then attn(q_t) ≈ phi(q_t)ᵀ Σ_i phi(k_i) ⊗ v_i divided by phi(q_t)ᵀ Σ_j phi(k_j), so the sums over keys no longer depend on the query.
    • Each sum is computed once (or updated step by step in a decoder), so cost is O(L) in sequence length rather than O(L²).
    • The state per layer is a fixed-size matrix Σ phi(k) ⊗ v and a vector Σ phi(k), which is why linear attention behaves like an RNN; Performer uses positive orthogonal random features to cut the estimation error.
  2. Mechanism

    The post groups RoPE, ALiBi and Transformer-XL memory under positional encoding and longer context. Explain how each lets a model use positions or context beyond what it saw in a single training segment.

    What a strong answer covers
    • RoPE rotates query and key pairs by angles proportional to position, so their dot product depends only on the relative offset.
    • ALiBi adds a fixed, head-specific linear penalty proportional to distance (slopes 1/2 to 1/2^8 for 8 heads); a 1.3B model trained on 1,024-token inputs extrapolated to 2,048-token inputs (the blog says 2,046; the ALiBi paper says 2,048).
    • Transformer-XL caches hidden states from the previous segment as extra keys and values, using relative positions, giving a temporal range of m × N for memory m and N layers.
    • RoPE and ALiBi change how scores depend on distance; Transformer-XL changes what is attended to. Only the memory approach adds context without longer training sequences.
  3. Critique

    Read the post's Rotary Position Embedding section closely. Identify what is wrong or loose in its description and equation, and give the corrected statements.

    What a strong answer covers
    • It says RoPE multiplies the key and value matrices; RoPE rotates queries and keys, and values are left unrotated.
    • In q_iᵀ k_j the query weight matrix should appear transposed, and the combined rotation is R for the offset j − i, which is the relative-position property.
    • Calling RoPE essentially equivalent to sinusoidal encoding is loose: it shares the frequencies, but it multiplies rather than adds and acts inside every attention layer.
    • Survey posts are excellent maps but should be checked against the source paper before you rely on an equation.

Done with this page?

Status