模型与实验室 4.0 · 优秀 2026-10-23 · 文章

RMSNorm

Giles Thomas 把 LayerNorm 与 RMSNorm 的差异算到运算次数再用四组训练验证:RMSNorm 省去均值步骤,理论上每向量少 3d−1 次加减和一次除法。8×A100 上跑 1.63 亿参数 GPT-2 small 风格模型:手写实现换 RMSNorm 只快 2.5%,换 PyTorch 内置只快 0.5%(判为噪声);大头在融合实现——内置比手写快约 10–11%,把算法差异整个盖过。质量上 RMSNorm 测试 loss 略差 0.001–0.006;去掉归一化的对照组从第 530 步起全 nan。结论:省下的加减法在现代 GPU 上几乎不值钱,账单上是融合 kernel 那 10%。

打开原文回到归档

RMSNorm

  • ID: bd81b6e2
  • 原文链接: https://www.gilesthomas.com/2026/10/rmsnorm
  • 作者: Giles Thomas
  • 日期: 2026-10-23
  • 分类: models
  • 来源类型: article
  • 标签: normalization, training, pytorch, gpt-2
  • 质量评分: 4/5
  • 抓取时间: 2026-10-24 (Asia/Shanghai),grounded in vault full-text sources

中文导读

Giles Thomas 把 LayerNorm 与 RMSNorm 的差别算到运算次数,再用四组训练验证。算账:LayerNorm 对长度 d 的向量要做 4d−2 次加减、2+d 次除、2d 次乘;RMSNorm 不去均值,只剩 d−1 次加减、1+d 次除、2d 次乘——理论省 3d−1 次加减和一次除法,乘法和开方省不掉。实测 8×A100 40GiB 跑 1.63 亿参数 GPT-2 small 风格模型(无权重共享、QKV 无 bias、无 dropout、warmup 5% 到 0.0014 再余弦降 0.00014、Chinchilla 口径约 20 token/参数):手写 LayerNorm 9,358 秒 / 348,364 tok/s / loss 3.5953;手写 RMSNorm 9,134 秒 / 356,899 tok/s / 3.6013;内置 LayerNorm 8,324 秒 / 391,659 tok/s / 3.5712;内置 RMSNorm 8,289 秒 / 393,294 tok/s / 3.5724。手写换 RMSNorm 只快 2.5%,换内置只快 0.5%(他判为噪声);大头在融合实现——内置比手写快 11%(LN)/约 10%(RMSNorm),把算法差异整个盖过。质量上 RMSNorm 略差 0.0060(手写)/ 0.0012(内置),倾向当噪声;去掉归一化的对照组第 530 步起 loss 全 nan、640 步强退。

为什么值得关注

按「换个归一化方式能省多少」做技术选型容易算错量级:省下的加减法在现代 GPU 上几乎不值钱,账单上写的是融合 kernel 那 10%。作者早年 JAX 重写 GPT-2 去掉 LayerNorm 一百步即崩,这次用更小模型把结论做成了可复现配置。

关键信息

  • 理论账:RMSNorm 省 3d−1 次加减 + 1 次除法/向量
  • 手写 LN→RMSNorm:+2.5%;手写→PyTorch 内置:+0.5%(噪声)
  • 融合实现收益:10–11%,盖过算法差异
  • 质量:RMSNorm loss 略差 0.0012–0.0060;无归一化 530 步起全 nan
  • 出处:Zhang & Sennrich 2019(arXiv:1910.07467)

English Summary

Giles Thomas prices the LayerNorm-to-RMSNorm swap in exact arithmetic, then verifies it with four training runs of a ~163M-parameter GPT-2-small-style model on 8xA100 40GiB under a reproducible Chinchilla-proportioned config. RMSNorm skips mean-centering, saving 3d-1 additions and one division per vector, but the hand-written swap bought only 2.5% wall-clock and switching to PyTorch's built-in norm only 0.5% (noise, in his judgment); the fused kernels beat the hand-written versions by 10-11%, drowning the algorithmic difference entirely. Quality-wise RMSNorm test loss came out 0.0012-0.0060 worse, treated as noise, and a no-normalization control went NaN from step 530. The practical reading: saved additions are nearly free on modern GPUs - the fused kernel is where the 10% lives.

Obsidian Notes

  • Fetched via AK-RSS-Digest 89源精选 2026-10-24 run; vault source: OpenClaw定时任务/AK-RSS-Digest(89源精选)/source/2026-10-24-giles-thomas-rmsnorm.md (full text, 42.6 KB).
  • Fetched 2026-10-24 via the evening intake pipeline; entry appended through pipeline_utils with URL dedup precheck.