← Back to Deep Learning Mind Map
🧠 Deep LearningID: kaiming-init-derivation

Kaiming Init Derivation

Kaiming 初始化方差推导
🎯Core Definition
The Kaiming (He) initialization derivation constructs a variance-preserving weight distribution for ReLU networks, concluding Var(w)=2/din\text{Var}(w) = 2/d_{\text{in}}. Full derivation chain: ① Core identity: for a single output neuron y=∑i=1dwixiy = \sum_{i=1}^{d} w_i x_i (d=dind = d_{\text{in}}), with wiw_i i.i.d., E[wi]=0E[w_i] = 0 and wiw_i independent of xix_i, Var(y)=∑i=1dVar(wixi)=∑i=1d(E[wi2]E[xi2]−E[wi]2E[xi]2)\text{Var}(y) = \sum_{i=1}^{d}\text{Var}(w_i x_i) = \sum_{i=1}^{d}\left(E[w_i^2]E[x_i^2] - E[w_i]^2E[x_i]^2\right). Since zero-mean ww, xx give Var(w)=E[w2]\text{Var}(w)=E[w^2], Var(x)=E[x2]\text{Var}(x)=E[x^2], we get Var(y)=d E[w2] E[x2]=d Var(w) Var(x)\text{Var}(y) = d\,E[w^2]\,E[x^2] = d\,\text{Var}(w)\,\text{Var}(x). ② Linear case: without an activation (or with a linear one), setting Var(y)=Var(x)\text{Var}(y) = \text{Var}(x) yields d Var(w)=1⇒Var(w)=1/dd\,\text{Var}(w) = 1 \Rightarrow \text{Var}(w) = 1/d, which is Xavier's forward condition. ③ The role of ReLU: assume the pre-activation z=wTxz = w^Tx is zero-mean and symmetric about 0 (guaranteed by zero-mean symmetric ww, xx), so P(z<0)=1/2P(z<0) = 1/2; the output x′=max⁡(0,z)x' = \max(0, z) zeroes the negative half, and its mean-square energy is E[(x′)2]=∫0∞z2p(z) dz=12∫−∞∞z2p(z) dz=12Var(z)E[(x')^2] = \int_0^{\infty} z^2 p(z)\,dz = \tfrac{1}{2}\int_{-\infty}^{\infty} z^2 p(z)\,dz = \tfrac{1}{2}\text{Var}(z) — ReLU exactly halves the activation energy. ④ Feed into the next layer: Var(y′)=d E[w2] E[(x′)2]=d Var(w)⋅12Var(x)\text{Var}(y') = d\,E[w^2]\,E[(x')^2] = d\,\text{Var}(w)\cdot\tfrac{1}{2}\text{Var}(x) (the previous layer already keeps Var(z)=Var(x)\text{Var}(z) = \text{Var}(x)); setting Var(y′)=Var(x)\text{Var}(y') = \text{Var}(x) gives 12d Var(w)=1⇒Var(w)=2d\tfrac{1}{2}d\,\text{Var}(w) = 1 \Rightarrow \text{Var}(w) = \frac{2}{d}. Where the factor 2 comes from: ReLU halves the activation energy each layer, so the weight variance must double to preserve variance. ⑤ Backward condition: the gradient ∂L∂x=WT∂L∂y\frac{\partial L}{\partial x} = W^T\frac{\partial L}{\partial y} is also a sum of doutd_{\text{out}} terms, and ReLU's derivative is 1 on the positive half and 0 on the negative half (gradient pass-through is also ½), so backward variance preservation requires Var(w)=2/dout\text{Var}(w) = 2/d_{\text{out}}. Forward uses fan_in, backward uses fan_out; frameworks such as PyTorch default to fan_in (dind_{\text{in}}). ⑥ PReLU generalization (negative slope aa): Var(w)=2(1+a2)din\text{Var}(w) = \frac{2}{(1+a^2)d_{\text{in}}}; a=0a=0 recovers ReLU's 2/din2/d_{\text{in}}.
💡Use Cases
a top interview derivation question (“derive the factor 2 in Kaiming init”), and the theoretical basis for the default initialization (kaiming_uniform) of all ReLU deep networks such as ResNet.
⚡Key Problems Solved
without the factor-2 compensation, each layer multiplies forward activation variance and backward gradient variance by ½, so after 50 layers signals vanish at (1/2)50≈10−15(1/2)^{50} \approx 10^{-15} — vanishing gradients; Kaiming keeps every layer's variance at 1, so signals traverse dozens or hundreds of layers stably. It also avoids ReLU saturation (weights too large push inputs into the negative half where gradients are 0 — dead neurons) and keeps the initial output magnitude at O(1)O(1), matching the loss scale for stable first updates.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Kaiming Init Derivation.
Use Cases
In production engineering, what are the primary use cases for Kaiming Init Derivation and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Full derivation: from Var(y)=d E[w2] E[x2]\text{Var}(y) = d\,E[w^2]\,E[x^2], through ReLU zeroing, derive Var(w)=2/din\text{Var}(w) = 2/d_{\text{in}} (write every step, including the zero-mean and independence assumptions).
2
Derive the factor 2: use the integral E[(x′)2]=12Var(z)E[(x')^2] = \tfrac{1}{2}\text{Var}(z) to show how ReLU zeroing halves the activation energy; which assumptions does it rely on (zero mean, symmetric distribution, ww independent of xx)?
3
Why are the forward and backward variance-preserving conditions 2/din2/d_{\text{in}} and 2/dout2/d_{\text{out}} respectively? How does ReLU's ½ gradient pass-through enter the backward derivation? Which does the framework default to (fan_in)?
4
Kaiming vs Xavier: how does Var(w)=2/d\text{Var}(w) = 2/d reduce to 1/d1/d without ReLU? Why do tanh networks use Xavier while ReLU networks must use Kaiming (what goes wrong with 1/d1/d)?
5
PReLU generalization: how does Var(w)=2(1+a2)din\text{Var}(w) = \frac{2}{(1+a^2)d_{\text{in}}} follow from E[(x′)2]=1+a22Var(z)E[(x')^2] = \tfrac{1+a^2}{2}\text{Var}(z); if the assumptions break (asymmetric or nonzero-mean inputs), which step of the derivation fails?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Kaiming Init Derivation"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardWeight InitializationNext Card →Gradient Clipping

🔗 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/kaiming-init-derivation
中文速览与面试要点

Kaiming 初始化方差推导 (Kaiming Init Derivation)

定义: Kaiming(He)初始化推导——为 ReLU 网络构造前向/反向方差保持的权重分布,结论是 Var(w) = 2/d_ in。完整推导链: ① 核心恒等式: 对单输出神经元 y = _i=1^d w_i x_i(d = d_ in),假设 w_i i.i.d.、E[w_i] = 0 且 w_i 与 x_i 相互独立,则 Var(y) = _i=1^d Var(w_i x_i) = _i=1^d (E[w_i^2]E[x_i^2] - E[w_i]^2E[x_i]^2 )。因 E[w]=0、E[x]=0 时 Var(w)=E[w^2]、 Var(x)=E[x^2],故 Var(y) = d\,E[w^2]\,E[x^2] = d\, Var(w)\, Var(x)。② 线性条件: 无激活(或线性激活)时令 Var(y) = Var(x),得 d\, Var(w) = 1 Var(w) = 1/d,即 Xavier 的前向条件。③ ReLU 的作用: 设前激活 z = w^Tx 均值为零且分布关于 0 对称(由零均值、对称的 w 与 x 保证),则 P(z<0) = 1/2;输出 x' = (0, z) 把负半轴全部置零,其均方能量 E[(x')^2] = _0^ z^2 p(z)\,dz = 12 _- ^ z^2 p(z)\,dz = 12 Var(z)——ReLU 恰好把激活的均方能量砍掉一半。④ 代入下一层: Var(y') = d\,E[w^2]\,E[(x')^2] = d\, Var(w) 12 Var(x)(上一层已保证 Var(z) = Var(x)),令 Var(y') = Var(x) 得 12d\, Var(w) = 1 Var(w) = 2d。因子 2 的来源: ReLU 每层把均方激活砍半,为保持方差不变,权重方差必须加倍。⑤ 反向条件: 梯度 L x = W^T L y 同样是 d_ out 项求和,且 ReLU 的导数正半轴为 1、负半轴为 0(梯度通过率也是 ½),故反向方差保持要求 Var(w) = 2/d_ out。前向用 fan_in、反向用 fan_out;PyTorch 等框架默认按 fan_in(d_ in)。⑥ PReLU 推广(负半轴斜率 a): Var(w) = 2(1+a^2)d_ in,a=0 时退化为 ReLU 的 2/d_ in。 使用场景: 面试手推高频题(“推导 Kaiming 因子 2”),也是 ResNet 等所有 ReLU 深度网络初始化配置(如 PyTorch 默认 kaiming_uniform)的理论依据。 解决的问题: 不做因子 2 补偿时,每层前向激活方差乘 ½、反向梯度方差乘 ½,50 层后信号按 (1/2)^50 10^-15 量级消失——梯度消失;Kaiming 初始化让每层方差保持 1,信号能稳定穿过数十上百层。同时避免权重过大导致 ReLU 全饱和(输入分布被推到负半轴、梯度为 0 的“死神经元”),方差保持也保证网络输出初始量级 O(1),与损失量级匹配、首步更新稳定。

核心要点

  • 完整推导链: 由 Var(y) = d\,E[w^2]\,E[x^2] 出发,经过 ReLU 置零推导出 Var(w) = 2/d_ in(要求写出每一步,含零均值与独立性假设)。
  • 推导 Kaiming 因子 2: 用积分 E[(x')^2] = 12 Var(z) 说明 ReLU 置零负半轴如何把激活均方砍半;依赖哪些假设(零均值、对称分布、w 与 x 独立)?
  • 前向与反向的方差保持条件为什么分别是 2/d_ in 与 2/d_ out?反向时 ReLU 导数的“梯度通过率 ½”如何进入推导?框架默认用哪个(fan_in)?
  • Kaiming 与 Xavier 的关系: 无 ReLU 时 Var(w) = 2/d 如何退化为 1/d?为什么 tanh 网络用 Xavier 而 ReLU 网络必须用 Kaiming(用 1/d 会怎样)?
  • PReLU 推广: 推导 Var(w) = 2(1+a^2)d_ in 如何来自 E[(x')^2] = 1+a^22 Var(z);如果假设不成立(如输入非对称、非零均值)推导哪一步失效?