Calculus of row normalization #
LayerNorm normalizes every row of a [seqLen, embedDim] matrix; the flattened form of BatchNorm
normalizes every row of a [channels, positions] matrix. Both share the map
x ↦ (x - mean(x)) / sqrt (var(x) + ε)
applied to each row, where mean and var are the population statistics of that row. This file
proves that map is differentiable on flattened matrices (for 0 < ε) and identifies its
derivative with the closed form
dx ↦ invStd * (dx - mean(dx) - xhat * mean(dx * xhat))
used by the normalization JVPs.
Mean of row i of a flattened m × n matrix.
Instances For
Centered entry (i, j).
Instances For
Population variance of row i.
Instances For
Inverse standard deviation 1 / sqrt (var + ε) of row i.
Instances For
Normalized entry (i, j).
Instances For
Closed-form differential of the normalized entry (i, j) in the direction dX.
Instances For
The row variance is a mean of squares.
The centered entries of a row sum to zero.
The centered row is orthogonal to constants, so ∑ c_j (d_j - a) = ∑ c_j d_j.
Derivative building blocks #
Coordinate projection as a continuous linear functional on flattened matrices.
Instances For
The projection functional reads coordinate k.
Derivative of the row mean.
Instances For
The row-mean derivative is the row mean of the perturbation, since the mean is already linear.
The centering derivative subtracts the perturbation's own row mean.
Centering is linear too, so its derivative is itself; the nonlinearity in row normalization enters only through the variance and the square root below.
Derivative of the row variance at X.
Instances For
The variance differential only sees the centered direction.
Derivative of sqrt (var + ε) at X.
Instances For
Derivative of the inverse standard deviation at X.
Instances For
Derivative of the normalized entry (i, j) at X.
Instances For
Coordinates of a flattened matrix are differentiable.
Derivative of the row mean.
Derivative of a centered entry.
Derivative of the row variance.
Derivative of the inverse standard deviation, for positive ε.
The normalized entry is differentiable for positive ε.
The derivative of the normalized entry is the closed-form JVP.
Whole-matrix normalization #
Row index of a flattened matrix coordinate.
Instances For
Column index of a flattened matrix coordinate.
Instances For
Every flattened coordinate is idxMN of its row and column.
Row of the flattened coordinate idxMN i j.
Column of the flattened coordinate idxMN i j.
The tape row-mean map computes rowMean.
The tape row-broadcast map at idxMN i j reads entry i.
The tape column-broadcast map at idxMN i j reads entry j.
Normalize every row of a flattened matrix.
Instances For
Coordinate ip of the normalized matrix is the normalized entry at its row and column.
Closed-form JVP of nrmVec at X, packaged as a continuous linear map.
Instances For
The bundled JVP agrees with the closed-form nrmJvp coordinatewise.
Row normalization is differentiable on a nonempty feature axis, with the closed-form JVP as derivative. The coordinatewise chain-rule calculation agrees with that JVP because positive epsilon keeps each row's denominator nonzero.