Glossary/ Architecture

Attention

Attention is a mechanism that computes weighted sums of input tokens, allowing the model to focus on the most relevant parts of the sequence when generating each output.

Attention is the core building block of transformer models, introduced in the 2017 paper 'Attention Is All You Need'. It enables each token to 'look at' all other tokens in the sequence, assigning relevance scores (weights) that determine how much each token influences the representation of the current one. The most common form is scaled dot-product attention: each token is projected into query (Q), key (K), and value (V) vectors; the dot product between a query and all keys gives attention scores, which are normalized via softmax and used to blend the values. This mechanism gives transformers their global receptive field-every output token can directly attend to any input token, unlike RNNs which process sequentially. Multi-head attention runs several attention heads in parallel, each learning different relationships (e.g., syntax, semantics, coreference). Attention's O(n^2) complexity in sequence length n is both its strength and weakness: it enables long-range dependencies but makes long-context inference expensive. Variants like causal attention (masked to prevent future token leakage) are used in autoregressive LLMs. FlashAttention reimplements the algorithm to reduce memory reads/writes, achieving up to 10x speedup for long sequences. Sparse attention patterns (e.g., sliding window, global+local) sacrifice some expressivity for efficiency. Attention is often visualized as heatmaps showing token-to-token relevance, useful for interpretability. In decoder-only models like GPT, each token's attention is computed over all preceding tokens in the context window.

Formula
Attention(Q, K, V) = softmax(Q * K^T / sqrt(d_k)) * V
Common misconception

Attention does not understand meaning-it is a statistical weighting mechanism that learns to correlate tokens based on training data, not symbolic reasoning.

Canonical reference
https://arxiv.org/abs/1706.03762

Related terms

Concepts you'll usually encounter alongside this one.

Used in benchmarks

Workloads on MyAI Bench that involve Attention.

Mentioned in tutorials

Hands-on guides that put this concept to work.

VRAM Calculator

See how this term affects your memory budget.

MyAI Bench

Real numbers, real chips, every workload.

Buying guides

Picks for builders, by use case.

Stay Ahead of the AI Curve

Get weekly AI hardware news, benchmark updates, and deals in your inbox. Founding-subscriber list, be one of the first.

✓ No spam✓ Weekly digest✓ Unsubscribe anytime