Attention Glossary

Canonical vocabulary for the attention-mechanisms curriculum. Every lesson adheres to these definitions and this notation. Notation (fixed throughout): = sequence length, = model dim, = number of heads, = per-head dim, = batch size, = number of layers.

Core mechanism

  • Query / Key / Value () — The three learned projections of the input : , , . Queries probe, keys are matched against, values are aggregated. See 01-scaled-dot-product-attention.
  • Attention score — The unnormalized query-key affinity ; the matrix before softmax. See 01-scaled-dot-product-attention.
  • Scaled dot-product attention — The core operation ; a softmax-weighted average of values with weights set by query-key similarity. See 01-scaled-dot-product-attention.
  • Softmax temperature / scaling — The factor (equivalently temperature ) that keeps score variance so softmax gradients don’t vanish; lowering sharpens the distribution. See 01-scaled-dot-product-attention.
  • Causal mask — An additive mask for applied to so position attends only to ; enforces autoregressive factorization. See 01-scaled-dot-product-attention.
  • Self-attention — Attention where all derive from the same sequence, mixing information within one stream. See 01-scaled-dot-product-attention.
  • Cross-attention — Attention where comes from one stream and from another (e.g. decoder queries over encoder states); the mechanism behind encoder-decoder and multimodal conditioning. See 08-attention-in-vits-and-vlms.

Multi-head & blocks

  • Multi-head attention (MHA) — Run attention operations in parallel on -dim subspaces, then concatenate: . Lets different heads specialize. See 02-multi-head-attention-and-the-block.
  • Head dimension () — Per-head width ; sets each head’s subspace size and the scaling. See 02-multi-head-attention-and-the-block.
  • Output projection () — The matrix mixing concatenated head outputs back into the residual stream. See 02-multi-head-attention-and-the-block.
  • Transformer block — One layer: attention sublayer + position-wise MLP, each wrapped in residual connection and LayerNorm; such blocks stacked. See 02-multi-head-attention-and-the-block.
  • Pre-LN vs post-LN — Placement of LayerNorm relative to the residual add. Pre-LN () gives clean residual gradient flow and stable deep training; post-LN () is the original Transformer, better-performing but harder to train without warmup. See 02-multi-head-attention-and-the-block.

Positional

  • Absolute vs relative position — Absolute encodings tag each token with its index ; relative encodings condition only on the offset , generalizing better across lengths. See positional-encoding.
  • Sinusoidal encoding — The original fixed absolute scheme adding (and ) to embeddings; no learned parameters. See positional-encoding.
  • RoPE (rotary position embedding) — Encodes position by rotating pairs by angle proportional to index, so depends only on ; the de facto standard in modern LLMs. See rope.
  • ALiBi — Adds a linear distance penalty to scores (per-head slope ) instead of positional embeddings; cheap length extrapolation. See positional-encoding.

Efficiency & KV-cache

  • KV cache — Stored from all past positions during autoregressive decoding so each new token is not ; memory and often the decode bottleneck. See kv-cache.
  • Prefill vs decode — Prefill processes the whole prompt in parallel (compute-bound, high arithmetic intensity); decode generates one token at a time (memory-bound, dominated by KV-cache reads). See kv-cache.
  • MQA (multi-query attention) — All query heads share a single head, shrinking the KV cache at some quality cost. See gqa-mqa.
  • GQA (grouped-query attention) — Interpolates MHA and MQA: KV heads shared across groups of query heads (); the common production choice. See gqa-mqa.
  • MLA (multi-head latent attention) — Compresses into a low-rank latent cached per token, then up-projects per head at use time; cuts KV memory while retaining MHA-like quality (DeepSeek-V2/V3). See mla.
  • Arithmetic intensity — FLOPs per byte of memory traffic; determines whether an attention kernel is compute- or memory-bound on the roofline. See arithmetic-intensity.

Sparse & linear

  • Sliding-window attention — Each query attends only to the last keys, giving cost and a bounded KV cache; stacking layers grows the effective receptive field (e.g. Mistral, Longformer). See sparse-attention.
  • Attention sink — Initial tokens that absorb disproportionate attention mass; retaining a few sink tokens alongside a sliding window (StreamingLLM) preserves quality under KV eviction. See sparse-attention.
  • Sparse attention — Any pattern restricting each query to a subset of keys (strided, block, global+local) to break the cost while approximating full attention. See sparse-attention.
  • Linear attention — Replaces softmax with a kernel feature map so , giving cost and a recurrent state; trades exactness for scaling. See linear-attention.
  • State-space model (SSM) — Sequence model with a linear recurrence , ; selective variants (Mamba) rival attention at with constant-size state. See state-space-models.

Multimodal

  • Perceiver / resampler — A cross-attention module where a small set of learned latent queries attends over a large (possibly variable-size) input, compressing it to a fixed token budget (Perceiver, Flamingo Perceiver-Resampler). See 08-attention-in-vits-and-vlms.

Long-context

  • Context length — The maximum sequence a model attends over in one forward pass; the primary axis of the long-context frontier. See long-context.
  • RoPE scaling / YaRN — Post-hoc rescaling of RoPE frequencies (position interpolation, NTK-aware, YaRN) to extend context beyond the trained length with minimal fine-tuning. See rope.
  • Ring attention — Distributes the sequence across devices, passing blocks around a ring while overlapping compute and communication, enabling near-arbitrary context via online softmax accumulation. See long-context.

Systems

  • FlashAttention — IO-aware exact attention kernel that tiles into SRAM and uses online softmax to avoid materializing the score matrix, cutting HBM traffic from to . See flash-attention.
  • Online softmax — Streaming softmax recurrence tracking running max and denominator so the normalization is computed in one pass without holding the full score row; the numerical core of FlashAttention and ring attention. See online-softmax.

Part of attention-mechanisms.