MATH ML Learning Lab
B11
B11 · 20–30 min

多路径链式法则与反向传播Multi-Path Chain Rule & Backpropagation

同一个输入通过多条路径影响损失时,怎样合并这些影响?How do we combine effects when one input influences a loss along multiple paths?

前置知识:Prerequisites: B08:一元链式法则;B09:梯度;B10:损失与更新。B08: single-variable chain rule; B09: gradients; B10: loss and updates.

复习前置:Review prerequisites: B08 · 一元链式法则The Single-Variable Chain Rule · B09 · 偏导数与梯度Partial Derivatives & Gradients · B10 · 损失函数与梯度下降Loss Functions & Gradient Descent

学完后你能:After this lesson you can: 计算共享节点两条路径的导数贡献,并正确累加。Calculate and correctly accumulate derivatives from two paths to a shared node.

动手观察Explore

单步执行 x→u、x→v、u+v 的前向与反向计算,观察回到 x 的两条贡献如何累加。Step through the forward and backward computation of x→u, x→v and u+v; observe the two contributions accumulating at x.

从观察到解释From observation to explanation

先做前向计算Compute forward first

令 u=x²、v=3x、L=u+v。x=2 时,u=4、v=6、L=10。计算图中 x 分别连接到 u 和 v,再在加法节点汇合。Let u=x², v=3x and L=u+v. At x=2, u=4, v=6 and L=10. The graph branches from x to u and v, then merges at addition.

每条路径相乘Multiply along each path

加法节点对 u 和 v 的局部导数都为 1。经 u 返回的贡献是 1×2x;经 v 返回的贡献是 1×3。x=2 时分别是 4 和 3。The addition node has local derivative 1 with respect to each input. The contribution through u is 1×2x; through v it is 1×3. At x=2 these are 4 and 3.

共享节点相加Add at shared nodes

两条路径同时影响 x,所以总导数为 4+3=7。反向传播把局部导数沿边相乘,在共享节点累加;重新运行前要把旧累计值清零。Both paths affect x, so the total derivative is 4+3=7. Backpropagation multiplies local derivatives along edges and accumulates them at shared nodes; clear old accumulated values before another pass.

公式与符号Formula and symbols

x 是共享输入,u 与 v 是中间结果,L 是标量输出;每项表示一条路径的局部导数乘积,两个贡献在 x 汇合时相加。x is a shared input, u and v are intermediate values, and L is a scalar output. Each term is a product of local derivatives along one path; contributions add where they meet at x.

留意这个区别Watch for this

分支贡献要相加,不能覆盖先到的值;如果不清零就重复反传,会错误地把两次结果叠加。Add branch contributions rather than overwriting the first. Repeating a backward pass without clearing accumulated gradients incorrectly adds the two runs.

继续探索Explore further

继续学习算法Continue to an algorithm

神经网络Neural networks

课后练习

检验你的理解