#372 · Deep Learning · Easy
⊣ Solve on deep-ml.comImplement RMSNorm (Root Mean Square Layer Normalization), a simpler alternative to LayerNorm that normalizes by the root mean square of the activations without centering (no mean subtraction).
import numpy as np
def rms_norm(x: np.ndarray, gamma: np.ndarray, eps: float = 1e-8) -> np.ndarray:
# x shape: (..., d) where d is the feature dimension
rms = np.sqrt(np.mean(x ** 2, axis=-1, keepdims=True) + eps)
x_norm = x / rms
return gamma * x_normrms = sqrt(mean(x^2) + eps).