rms_norm
rms_norm
¶
Root Mean Square Layer Normalization.
From Zhang et al. (2019): https://arxiv.org/abs/1910.07467
RMSNorm normalizes using only the root mean square statistic, without centering (no mean subtraction). This is more efficient than LayerNorm and works well in practice for LLM-scale models.
RMSNorm
¶
Bases: Module
Root Mean Square Layer Normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_shape
|
int
|
Input shape from an expected input of size [*, normalized_shape] |
required |
epsilon
|
float
|
A value added to the denominator for numerical stability |
1e-06
|
elementwise_affine
|
bool
|
If True, learns affine scaling parameters |
True
|
Initialize RMSNorm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_shape
|
int
|
Feature dimension to normalize |
required |
epsilon
|
float
|
Small constant for numerical stability |
1e-06
|
elementwise_affine
|
bool
|
Whether to learn scaling parameters |
True
|
Source code in src/versatil/models/layers/normalization/rms_norm.py
forward
¶
Apply RMS normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor (..., normalized_shape) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Normalized tensor of same shape |