rms_norm(x: Tensor, normalized_shape: list[int] | tuple[int, ...], weight: Tensor | None = None, eps: float | None = None)Implementing kernel
C++ engine symbols that back this Python API.Root-mean-square layer normalization (Zhang & Sennrich, 2019).
A simplified variant of layer_norm that drops mean
centering and the additive bias. Cheaper to compute and shown to
perform competitively in large language models (LLaMA, T5,
PaLM, ...), where its lower latency and memory footprint matter at
scale.
Parameters
Input whose last dimension matches
normalized_shape.normalized_shapelist of int or tuple of intTrailing dims to normalise over. Typically
(d,) where
d is the model hidden size.Per-element scale . Defaults to ones.
epsfloat= NoneNumerical safety added inside the square root.
None (the
default) uses the machine epsilon of x's dtype, as the
reference framework does — a fixed 1e-8 rounds to zero in
float16, so a half-precision export divided by an exact zero on
an all-zero row.Returns
TensorSame shape as x.
Notes
Math:
The dropped mean-centering step costs LayerNorm one extra reduction and a subtraction; RMSNorm trades that for a small amount of expressivity (no shift invariance). In practice the loss is negligible at scale.
Examples
>>> import lucid
>>> from lucid.nn.functional import rms_norm
>>> x = lucid.randn(2, 128, 512)
>>> y = rms_norm(x, normalized_shape=(512,))
>>> y.shape
(2, 128, 512)