Transformer
A neural network architecture using self-attention mechanisms to process sequential data in parallel, forming the foundation of modern LLMs.
The Transformer architecture, introduced in the 2017 paper 'Attention Is All You Need', revolutionized natural language processing by replacing recurrent neural networks (RNNs) with self-attention. Its key innovation is the use of multi-head self-attention and feed-forward layers stacked in encoder-decoder blocks. Self-attention computes the relevance of every token in a sequence to every other token, allowing the model to capture long-range dependencies without sequential recurrence. This enables parallel training on GPUs, drastically reducing training time. The Transformer consists of an encoder (which processes the input) and a decoder (which generates output), but many modern LLMs (like GPT) use only the decoder stack, while BERT uses only the encoder. Each layer includes layer normalization and residual connections to stabilize training. The key parameters: number of layers (depth), hidden dimension (width), number of attention heads, and feed-forward size. Scaling laws show that larger models (more parameters) with more data yield better performance, but inference cost grows quadratically with sequence length due to attention's O(n) complexity. Efficient variants like sparse attention, FlashAttention, and linear attention tackle this. The Transformer's versatility extends to vision (ViT), audio (Whisper), and multimodal models. For AI builders, understanding Transformer internals helps optimize batch size, sequence length, and hardware choice (e.g., HBM bandwidth for attention operations).
Transformers don't inherently understand order; they rely on positional encodings to track token positions.
Related terms
Concepts you'll usually encounter alongside this one.
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.
FlashAttention is an I/O-aware algorithm that computes exact attention without materializing the full attention matrix, reducing memory usage from O(n^2) to O(n) and improving speed 2-10x on GPUs.
The KV cache stores intermediate key and value tensors from previous tokens during autoregressive generation, enabling subquadratic computation by avoiding redundant re-encoding of the full context.
Used in benchmarks
Workloads on MyAI Bench that involve Transformer.
Mentioned in tutorials
Hands-on guides that put this concept to work.
Stand up a fully functional local LLM stack on Ubuntu 22.04, NVIDIA drivers, CUDA, Ollama, and your first model, in under 30 minutes.
Run local LLMs on Windows 11 the right way, WSL2, the WSL CUDA toolkit, and Ollama with full GPU acceleration. Native installer covered too.
Apple Silicon is shockingly good at LLM inference. Get Ollama running with unified memory acceleration on any M-series Mac in 15 minutes.
DeepSeek's reasoning model rivals GPT-4 on math and code. Run the distilled 7B/14B/32B variants on consumer hardware in 30 minutes.
See how this term affects your memory budget.
Real numbers, real chips, every workload.
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.