Skip to Content
OchreML
Layers & Activations

LayerNorm & RMSNorm

Row-wise Layer Normalization and Root Mean Square Normalization backed by N8 Rust kernels.

ochreml.nn.LayerNorm and ochreml.nn.RMSNorm normalize the last dimension of an input tensor using OchreML's fused N8 Rust kernels (forward and backward).

Import & Signatures

import ochreml.nn as nn

ln = nn.LayerNorm(
    normalized_shape,
    eps=1e-5,
    elementwise_affine=True,
    dtype="float32",
    device=None,
)

rms = nn.RMSNorm(
    normalized_shape,
    eps=1e-5,
    dtype="float32",
    device=None,
)

Parameters

ClassParameterTypeDefaultDescription
LayerNormnormalized_shapeintrequiredSize of the trailing feature dimension to normalize.
LayerNormepsfloat1e-5Stability epsilon added to variance.
LayerNormelementwise_affineboolTrueCreates learnable gamma (scale) and beta (shift) parameters.
RMSNormnormalized_shapeintrequiredSize of the trailing feature dimension.
RMSNormepsfloat1e-5Stability epsilon added to mean squared value; learns gamma scale.

Usage Example

import ochreml.nn as nn

x = nn.Tensor.randn([4, 16, 64])
y_ln = nn.LayerNorm(64)(x)
y_rms = nn.RMSNorm(64)(x)

On this page