Documentation

LeanMlir.Proofs.Nets.Small.CnnChainClose

Upgrading the CNN conv close from a generic cotangent to the actual backward chain #

cnn_render_conv{W,b}_certified (CnnTrainStep.lean) certify each conv parameter output for any cotangent c at that conv layer's output. This file pins c to the cotangent the CNN backward chain actually delivers — the conv analogue of the MLP's mlpCotOut0/1.

The chain, from the loss cotangent dy at the logits, all in flattened Vec space:

The relu masks sit between the maxpool and conv Back3 nodes, so the cotangent is a flat-level composition of the rendered backward denotations (not a single Back3 graph) — but the maxpool/conv steps are exactly the Back3 subgraphs flatDenote denotes. Instantiating the generic conv bridges at these cotangents gives: each conv θ output denotes θ − lr·(certified ∂conv/∂θ · the-actual-chain-cotangent). (This pins the cotangent — the further "= ∂loss/∂θ" fold is the separate pdiv G = Back.denote step, as in the MLP mlp_*_total_loss_grad.) See planning/archive/render_close_handoff.md §1 "Optional polish".

def Proofs.cnnDenseHeadCot {c h w d1 nClasses : } (W₃ : Mat (c * h * w) d1) (W₄ : Mat d1 d1) (W₅ : Mat d1 nClasses) (h3 h4 : Vec d1) :
IR.Back nClasses (c * h * w)

Dense-head backward subgraphdy at the logits to the cotangent at the flattened pool output: W₃·(relu'(h3)⊙(W₄·(relu'(h4)⊙(W₅·dy)))). The flat Back chain of the CNN's classifier head (3 dense + 2 relu); the 3-layer analogue of mlpCotOut0.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    noncomputable def Proofs.cnnChainCotW2 {c h w d1 nClasses : } (W₃ : Mat (c * h * w) d1) (W₄ : Mat d1 d1) (W₅ : Mat d1 nClasses) (h3 h4 : Vec d1) (ac2 : Tensor3 c (2 * h) (2 * w)) (hc2 : Vec (c * (2 * h) * (2 * w))) (dy : Vec nClasses) :
    Vec (c * (2 * h) * (2 * w))

    The cotangent the backward chain delivers at conv2's output (W₂'s layer): relu'(hc2) ⊙ maxpool-back(dense-head-cot dy). The maxpool step is the Back3 maxpool node through flatDenote (crossing the flatten/pool boundary); the relu-back is the rendered selMask4 mask.

    Equations
    Instances For
      noncomputable def Proofs.cnnChainCotW1 {c h w kH kW : } (W₂ : Kernel4 c c kH kW) (hc1 cotW2 : Vec (c * (2 * h) * (2 * w))) :
      Vec (c * (2 * h) * (2 * w))

      The cotangent the backward chain delivers at conv1's output (W₁'s layer): relu'(hc1) ⊙ conv2-back(W₂, conv2-cotangent). The conv2-back step is the Back3 conv node through flatDenote; the relu-back is the rendered selMask4 mask. Builds on cnnChainCotW2 exactly as mlpCotOut0 prepends one more relu-back ∘ dense-back to mlpCotOut1.

      Equations
      Instances For
        theorem Proofs.cnnChainCotW1_eq {c h w kH kW : } (W₂ : Kernel4 c c kH kW) (hc1 cotW2 : Vec (c * (2 * h) * (2 * w))) :
        cnnChainCotW1 W₂ hc1 cotW2 = fun (i : Fin (c * (2 * h) * (2 * w))) => if hc1 i > 0 then (IR.convBackDenote W₂ (Tensor3.unflatten cotW2)).flatten i else 0

        The conv1-output cotangent equals the explicit rendered backward form relu'(hc1) ⊙ flatten(convBackDenote W₂ (unflatten cotW2)) — i.e. the relu mask applied to the reversed-kernel conv backward the renderer emits (selMask4 ∘ convBack).

        theorem Proofs.cnnChainCotW2_eq {c h w d1 nClasses : } (W₃ : Mat (c * h * w) d1) (W₄ : Mat d1 d1) (W₅ : Mat d1 nClasses) (h3 h4 : Vec d1) (ac2 : Tensor3 c (2 * h) (2 * w)) (hc2 : Vec (c * (2 * h) * (2 * w))) (dy : Vec nClasses) :
        cnnChainCotW2 W₃ W₄ W₅ h3 h4 ac2 hc2 dy = fun (i : Fin (c * (2 * h) * (2 * w))) => if hc2 i > 0 then (IR.maxPoolBackDenote ac2 (Tensor3.unflatten ((cnnDenseHeadCot W₃ W₄ W₅ h3 h4).denote dy))).flatten i else 0

        The conv2-output cotangent equals the explicit rendered backward form relu'(hc2) ⊙ flatten(maxPoolBackDenote ac2 (unflatten (dense-head-cot dy))) — the relu mask applied to the select_and_scatter maxpool backward the renderer emits.

        theorem Proofs.cnn_render_convW2_chain_certified {c h w d1 nClasses kH kW : } (b₂ : Vec c) (ac1 : Tensor3 c (2 * h) (2 * w)) (W₃ : Mat (c * h * w) d1) (W₄ : Mat d1 d1) (W₅ : Mat d1 nClasses) (h3 h4 : Vec d1) (ac2 : Tensor3 c (2 * h) (2 * w)) (hc2 : Vec (c * (2 * h) * (2 * w))) (dy : Vec nClasses) (v : Vec (c * c * kH * kW)) (lr : ) (idx : Fin (c * c * kH * kW)) :
        v idx - lr * (conv2d_weight_grad_has_vjp b₂ ac1).backward v (cnnChainCotW2 W₃ W₄ W₅ h3 h4 ac2 hc2 dy) idx = v idx - lr * j : Fin (c * (2 * h) * (2 * w)), pdiv (fun (v' : Vec (c * c * kH * kW)) => (conv2d (Kernel4.unflatten v') b₂ ac1).flatten) v idx j * cnnChainCotW2 W₃ W₄ W₅ h3 h4 ac2 hc2 dy j

        Conv-2 weight output, chain-certified. W₂ⁿ = W₂ − lr·(transpose-trick kernel grad) denotes W₂ − lr·(certified ∂conv2/∂W₂ · the cotangent the chain delivers at conv2) — the generic cnn_render_convW_certified instantiated at cnnChainCotW2.

        theorem Proofs.cnn_render_convb2_chain_certified {c h w d1 nClasses kH kW : } (W₂ : Kernel4 c c kH kW) (b₂ : Vec c) (ac1 : Tensor3 c (2 * h) (2 * w)) (W₃ : Mat (c * h * w) d1) (W₄ : Mat d1 d1) (W₅ : Mat d1 nClasses) (h3 h4 : Vec d1) (ac2 : Tensor3 c (2 * h) (2 * w)) (hc2 : Vec (c * (2 * h) * (2 * w))) (dy : Vec nClasses) (lr : ) (o : Fin c) :
        b₂ o - lr * (conv2d_bias_grad_has_vjp W₂ ac1).backward b₂ (cnnChainCotW2 W₃ W₄ W₅ h3 h4 ac2 hc2 dy) o = b₂ o - lr * j : Fin (c * (2 * h) * (2 * w)), pdiv (fun (b' : Vec c) => (conv2d W₂ b' ac1).flatten) b₂ o j * cnnChainCotW2 W₃ W₄ W₅ h3 h4 ac2 hc2 dy j

        Conv-2 bias output, chain-certified.

        theorem Proofs.cnn_render_convW1_chain_certified {ic c h w kH kW : } (b₁ : Vec c) (x : Tensor3 ic (2 * h) (2 * w)) (hc1 cotW2 : Vec (c * (2 * h) * (2 * w))) (W₂ : Kernel4 c c kH kW) (v : Vec (c * ic * kH * kW)) (lr : ) (idx : Fin (c * ic * kH * kW)) :
        v idx - lr * (conv2d_weight_grad_has_vjp b₁ x).backward v (cnnChainCotW1 W₂ hc1 cotW2) idx = v idx - lr * j : Fin (c * (2 * h) * (2 * w)), pdiv (fun (v' : Vec (c * ic * kH * kW)) => (conv2d (Kernel4.unflatten v') b₁ x).flatten) v idx j * cnnChainCotW1 W₂ hc1 cotW2 j

        Conv-1 weight output, chain-certified. W₁ⁿ denotes W₁ − lr·(certified ∂conv1/∂W₁ · the deepest chain cotangent) — the generic bridge at cnnChainCotW1 (which crosses one more conv-back than cnnChainCotW2, the Back3 chain step).

        theorem Proofs.cnn_render_convb1_chain_certified {ic c h w kH kW : } (W₁ : Kernel4 c ic kH kW) (b₁ : Vec c) (x : Tensor3 ic (2 * h) (2 * w)) (hc1 cotW2 : Vec (c * (2 * h) * (2 * w))) (W₂ : Kernel4 c c kH kW) (lr : ) (o : Fin c) :
        b₁ o - lr * (conv2d_bias_grad_has_vjp W₁ x).backward b₁ (cnnChainCotW1 W₂ hc1 cotW2) o = b₁ o - lr * j : Fin (c * (2 * h) * (2 * w)), pdiv (fun (b' : Vec c) => (conv2d W₁ b' x).flatten) b₁ o j * cnnChainCotW1 W₂ hc1 cotW2 j

        Conv-1 bias output, chain-certified.

        Clause Props for the per-example conv ties #

        Each is a conv _den lemma's statement (CifarPoC.convW_den / convB_den, CnnPoC.cW2_den …) under , so a tie theorem states one line per parameter tensor and intro unfolds it back. The batched peers are ResNet34PoCB.ConvWTiedB and EnetPoC.ConvWSgdTiedB.

        def Proofs.ConvWSgdTied {ic oc h w kH kW : } (xN wN lrStr cotN : String) (b : Vec oc) (x : Tensor3 ic h w) (W : Kernel4 oc ic kH kW) (c : Vec (oc * h * w)) (lr : ) :

        The emitted convWeightSgd op, fed the cotangent c at the conv output, is the certified SGD step on the kernel W.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Proofs.ConvBSgdTied {ic oc h w kH kW : } (bN lrStr cotN : String) (W : Kernel4 oc ic kH kW) (x : Tensor3 ic h w) (b : Vec oc) (c : Vec (oc * h * w)) (lr : ) :

          The emitted convBiasSgd op, fed the cotangent c at the conv output, is the certified SGD step on the bias b.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For