Skip to content

Chapter 0 · Architecture Overview and Evolution

0.1 What is the overall structure of the Transformer, and how do encoder-only, encoder-decoder and decoder-only models differ? ★★

One-sentence answer

A Transformer is a stack of identical blocks, each containing an attention sublayer and an FFN sublayer, wrapped with residual connections and normalization. The three families use the same modules and differ in the attention mask, i.e. which tokens each token may see: encoder-only models (e.g. BERT) are bidirectional and excel at understanding; encoder-decoder models (e.g. T5) read the input with a bidirectional encoder and then generate the output with a causal decoder, which suits tasks with clearly separate input and output; decoder-only models (e.g. GPT, Llama) are causal, excel at open-ended generation, and are the standard structure of today's general-purpose LLMs.

Figure
The Transformer architecture: the encoder on the left and the decoder on the right (Vaswani et al. 2017, Figure 1)

I will address three aspects: the basic components of the Transformer, how the three families differ, and what each is good at.

(1) A Transformer consists of an embedding, \(L\) identical blocks and an output layer, and each block is "attention + FFN".

The original Transformer (Vaswani et al. 2017) was an encoder-decoder model designed for machine translation. The text is first split into tokens, each token looks up a \(d\)-dimensional vector, and positional information is added; these vectors pass through \(L\) identical blocks, and the output layer finally maps them to a probability for every word in the vocabulary. Each block has two sublayers: attention moves information between positions, for example finding the noun that the pronoun "it" refers to earlier in the text, while the FFN applies a nonlinear transformation to each position separately. Both sublayers are wrapped with a residual connection and normalization, so that even very deep networks train stably (details of each component are in Chapter 1).

(2) The three families differ in the attention mask, and the mask in turn determines the training objective.

  • Encoder-only: every token can see all tokens on both its left and its right, i.e. bidirectional attention. Because the model sees the later text during training, it cannot be trained to "predict the next word"; instead it uses masked language modeling (MLM): about 15% of tokens are masked at random, and the model has to recover them from the context on both sides. The representative model is BERT (Devlin et al. 2018).
  • Encoder-decoder: the encoder reads the entire input with bidirectional attention, and the decoder generates the output token by token with causal attention, reading the input representation at any time through cross-attention (attention whose query comes from the decoder and whose key and value come from the encoder output). Representative models are the original Transformer and T5 (Raffel et al. 2019); T5 is pretrained with span corruption, which masks several spans of the input and has the decoder generate the masked content.
  • Decoder-only: only the decoder is kept, and cross-attention is removed; each token can see only itself and earlier tokens, i.e. causal attention, and the training objective is next-token prediction. Input and output live in the same sequence, and the model simply continues writing after reading the prompt. Representative models are the GPT series (Radford et al. 2018) and Llama (Touvron et al. 2023).

(3) The mask determines what each family is good at.

Bidirectional attention gives encoder-only models the most thorough understanding of a piece of text, and one forward pass yields representations for all positions, so they suit classification, text embeddings, retrieval and reranking; but they have never learned to continue text from left to right, so they are unsuitable for generation. The "understand first, then generate" division of labor in encoder-decoder models suits tasks such as translation and summarization, where input and output are clearly separate. Decoder-only models cast every task as "given the preceding text, continue it", so they are the best fit for open-ended generation and dialogue, and the easiest to extend into general-purpose models.

In summary: the three families share the same modules, and the real difference is the attention mask: the mask determines the training objective, and the training objective determines whether the model is better at understanding or at generation.

Comparing the three families:

Encoder-only Encoder-decoder Decoder-only
Attention Bidirectional: every token sees the whole input Encoder bidirectional; decoder causal and reads the encoder through cross-attention Causal: sees only itself and earlier tokens
Pretraining objective MLM (recover masked tokens) Sequence-to-sequence objectives such as span corruption Next-token prediction
Representative models BERT, RoBERTa Original Transformer, T5, BART GPT series, Llama, Qwen, DeepSeek
Good at Understanding: classification, embeddings, retrieval, reranking Tasks with separate input and output: translation, summarization Open-ended generation, dialogue, general-purpose LLMs

Going deeper: the forward pass of a decoder-only model and the residual-stream view

(1) The forward pass: embedding → \(L\) blocks → final normalization → LM head.

One block of a modern decoder-only model can be written as

\[ h = x + \mathrm{Attn}(\mathrm{Norm}(x)), \qquad y = h + \mathrm{FFN}(\mathrm{Norm}(h)) \]

Here \(x\) is the input to the block, \(h\) the intermediate result after the attention sublayer, \(y\) the output of the block, and \(\mathrm{Norm}\) the normalization (modern LLMs usually use RMSNorm; see 1.6 in Chapter 1). After the last block there is one more normalization, and the LM head (a \(d\times V\) matrix, where \(V\) is the vocabulary size) maps each position's vector to logits over the vocabulary; a softmax over the logits at the last position gives the probability distribution of the next token.

(2) The residual stream: every sublayer reads, modifies and writes back the same stream of information.

Imagine that each token owns a vector running from the bottom of the network to the top, called the residual stream. Each sublayer reads the current information from it, computes an update, and adds the update back. Attention is therefore "communication between tokens", the FFN is "computation within a token", and the whole network accumulates information on this stream layer by layer. This view is widely used in interpretability research (Elhage et al. 2021).

(3) The size of the original Transformer.

The base model has 6 layers each in the encoder and the decoder, \(d=512\), 8 heads and an FFN inner dimension of 2048, and was trained on WMT English–German and English–French translation data.

Follow-up questions

Follow-up 1: Can BERT be used to generate text?

Not well. During training every position in BERT sees context on both sides, so it learns "fill in the blank from the surrounding context", not "continue from the preceding text". Forcing it to generate token by token from left to right creates a mismatch between the conditions at inference and those at training, and the results are poor.

Follow-up 2: How does cross-attention differ from self-attention?

The difference is whether the query and the key/value come from the same sequence. In self-attention, Q, K and V all come from the same sequence; in cross-attention, the query comes from the decoder's current representation and the key and value come from the encoder output, so the decoder can consult the whole input when generating every token.

Follow-up 3: Are encoder-only models still useful?

Yes, especially for embeddings and reranking. These tasks need the model to see the context on both sides of a text and produce a result in one forward pass, which is exactly the strength of a bidirectional encoder; there have also been modernized versions of BERT in recent years, such as ModernBERT (Warner et al. 2024). That said, many of today's best embedding models are also adapted from decoder-only LLMs.

Common mistakes

  • Do not say that the three families use different basic modules: They use the same attention and FFN; the differences are the attention mask and whether there is cross-attention.
  • Do not say that decoder-only models cannot "understand" their input: They understand the input just as well; they simply apply causal attention to the input too.
  • Do not describe GPT as encoder-decoder: The GPT series has been decoder-only from the start.

0.2 Why are almost all LLMs today decoder-only? ★★

One-sentence answer

There are four main reasons: next-token prediction makes every position provide a training signal, so training is efficient; the single format "given the preceding text, continue it" covers every task and naturally gives rise to in-context learning; causal attention means the keys and values of past tokens never change, so the KV cache can be reused indefinitely and inference is cheaper; and in practice it has scaled best, with the whole ecosystem built around it. Encoders have not been eliminated; they are still widely used for embeddings and reranking.

I will address four aspects: training efficiency, task format, inference cost, and scalability in practice.

(1) Training is more efficient: every position provides a training signal.

With next-token prediction, every position in the sequence predicts its next token, so a 1,000-token text provides about 1,000 training signals; BERT's MLM masks only about 15% of tokens, so the same text provides only about 150. With the same data and compute, a decoder-only model therefore extracts more learning signal from each token. The causal mask plays a key role here: it lets the predictions at all positions be computed in parallel in a single forward pass, with no possibility of peeking at the answer (see 1.4 in Chapter 1).

(2) One format covers every task and naturally gives rise to in-context learning.

Because input and output live in the same sequence, question answering, translation, coding and other tasks can all be written as "here is a prompt, keep writing", with no task-specific input and output structure. It is precisely this format that lets a model learn a new task directly from a few examples in the prompt, i.e. in-context learning (Brown et al. 2020). By contrast, an encoder-decoder model must decide in advance what is "input" and what is "output", which is unnatural in settings where input and output interleave, such as multi-turn dialogue and tool calling.

(3) Inference is cheaper: the keys and values of past tokens can be reused indefinitely.

Under causal attention, newly added tokens never change the computations for earlier tokens, so the keys and values already computed can be cached and reused, i.e. the KV cache; in a multi-turn dialogue only the newly added part needs processing. A bidirectional encoder cannot do this: once a new token is added, every position can see it, every position's representation changes, and everything has to be recomputed.

(4) It has scaled best in practice, and the ecosystem has formed a positive feedback loop.

Wang et al. (2022) systematically compared architectures and training objectives under the same compute and found that, with self-supervised pretraining alone, decoder-only models trained with a causal language-modeling objective have the strongest zero-shot ability; however, after additional multitask finetuning, encoder-decoder models performed best. After GPT-3, scaling laws, training frameworks and inference engines were all built around decoder-only models, and the more was invested, the more mature they became, which further consolidated their dominance.

In summary: decoder-only models won because they have the densest training signal, the most unified task format, and a cache that can be reused at inference, and they have been validated repeatedly at scale; the reasons are partly technical and partly ecosystem inertia.

Going deeper: designs in between, a comparison of costs, and the full-rank intuition

(1) Prefix LM: bidirectional attention over the prompt, causal attention over the generated part.

A prefix LM (e.g. UniLM, Dong et al. 2019) lets the tokens within the prompt see one another, while the generated part still sees only the preceding text. It combines bidirectional understanding with autoregressive generation, but in a multi-turn dialogue, if the new turn's input is merged into the bidirectional prefix, the representations computed earlier must be recomputed, so cache reuse is less convenient than in a purely causal structure, and it did not become mainstream.

(2) Typical trade-offs of the three families in training and inference.

Encoder-only Encoder-decoder Decoder-only
Positions providing a training signal About 15% (the masked positions) Only the output part All positions
Task format Needs a task-specific output layer Needs a split into input and output Unified as continuation
Reuse of earlier computation when content is appended No, everything is recomputed The encoder part is recomputed Yes, the KV cache is reused indefinitely

(3) An intuitive argument: the causal attention matrix is always full-rank.

The causal attention weight matrix is lower-triangular, and the softmax makes its diagonal entries strictly positive, so it is always full-rank; the score matrix \(QK^\top\) of bidirectional attention has rank at most the head dimension, and some argue that this limits the expressiveness of bidirectional attention. This is only an intuitive argument without rigorous experimental support; it can be mentioned in an interview, but it should not be presented as a main reason.

Follow-up questions

Follow-up 1: Is anyone still using encoder-decoder models?

Yes, but they are no longer the mainstream for general-purpose LLMs. They remain common in tasks with clearly separate input and output, such as translation and speech recognition (e.g. Whisper, Radford et al. 2022). Google's T5Gemma (Zhang et al. 2025) even converts pretrained decoder-only models into encoder-decoder models and reports advantages in the trade-off between quality and inference efficiency.

Follow-up 2: With the same number of parameters, do encoder-decoder and decoder-only models cost the same compute?

No; in an encoder-decoder model each token passes through only half of the parameters. The T5 paper points out that a model with \(L\) layers each in the encoder and the decoder has about as many parameters as a \(2L\)-layer decoder-only model, but only about the compute of an \(L\)-layer decoder-only model, because input tokens pass only through the encoder and output tokens mainly through the decoder (Raffel et al. 2019). Hence, when comparing architectures, one must state whether the comparison is at equal parameters or at equal compute.

Follow-up 3: What are the limitations of decoder-only next-token prediction?

Mainly that it uses context in one direction only and that generation is sequential. When predicting, each position sees only the preceding text and cannot use information from later text; at inference, each step must wait until the previous token has been generated. The former is usually mitigated by placing the needed information in the prompt, and the latter has motivated acceleration methods such as speculative decoding and multi-token prediction (see 0.5, and Chapter 3 of the Inference, Evaluation & Deployment direction).

Common mistakes

  • Do not say that encoders have been eliminated: For tasks such as embeddings and reranking, bidirectional encoders remain a common choice.
  • Do not say that decoder-only models beat other architectures on every task: Wang et al. (2022) found that encoder-decoder models performed best after multitask finetuning; the advantage of decoder-only models comes mainly from generality and scalability.
  • Do not treat the "full-rank" argument as established: It is only an intuitive explanation.

0.3 What changes have modern LLMs made relative to the original Transformer? ★★

One-sentence answer

The skeleton of the block (attention + FFN + residual) is essentially unchanged; the main changes are: the overall structure moved from encoder-decoder to decoder-only; normalization moved to Pre-norm with RMSNorm, which makes deep training more stable; positional encoding moved to RoPE, which suits long context better; attention moved to GQA to shrink the KV cache; bias terms were removed; and large models commonly replace the FFN with MoE, expanding capacity while keeping the compute per token roughly unchanged.

I will address three aspects: what has not changed, the main component-level changes, and the goals these changes serve.

(1) The overall structure moved from encoder-decoder to decoder-only, but the skeleton of the block did not change.

Modern LLMs remove the encoder and cross-attention and keep only the causal decoder (see 0.2 for why). Each block is still "attention sublayer + FFN sublayer", plus residual connections and normalization. In other words, nearly all the improvements since 2017 have been replacements of components rather than an overhaul of the overall design.

(2) There are five main component-level changes.

  • Pre-norm and RMSNorm: normalization moved from after the residual addition to before each sublayer, so gradients can flow straight back along the residual path and deep training is more stable; at the same time, RMSNorm, which skips mean subtraction, replaced LayerNorm and is cheaper to compute (see 1.6–1.7 in Chapter 1).
  • RoPE: instead of adding absolute position vectors to the input, each layer rotates the query and key according to their positions, so the attention score depends only on the relative distance, which also makes context extension easier (Su et al. 2021; see Chapter 3).
  • GQA: a group of query heads shares one key/value head, so the KV cache shrinks proportionally; for example, with 32 query heads sharing 8 KV heads, the KV cache drops to 1/4 (Ainslie et al. 2023; see Chapter 2).
  • No bias terms: linear layers and normalization layers no longer use bias terms; the parameter count barely changes, but PaLM reported that this made training of large models more stable (Chowdhery et al. 2022).
  • MoE: the FFN is replaced by multiple experts, and a router activates only a few of them for each token, greatly increasing the total parameter count while the compute per token stays roughly the same (see Chapter 5).

(3) These changes serve three goals: training stability, long context and inference efficiency.

Pre-norm, RMSNorm and the removal of bias terms mainly address training stability as models become deeper and larger; RoPE addresses the extension of positional encoding to long context; GQA and MoE reduce inference cost and raise capacity, through the KV cache and the compute per token respectively. The original Transformer was designed for translation, with on the order of a hundred million parameters and sentences of tens to hundreds of tokens, whereas modern LLMs are trained and deployed at hundreds of billions of parameters and hundreds of thousands of tokens; all of these changes respond to new bottlenecks brought by scale.

In summary: from the original Transformer to modern LLMs, the skeleton is unchanged and the components were changed for scale: training stability, long context and inference efficiency are the three main threads.

Comparing the original Transformer with modern LLMs:

Component Transformer (2017) Modern LLM (e.g. Llama 3, DeepSeek-V3) Reason for the change
Overall structure Encoder-decoder Decoder-only One unified format; reusable KV cache
Normalization Post-LN, LayerNorm Pre-norm, RMSNorm Stable deep training; cheaper
Positional encoding Sinusoidal absolute encoding RoPE Encodes relative position; easier context extension
Attention MHA GQA or MLA Smaller KV cache; faster inference
Bias terms Yes None Little benefit; more stable at scale
Dropout 0.1 None in pretraining Data is seen about once; no overfitting
FFN Dense MoE common in large models Larger capacity at the same compute per token
Vocabulary About 37K (BPE) About 100K to 150K Better compression and multilingual coverage (see Chapter 4)

Going deeper: why bias and dropout were removed, and a concrete configuration

(1) Removing bias: little benefit, and possibly harmful to stability.

In a \(d\times d\) linear layer, the bias adds only \(d\) parameters and barely helps expressiveness, while normalization layers already handle overall shifts in the values. PaLM used no bias in any dense layer or normalization layer and reported that this improved training stability for large models. Most later models followed this practice (a few kept the bias in the QKV projections, e.g. Qwen2).

(2) Removing dropout: pretraining faces underfitting, not overfitting.

Dropout exists to prevent overfitting. But LLM pretraining uses so much data that each token is seen roughly once; the model's problem is "not having learned everything", not "memorizing too rigidly". Dropout would then only add noise to training and slow convergence. When finetuning on a small dataset, overfitting becomes a concern again, and only then can dropout help.

(3) A concrete configuration: Llama 3 8B.

32 layers, hidden dimension \(d=4096\), 32 query heads and 8 KV heads (GQA), a RoPE base frequency \(\theta=500{,}000\), a vocabulary of about 128K, Pre-norm with RMSNorm, and no bias in the linear layers (Dubey et al. 2024).

Follow-up questions

Follow-up 1: Which changes were proposed but not widely adopted?

Typical examples are parallel blocks and ALiBi. A parallel block (GPT-J, PaLM) lets attention and the FFN read the same input and compute simultaneously, i.e. \(y = x + \mathrm{Attn}(\mathrm{Norm}(x)) + \mathrm{FFN}(\mathrm{Norm}(x))\); PaLM reported that it made training about 15% faster at large scale, but with a slight quality loss in small models, and most later mainstream models still use sequential blocks. ALiBi (Press et al. 2021) replaces positional encoding with a linear bias proportional to distance and extrapolates well, but RoPE together with scaling methods ultimately became the mainstream (see Chapter 3).

Follow-up 2: How were these changes selected? Are conclusions from small-scale experiments reliable?

Not necessarily; the changes that survived are mostly those that remain effective at scale and mainly improve stability or efficiency. Narang et al. (2021) re-implemented a large number of Transformer modifications in a single codebase and experimental setup and found that most did not bring meaningful improvements, with many reported gains depending on implementation details. Industry therefore tends to reuse recipes that have been validated repeatedly at scale and changes the architecture only when there is a clear bottleneck (such as the KV cache or long context).

Follow-up 3: How does the architecture of modern LLMs differ from that of GPT-3?

GPT-3 was already decoder-only with Pre-LN; the main differences lie in the details of positional encoding, attention and normalization. GPT-3 used learned absolute position vectors, standard MHA and LayerNorm, and kept bias terms (it also alternated dense attention with locally banded sparse attention); modern models switched to RoPE, GQA or MLA and RMSNorm, and removed bias terms.

Common mistakes

  • Do not say that the block structure of modern LLMs is completely different: The skeleton is still attention + FFN + residual; the changes are mainly replacements of components.
  • Do not say that RoPE is added to the input embedding: It acts on the query and key in every layer.
  • Do not say that GQA is mainly meant to speed up training: Its benefit lies mainly in the KV cache at inference.
  • Do not say that MoE reduces the parameter count: MoE increases the total parameters; what it reduces is the parameters activated, and the compute spent, per token.

0.4 How do you estimate a Transformer's parameter count and compute? ★★

One-sentence answer

Each layer has about \(12d^2\) parameters (the four attention matrices Q, K, V, O give \(4d^2\), and an FFN of 4× width gives \(8d^2\)), so the whole model has about \(12Ld^2\) plus the vocabulary embedding. For compute, every parameter performs one multiply-add per token in the forward pass, so each token costs about \(2N\) FLOPs; training adds a backward pass costing about twice the forward pass, so the total compute is about \(6ND\), where \(N\) is the parameter count and \(D\) the number of training tokens.

I will address three aspects: the parameter count, the forward compute, and the training compute.

(1) Parameter count: about \(12d^2\) per layer, and about \(12Ld^2\) plus the embedding for the whole model.

Attention has four \(d\times d\) matrices \(W_Q, W_K, W_V, W_O\), giving \(4d^2\); the FFN expands the dimension from \(d\) to \(4d\) and projects it back to \(d\), with two matrices giving \(2\times d\times 4d = 8d^2\). Each layer therefore has about \(12d^2\), about two-thirds in the FFN and one-third in attention; normalization and similar parameters are of order \(O(d)\) and can be ignored. Multiplying by the number of layers \(L\) and adding the embedding table's \(Vd\) (\(V\) is the vocabulary size; if the LM head is not shared with the embedding, add another \(Vd\)) gives the parameter count of the whole model. For example, Llama 2 7B has 32 layers and \(d=4096\): \(12\times32\times4096^2\approx6.4\)B, plus about 0.26B for the embedding and LM head, about 6.7B in total, matching the published figure.

(2) Forward compute: about \(2N\) FLOPs per token.

In a matrix multiplication, every parameter performs one multiplication and one addition for each token, i.e. 2 floating-point operations (FLOPs), so the forward pass costs about \(2N\) FLOPs per token, and generating one token at inference also costs about \(2N\). For example, a 7B model needs about 14 GFLOPs per generated token. This estimate counts only the matrix multiplications involving parameters; the two attention steps \(QK^\top\) and the multiplication by \(V\) have no parameters and add an extra term that grows with context length, which can be ignored when the context is not too long (see "Going deeper" below).

(3) Training compute: about \(6N\) per token, about \(6ND\) in total.

The backward pass computes two kinds of gradients: gradients with respect to activations, used to keep propagating backward, and gradients with respect to weights, used to update the parameters; each costs about as much as the forward pass, so the backward pass costs about \(4N\). Forward plus backward, training costs about \(6N\) per token, and training on \(D\) tokens costs about \(C\approx6ND\) in total. For example, training a 7B model on 2T tokens takes about \(6\times7\times10^9\times2\times10^{12}\approx8\times10^{22}\) FLOPs. Combined with the GPU's peak throughput and the MFU, this gives an estimate of training time (see 3.9 in Chapter 3 of the LLM Training Pipeline direction).

In summary: remember three numbers, \(12d^2\) parameters per layer, \(2N\) forward FLOPs per token, and \(6ND\) in total for training, and you can quickly estimate a model's size and training cost.

Going deeper: corrections for GQA and MoE, and the extra compute of attention

(1) With GQA, only \(W_K\) and \(W_V\) shrink.

With \(g\) KV heads of dimension \(d_h\), \(W_K\) and \(W_V\) change shape from \(d\times d\) to \(d\times g d_h\), and the attention parameters go from \(4d^2\) to \(2d^2 + 2d\cdot g d_h\). For example, with 32 query heads sharing 8 KV heads, \(W_K\) and \(W_V\) each shrink to 1/4, and the attention parameters drop from \(4d^2\) to \(2.5d^2\).

(2) For MoE models, distinguish total parameters from activated parameters.

The memory footprint of an MoE model is determined by its total parameters, whereas the compute per token is determined by its activated parameters, so \(N\) in FLOP estimates should be the activated parameters. For example, DeepSeek-V3 has 671B total parameters and activates 37B per token (DeepSeek-AI 2024), so its training compute should be estimated as \(6\times37\text{B}\times D\) (details in Chapter 5).

(3) The extra compute of attention scoring: about \(n_{\text{ctx}}/(12d)\) relative to the parameter part.

\(QK^\top\) and the multiplication by \(V\) involve no parameters and add about \(2Ln_{\text{ctx}}d\) forward FLOPs per token (Kaplan et al. 2020), where \(n_{\text{ctx}}\) is the context length. Its ratio to the parameter part \(2N\approx24Ld^2\) is about \(n_{\text{ctx}}/(12d)\): with both the context length and \(d\) equal to 4096, it adds only about 8%; but once the context reaches hundreds of thousands of tokens, this term becomes the dominant cost.

(4) Rough memory estimates.

At inference, bf16 weights take 2 bytes per parameter, about 14 GB for a 7B model, plus the KV cache (see Chapter 1 of the Inference, Evaluation & Deployment direction). Mixed-precision training also stores gradients and Adam states, about 16 bytes per parameter, about 112 GB for a 7B model, still excluding activations (see 3.2 in Chapter 3 of the LLM Training Pipeline direction).

Follow-up questions

Follow-up 1: Why does the backward pass cost about twice the forward pass?

Because every matrix multiplication has to be computed twice in the backward pass. For \(Y=XW\) (\(X\) the input, \(W\) the weights), the backward pass computes both the gradient with respect to the input, \(\partial \mathcal{L}/\partial X = (\partial \mathcal{L}/\partial Y)W^\top\), to keep propagating backward, and the gradient with respect to the weights, \(\partial \mathcal{L}/\partial W = X^\top(\partial \mathcal{L}/\partial Y)\), to update the parameters, where \(\mathcal{L}\) is the loss. Each costs the same as the forward \(XW\), so the backward pass costs about twice the forward pass.

Follow-up 2: Should the embedding parameters be counted in the compute?

The embedding lookup needs almost no compute, but the LM head does. The embedding simply fetches one row by token id, with no matrix multiplication; the LM head is a \(d\times V\) matrix multiplication costing about \(2Vd\) FLOPs per token. Kaplan et al. (2020) use the non-embedding parameter count in their scaling laws. In small models the embedding takes a large share, so this distinction matters more there.

Follow-up 3: For a fixed parameter count, should the model be deeper or wider?

Within a reasonable range, it matters little. Kaplan et al. (2020) found that, for a fixed non-embedding parameter count, the loss is insensitive to shape parameters such as the depth-to-width ratio, differing by only a few percent over a wide range. In practice the choice depends more on engineering factors: a very deep model has more sequential steps and is harder to pipeline, while a very wide model has larger matrices per layer. For example, Llama 2 7B has \(d/L=4096/32=128\).

Common mistakes

  • Do not apply \(6ND\) to inference: Inference is forward-only, about \(2N\) per token.
  • Do not forget that \(N\) for MoE is the activated parameter count: Using total parameters severely overestimates compute.
  • Do not say that \(12Ld^2\) already includes the embedding: The vocabulary embedding must be added separately, and its share is not negligible in small models.
  • Do not confuse FLOPs with FLOPS: The former is a total amount of computation; the latter is floating-point operations per second, i.e. hardware speed.

One-sentence answer

The base is still a decoder-only Transformer with MoE, and the changes concentrate in three places: attention layers are no longer full attention in every layer, but mix in linear attention (e.g. Qwen3-Next, Kimi Linear) or sparse attention (e.g. DeepSeek-V3.2's DSA), with MLA used to compress the KV cache; MoE is becoming sparser, with more experts and a lower activation ratio; and multi-token prediction is used to add training signal and accelerate decoding. The common goal is to lower the cost of long context and inference.

I will address three aspects: changes in the attention layers, changes in MoE, and changes in the training objective and decoding.

(1) Attention layers: from "full attention in every layer" toward hybrid and sparse designs.

Long context and long reasoning chains (reasoning models routinely generate tens of thousands of tokens) have made the quadratic complexity of full attention and the ever-growing KV cache the main bottlenecks, so labs have reworked the attention layers in three directions.

  • Hybrid linear attention: most layers are replaced by linear attention, which compresses the history into a fixed-size state so that compute grows linearly with length; only a few full-attention layers are kept for precise retrieval. Qwen3-Next (Qwen Team 2025) alternates Gated DeltaNet (Yang et al. 2024) and gated attention at a 3:1 ratio, and Qwen3.5 brought this structure into the flagship series; Kimi Linear (Kimi Team 2025) mixes Kimi Delta Attention (KDA) and MLA at a 3:1 ratio and reports up to a 75% reduction in KV cache at 1M context.
  • Sparse attention: each query attends only to a small set of selected tokens. DeepSeek Sparse Attention (DSA), introduced in DeepSeek-V3.2 (DeepSeek-AI 2025), uses a lightweight lightning indexer to score all past tokens, and each query attends only to the 2048 highest-scoring tokens; GLM-5 (GLM-5 Team 2026) also adopted DSA.
  • Compressing the KV cache with MLA: MLA compresses the key and value into a low-dimensional vector before caching. Beyond DeepSeek, models such as Kimi K2 (Kimi Team 2025) and Mistral Large 3 have adopted it (the mechanism is in Chapter 2).

(2) MoE: total parameters keep growing while the activation ratio keeps falling.

MoE is already the default for large models, and the trend of the past two years is more and finer-grained experts with a lower fraction activated per token. DeepSeek-V3 has 256 routed experts and selects 8 per token; Kimi K2 has 384 and selects 8, with 1T total and 32B activated parameters; Qwen3-Next has 512 and selects 10, with 80B total and about 3B activated; Kimi K3 (Kimi Team 2026) has 896 and selects 16, with 2.8T total parameters. Finer experts allow more flexible combinations, so the same activated compute corresponds to a larger total capacity; the price is higher demands on load balancing, cross-device communication and memory (see Chapter 5).

(3) Training objective and decoding: multi-token prediction is widely adopted.

DeepSeek-V3 adds an MTP module after the main model, which during training has each position additionally predict the token after next, providing a denser training signal; at inference, this module can serve as the draft model for speculative decoding, and the paper reports that the additionally predicted token is accepted 85% to 90% of the time, making generation about 1.8 times as fast. Qwen3-Next and DeepSeek-V4 also keep MTP (speculative decoding is covered in Chapter 3 of the Inference, Evaluation & Deployment direction).

In summary: architectural evolution in 2025–2026 has not overturned the Transformer but refined it around the cost of long context and inference: attention layers have become hybrid and sparse, MoE sparser, and MTP is used to accelerate decoding.

Going deeper: representative models, DeepSeek-V4, and a counterexample

(1) Architectural choices of representative open models from the past two years.

Model Release Attention Total / activated parameters
DeepSeek-V3 December 2024 MLA 671B / 37B
Kimi K2 July 2025 MLA 1T / 32B
Qwen3-Next September 2025 Gated DeltaNet and gated attention mixed 3:1 80B / 3B
DeepSeek-V3.2 September 2025 (Exp), December 2025 MLA with DSA sparse attention 671B / 37B
Kimi Linear October 2025 KDA and MLA mixed 3:1 48B / 3B
MiniMax M2 October 2025 Full attention in every layer 230B / 10B
GLM-5 February 2026 DSA sparse attention 744B / 40B
Qwen3.5 February 2026 Hybrid attention dominated by Gated DeltaNet 397B / 17B
DeepSeek-V4 April 2026 Compressed attention alternating CSA and HCA 1.6T / 49B (Pro)
Kimi K3 July 2026 Hybrid attention dominated by KDA 2.8T / 104B

(2) DeepSeek-V4: combining compression with sparsity.

DeepSeek-V4 (DeepSeek-AI 2026) alternates two kinds of attention: CSA first compresses the KV of every few tokens along the sequence into a single entry and then, in the manner of DSA, selects a small number of entries for each query to attend to; HCA compresses much more aggressively but applies dense attention over the compressed entries. The paper reports that at 1M context, V4-Pro needs only 27% of DeepSeek-V3.2's inference compute per token and 10% of its KV cache. (V4 also reworks the residual connection, and Kimi K3 likewise proposes a new residual design, which may be the next direction to watch.)

(3) A counterexample: not every team has moved to efficient attention.

MiniMax's previous model, MiniMax-01 (MiniMax 2025), used a hybrid of linear attention and full attention, but MiniMax M2 went back to full attention in every layer. The reasons given in the official blog are that the hybrid matched full attention in small-scale evaluations but showed clear deficits in complex multi-hop reasoning at larger scale; moreover, linear attention is more sensitive to numerical precision, many implementations are memory-bound even during training, and the supporting inference infrastructure is still immature.

Follow-up questions

Follow-up 1: If linear attention has linear complexity, why not replace every layer with it?

Because a fixed-size state loses detail, so its precise retrieval is weaker than that of full attention. Linear attention compresses the entire history into a state of fixed size; the longer the sequence, the less information can be retained per token, so it underperforms full attention on tasks that require exact recall, such as needle-in-a-haystack and multi-hop retrieval. A hybrid structure keeps a few full-attention layers dedicated to precise retrieval and uses linear attention in the remaining layers to lower cost, striking a balance between quality and efficiency.

Follow-up 2: How does DSA differ from FlashAttention and sliding-window attention?

The three change different things. FlashAttention changes neither the result nor the amount of computation; it only reduces memory traffic (see Chapter 2); sliding-window attention lets each token see only a fixed number of the most recent positions, regardless of content; DSA dynamically selects the most relevant tokens for each query based on content, and they can come from anywhere in the context. Note that DSA's indexer itself still scores all past tokens, so its complexity is still quadratic; each score is simply far cheaper than full attention.

Follow-up 3: With a hybrid architecture, does memory usage become independent of sequence length?

No. The state of a linear-attention layer has a fixed size, but the remaining full-attention layers still have a KV cache that grows with length. A hybrid structure only reduces the part that grows with length; for example, with a 3:1 mix, only a quarter of the layers need a full KV cache.

Common mistakes

  • Do not say that 2025–2026 models have abandoned the Transformer: Mainstream models still use the Transformer skeleton; the changes concentrate in the attention layers and MoE.
  • Do not say that every new model has switched to linear attention: MiniMax M2 went back to full attention, and many models still use GQA or MLA.
  • Do not say that DSA reduces the overall complexity to linear: The main attention compute drops from \(O(n^2)\) to \(O(nk)\) (\(n\) is the sequence length and \(k\) the number of tokens kept per query), but the indexer is still \(O(n^2)\), just with a very small constant.