← Back to Deep Learning Mind Map
🧠 Deep LearningID: batchnorm

Batch Normalization

BatchNorm 批归一化
🎯Core Definition
Batch Normalization normalizes activations along the batch axis per feature channel to combat internal covariate shift. Given input xx, compute the batch mean and variance μB=1m∑i=1mxi\mu_B = \frac{1}{m}\sum_{i=1}^{m} x_i, σB2=1m∑i=1m(xi−μB)2\sigma_B^2 = \frac{1}{m}\sum_{i=1}^{m}(x_i - \mu_B)^2, normalize x^=x−μBσB2+ϵ\hat{x} = \frac{x - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}, then apply a learned affine transform y=γx^+βy = \gamma\hat{x} + \beta (per-channel γ,β\gamma, \beta for CNNs; ϵ\epsilon around 1e-5 prevents division by zero).
💡Use Cases
the default for image CNNs (ResNet and successors) to stabilize training, allow larger learning rates, and reduce sensitivity to initialization and dropout; interviews focus on the train/inference statistics gap, why small batches break it, and why NLP/Transformers switched to LayerNorm.
⚡Key Problems Solved
keeps activations at zero mean / unit variance, smoothing the loss landscape so convergence is often several times faster (training epochs can be roughly halved), with a mild regularizing side effect from batch-statistics noise. Key engineering point: training uses current batch statistics, while inference uses exponentially moving averages (EMA, momentum usually 0.1) accumulated during training — so small batches (batch=1 makes σB=0\sigma_B=0) distort the statistics and create train/inference mismatch, effectively breaking the model, an inherent weakness of BN.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Batch Normalization.
Use Cases
In production engineering, what are the primary use cases for Batch Normalization and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Write the full BatchNorm computation: how μB\mu_B and σB2\sigma_B^2 are computed, the normalization x^=x−μBσB2+ϵ\hat{x} = \frac{x-\mu_B}{\sqrt{\sigma_B^2+\epsilon}}, and the role of the affine parameters γ,β\gamma,\beta.
2
Train vs inference behavior: why must inference use the running mean/variance (EMA) instead of batch statistics, and when is the EMA updated?
3
Why does BN fail with small batches? What happens at batch=1, and what problems arise from train/inference statistic mismatch?
4
Why do Transformers/LLMs use LayerNorm instead of BatchNorm? What issues does BN face with variable-length sequences and padding?
5
Why does BN speed up convergence (ICS / loss-surface smoothing)? What is its regularizing side effect, and what order is used when combining it with Dropout?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Batch Normalization"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardLoss FunctionsNext Card →LayerNorm & RMSNorm

🔗 More Deep Learning Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/DL/card/batchnorm
中文速览与面试要点

BatchNorm 批归一化 (Batch Normalization)

定义: BatchNorm (批归一化) 沿 batch 维对每个特征通道做标准化, 消除内部协变量偏移 (ICS)。对输入 x, 先计算当前 batch 的均值与方差 _B = 1m _i=1^m x_i、 _B^2 = 1m _i=1^m(x_i - _B)^2, 再归一化 x = x - _B _B^2 + , 最后做可学习的仿射变换 y = x + (CNN 中每个通道一组 , , 取 1e-5 量级防除零)。 使用场景: 图像 CNN 标配 (ResNet 等), 用于稳定训练、允许更大学习率、降低对初始化与 Dropout 的依赖; 面试常问训练/推理统计量差异、小 batch 为何失效、为什么 NLP/Transformer 改用 LN。 解决的问题: 使每层激活保持零均值单位方差, 大幅平滑 loss 曲面, 收敛速度通常提升数倍 (训练 epoch 可减半量级), 并带轻微正则化副作用 (batch 统计噪声)。关键工程点: 训练时用当前 batch 统计量; 推理时用训练期指数滑动平均 (EMA, momentum 通常 0.1) 累积的 running mean/var——因此小 batch (batch=1 时 _B=0) 会使统计量失真、训练与推理行为不一致, 模型近乎失效, 这是 BN 的固有缺陷。

核心要点

  • 写出 BatchNorm 的完整计算流程: 如何算 _B、 _B^2, 归一化公式 x = x- _B _B^2+ 与仿射变换 y = x+ 中 , 的作用?
  • 训练与推理时 BN 的行为差异: 训练用 batch 统计量, 推理为什么必须用滑动平均 (running mean/var)? EMA 在哪个阶段更新?
  • 小 batch 下 BN 为什么失效? batch=1 时会发生什么? 训练/推理统计量不一致会造成什么问题?
  • 为什么 Transformer/LLM 中 BN 很少用而改用 LayerNorm? BN 在变长序列、padding 上的问题是什么?
  • BN 为何能加速收敛 (内部协变量偏移/loss 平滑)? 它有什么正则化副作用, 与 Dropout 并用的顺序如何?