Dropout and Stacking Preserve the Interface

Inverted dropout changes branch values during training but becomes the identity at evaluation. Stacked blocks preserve model width while ordinarily using distinct parameters at each depth.

Dropout changes values during training without changing tensor shape. Stacking then passes the model-width output of one block to the next block. These two facts preserve the interface (B,T,dmodel)(B,T,d_{model}), but they do not make repeated blocks identical.

Training and Evaluation Calculate Different Functions

Under inverted dropout with drop probability pp, each branch coordinate uses

Dropout(zi)=mizi1p,miBernoulli(1p)\operatorname{Dropout}(z_i)=\frac{m_i z_i}{1-p}, \qquad m_i\sim\operatorname{Bernoulli}(1-p)

during training. During evaluation, dropout returns ziz_i unchanged. The factor 1/(1p)1/(1-p) keeps the training-time expectation equal to ziz_i under the mask distribution.

For z=[2,4]z=[2,4], p=0.5p=0.5, and mask m=[1,0]m=[1,0], training returns [4,0][4,0]. Evaluation returns [2,4][2,4].

Place Dropout Precisely

One explicit pre-norm residual branch is

y=x+Dropout(F(N(x))).y=x+\operatorname{Dropout}(F(N(x))).

Moving dropout before FF, after the residual addition, or into attention weights defines another computation. A reproducible account names the exact placement and the training/evaluation mode.

A Stack Reuses Shapes, Not Parameters

If each block maps (B,T,dmodel)(B,T,d_{model}) to the same shape, LL blocks can be composed:

x(+1)=Block()(x()).x^{(\ell+1)}=\operatorname{Block}^{(\ell)}(x^{(\ell)}).

Ordinary Transformer stacks use different learned parameters at different depths. Sharing parameters across layers is possible, but it is a separate architectural choice.

Reproducible Dropout Checks

  • Fix a random seed when comparing exact training outputs.
  • Test evaluation mode separately and expect deterministic values.
  • Verify that dropout changes no dimensions.
  • Compare averages over many masks when testing the expectation, not one mask.
  • Record probability and placement with the architecture.

Q1. Apply inverted dropout

With p=0.25p=0.25, input coordinate zi=3z_i=3, and retained mask value mi=1m_i=1, what training-time value is returned?

Compute it first, then check your number.

Hint
Use mizi/(1p)m_i z_i/(1-p).
Solution
3/(10.25)=43/(1-0.25)=4.
Not attempted
Review

Not marked done.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 1 exercises marked done

Review

Not marked done.

LLM PrimerDropout and Stacking Preserve the Interfacehttps://llmprimer.com/transformers/inside-a-transformer-block/dropout-and-stacking-preserve-the-interface© 2026 LLM Primer