LAWS.residual: law of bendtorch@1.3.0.0 Import: import bendtorch@1.3.0.0/LAWS.bend as LAWS Lines 76-86 of bendtorch@1.3.0.0/LAWS.bend: https://jend.leeeet.dev/read.txt?path=bendtorch@1.3.0.0/LAWS.bend&start_line=76&end_line=86 import Base import bendtorch@1.3.0.0/main.bend as T import bendtorch@1.3.0.0/spec.bend as Spec # LAW (residual): T.Residual's own code (T.ResidualOf: Seq(Fork(Id, f), Add2)), with a linear layer as f, gives a # backward pass that is the adjoint of its forward pass: for y = x + W·x and its dx, dy·y == dx·x. The backward pass # hands dy to both branches and adds what comes back, dx = dy + Wᵀ·dy: the gradient goes through the skip connection # untouched and through the layer, the rule every block of the Llama models relies on twice. (Over matrices the join # is Add2; here it is its twin over vectors, a + b forward and dy to both backward.) law residual: for +w: List<&2, List<&2, Nat>> for +x: List<&2, Nat> for +dy: List<&2, Nat> for g: List<&2, List<&2, Nat>> {Spec.dotn(dy, Spec.fy(T.Two>>, Unit>, List<&2, Nat>, T.Two>, Unit>, T.Layer.fwd(T.Two>>, Unit>, List<&2, Nat>, List<&2, Nat>, T.Two>, Unit>, Spec.ResL(), T.Two{T.Two{Unit{}, w}, Unit{}}, x))) == Spec.dotn(Spec.bdx(T.Two>>, Unit>, List<&2, Nat>, T.Layer.bwd(T.Two>>, Unit>, List<&2, Nat>, List<&2, Nat>, T.Two>, Unit>, Spec.ResL(), T.Two{T.Two{Unit{}, w}, Unit{}}, Spec.fsv(T.Two>>, Unit>, List<&2, Nat>, T.Two>, Unit>, T.Layer.fwd(T.Two>>, Unit>, List<&2, Nat>, List<&2, Nat>, T.Two>, Unit>, Spec.ResL(), T.Two{T.Two{Unit{}, w}, Unit{}}, x)), dy, T.Two{T.Two{Unit{}, g}, Unit{}})), x) : Nat} Uses (21): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Equal.cong https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Equal.sym https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Equal.trans https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Unit https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/LAWS.bend&name=adjoint https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/PROOF.bend&name=dot_comm https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/PROOF.bend&name=dot_vadd https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=Layer.bwd https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=Layer.fwd https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=Two https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=ResL https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=bdx https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=dotn https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=fsv https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=fy https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=mtv https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=mv https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/spec.bend&name=vadd