| Approximation and depth | |
|---|---|
| ReLU, | |
| input dimension of the target function, defined on | |
| approximation accuracy; a grid of hinges needs about units to reach it | |
| the fold on , computed by two ReLU layers | |
| the fold composed times, a sawtooth with teeth and linear pieces | |
| number of folds; also the depth limit of the shallow class in Telgarsky's theorem | |
| a comparison ReLU network of one input variable, measured against the sawtooth | |
| number of layers of the comparison network | |
| total number of units of the comparison network | |
| crossing number, the number of intervals on which stays on one side of ; for a ReLU network | |
| standard deviation of noise added to the weights; the sawtooth's teeth survive only for | |
| a neuron's preactivation, the input to its ReLU, an affine function of the previous layer's outputs | |
| a segment of a line in input space, of length , on which linear pieces are counted | |
| Transformer shapes | |
| residual width (512 in d8) | |
| vocabulary size (4,096 in d8) | |
| final hidden state of one context, | |
| output head (unembedding) , which maps the final hidden state to the logits | |
| logits , one score per vocabulary token | |
| matrix whose rows are the final hidden states of all contexts | |
| column of the log softmax normalizers, one per context (row of ) | |
| matrix of next-token probabilities, one row per context and one column per token, | |
| gradient of the cross-entropy with respect to the logits at position , | |
| one-hot vector of token | |
| orthonormal basis of the column space of the output head | |
| fraction of gradient energy outside the column space of , ; a random subspace gives (0.875 in d8) | |
| queries and keys of one attention head; the score matrix has rank at most | |
| head dimension, which caps the rank of the score matrix (64 in d8) | |
| number of keys a head attends over (128 in Lecture 9's fitting experiment) | |
| number of experts in a mixture of experts | |
| fraction of the tokens in a batch sent to expert , counted from the hard assignments | |
| the router's mean probability for expert over a batch | |
| number of tokens per batch | |
| Automata | |
| finite state set of a semiautomaton | |
| state of the semiautomaton after step , | |
| input symbol read at step (Liu et al. write ) | |
| transition map, which gives the next state from a state and an input | |
| the map from to that input applies | |
| sequence length | |
| Compute yardstick (Assignment 5) | |
| training compute of a model or method | |
| training compute of d8, the unit of the dense reference curve | |
| asymptote of the dense reference curve , the loss it approaches as compute grows | |
| coefficient of the dense reference curve | |
| exponent of the dense reference curve | |
| compute a dense model needs to reach loss , | |
| Constants | |
| bound on the mean gradient norm of every neuron's preactivation, set by the initialization, in Hanin and Rolnick's piece count | |
| bound on the probability density of every neuron's bias, set by the initialization, in Hanin and Rolnick's piece count | |
| weight of the Switch Transformer's load-balancing loss | |
Context. One hidden layer can approximate any continuous function on a compact set whenever the activation is not a polynomial. With ReLU , a single hidden layer matches a one-dimensional target by placing a hinge at each grid point , weighted by the slope jump there. Higher dimensions reduce to one by approximating the target as a sum of powers of linear projections and fitting each power along its line. Universal approximation says little about practice. On , a hinge grid needs about units to reach accuracy on a 1-Lipschitz function, where is the input dimension. Any ReLU architecture that approximates every 1-Lipschitz function on to accuracy needs of order weights (Yarotsky, 2017). Even when a compact network can represent a function, gradient descent may never find it. Lecture 9 of Stanford CS 312 (Hashimoto and Kotha, Fall 2026) asks which network shapes express more, how much of that expressivity trained models use, and which transformer matrices create real bottlenecks.
Depth beats width exponentially in the worst case, but the separating functions oscillate sharply and collapse under tiny weight noise. Typical random and trained ReLU networks produce roughly one linear piece per neuron regardless of depth. Language-model loss shows the same pattern, tracking total parameter count far more than aspect ratio. Adding parameters at fixed per-token compute therefore relies on sparse layers such as mixtures of experts. The real architectural bottlenecks are narrow matrix products. An output head of rank at most the residual width caps log-probability rank at and discards most of the backward gradient. Low-rank attention scores hurt far less because point lookups need little rank. On sequential tasks, fixed-depth transformers find parallel shortcuts that succeed in distribution but break on shifted distributions or longer sequences. Generating intermediate states through chain of thought supplies the serial depth they lack.
Setting. The course's d8the course's model organism: a transformer with 8 blocks and residual width 512, pre-trained on about 614M tokens of web text. Reading note: Prediction as understanding: the d8 model organism model fixes concrete dimensions: residual width , 64-dimensional attention heads, and SwiGLU MLPs of shape . Its output head (the unembedding) projects onto a vocabulary of tokens, eight times the width. Assignment 5 runs four interventions on d8: a depth-width grid, low-rank factored output heads, a four-expert mixture of experts, and weight-shared block looping. Each is judged against ordinary dense scaling on the ladder d4 through d10, where model dD has blocks and width . Fit a power-law reference curve to loss against training compute , with the compute of d8, and invert it: A method reaching loss at compute has dense-equivalent efficiency . It pays off only when it beats spending the same compute on a larger dense model.
Folded sawtooths separate depth from width. Composing one ReLU fold multiplies linear pieces exponentially with depth. Two ReLU layers fold onto itself: Composing with itself times yields a sawtooth with teeth and linear pieces. A network layers deep and two units wide builds it. A single hidden layer of units sums hinges and has at most linear pieces on a line, so matching takes width of order .
Telgarsky's crossing-number lower bound. Telgarsky (2016) turns piece counting into a formal separation. Write the crossing number of a function of one variable: the number of intervals on which stays on one side of , the pieces of the classifier for the number of intervals where a one-variable network stays on one side of . Any ReLU network with layers and total units obeys Depth sits in the exponent and average width in the base, while . If has at most intervals, each covers many alternating intervals of , putting on the wrong side of across at least a quarter of 's intervals. Each missed interval adds an error triangle of base and height , with area , giving in the lecture's simplified count. Telgarsky's full theorem extends this separation to for every . Some ReLU network with layers and units stays at distance at least from every network with at most layers and at most units. The bound still holds when the shallow network uses arbitrary semi-algebraic gatesa unit whose output is piecewise polynomial in its inputs, with the pieces cut out by polynomial inequalities; ReLU, max and indicator units are examples or boosted decision trees. Other worst-case constructions match this picture. Linear-region counts can grow exponentially with depth (Montúfar et al., 2014), and radial functions built cleanly in three layers require exponential width in two (Eldan and Shamir, 2016).
In practice, loss tracks parameter count far more than shape. Empirical scaling sweeps find almost none of this exponential depth advantage. Kaplan et al. (2020) hold non-embedding parameters fixed across language models from 50M to 1.5B parameters and vary the aspect ratiothe residual width divided by the number of layers, by a factor of 40. Loss barely moves: a 6-layer model of width 4,288 lands within 3% of a 48-layer model of width 1,600. Only models with zero or one layer, or with extreme depth-to-width ratios, leave the shared loss-versus-parameters curve. Vision models behave similarly. A 40-layer wide ResNet beats a 1,001-layer thin ResNet of comparable size on CIFAR-100 (Zagoruyko and Komodakis, 2016). Scaling depth, width, and resolution together also outperforms scaling any single axis (Tan and Le, 2019). Depth can still matter more on downstream benchmarks than on pre-training loss (Tay et al., 2022). Deployment hardware also shifts the best shape, as in MobileLLM, which uses a deep, thin layout with shared embeddings and repeated blocks to save parameters on phones.
Adding parameters at fixed compute via mixture of experts. Because loss tracks total parameter count, raising capacity at a fixed per-token compute budget requires parameters that only some tokens activate. A mixture of expertsa layer of several feed-forward networks (experts) with a learned router that sends each token to one or a few of them, so total parameters grow while compute per token stays fixed does this, and its router must spread tokens evenly across the experts to keep hardware busy. The Switch Transformer (Fedus et al., 2022) enforces balance with the auxiliary loss . Here is the fraction of the batch tokens routed to expert , counted from hard assignments so it carries no gradient, and is the router's mean probability for expert . Differentiating with respect to one token's router probability yields . That gradient pushes down routing probability hardest for experts that are already overloaded.
Deep sawtooths collapse under tiny weight noise. Trained networks miss Telgarsky's exponential piece count first because the construction is fragile. Each fold has slope , so a perturbation at layer grows by a factor of at the output. Weight noise of standard deviation therefore shifts the output by roughly , erasing the teeth unless . Hanin and Rolnick (2019) test this directly by adding Gaussian noise of standard deviation 0.1 to the sawtooth's weights and biases. The dense oscillations collapse into a few isolated spikes.
Random and trained networks realize roughly one piece per neuron. Typical networks also stay far below exponential region counts, both at initialization and after training. Hanin and Rolnick (2019) restrict a ReLU network to a line in input space. Each neuron's preactivationthe input to a neuron's ReLU, an affine function of the previous layer's outputs is piecewise linear along the line and adds a breakpoint whenever it crosses its bias. Under He initializationindependent zero-mean Gaussian weights with variance , where fan-in is the number of inputs to the unit; it keeps activations at the same scale through depth, every preactivation has order-one slope along the line and crosses its bias a bounded number of times per unit length, whatever the layer depth. On a segment of length , The constants a bound on the mean gradient norm of every neuron's preactivation and a bound on the probability density of every neuron's bias depend only on the initialization. Counted on , random He-initialized ReLU networks of depths 1, 2, 4, and 8 all sit on one line of about one piece per neuron. Over 20 epochs of MNIST training, the piece count per neuron dips and rebounds near its starting value without growing with depth. The mean distance from an input to the nearest region boundary stays between 0.4 and 1.5 divided by the neuron count. Gradient descent also fits low frequencies first (Rahaman et al., 2019). On a sum of sinusoids, a three-layer MLP learns low frequencies well before high ones, because high-frequency structure demands many active breakpoints or large weights that grow slowly.
The softmax bottleneck at the output head. Narrow matrix products inside a transformer can bind much more tightly than depth-versus-width shape. In d8, MLPs are full rank and each attention head's score matrix has rank at most 64. The output head maps the final hidden state to vocabulary logits , capping logit rank across contexts at against tokens. Stack the final hidden states of all contexts as rows of , and let be the column of log softmax normalizers. The context-by-token log-probability matrix then satisfies Yang et al. (2018) call this the softmax bottleneckthe limit on the rank of the log-probability matrix of any model whose logits are a linear map of a -dimensional hidden state: has rank at most , however many contexts and tokens there are (Yang et al., 2018). If natural language has true conditional log-probabilities of rank above , no depth or width below the head can match them, and nothing follows the head to restore rank. Replacing the single softmax with a mixture of softmaxes, a mixture of several softmax distributions with weights that depend on the context; its log is not linear in , so its rank is not capped by lifts the cap. On Penn Treebank (), log-probability rank jumps from the embedding width of 400 to 9,981. On One Billion Word, where overfitting is minimal, test perplexity falls from 42.8 to 37.1 and training perplexity drops from 41.5 to 36.4, confirming an expressivity gain rather than regularization. On character-level models, where is smaller than and the cap never binds, the mixture adds nothing.
The output head also filters the backward gradient. The same rank cap chokes learning signal entering the body. At position , the cross-entropy gradient with respect to the logits is , where is the next token's one-hot vector. Backpropagation passes to the final layer, wiping out every component of outside the column spacethe span of the columns of , here a subspace of of dimension at most of . Let be an orthonormal basis of that subspace. The fraction of logit-gradient energy discarded is against for a random subspace, or 0.875 in d8. Across GPT-2, Pythia, Llama 3, OLMo 2, and Qwen 3, Godey and Artzi (2026) find 95 to 99% of the gradient norm lost. In 2B-parameter models with a factored output head, raising head rank from 32 to 4,096 speeds training 16-fold. The rank-4,096 model reaches the rank-32 model's final loss, set after about 11B tokens, in 700M tokens. As a control, a one-layer model repeating a random symbol 64 times needs only a copying rule that a low-rank head can express. Failing to learn that task therefore does not implicate head expressivity. Assignment 5 compares how much a mixture of softmaxes, Kanai et al.'s (2018) sigmoid-corrected softmax, and a context copy path lift the head's effective rankthe rank an ordinary softmax head would need to reach a method's loss, read off the curves of loss against head rank (Assignment 5).
Attention score rank rarely binds. An attention head of dimension forms a score matrix of rank at most , below the key count in long contexts. In practice, that cap costs far less than the output head's. In a width-512 BERT-style model with , adding heads from 8 to 32 raises SQuADa reading-comprehension benchmark, scored here by F1, the overlap between predicted and true answer spans F1 from 89.6 to 90.95, though total parameters also climb from 168M to 319M (Bhojanapalli et al., 2020). In standard BERT-large, splitting width 1,024 into 32 heads instead of 8 shrinks and nudges F1 down slightly, from 90.89 to 90.45. Lecture 9's fitting test shows why. Over keys, a head matches a one-hot target row closely at , whereas a random diffuse row needs . Point lookups require little rank, and retrieval accounts for many practical attention patterns.
Parallel shortcuts for sequential tasks. Attention handles lookups and copying easily, whereas copying a length- string takes bits of state in a recurrence (Sanford et al., 2023; Jelassi et al., 2024). State tracking, by contrast, is sequential. Model a sequential process as a semiautomaton: a finite set of states , a finite set of input symbols , and a transition map that gives the next state from the current state and input; it reads the inputs one at a time and updates its state, , with states and inputs . Write for the transition applied at step . Associativity lets a fixed-depth network compose transitions in a binary tree (Liu et al., 2023): A transformer of depth and width polynomial in can therefore simulate any semiautomaton over length . Some tasks collapse even further. Parity takes one layer: attention averages the inputs to count ones, and the MLP reduces mod 2. Every solvablebuilt from no non-solvable group such as , the permutations of five objects; such a semiautomaton splits into counters and memory units (the Krohn-Rhodes decomposition) semiautomaton needs depth depending only on , independent of , and a 1D gridworld moving left or right between walls needs depth 2. Gradient descent finds these shortcuts in practice. Across 19 semiautomata at , transformers with at most 16 layers top 99% held-out accuracy on every one.
Shortcuts fail out of distribution and at new lengths. Parallel shortcuts are brittle because they rely on the training distribution. A transformer that solves parity by counting ones breaks on rarely encountered counts, so accuracy falls as the probability of a 1 shifts away from the training value of 0.5. Both parity and bracket matching also degrade rapidly on sequences longer than those seen in training, while an LSTM tracks the recurrence at 100% accuracy. Shifting positions during training or dropping positional encodings helps only partially. Writing each intermediate state to a scratchpadintermediate tokens the model writes before its answer, here the automaton's state at each step, combined with attention biased toward recent tokens, restores the recurrent algorithm.
Complexity limits and chain of thought. Circuit complexity makes the fixed-depth barrier sharp (Merrill and Sabharwal, 2023; Merrill et al., 2024). A fixed-depth transformer with logarithmic precisionnumbers stored with bits for inputs of length , enough to index positions lies inside the class of problems solved by constant-depth, polynomial-size circuits with AND, OR, NOT and majority gates of any fan-in; it includes counting and parity. It can count and compute parity, yet it cannot simulate every finite automaton at arbitrary length unless equals the class of problems solved by polynomial-size circuits of logarithmic depth with gates of fan-in two; it includes every regular language, which is widely believed false. The canonical hard example is the word problem of , tracking a product of permutations of five objects. Under constant precision, a fixed-depth transformer cannot even compute parity. Chain of thoughtintermediate tokens a model generates before its answer, each computed from the input and all earlier tokens, so that each token adds one step of serial computation beyond the model's fixed depth (Merrill and Sabharwal, 2024) supplies the missing serial depth. Linearly many extra tokens in the input length suffice for every regular language, and polynomially many solve exactly the problems in P (Merrill and Sabharwal, 2024; Li et al., 2024). Looping a transformer block adds depth in the same spirit without adding parameters.
Limits. Depth-separation theorems rely on worst-case oscillating functions that trained networks rarely build, though that does not prove depth never helps, especially downstream. Hanin and Rolnick prove their region-count formula at initialization for fully connected ReLU networks and test it during MNIST training; no comparable count is given here for transformers. Kaplan et al.'s aspect-ratio invariance comes from one family of language models. Rank bounds capture representational limits, not compute tradeoffs. Whether a richer output head earns its extra compute is empirical, which Assignment 5's dense-equivalent efficiency tests directly.
Terms
- universal approximation
- one hidden layer approximates any continuous function on a compact set for a non-polynomial activation; the width needed can grow like
- sawtooth
- folds of : linear pieces from a network deep and 2 wide; one hidden layer needs about units
- crossing bound
- for layers and units: depth in the exponent, width in the base
- Telgarsky's theorem
- layers and units stay distance from every network with layers and units
- realized pieces
- at initialization, pieces on a segment , independent of depth; stays near that in training
- shape vs size
- LM loss changes slightly over a 40-fold range of aspect ratio at fixed parameters; 0- and 1-layer models and extreme ratios are the exceptions
- softmax bottleneck
- has rank
- gradient bottleneck
- keeps only the part of the logit gradient in the column space of ; a random subspace keeps of the energy
- attention rank
- has rank ; one-hot rows need little rank, diffuse random rows need
- shortcuts to automata
- associativity gives depth for any semiautomaton, depth independent of for solvable ones; brittle out of distribution and at new lengths
- chain of thought
- linearly many extra tokens: every regular language; polynomially many: exactly P
- dense-equivalent efficiency
- : compute a dense model needs for loss , over the compute used
Sources
Lecture 9, “Architecture 2: Expressivity (depth vs. width, realized expressivity, transformer bottlenecks)” (Nov 5, 2026), of Stanford CS 312 Deep Learning Alchemy, Fall 2026. Taught by Tatsunori Hashimoto and Suhas Kotha; course staff Kaiyue Wen and Tristan Thrush (CAs).
Course site Lecture slides Assignment Assignment code
The lessons, experiments, figures and quiz problems in this note are the course's, shown here with the instructors' permission.
- Tatsunori Hashimoto and Suhas Kotha. CS 312 Deep Learning Alchemy, Lecture 9: Architecture 2: Expressivity. Stanford, Fall 2026.
- Tatsunori Hashimoto and Suhas Kotha. CS 312 Deep Learning Alchemy, Assignment 5: Capacity. Stanford, Fall 2026.
- Matus Telgarsky. Benefits of depth in neural networks. COLT, 2016.
- Boris Hanin and David Rolnick. Complexity of Linear Regions in Deep Networks. ICML, 2019.
- Zhilin Yang, Zihang Dai, Ruslan Salakhutdinov, and William W. Cohen. Breaking the Softmax Bottleneck: A High-Rank RNN Language Model. ICLR, 2018.
- Bingbin Liu, Jordan T. Ash, Surbhi Goel, Akshay Krishnamurthy, and Cyril Zhang. Transformers Learn Shortcuts to Automata. ICLR, 2023.
- Jared Kaplan, Sam McCandlish, Tom Henighan, Tom B. Brown, Benjamin Chess, Rewon Child, Scott Gray, Alec Radford, Jeffrey Wu, and Dario Amodei. Scaling Laws for Neural Language Models. arXiv preprint, 2020.
- Nathan Godey and Yoav Artzi. Lost in Backpropagation: The LM Head is a Gradient Bottleneck. COLM, 2026.
- William Merrill and Ashish Sabharwal. The Expressive Power of Transformers with Chain of Thought. International Conference on Learning Representations, 2024.
Connected notes
- Understanding deep learning requires rethinking generalizationGeneralization bounds · Implicit bias of the optimizer
SGD started at zero stays in the row space of the data, so on a linear model it returns the minimum-norm interpolant, which reaches 1.2% test error on raw MNIST with no regularization.
- Double descentBenign overfitting · Implicit bias of the optimizer
Past the interpolation threshold every model fits the data, so the test risk is set by which interpolant is chosen, and the minimum-norm one spreads the noise over more directions as features are added, which gives the second descent.
- Temperature scaling and calibrationCost-sensitive classification and calibration · Implicit bias of the optimizer
Once nearly every training point is classified correctly, the loss keeps falling by scaling up the logits, the analogue of the growing weight norm Soudry et al. prove for linear models, and that is how modern nets become overconfident.
One-pass SGD on samples with step size acts like ridge regression at implicit penalty , updating only the top directions so extra parameters stop adding variance once model size passes that cutoff.