<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>BatchNorm - Tag - Naifan Li's Blog</title><link>https://blog.omagiclee.com/tags/batchnorm/</link><description>BatchNorm - Tag - Naifan Li's Blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 16 Mar 2026 17:05:46 +0800</lastBuildDate><atom:link href="https://blog.omagiclee.com/tags/batchnorm/" rel="self" type="application/rss+xml"/><item><title>归一化：BatchNorm、LayerNorm 与 RMSNorm</title><link>https://blog.omagiclee.com/posts/basics/norms/</link><pubDate>Mon, 16 Mar 2026 17:05:46 +0800</pubDate><author>Naifan Li</author><guid>https://blog.omagiclee.com/posts/basics/norms/</guid><description><![CDATA[<h2 id="为什么需要归一化">为什么需要归一化</h2>
<p>深层网络中，每一层的输出尺度会随着层数的增加变得不可控——有些层输出极大，有些极小。这直接导致梯度不稳定，学习率难以调整，训练容易发散。</p>
<p>归一化的本质作用是<strong>把中间表示拉回一个可控的尺度附近</strong>，从而：</p>
<ul>
<li>让 loss landscape 更平滑，梯度更稳定</li>
<li>允许使用更大的学习率，加速收敛</li>
<li>降低对参数初始化的敏感度</li>
</ul>
<p>BatchNorm 论文最初将此解释为&quot;缓解 internal covariate shift&quot;，但后续研究表明，归一化真正的价值更多在于<strong>改善优化条件</strong>，而不仅仅是修正分布漂移。</p>
<h2 id="batchnorm">BatchNorm</h2>
<h3 id="算法">算法</h3>
<p>设输入为 $x$，对某个特征维（或通道），BatchNorm 分四步：</p>
<ol>
<li><strong>计算 batch 均值</strong></li>
</ol>
$$
\mu = \frac{1}{|\mathcal{B}|}\sum_{i \in \mathcal{B}} x_i
$$<ol start="2">
<li><strong>计算 batch 方差</strong></li>
</ol>
$$
\sigma^2 = \frac{1}{|\mathcal{B}|}\sum_{i \in \mathcal{B}} (x_i - \mu)^2
$$<ol start="3">
<li><strong>标准化</strong></li>
</ol>
$$
\hat{x}_i = \frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}}
$$<ol start="4">
<li><strong>仿射变换</strong></li>
</ol>
$$
y_i = \gamma\, \hat{x}_i + \beta
$$<p>其中 $\gamma, \beta$ 是可学习参数，$\epsilon$ 防止除零。</p>
<p>统计维度取决于输入形状：</p>
<ul>
<li><strong>全连接层</strong> $x \in \mathbb{R}^{B \times D}$：对每个特征维 $d$，在 batch 维 $B$ 上统计</li>
<li><strong>卷积层</strong> $x \in \mathbb{R}^{B \times C \times H \times W}$：对每个通道 $c$，在 $(B, H, W)$ 上统计</li>
</ul>
<p>每个特征维（或通道）有独立的一组 $\gamma, \beta$。</p>]]></description></item></channel></rss>