Sitemap

Member-only story

RMS Norm Explained

2 min readJun 9, 2025

--

The math and code

The Root Mean Square Layer Normalization (RMSNorm) is a common type of normalization layer in Deep Learning. In the original paper the is defined as:

Where x is a vector of D dimension and x_i is the i-th component of vector x and γ is a learnable parameter.

However this normalization is applied over the layer dimension. If we are operating with computer vision then we would need to adapt it to compute the normalization over the channel dimension C of the x input tensor now with dims : [B, H, W, C].

The equation would change and the RMS term would only be computed over the C dimension:

We could interpret this visually as an image with 3 colors channels and a normalization tensor 1/RMS(x):

Press enter or click to view image in full size

And then, the learnable parameter γ would only learn one value per channel:

Press enter or click to view image in full size

This was all for the math and the conceptual understanding in visual terms. Now show me the code:

import torch
from torch import nn

class RMSNorm(nn.Module):
"""Root Mean Square Layer Normalization over channel dimension"""

def __init__(self, dim: int):
super().__init__()…

--

--

Javier
Javier

Written by Javier

AI Research Engineer in Deep Learning. Living between the math and the code. A philosophic seeker interested in the meaning of everything from faith to AI.