Transformers are now widely adopted in recommender systems too, and scaling up parameters and compute keeps delivering gains. But from day-to-day interviews I've found that most recommender practitioners lack basic intuition about Transformers, which leads to common-sense mistakes — and failures — when scaling.
The core problem of Transformer scaling is scale matching.
A Transformer has never been a black box you can enlarge at will. When depth and width change, the scale of the residual stream, per-layer gradients, update magnitudes, attention logits, the optimizer's second-moment estimates, and even the optimal learning rate all change together. If these quantities aren't kept in the right range, the added parameters won't become effective capacity; the model may instead end up "trainable, but never really well trained."
Therefore, a Transformer that can stably scale relies not on adjusting a single dimension, but on a complete set of designs that work together:
- Norm and residual determine how information and gradients pass through dozens or even hundreds of layers of the network.
- Initialization and residual scaling determine whether the scale at which each layer writes to the residual stream is still appropriate after the model is deepened.
- Attention scale control determines whether the model drifts toward over-sharpening or token averaging;
- Optimizer and parameterization determine whether, after the model is widened and the batch size is increased, the parameter updates still remain within the original working range.
- Ultimately,scaling the model capacity must also be accompanied by scaling the complexity of the input and the complexity of the data.Otherwise, no matter how large the Transformer is, it will only be used to solve a problem that does not actually require such a large capacity.
Post-Norm
Back in BERT's day, models already had 24 layers, and the original code implemented Post-Norm — the first obstacle to stacking layers.
Post-Norm means “Norm after the residual add,” and a block of the Transformer can be written as:
“On Layer Normalization in the Transformer Architecture” is a key theoretical study in the debate between Pre-LN and Post-LN. It discusses the stability issues of Post-LN:Why does the Post-LN Transformer rely on learning rate warm-up, and can this stage be removed?
In Post-Norm, the gradient norm of parameters near the output layer is very large, on the order of O(d√(ln d)), and itdoes not decrease with the number of layers L. That means starting training with a normal-sized learning rate blows the model up immediately. So it must use warmup; the root cause is an imbalance in gradient scale at initialization.
In hindsight, BERT-Large's 24 layers / 340M were already in the zone where the original Post-Norm recipe is very fragile: peak LR of only 1e-4, 10k steps of linear warmup, Adam (β2=0.999). When Megatron-LM tried to scale BERT beyond 340M, it found that the post-norm architecture's loss degraded outright at larger scale, and LayerNorm had to be moved (to a pre-norm style residual arrangement) to train a 3.9B BERT. In other words, 24 layers / 340M is roughly the limit operating point for post-norm with a naive recipe.
A crash would actually be fine — you'd see the loss blow up and NaNs everywhere, and you'd start fixing it. More often, though, it's a "metrics look normal but the results are poor" silent failure.
A loss spike that recovers but leaves permanent damage. Mid-training, the gradient blows up momentarily; the loss spikes and falls back, and the curve appears to "self-heal." But the damage can be lasting:
- after a spike inflates Adam's second moment, it takes ~1/(1−β₂) steps to decay back, and during that time those layers' learning rate is suppressed — effectively under-training;
- during the spike, attention entropy collapse or dead neurons may occur; the loss recovers, but model quality has dropped a notch.
Or training is smooth throughout yet converges to a worse solution. Those runs avoided the crash — the oversized gradients near the output — with warm-up and a small LR. Post-Norm has another problem, near the input layer:gradients decay layer by layer.
Assume a Transformer has L blocks, each with one Attention layer and one FFN layer. Without Norm, a multi-layer network with residual connections outputs the sum of every layer's output; we call this the residual stream.
The Post-Norm configuration places the Norm layer on top of the residual stream, which alters the identity property of the residual stream. During backpropagation, each layer multiplies the Jacobian of the LN, causing the gradient to significantly decay by the time it reaches the input layer. The loss curve shows a smooth decline, the gradient norm is normal, and there are no spikes. However, the parameters of the bottom few layers barely change, and the model is essentially working with "half its depth." This is a more common form of silent failure.
Pre-Norm
Today the more mainstream choice for LLMs is Pre-Norm: pull Norm out of the residual stream and apply it to the input of each branch:

Without Norm on the stream, a Pre-LN block is xₗ₊₁ = xₗ + Fₗ(LN(xₗ)), and its Jacobian is:
The gradient passed back from the top layer to the l-th layer is the product of these Jacobians. The key step is to expand the product:
Each term corresponds to a "path" through the residual stream — a choice of which blocks to pass through and which to skip. That's the precise meaning of the "gradient highway":there is always a pure identity path whose coefficient is exactly 1.
As for output blow-up: although the residual stream's norm keeps growing as layers accumulate, every branch normalizes its input before reading, which counteracts it. For a Pre-LN network of total depth L, the parameter gradient norms of every layer are all roughly O(d√(ln d / L)), with no large-gradient problem near the output.
Patching Pre-Norm
Pre-Norm greatly improved training stability, but it isn't a perfect replacement. People found that with the same number of layers, once training stability is solved, Post-Norm outperforms Pre-Norm. DeepNorm studied exactly this, conjecturing that "in Pre-LN, gradients of earlier layers tend to be larger than those of later layers, so layers train unevenly, which may hurt final performance." In other words, at equal depth Pre-Norm tends to underuse the layers near the output, so the effective depth is lower and results are worse. DeepNorm patches stability within Post-Norm and isn't mainstream today, but it exposed Pre-Norm's hidden problem.
The crux of Pre-Norm's problem is that the residual stream is the sum of all layers, so its norm and variance accumulate layer by layer.
A Pre-LN residual block can be simplified and written as:
Therefore, its Jacobian is:
The key is the second term. For LayerNorm / RMSNorm, roughly:
In other words,the larger the scale of the residual stream, the smaller the Jacobian of the Norm.Pre-LN keeps accumulating into the residual stream, so in deeper layers the second Jacobian term approaches 0 and the identity dominates; the contribution of layers near the output naturally weakens. In the internal health metrics, this shows up as hidden states of adjacent layers pointing in increasingly similar directions — the angular distance shrinks.
Moreover, because the residual stream's scale changes with depth, the optimal hyperparameters change when depth L changes, which also distorts conclusions about scaling.
What follows are the classic patches applied to Pre-LN.
GPT-2 contains a high-ROI trick that takes one line of code and helps a lot: initialize the layers that write back into the residual stream as follows:
The 2L comes from the fact that a Transformer with L blocks writes to the residual stream 2L times: once from the Attention output and once from the FFN down projection.depth-aware initialization made the other hyperparameters largely depth-independent, preventing them from going stale when scaling — the real cause being that growing variance invalidates the other hyperparameters.
"The Curse of Depth in Large Language Models" uses GPT-2's scaled initialization as its baseline. It prints each layer's variance; interestingly, although this initialization gives better results, the final variance distribution barely changes — it mainly affects early parameter updates.

This also shows what we said above: layers near the output are dominated by the identity, their update directions are ineffective, yet they contribute huge variance.
Driven by the idea of controlling variance, Pre-Norm has a series of variants:
- Pre-Norm — Formula:x ← x + F(Norm(x))
- Classic Post-Norm — Formula:x ← Norm(x + F(x))
- Sandwich-Norm — Formula:x ← x + Norm₂(F(Norm₁(x)))
- OLMo 2-reordered norm — Formula:x ← x + Norm(F(x))
- LNS: LayerNormScaling — Formula:x ← x + F(Norm(x)/√l)
Sandwich-Norm adds another Norm on each branch's output before it's written back to the residual stream, controlling the variance being written and thus curbing the residual stream's overly fast scale growth with depth.
OLMo 2 moves Norm to each branch's output, controlling the norm and variance written into the residual stream; the stream's norm then grows only linearly with depth, so dropping the input Norm is harmless.
Rather than changing Pre-Norm's form, patches may be more effective. "The Curse of Depth in Large Language Models" divides each branch's output by √l , l is the layer index. The idea is simple: since deeper layers write larger variance, push it back down. It works in a similar spirit to GPT-2's initialization, but the two turn out not to combine — using both makes things worse.

Comparison of Pre-Norm variants:

We've been through this ourselves: stacking Post-Norm to 3 layers already caused trouble, though maybe because early on we didn't know how to initialize and set hyperparameters. Switching to pre-norm let us stack a few more layers — as said above, it widens the feasible hyperparameter range a lot, but there's still a depth limit. Adding residual-scale control lets you keep stacking. Residual-scale control and making the optimal hyperparameters depth-independent are the key techniques of Transformer scaling.
Scale-Aware Hyperparameters
When scaling a Transformer, comparing by changing only depth or only width gives wrong conclusions, because the optimal hyperparameters move with the scaling axis. The value of scale-aware hyperparameters is that you can comfortably tune one axis and observe the effect without retuning every time. An even more economically valuable benefit: tune hyperparameters on a small model and transfer them to a larger one, saving a lot of compute.
The scaled initialization and LayerNorm Scaling mentioned above make hyperparameters scale-aware along depth to some extent. The width axis of model scaling has the same problem.
The work “Tensor Programs V” points out (as shown in the figure) that as you scale a Transformer’s
d_model from 128 all the way up to 8192, the effect of using the same Adam LR changes very noticeably, and the optimal LR shifts with width. This is the classic problem: after scaling, performance actually gets worse.
Its method is also simple. Parameters already use Xavier initialization; the QKVO and FFN weights are handled as follows, e.g.
The difference is that Adam's LR is also rescaled when scaling. Suppose d₀ is tuned to give LR = η; after scaling:
The key point is that initialization actually scales with √(d), but the LR is divided by d. The paper explains that parameter updates are correlated, whereas at initialization each variable is random with zero mean. By the same reasoning, the usual QK of Attention is divided by √(d); it changes this to divide by d.
The core purpose of the above operations isto ensure that as the width increases, the impact of each layer update on the activation remains O(1), thereby stabilizing the optimal hyperparameters across different widths.
Attention collapse
Attention collapse comes in two forms. One is excessive sharpening — attention concentrates on a single token — called attention entropy collapse; the other is the opposite, excessive averaging — rank collapse. Both seriously hurt performance.
As the model size increases and the training time becomes longer,||Q||, ||K|| may continue to increase, even if the direction remains unchanged,QKᵀ grows too, and as logits double the probabilities approach one-hot. E.g., [2, 1, 0] → softmax ≈ [0.67, 0.24, 0.09], but [200, 100, 0] → softmax ≈ [1, 0, 0].
QK-Norm normalizes Q andK first and then takes the dot product, effectively avoiding over-sharpening; it's used in OLMo 2 and Gemma 3. It doesn't eliminate scale: RMSNorm has a learnable
γ, which controls the actual scale.Now attention rank collapse. Attention is inherently a "token mixing / averaging operator"; "Attention is Not All You Need" proved that pure self-attention, without skip connections or MLPs, converges to token averaging very rapidly.
Intuitively, the residual stream lets the original token information pass straight to any layer, injecting the token's original distinctiveness. So the key is the strength ratio between the residual stream and the incoming branches: if branches are too strong, token mixing across many layers is too strong and the result averages out.
So the natural approach is to weaken the incoming branches. Recall the pre-norm patches above: GPT-2's √(2L) std initialization, and LNS dividing by √(l) — which explains their effect from another angle: besides controlling residual-stream variance, they also keep accumulated mixing from drowning out the token-specific signal.
Overall, residual connections provide not only a gradient highway but also a representation highway. Attention is essentially repeated token mixing: once token representations start to converge, the attention map from Q/K converges further, so the next layer loses token differences at a cubic rate, ultimately heading to rank 1 with depth. Residual connections always keep an identity path free of attention mixing, structurally preventing this representation collapse.
The core formula it derives: the larger the right-hand side, the less prone to collapse. β depends on the parameter count of W_q, Wₖ, Wᵥ; H is the number of heads and L the number of layers. L is the dominant factor: the whole is less than 1, and as L grows the constraint tightens exponentially (more prone to collapse), while increasing parameter capacity and head count effectively mitigates collapse. The paper also shows experimentally that increasing the hidden size slows collapse, and that holding the final hidden dimension fixed while increasing only W_q, Wₖ is also effective, showing it really is tied to parameter capacity. To some extent, when you go deeper you should also go wider to counter attention rank collapse.
The paper “The Depth-to-Width Interplay in Self-Attention” pointed out that Self-Attention initially benefits greatly from increased depth, but this effectiveness is limited by the network's width. When the network becomes too deep relative to its width, further increasing the depth yields diminishing returns, and increasing the width becomes more effective.
The recent "The Depth Delusion: Why Transformers Should Be Wider, Not Deeper" also gives a counterintuitive experiment: for a fixed width there's an optimal depth — deeper isn't always better. My reading is that depth brings representation collapse, so you look for the best balance between representational power and collapse risk.

Today's large models show the same trend. Qwen3 already has 28 layers at 0.5B and only 64 at 30B, while d_model grows 5× and the FFN dimension 8×. A Transformer first needs a minimum computational depth for basic representational power, then grows mostly in width. Widening expands capacity more directly and better matches GPUs' parallel efficiency on large matrices.

AdamW and gradient dynamics
Recommender systems use all sorts of optimizers. Years ago I benchmarked many of them; my conclusion then was that after careful tuning, the choice of optimizer wasn't critical. But for Transformers, AdamW has become the industry standard.
So, to put it bluntly: if you use a Transformer, you should at least be on AdamW; otherwise you can't tell where any anomaly comes from. The core logic isn't that AdamW is a great optimizer, but that in zero-homogeneous networks full of Norm layers, gradient dynamics are fundamentally changed. Compared with its predecessors, AdamW is basically correct rather than better.
The article above contains a very detailed discussion, which can be summarized as follows:
- Deep networks rely on LayerNorm (RMSNorm), which creates localscale invariance, and this leads to unique gradient dynamics.
- In this unique dynamical regime, our machine-learning intuitions are overturned. The physical meaning of the norm shifts from representing feature strengthtoa knob for learning progress. The norm grows steadily in theory, so SGD comes with built-in learning-rate decay — but it brakes too hard and learning stops early. Weight decay evolves from a regularizer into a dynamic valve on the effective learning rate.
- How AdamW became standard: Adam keeps the gradient step size constant, so the effective learning rate brakes gently; warmup handles too-small weights (gradient explosion) and inaccurate second-moment estimates early in training; AdamW fixes the L2-regularization issue by introducing decoupled weight decay, splitting "direction update” and “progress control" into two clean knobs.
The direct symptom: if your norms keep growing throughout training, it won't crash, but it's very likely suboptimal. In fully open-source LLM checkpoints, you'll see the norms stabilize very early, pulled in by weight decay.
β₁ and β₂ in Adam also matter a lot, representing the strength of "direction memory" and "scale memory" respectively. In recommender systems freshness is critical and features generalize poorly, so historical gradient directions go stale faster. β₂ must balance noise level against effective batch size: BERT used small batches and inherited the then-common β₂ = 0.999, while LLMs today more often use 0.95 because batches are larger, noise is lower, and vₜ must respond faster when spikes appear.
As distributed training and gradient accumulation arrive in recommender systems, the effective batch is growing, and continuously updated models must cope with possible spikes too — so Adam's β₁ and β₂ need retuning.
Monitoring internal health metrics
Beyond loss and norm, you should monitor more internal health metrics targeting the issues above.
per-layer grad norm ratio(bottom vs top layers): The silent failure of Post-LN manifests as the gradient in the bottom layers being consistently one to two orders of magnitude smaller than in the top layers.
update-to-weight ratio (‖ΔW‖/‖W‖, healthy value ~1e-3): directly shows whether each layer's parameters are actually moving — closer to "is it learning" than grad norm.
Inter-layer representation similarity: cosine similarity between adjacent layers' outputs staying near 1 means the deep layers are idling. Use this to check, under pre-norm, whether layers near the output are working.
max attention logit: watches for attention entropy collapse; a normal range suggests attention is basically healthy. But it's easy to hit cases where all logits are high, and softmax is insensitive to adding a constant to a whole row.
You can also add the normalized entropy of Attention: H(p) / log N. As it approaches 0, Attention is extremely focused on a few tokens, leading to entropy collapse; as it approaches 1, Attention becomes more uniform, leading to rank collapse.
Richer inputs
Scaling parameters alone doesn't bring such big gains, and that's often used to dismiss scaling. It's the same as in NLP: scaling laws don't say that pushing parameters up makes results appear. They're about the ratio of data to parameters and the allocation of compute — data and parameters must scale together.
The same holds for recommender systems. If all historical data is already in use, recommenders seem to have finished data scaling early. But the richness and complexity of input features are also part of scaling, and they must grow together with parameters for scaling to deliver its huge value.
For example, maybe four years ago we built multimodal embedding features and found that adding them directly didn't help; what finally worked was using them to compute the distance between the target item and the sequence as an intermediate feature inside the graph. After scaling parameters, we found that simply feeding the multimodal embedding in directly gave a huge gain. The difference comes from the model's parameter capacity.
Take LLMs' native multimodality. Non-native multimodality grafts a pretrained ViT onto a pretrained LLM and co-trains them, with the ViT as an encoder. Native multimodality directly embeds image patches and relies on the LLM's main Transformer to handle visual tokens, text tokens, and their complex interactions. The modeling capacity once carried by the vision encoder must move into the main Transformer, so the main model must reserve enough parameter capacity and compute for visual modeling.
Recommender systems have gone through a very similar evolution. We used to design an elaborate sub-network for a group of features — DIN, DCN, a multimodal encoder, a sequence encoder — first compressing complex information into an embedding and then handing it to the main ranking network. Such a sub-network is essentially also an Encoder.
However, if the main Transformer is large enough and the original information can be input directly in a suitable token format, then we can further ask:Why must this information be compressed before it reaches the Transformer?
Conversely, if scaling doesn't help, another possibility is that the input isn't complex enough or there isn't enough data — the problem simply doesn't need that much capacity or that many layers, and you might as well honestly go back to your DCN.
Summary
To use a computer analogy: when using Transformers for recommendation, don't treat it as an out-of-the-box laptop; think of it as a high-performance motherboard covered in ports and loose wires.
The Transformer only provides a general, powerful compute skeleton. Your features, sequences, optimizer, model size, hyperparameters, and training and inference setup must all be redesigned around this motherboard and matched to one another. Only by truly assembling these parts can you build a high-performance PC.
Therefore,using a Transformer isn't the same as being Transformer-native; only a Transformer that can scale is the real thing.
references
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
2 OLMo 2 Furious
Gemma 3 Technical Report
Language Models are Unsupervised Multitask Learners
A Theory on Adam Instability in Large-Scale Machine Learning
The Curse of Depth in Large Language Models
Tensor Programs V: Tuning Large Neural Networks via Zero-Shot Hyperparameter Transfer
Query-Key Normalization for Transformers
Scaling Vision Transformers to 22 Billion Parameters.
On Layer Normalization in the Transformer Architecture
Attention is Not All You Need: Pure Attention Loses Rank Doubly Exponentially with Depth
Residual connections are not just for gradient highways; they also provide arepresentation highway, stopping Attention from mixing tokens into sameness. The width of QKV is also an important factor in collapse.
The Shaped Transformer: Attention Models in the Infinite Depth-and-Width Limit
The Depth-to-Width Interplay in Self-Attention
The Depth Delusion: Why Transformers Should Be Wider
DeepNet: Scaling Transformers to 1,000 Layers
CogView: Mastering Text-to-Image Generation via Transformers