Python wrappers
Public Python APIs implemented by this engine symbols.Autograd node for Layer Normalization.
Computes
over the last
dimensions of x (one (\mu, \sigma^2) pair per leading-axis
slice), then applies the element-wise affine
. The per-slice mean
saved_mean_ and reciprocal standard deviation
saved_rstd_ are cached for the backward closed-form.
Inherits FuncOp<LayerNormBackward, 3> with three saved-input
slots — x, gamma, and beta. outer_ * N_ always
equals numel(x): outer_ is the product of the leading
(non-normalised) dims and N_ is the product of the trailing
(normalised) dims.
Math
For each leading-axis slice of x (flattened length ):
Mean and variance use the biased estimator (correction=0), as is
standard for layer norm.
References
[Ba, Kiros & Hinton, "Layer Normalization" (arXiv:1607.06450, 2016)](https://arxiv.org/abs/1607.06450).
Attributes
schema_v1OpSchemaname="layer_norm", version=1, amp_policy=ForceFP32, produces_grad=true).saved_mean_Storage(outer_,).saved_rstd_Storage(outer_,).outer_std::size_tx.N_std::size_tx (== numel(gamma)).Notes
Thread safety: instances are created during forward and consumed during backward — no concurrent access expected.
Static methods
1forward
→TensorImplPtrint forward(const int & x, const int & gamma, const int & beta, double eps)Run the forward pass.
Reduces x over its last dimensions (where is the rank
of gamma), normalises, applies the affine, and (when grad mode
is on) registers this as the grad_fn of the returned
output. Caches saved_mean_ and saved_rstd_ for backward.
Parameters
xTensorImplPtr(*, normalized_shape).gammaTensorImplPtrx.betaTensorImplPtrgamma.epsdoubleReturns
TensorImplPtrNormalised output, same shape as x.
Raises
ShapeMismatchgamma.ndim > x.ndim, if the trailing dims of x do not match gamma, or if gamma.shape != beta.shape.Methods
1Compute gradients for the three saved inputs.
Returns {dx, d_gamma, d_beta} in the saved-input order.
Closed-form (per leading slice of length ):
and the input gradient follows the standard LN backward expansion (a difference of the centred grad and two reduction terms scaled by ).
Parameters
grad_outStorageReturns
std::vector<Storage>Three-element vector {dx, d_gamma, d_beta}.