Step 6 of 6
GPTs, diffusion & beyond
Decoder-only transformers (GPT), vision transformers (ViT), diffusion models, mixture of experts, and the frontier architectures shaping AI today.
18 min read
The transformer is the foundation, but the models shipping today are built on a stack of architectural refinements: better normalization, efficient attention, mixture of experts, and multimodal fusion. This is the landscape of modern architectures - what's changed since "Attention Is All You Need," and where the field is heading.
The modern transformer recipe#
The original 2017 transformer has been refined in nearly every component. The modern LLM recipe looks like this:
| Component | Original (2017) | Modern (2024+) |
|---|---|---|
| Normalization | Post-LayerNorm | Pre-RMSNorm |
| Activation | ReLU | SiLU/SwiGLU |
| Position encoding | Sinusoidal | RoPE |
| Attention | Multi-head (MHA) | Grouped-query (GQA) |
| Architecture | Encoder-decoder | Decoder-only |
| Vocabulary | BPE (30K tokens) | BPE/SentencePiece (32K-256K) |
Pre-normalization (normalizing before attention/MLP instead of after) makes training more stable. RMSNorm replaces LayerNorm by dropping the mean-centering step - simpler, faster, and equally effective.
SwiGLU (SiLU-gated linear unit) replaces the simple two-layer MLP with a gated version that's empirically better:
- RMSNorm
- Root Mean Square Normalization - a simpler alternative to LayerNorm that skips mean-centering, normalizing only by the root mean square of activations.
- SwiGLU
- A gated MLP activation where one linear projection controls how much of another passes through - empirically better than ReLU or GELU in transformer MLPs.
- BPE
- Byte Pair Encoding - a tokenization method that builds a vocabulary by iteratively merging the most frequent character pairs, balancing vocabulary size with coverage.
- GQA
- Grouped Query Attention - multiple query heads share the same key-value heads, cutting KV cache memory 4-8× with minimal quality loss.
SwiGLU: the MLP uses a gating mechanism where one projection controls how much of the other passes through.
Grouped query attention (GQA)#
Standard multi-head attention gives each head its own Q, K, and V projections. This means the KV cache scales linearly with the number of heads - expensive for serving.
GQA groups multiple query heads to share the same K and V heads:
| Variant | Q heads | KV heads | KV cache size |
|---|---|---|---|
| MHA | 32 | 32 | 1× |
| GQA | 32 | 8 | 0.25× |
| MQA | 32 | 1 | 0.03× |
GQA gives most of MHA's quality with a fraction of the memory. LLaMA 2 70B, Mistral, and most modern LLMs use GQA. Multi-query attention (MQA) goes further with a single KV head, but quality drops more noticeably.
Mixture of experts (MoE)#
A standard transformer processes every token through every parameter. A Mixture of Experts model has multiple expert MLPs per layer, but each token is routed to only a few of them:
- 01Token enters the MoE layer
- 02Router network scores all experts for this token
- 03Top-k experts are selected (typically k=2)
- 04Token is processed by selected experts only
- 05Outputs are combined using router weights
The result: a model with many parameters (high capacity) but low per-token compute (only the active experts run). Mixtral 8×7B has 47B total parameters but only uses ~13B per token - matching dense 13B models in compute while outperforming them in quality.
Multimodal architectures#
Modern models process multiple modalities - text, images, audio, video - through a unified transformer:
| Approach | How it works | Examples |
|---|---|---|
| Late fusion | Separate encoders, combined at the end | CLIP (image + text) |
| Early fusion | All modalities tokenized and processed together | Gemini, GPT-4o |
| Cross-attention | Image/audio features attend to text features | Flamingo, LLaVA |
The key insight: everything becomes tokens. An image is patched into 16×16 pixel blocks, each projected to a vector (as in ViT). Audio is chunked into frames. Video is a sequence of image patches. Once tokenized, the same transformer processes all modalities.
Vision Transformers (ViT) divide an image into fixed-size patches (typically 16×16 pixels), flatten each patch into a vector, add position embeddings, and feed them through a standard transformer. No convolutions needed - pure attention over patches.
Efficient attention variants#
Standard attention is O(n²) in sequence length, which limits context windows. Several approaches reduce this:
| Method | Complexity | Approach |
|---|---|---|
| Flash Attention | O(n²) compute, O(n) memory | Fused kernel; exact, just memory-efficient |
| Sliding window | O(n·w) | Each token attends to w nearest neighbors |
| Linear attention | O(n) | Kernel approximation of softmax |
| Ring attention | O(n²) across devices | Distributes long sequences across GPUs |
Flash Attention doesn't change the math - it's an exact implementation that avoids materializing the full n×n attention matrix by computing attention in tiles. This reduces memory from O(n²) to O(n) and is 2-4× faster due to better GPU memory access patterns. It's now the default in all major frameworks.
State space models - beyond transformers?#
State space models (SSMs) like Mamba offer an alternative to attention for sequence modeling:
SSM: a continuous-time state equation discretized for sequences. Linear recurrence enables O(n) inference and O(n log n) training.
SSMs process sequences in O(n) time (linear in sequence length) and can be trained with a parallel scan in O(n log n). The Mamba architecture adds selective state spaces - the matrices A, B, C depend on the input, making the model content-aware like attention.
Hybrid architectures (Jamba, Zamba) combine transformer layers with Mamba layers, getting attention's quality for tasks that need global reasoning and Mamba's efficiency for long sequences.
- State space model (SSM)
- A sequence model based on continuous-time state equations - processes sequences in linear time O(n) instead of attention's quadratic O(n²).
- Mamba
- A selective state space model where the state transition matrices depend on the input, making the model content-aware like attention while keeping linear-time efficiency.
- MoE
- Mixture of Experts - routes each token to only a few expert MLPs out of many, giving large model capacity with low per-token compute cost.
- Flash Attention
- An exact attention implementation that avoids storing the full N×N attention matrix, reducing memory from O(n²) to O(n) with no quality loss.
Where it shows up in ML#
The LLaMA recipe is the standard
Pre-RMSNorm, SwiGLU, RoPE, GQA - this combination (from LLaMA/Mistral) is now the default for open-source LLMs.
MoE enables scale without cost
Mixtral, DBRX, and likely GPT-4 use MoE to scale total parameters while keeping inference cost manageable.
Flash Attention is universal
Every modern training and inference framework uses Flash Attention. It's exact (no approximation), just dramatically more memory-efficient.
Multimodal is the new default
GPT-4o, Gemini, Claude - frontier models natively process text, images, and audio. The trend is toward single-model, multi-modal systems.