4.1.8 · D3Transformer Architecture

Worked examples — Feed-forward network sublayers

2,069 words9 min readBack to topic

Before we start, remember the pieces (no new symbol used before this line):

  • = one token's vector, a list of numbers, e.g. .
  • = the expansion matrix; multiplying by it gives a longer list.
  • = bias, a fixed list we add on.
  • = the activation — a rule applied number-by-number that bends the line (ReLU, GELU, SiLU).
  • = the projection back to the original length.

The scenario matrix

Every FFN example you could ever face falls in one of these cells. The worked examples below are labelled with the cell they hit.

Cell Scenario What can go wrong / what to watch
A Pre-activation positive ReLU passes it straight through
B Pre-activation negative ReLU kills it → dead neuron
C Pre-activation exactly zero Degenerate: , gradient boundary
D Full forward pass Shapes must match at each stage
E Residual + LayerNorm wrapper Add then normalize, order matters
F GELU vs ReLU vs SiLU on same input Negative values survive smoothly
G Position-wise check (2 tokens, shared weights) Same , different data, no mixing
H Real-world word problem Parameter budget / memory
I Exam twist — "collapse to linear" trap Why is non-optional
J Limiting behaviour Activations saturate or grow

Example 1 — Cells A, B, C: one neuron, all three sign cases

Forecast: Will each pre-activation be positive, negative, or zero — and which will ReLU zero out?

Step 1 — Compute . . Why this step? The dot product is the neuron asking "how much does this pattern appear in ?" A large positive score means the pattern is strongly present.

Step 2 — Apply ReLU to . . (Cell A) Why this step? Positive pre-activation → the neuron "fires" and passes its strength through unchanged.

Step 3 — Compute . . . (Cell B) Why this step? Negative pre-activation → the pattern is absent (or anti-present), so ReLU outputs . This neuron is dead for this input, and its gradient is too — that's the dead-neuron problem.

Step 4 — Compute . . Not quite zero, so let's engineer the zero case: with instead, exactly. . (Cell C) Why this step? Zero is the boundary. ReLU outputs , but its derivative is undefined here (left slope , right slope ); frameworks pick by convention.

Verify: Sanity — the only sign that survives ReLU is the positive one (). The negative () and the exact-zero both give . Dot-product magnitudes are all , e.g. , , product ; our . ✓


Example 2 — Cell D: full forward pass with shape tracking

Forecast: The hidden vector has length 3. Guess how many of its entries survive ReLU.

Step 1 — Expand: . So . Why this step? Multiplying by lifts the 2-D token into a richer 3-D feature space where more patterns can be separated.

Step 2 — Activate: . . Why this step? Non-linearity — one of the three neurons () is switched off, giving the sparsity the parent note mentioned.

Step 3 — Project: . So . Why this step? We compress back to so the result can be added to the residual stream (next example).

Verify: Shapes: ✓, then ✓. One of three hidden units died — matches the forecast of ~sparse activation. ✓

Figure — Feed-forward network sublayers

Example 3 — Cell E: residual connection + Layer Normalization

Forecast: After adding and normalizing, the two output numbers must have mean . Guess their signs.

Step 1 — Residual add: . . Why this step? Residual Connections give the FFN an easy identity path — the network only has to learn the change , not rebuild from scratch.

Step 2 — Mean over the 2 features. . Why this step? Layer Normalization centers each token's own features (unlike batch norm which uses the batch).

Step 3 — Variance and std. Deviations: , . , . Why this step? We divide by std so the vector has unit spread — keeps activations from blowing up across 24 stacked layers.

Step 4 — Normalize. , . Output . Why this step? maps the vector to mean , std .

Verify: Mean of ✓ (as forecast). Std ✓. Signs match 's signs (positive, negative) ✓.


Example 4 — Cell F: ReLU vs GELU vs SiLU on the SAME input

Forecast: For the negative input , which of the three give exactly zero, and which give a small negative number?

Step 1 — ReLU. ; . Why this step? Baseline: hard cutoff, no negative information kept.

Step 2 — SiLU at . . . Why this step? SiLU is self-gated — the input scales its own probability of passing, so small negatives leak through with a small negative value (non-zero gradient!).

Step 3 — GELU at . . . Why this step? GELU multiplies input by "chance it beats a Gaussian." Negative but non-zero — no dead neuron.

Step 4 — At . . . ReLU . Why this step? For large positive input all three approach — they agree where it matters least.

Verify: At : ReLU (only ReLU is exactly zero, as forecast), GELU, SiLU, both small and negative ✓. At all lie just below or at ✓.

Figure — Feed-forward network sublayers

Example 5 — Cell G: position-wise means shared weights, no mixing

Forecast: Does depend in any way on ? Guess yes/no.

Step 1 — , . ; . . Why this step? Same as any other token — the network is broadcast across positions.

Step 2 — , . ; . . Why this step? Computed with zero knowledge of — the two computations never touch.

Step 3 — Swap invariance. Feeding produces — just the reverse. Why this step? Confirms the position-wise property from the parent note.

Verify: used only ; no term contains ✓ (answer to forecast: no dependence). Output list is a per-token map. ✓


Example 6 — Cell H: real-world parameter budget

Forecast: Guess whether one FFN sublayer is above or below 5 million parameters.

Step 1 — Count and . ; . Why this step? Every entry of a weight matrix is a learned parameter.

Step 2 — Count and . ; . Why this step? Symmetric projection back — same size matrix.

Step 3 — Sum for one sublayer. . Why this step? Compare to the estimate: — the estimate drops the tiny biases.

Step 4 — All 12 layers, and RAM. Total params. RAM bytes MiB. Why this step? FFN alone is a big chunk of BERT-base's ~110 M parameters.

Verify: One sublayer ✓ (forecast). matches within the two bias vectors ✓. MiB ✓.


Example 7 — Cell I: the "collapse to linear" exam trap

Forecast: Two matrix multiplies with no bend in between — can they really collapse into one? Guess yes/no.

Step 1 — Multiply the weight matrices. . Why this step? by associativity — no activation to break the chain.

Step 2 — Fold the biases. . Why this step? Distribute: .

Step 3 — Test . Direct-bad: ; then . Collapsed: . Same! Why this step? Proves the collapse: without , stacking layers buys zero extra expressive power. That is exactly why the non-linearity is mandatory (ties to Universal Approximation Theorem).

Verify: Both paths give ✓ (forecast: yes, they collapse). This is the whole reason ReLU/GELU/SiLU exist.


Example 8 — Cell J: limiting behaviour of the activations

Forecast: As , which activation's output goes to fastest? Guess before computing.

Step 1 — Large positive . ReLU. SiLU. GELU. Why this step? All three for big positive input — they agree in the "definitely fire" regime.

Step 2 — Large negative . ReLU (flat). SiLU. GELU. Why this step? GELU decays like a Gaussian tail — astronomically faster than SiLU's exponential tail.

Step 3 — Verdict. As : ReLU is exactly ; SiLU like ; GELU but far faster (Gaussian ). Why this step? Explains why GELU behaves "almost like ReLU" for very negative inputs yet stays smooth near zero.

Verify: (magnitude tiny) ✓; magnitude SiLU's ✓ — so GELU decays fastest, as this was the forecast to check. ✓


Recall Self-test

ReLU output for pre-activation ? ::: (dead neuron) Does ever use 's data? ::: No — position-wise, independent, shared weights. Why can't we drop the activation ? ::: Two linear layers collapse to one (), gaining no expressive power. One BERT-base FFN sublayer parameter count? ::: . After residual + LayerNorm, what is the mean of a token's features? ::: (by construction).

Parent: Feed-forward network sublayers (index 4.1.8) · see also Transformer Encoder Block, Positional Encoding.