Documentation

LeanMlir.Proofs.Nets.Small.Cifar8StepTie

The cifar8 (Chapter 4 deeper, 8-conv no-BN) TIE — tied through the real forward #

The 4-stage peer of CifarFold's tie (cifar_train_step_tied_certified). cifar8 is cifar (ch4) with four conv→conv→pool stages instead of two, so its conv backward chain is the cifar chain repeated: within each stage the second conv is the maxpool-back layer (cnnChainCotW2 for the very last, then cifarChainCotW2's cross-pool move) and the first conv is the conv-back layer (cnnChainCotW1). Every chain cotangent reuses an existing constructor (cnnChainCotW2 / cnnChainCotW1 / cifarChainCotW2) at the 4-stage dims — no new constructor, no new ops, no new bridges. The conv ties are SgdNode.convW_den/convB_den (generic in the cotangent); the dense head ties are SgdNode.denseW_den/denseB_den at the mlpCotOut0/mlpCotOut1/g cotangents, and the loss cotangent mirrors cifar.

No per-net fold file. cifar8 needs zero new core ops and zero new fold lemmas: every conv layer is the generic SgdNode.convW_den/convB_den (dim- and cotangent-generic, so they certify W₁…W₈ by instantiation), and the three dense layers are the generic SgdNode.denseW_den/ denseB_den (Foundation/SgdNodes.lean, free in activation, weight, bias and cotangent).

Spatial bookkeeping (the 2-stage (h,w) convention nested two levels deeper): final pooled (h,w); stage 4 (conv₇/conv₈) at (2h,2w); stage 3 (conv₅/conv₆) at (2(2h),2(2w)); stage 2 (conv₃/conv₄) at (2(2(2h)),…); stage 1 (conv₁/conv₂) at (2(2(2(2h))),…).

Not the trained artifact. No trainer runs cifar8_train_step.mlir; the packed cifar8w_* arms the chapter's runs use feed the same chain to *Grad nodes and a separate optimizer, tied in Cifar8TieG.cifar8_train_step_tiedG.

Scope (same as cifar) #

theorem Proofs.Cifar8Tie.cifar8_train_step_tied_certified {ic c1 c2 c3 c4 h w d1 nClasses kH kW : ℕ} (xN wN bN lrStr cotN : String) (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (W₅ : Kernel4 c3 c2 kH kW) (b₅ : Vec c3) (W₆ : Kernel4 c3 c3 kH kW) (b₆ : Vec c3) (W₇ : Kernel4 c4 c3 kH kW) (b₇ : Vec c4) (W₈ : Kernel4 c4 c4 kH kW) (b₈ : Vec c4) (W₉ : Mat (c4 * h * w) d1) (b₉ : Vec d1) (Wa : Mat d1 d1) (ba : Vec d1) (Wb : Mat d1 nClasses) (bb : Vec nClasses) (x : Tensor3 ic (2 * (2 * (2 * (2 * h)))) (2 * (2 * (2 * (2 * w))))) (label : Fin nClasses) (lr : ℝ) :
have xv := x.flatten; have cc1 := flatConv W₁ b₁ xv; have r1 := relu (c1 * (2 * (2 * (2 * (2 * h)))) * (2 * (2 * (2 * (2 * w))))) cc1; have r1t := Tensor3.unflatten r1; have cc2 := flatConv W₂ b₂ r1; have r2 := relu (c1 * (2 * (2 * (2 * (2 * h)))) * (2 * (2 * (2 * (2 * w))))) cc2; have r2t := Tensor3.unflatten r2; have zp1 := maxPoolFlat c1 (2 * (2 * (2 * h))) (2 * (2 * (2 * w))) r2; have zp1t := Tensor3.unflatten zp1; have cc3 := flatConv W₃ b₃ zp1; have r3 := relu (c2 * (2 * (2 * (2 * h))) * (2 * (2 * (2 * w)))) cc3; have r3t := Tensor3.unflatten r3; have cc4 := flatConv W₄ b₄ r3; have r4 := relu (c2 * (2 * (2 * (2 * h))) * (2 * (2 * (2 * w)))) cc4; have r4t := Tensor3.unflatten r4; have zp2 := maxPoolFlat c2 (2 * (2 * h)) (2 * (2 * w)) r4; have zp2t := Tensor3.unflatten zp2; have cc5 := flatConv W₅ b₅ zp2; have r5 := relu (c3 * (2 * (2 * h)) * (2 * (2 * w))) cc5; have r5t := Tensor3.unflatten r5; have cc6 := flatConv W₆ b₆ r5; have r6 := relu (c3 * (2 * (2 * h)) * (2 * (2 * w))) cc6; have r6t := Tensor3.unflatten r6; have zp3 := maxPoolFlat c3 (2 * h) (2 * w) r6; have zp3t := Tensor3.unflatten zp3; have cc7 := flatConv W₇ b₇ zp3; have r7 := relu (c4 * (2 * h) * (2 * w)) cc7; have r7t := Tensor3.unflatten r7; have cc8 := flatConv W₈ b₈ r7; have r8 := relu (c4 * (2 * h) * (2 * w)) cc8; have r8t := Tensor3.unflatten r8; have zp4 := maxPoolFlat c4 h w r8; have h9 := dense W₉ b₉ zp4; have ha := dense Wa ba (relu d1 h9); have g := fun (k : Fin nClasses) => softmax nClasses (cifarCnn8Forward W₁ b₁ W₂ b₂ W₃ b₃ W₄ b₄ W₅ b₅ W₆ b₆ W₇ b₇ W₈ b₈ W₉ b₉ Wa ba Wb bb xv) k - oneHot nClasses label k; have cotC8 := cnnChainCotW2 W₉ Wa Wb h9 ha r8t cc8 g; have cotC7 := cnnChainCotW1 W₈ cc7 cotC8; have cotC6 := CifarFold.cifarChainCotW2 W₇ r6t cc6 cotC7; have cotC5 := cnnChainCotW1 W₆ cc5 cotC6; have cotC4 := CifarFold.cifarChainCotW2 W₅ r4t cc4 cotC5; have cotC3 := cnnChainCotW1 W₄ cc3 cotC4; have cotC2 := CifarFold.cifarChainCotW2 W₃ r2t cc2 cotC3; have cotC1 := cnnChainCotW1 W₂ cc1 cotC2; ConvWSgdTied xN wN lrStr cotN b₁ x W₁ cotC1 lr ∧ ConvBSgdTied bN lrStr cotN W₁ x b₁ cotC1 lr ∧ ConvWSgdTied xN wN lrStr cotN b₂ r1t W₂ cotC2 lr ∧ ConvBSgdTied bN lrStr cotN W₂ r1t b₂ cotC2 lr ∧ ConvWSgdTied xN wN lrStr cotN b₃ zp1t W₃ cotC3 lr ∧ ConvBSgdTied bN lrStr cotN W₃ zp1t b₃ cotC3 lr ∧ ConvWSgdTied xN wN lrStr cotN b₄ r3t W₄ cotC4 lr ∧ ⋯ ∧ ⋯

Whole cifar8 train step, tied. All 22 parameter ops (8 conv W+b, then the dense head W₉,b₉,Wa,ba,Wb,bb), at the real cifar8 forward, denote θ − lr·(certified ∂layer/∂θ · c) with c the rendered backward-chain cotangent driven by the composed softmax-CE cotangent g (the loss-gradient form is Cifar8TieG.cifar8_net_lossGrad, see the module's Scope). Each conv op is fed the cotangent the 4-stage backward chain delivers: cnnChainCotW2 (conv₈, the last before pool₄), cnnChainCotW1 (conv₇/₅/₃/₁, the within-stage conv-back), cifarChainCotW2 (conv₆/₄/₂, the cross-pool move); the dense head is fed mlpCotOut0, mlpCotOut1 and g.