Documentation

Formalizations.Analysis.TransformerAttention.ResidualJacobian

The Jacobian of a residual stream is an ordered product #

For a residual stream h_{ℓ+1} = h_ℓ + w_ℓ(h_ℓ) with differentiable layers w_ℓ on a real normed space, the derivative of the whole stream is the ORDERED product of the layer Jacobians I + w_ℓ′, each evaluated at the point the stream has reached (Theorem 1 of transformers-attend-III, «recurrence factorisation»). Expanding the product gives J − I = Σ_k w_k′ + (cross terms).

Main results #

References #

def TransformerAttention.ResidualJacobian.step {E : Type u_1} [NormedAddCommGroup E] (w : E → E) :
E → E

One residual layer h ↦ h + w h.

Equations
Instances For
    noncomputable def TransformerAttention.ResidualJacobian.jac {E : Type u_1} [NormedAddCommGroup E] [NormedSpace ℝ E] :
    List (E → E) → E → E →L[ℝ] E

    The ordered product of the layer Jacobians I + w′ along the trajectory, the head layer first (rightmost).

    Equations
    Instances For
      theorem TransformerAttention.ResidualJacobian.hasFDerivAt_flow {E : Type u_1} [NormedAddCommGroup E] [NormedSpace ℝ E] (ws : List (E → E)) (hw : ∀ w ∈ ws, Differentiable ℝ w) (x : E) :
      HasFDerivAt (flow ws) (jac ws x) x

      Recurrence factorisation: for differentiable layers, the derivative of the residual stream at x is the ordered product of the layer Jacobians I + w_k′ evaluated along the trajectory from x.