TorchLean API

NN.Proofs.Gradients.Linear

Spec-level gradient identities for the linear layer #

This file records the tensor formulas used by the derivative specification of a linear layer:

y = W x + b

namely:

These are normalization lemmas for TorchLean's derivative specification. They do not prove that a runtime backward pass is the Fréchet derivative of the forward pass; those results live under NN.Proofs.Autograd.

PyTorch correspondence / citations #

References #

Spec identity: weight gradient for a linear layer.

For y = W x + b, if δ = ∂L/∂y then the weight gradient is

∂L/∂W = δ ⊗ x.

For a batch, PyTorch evaluates the corresponding formula as a matrix multiplication against the input batch.

Spec identity: input gradient for a linear layer.

For y = W x + b, the input gradient is

∂L/∂x = Wᵀ δ.

theorem Proofs.linearBackwardSpec_biasGradient {inDim outDim : ℕ} (layer : Spec.LinearSpec ℝ inDim outDim) (x : TorchLean.Tensor ℝ [inDim]) (δ : TorchLean.Tensor ℝ [outDim]) :

The complete linear backward result passes the bias cotangent through unchanged.

For y = W x + b, the bias gradient is ∂L/∂b = δ.