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
| Class | Parameter | Type | Default | Description |
|---|---|---|---|---|
LayerNorm | normalized_shape | int | required | Size of the trailing feature dimension to normalize. |
LayerNorm | eps | float | 1e-5 | Stability epsilon added to variance. |
LayerNorm | elementwise_affine | bool | True | Creates learnable gamma (scale) and beta (shift) parameters. |
RMSNorm | normalized_shape | int | required | Size of the trailing feature dimension. |
RMSNorm | eps | float | 1e-5 | Stability 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)