LayerNorm JVP and VJP adjointness #
Spec.layerNormJvp is the forward-mode rule and Spec.layerNormBackward the reverse-mode rule
shipped with Spec.layerNorm. This file proves that they are adjoint: pairing an input and
parameter tangent with the JVP gives the same scalar as pairing the upstream gradient with the
three backward outputs. LayerNormFDeriv identifies this JVP with the derivative of the actual
specification for positive epsilon, then uses this pairing to prove that the backward rule is
the adjoint derivative. The pairing itself is algebraic and allows any real epsilon.
The proof is entrywise. Both spec functions are unfolded to explicit matrix forms (rfl), every
entry is rewritten as a real expression, and the per-row identity row_adjoint finishes with
ring.
Entry lemmas #
Column sums along the sequence axis.
Explicit matrix forms #
Row broadcast of a length-m vector to an m × n matrix.
Instances For
1 / std, as computed by the spec.
Instances For
Spec.layerNormJvp with its axis, broadcast, and cast evidence spelled out.
Instances For
Spec.layerNormBackward with its axis, broadcast, and cast evidence spelled out.
Instances For
Spec.layerNormJvp is layerNormJvpMat by unfolding.
Spec.layerNormBackward is layerNormBackwardMat by unfolding.
The per-row identity #
Scalar adjointness of the LayerNorm rules on one row: s is the inverse standard deviation,
xh the normalized row, γ the per-column scale.
Adjointness #
Entries of the JVP output.
Entries of the backward input gradient.
Entries of the backward scale gradient.
Entries of the backward bias gradient.
1 / std times centered is centered / std.
The LayerNorm reverse rule is adjoint to its forward differential.
Pairing the input tangent and both parameter tangents with Spec.layerNormJvp gives the same
scalar as pairing the upstream gradient with the three outputs of Spec.layerNormBackward.