Documentation

LeanMlir.Proofs.Architectures.DepthwiseBackCertifiedTie

The depthwise adjoint gate + leaf ties #

The certified-VJP ties for the three CNNs (ConvNeXt / MobileNetV2 / EfficientNet) all reverse a depthwise convolution, so they all need the depthwise twin of the conv adjoint gate IR.convBackDenote_eq_input_grad_formula. This file builds it once.

theorem Proofs.depthwiseConv2d_dwReverse_eq_input_grad_formula {c h w kH kW : ℕ} (hkH : 2 * ((kH - 1) / 2) + 1 = kH) (hkW : 2 * ((kW - 1) / 2) + 1 = kW) (W : DepthwiseKernel c kH kW) (dy : Tensor3 c h w) :

The depthwise conv-adjoint identity (odd kernels), all dims. The emitted reversed-kernel forward depthwise conv depthwiseConv2d (dwReverse W) 0 equals the certified depthwise input-gradient depthwiseConv2dInputGradFormula W, for arbitrary c h w kH kW with odd kernels. The depthwise twin of IR.convBackDenote_eq_input_grad_formula: no Σ co (depthwise channel ch is fixed), so per output coordinate it is IR.reverseSlab_eq_gradSlab at the channel's own slabs W ch, dy ch. The leaf the depthwise certified-VJP ties (convnext/mnv2/enet) stand on.

theorem Proofs.depthwiseFlatBack_eq_vjp_backward {c h w kH kW : ℕ} (hkH : 2 * ((kH - 1) / 2) + 1 = kH) (hkW : 2 * ((kW - 1) / 2) + 1 = kW) (W : DepthwiseKernel c kH kW) (b : Vec c) (x : Vec (c * h * w)) :

Depthwise conv input-VJP leaf tie. The backward map depthwiseFlatBack W (= reversed-kernel forward depthwise conv) IS the certified depthwise input-VJP (depthwiseFlatHasVJP W b).backward x (depthwise conv is linear, so the saved activation x is ignored), for odd kernels. Routes through depthwiseConv2d_dwReverse_eq_input_grad_formula; the depthwise peer of convFlatBack_eq_vjp_backward.

theorem Proofs.depthwiseStride2FlatXlaBack_eq_vjp_backward {c h w kH kW : ℕ} (hkH : 2 * ((kH - 1) / 2) + 1 = kH) (hkW : 2 * ((kW - 1) / 2) + 1 = kW) (W : DepthwiseKernel c kH kW) (b : Vec c) (x : Vec (c * (2 * h) * (2 * w))) :

XLA-SAME strided depthwise input-VJP leaf tie. depthwiseStride2FlatXlaBack W (= depthwiseFlatBack ∘ decimateOddBack) IS the certified (depthwiseStride2FlatXlaHasVJP W b).backward x, for odd kernels. MobileNetV2's four strided depthwises and B0's downsample depthwise, at the TF-origin convention.