Backpropagation & Tied Weights
Analyze analytical weight gradients dL/dW_j = (p_j - y_j) * x and why unobserved tokens require balanced regularization.
Backpropagation answers: 'How much did each of our 185K weights contribute to the prediction error, and in which direction should we nudge them?' It works backward through the chain rule. Residual skip connections are critical because their derivative contains the identity matrix (+I), letting gradients flow across layers without vanishing.
PyTorch handles backprop automatically with loss.backward(). The manual analytical derivations shown here are what autograd calculates under the hood. Understanding weight gradients explains subtle training failures like unobserved token collapse and the AdamW weight decay necessity.
The Chain Rule (Backpropagation)
Residual Connection Gradient Highway
Tied Weight Gradient Derivation
AdamW Optimizer with Decoupled Weight Decay
In byte-level vocabularies, ASCII control codes 0 to 9 never appear in natural Shakespeare or Hafez text. Because their target $y_j = 0$ permanently, their gradients are strictly $p_j \cdot x$. In inspections, these unobserved rows exhibit parallel vertical striping reflecting mean residual activations.
In contrast, printable ASCII and Persian UTF-8 subwords receive active updates $(p_j - 1) \cdot x$ whenever they appear in text. This breaks symmetry and pushes each subword embedding into its unique semantic direction in 64D space, eliminating vertical striping.
- The chain rule decomposes dL/dw into a product of local Jacobian matrices backwards through the network.
- Residual connections create a gradient highway: the identity matrix (+I) allows error signals to skip layers.
- Analytical output weight gradient is dL/dW_j = (p_j - y_j) * x.
- AdamW decouples weight decay from adaptive gradient scaling, stabilizing training across 50 epochs.
Run the verification code snippet above in Python. Notice how the analytical formula matches autograd down to machine precision (< 1e-7).