The MLP train step: per-layer parameter-gradient assembly #
The MLP (dense → relu → dense → relu → dense) train step updates six parameters
W₀,b₀,W₁,b₁,W₂,b₂. Each layer's gradient is the assembly of backprop:
∂L/∂Wᵢ = (layer-i input) ⊗ (cotangent the backward chain delivers at layer i),
∂L/∂bᵢ = (that cotangent).
The generic per-layer bridges already certify this for any backward subgraph
e : Back (weight_grad_bridge/bias_grad_bridge, IR.lean) — emit*Grad equals
the certified Jacobian of that dense layer contracted with e.denote dy. So the
assembly is choosing the right cotangent subgraph per layer:
- layer 2 (logits): the loss cotangent
gitself —Back.cotangent(weight_grad_bridge … Back.cotangent, withBack.cotangent.denote g = g). - layer 1 (
p₁):relu'(p₁) ⊙ (W₂ · g)—mlpCotOut1(IR.lean;mlp_layer1_weight_grad_bridge). - layer 0 (
p₀):relu'(p₀) ⊙ (W₁ · mlpCotOut1)—mlpCotOut0, below.
This file supplies mlpCotOut0 and its weight/bias bridges — completing the three-layer
assembly, the multi-layer step the one-layer linear net has no analogue of — and the
total-loss folds (StableHLO.lossWeightGrad_eq_sum, and at smooth points
mlp_hidden_total_loss_grad, mlp_input_total_loss_grad, mlp_whole_net_weight_grads). The SGD
wrapping θ − lr·∇ on top is identical to the linear case (StableHLO.sgdW).
Layer-0 cotangent subgraph — the cotangent the backward chain delivers at
the layer-0 dense output p₀: relu'(p₀) ⊙ (W₁ · mlpCotOut1). Prepends one more
relu-back ∘ dense-back to mlpCotOut1, exactly as mlpCotOut1 extends
Back.cotangent.
Equations
- Proofs.IR.mlpCotOut0 W₁ W₂ p₀ p₁ = (Proofs.IR.emitReluBack p₀).subst ((Proofs.IR.emitDenseBack W₁).subst (Proofs.IR.mlpCotOut1 W₂ p₁))
Instances For
MLP layer-0 weight-gradient bridge. The emitted layer-0 weight gradient
(x₀ ⊗ mlpCotOut0) equals the certified Jacobian of the layer-0 dense wrt W₀,
contracted with the cotangent the backward chain delivers there — the deepest
chain (relu'(p₀) ⊙ W₁ · relu'(p₁) ⊙ W₂ · dy). The layer-0 peer of
mlp_layer1_weight_grad_bridge.
MLP layer-0 bias-gradient bridge. Likewise the layer-0 bias gradient is the certified ∂/∂b₀ Jacobian contracted with the same deepest cotangent.
MLP layer-1 bias-gradient bridge (the bias peer of the existing
mlp_layer1_weight_grad_bridge).
MLP layer-2 (output) weight-gradient bridge — the output layer's cotangent
is the loss cotangent dy itself (Back.cotangent, denote dy = dy); the
bridge is the generic one specialized there.
Input-layer total-loss fold (conditional, deepest). The same fold for the
first layer W₀, whose chain runs back through both ReLUs — so it carries both
smoothness hypotheses (the same pair as mlpHasVJPAt). The total loss gradient
wrt W₀ = certified ∂p₀/∂W₀ contracted with the loss gradient at p₀, left as a
pdiv (its identification with the chain cotangent mlpCotOut0_denote computes is not
stated here).
Whole-network MLP weight-gradient capstone. The three weight layers' total-loss gradients, jointly, under the two smoothness hypotheses.