Home Knowledge Base Attention Mechanisms

Attention Mechanisms are the neural network operations that dynamically compute weighted combinations of value vectors based on query-key similarity — enabling each element in a sequence to gather information from all other elements based on relevance, forming the computational core of transformer architectures and the single most impactful innovation in modern deep learning.

Scaled Dot-Product Attention

The fundamental operation: Attention(Q, K, V) = softmax(QKᵀ/√dₖ)V

where Q (queries), K (keys), V (values) are linear projections of the input. The dot product QKᵀ computes pairwise similarity between all query-key pairs, softmax normalizes to a probability distribution, and the result weights the values. The √dₖ scaling prevents attention scores from becoming extreme in high dimensions.

Multi-Head Attention

Instead of one attention function with d-dimensional keys, queries, and values, the computation splits into h parallel heads, each with dₖ=d/h dimensions. Each head can attend to different aspects of the input (syntactic structure, semantic similarity, positional relationships). The concatenated head outputs are linearly projected to produce the final output.

Self-Attention vs. Cross-Attention

KV Cache

During autoregressive inference, each new token only needs its own query vector — the keys and values from all previous tokens are cached and reused. This reduces per-token computation from O(N²) to O(N) but requires O(N × L × d) memory that grows with sequence length. KV cache memory management is the primary bottleneck for long-context LLM serving.

Efficient Attention Variants

Attention Mechanisms are the core computation that makes transformers transformers — the dynamic, content-dependent information routing that replaced fixed convolution kernels and recurrent state updates with a universally flexible mechanism for relating any part of the input to any other.

attention mechanism transformerself attention multi headcross attentionkv cache attentionflash attention

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.