Layer NormalizationとRMSNorm:数学的原理と数値安定性
Agent支援工学分析
前提条件
第28日の分散と標準偏差;第22日のベクトル代数。
学習目標
入力ベクトル x = [2.0, -1.0, 0.0, 3.0] に対しLayerNormとRMSNormを順に計算し、現代アーキテクチャがRMSNormを好む理由を説明する。
手順
次元 d=4 のベクトル x = [2.0, -1.0, 0.0, 3.0] について:(1) 平均 mu = 1.0、分散 sigma^2 = 2.5 を求め、eps=1e-5 の場合の LayerNorm 出力を計算せよ。(2) RMS(x) = sqrt(mean(x^2)) = sqrt(3.5) ≈ 1.8708 を求め、RMSNorm 出力 x / RMS(x) を計算せよ。(3) 計算コストを対比せよ:RMSNorm はメモリ上の平均中心化のパスを省く。
演習と予測記録
1. LayerNorm(x) を小数点以下4桁まで求めよ。
2. RMSNorm(x) を小数点以下4桁まで求めよ。
3. RMSNormがGPU実行において帯域幅効率で有利な理由を述べよ。
xの平均は (2 - 1 + 0 + 3)/4 = 1.0。偏差の二乗和は (1 + 4 + 1 + 4) = 10 なので、sigma^2 = 2.5。二乗和の平均(RMSの二乗)は (4 + 1 + 0 + 9)/4 = 3.5。
LayerNorm: (x - 1.0)/sqrt(2.5) = [0.6325, -1.2649, -0.6325, 1.2649]。RMSNorm: x / sqrt(3.5) = [1.0690, -0.5345, 0.0, 1.6036]。RMSNormは、高帯域幅メモリ(HBM)をまたぐ活性化次元上の縮約パスを一回分丸ごと省く。
両方の正規化を手計算し、RMSNormのメモリ効率の優位性を説明できること。
公式ソースリソースと権利証跡
Root Mean Square Layer Normalization
該当セクション・タイムスタンプ: Section 4 RMSNorm (Equation 4) and Section 4.1 Invariance Analysis
検証バージョンと日付: NeurIPS 2019 / arXiv:1910.07467v1 (Verified: 2026-10-30)
Primary paper showing that mean-centering in LayerNorm can be discarded without performance loss, speeding up modern LLMs (LLaMA, Gemma).
Variance, standard deviation, and LayerNorm basics.
RMSNorm formulas and numerical comparisons are derived completely in the lesson.
比較対象候補リソースと選定評価 (2)
Original LayerNorm formulation with mean-centering; RMSNorm is compared directly against it as an optimization.
Batch-dependent statistics; unsuitable for autoregressive sequence modeling.
The Annotated Transformer
該当セクション・タイムスタンプ: Encoder and Decoder Stacks (class LayerNorm, class SublayerConnection)
検証バージョンと日付: Updated PyTorch 2.0 edition (Verified: 2026-10-30)
Clear reference implementation of Transformer modules, residual connections, and layer normalization.
PyTorch tensor operations and attention theory.
All block assembly and normalization logic are provided in runnable local Python snippets.
比較対象候補リソースと選定評価 (2)
Industrial scale with hundreds of model variations; Annotated Transformer is pedagogically focused on the core architecture.
Standard library implementation, but internal C++ bindings obscure the first-principles data flow.