The CIFAR-CNN (Chapter 4, no-BN) train step, proof-tied to the certified SGD step #
The Chapter-4 peer of CnnFold — a deeper, two-spatial-scale conv net
((conv→relu)×2 → pool → (conv→relu)×2 → pool → (dense→relu)×2 → dense; 14 params:
4 conv kernels/biases + 3 dense layers). MainCifarVerified trains on
verified_mlir/cifar_train_step.mlir; this file states what its parameter updates denote: each
emitted SGD op denotes θ − lr·(certified per-layer Jacobian · the cotangent the rendered chain feeds it) (cifar_train_step_tied_certified, all fourteen); only the output weight W₇ is
tied to the whole-loss gradient (cifar_W7_tied_totalloss).
Zero new core ops. The conv layers reuse the convWeightSgd/convBiasSgd ops
added for cnn (CnnFold); the dense head reuses weightSgd/biasSgd. The
only new content is the per-net den = certified capstones below.
- Conv layers (all four):
convW_den/convB_denare generic in the conv dims and the cotangentc—den (convWeightSgd … (.operand _ c)) = θ − lr·(certified ∂conv/∂θ · c), the emitted op'sdenreduced (rfl) to the LHS of the genericcnn_render_conv{W,b}_certified. Instantiated at each conv layer's(b,x,W)and the cotangent the renderer feeds there, they certify W₁/b₁ … W₄/b₄ (one lemma each, all four layers — conv2d's weight/bias VJP is dim-generic). - Dense head (W₅/W₆/W₇): the classifier head is a 3-layer MLP over the flattened
pool output, so its cotangents are the IR
mlpCotOut0/1and itsdens close viaweight_grad_bridge/bias_grad_bridge— verbatimCnnFold(dW7_den, the op the whole-loss fold rewrites with).
Scope (same boundary as cnn/mlp/linear) #
- Below the output layer the cotangents are the rendered chain (
mlpCotOut1/mlpCotOut0in the head;cnnChainCotW1,cnnChainCotW2,cifarChainCotW2below it). The loss-gradient statement iscifar_net_lossGrad(CifarParamGrad), at the un-fused*Gradnodes these ops step by and with each pool's cotangent routed to one maximal cell, as the renderedselect_and_scatterdoes; this chain'smaxPoolBackDenoteroutes it to the first maximal cell (maxPool2Argmax), the op's own choice, so it is the capstone's chain at that selection (cifarChainCotW2_eq_sel,CnnFold.cnnChainCotW2_eq_sel). - Per-op
prettylexing + ℝ → Float32.
Dense classifier head (W₅/W₆/W₇) — weightSgd/biasSgd, mirrors CnnFold #
The head pool2 → W₅→relu→W₆→relu→W₇ is a 3-layer MLP; per-layer cotangents are the
IR mlpCotOut0/1 (with (W₇,W₆,W₅) playing the MLP's (W₂,W₁,W₀)). Every head op's
den = certified is SgdNode.denseW_den / SgdNode.denseB_den at that layer, and
cifar_train_step_tied_certified states all six at the real forward; the output-layer weight op
is stated here on its own because the whole-loss fold cifar_W7_tied_totalloss rewrites with it.
Output-layer weight op W₇ = certified step (cotangent = the loss cotangent dy).
The tie — the conv layers/dense head, tied through the REAL cifar forward #
The conv/dense *_den theorems above hold for a FREE cotangent (convW_den/convB_den are ∀ c;
the dense head's mlpCotOut0/1 are ∀ dy). The capstones below pin those cotangents to the ones the
real cifar forward + softmax-CE loss actually drives — the cifar peer of CnnFold's last
three theorems (cnnLossCot_den / cnn_W5_tied_totalloss / cnn_train_step_tied_certified).
cifar is the cnn shape with two conv→conv→pool stages instead of one, so its conv backward chain crosses an extra pool boundary. Three of the four conv-layer cotangents reuse the cnn chain cots verbatim (every one is generic in its downstream cotangent):
- W₄ (last conv before pool₂):
cnnChainCotW2 W₅ W₆ W₇ h5 h6 ac4 hc4 g— relu₄ mask on the pool₂ input-VJP of the dense-head cotangent (the cnn conv₂ pattern, at the cifar head dims). - W₃:
cnnChainCotW1 W₄ hc3 cotW4— relu₃ mask on conv₄'s input-VJP (the cnn conv₁ pattern). - W₁:
cnnChainCotW1 W₂ hc1 cotW2— relu₁ mask on conv₂'s input-VJP (same pattern).
Only W₂ needs a new constructor cifarChainCotW2: its cotangent crosses pool₁ at the relu-free
conv₃-input boundary, so it is relu₂ mask on maxpool₁-back(conv₃-back(W₃, cotW3)) — a conv input-VJP
then a maxpool input-VJP, the step cnn (one pool) never had.
Cotangent the cifar backward chain delivers at conv₂'s output (c1 ch @ 2(2h)): the relu₂
mask on maxpool₁-back(conv₃-back(W₃, cotW3)). conv₃-back (the Back3.conv input-VJP via
flatDenote) carries cotW3 from conv₃'s output to pool₁'s output (c1 @ 2h); maxpool₁-back
(the Back3.maxpool input-VJP) lifts that to conv₂'s output (c1 @ 2(2h)). ac2 is the pool₁
input (= relu₂ output), hc2 the conv₂ pre-activation (the relu₂ mask).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The emitted loss-cotangent graph denotes the composed softmax-CE gradient of the cifar forward
(= softmax(cifarCnnForward … x) − onehot = ∂CE/∂logits at the real forward logits). The cifar
peer of CnnFold.cnnLossCot_den (same proof, cifarCnnForward for the logits operand).
Dense output weight W₇, tied to the WHOLE softmax-CE loss through the cifar forward. With the
dense-head input = the real cifar forward pool₂ output and the cotangent the emitted loss graph
denotes (cifarLossCot_den), the weightSgd for W₇ denotes W₇ − lr·∂(crossEntropy ∘ forward)/∂W₇.
The cifar peer of CnnFold.cnn_W5_tied_totalloss.
Whole cifar train step, tied. All fourteen parameter ops — the dense head
W₇,b₇,W₆,b₆,W₅,b₅ and the four conv kernels/biases — at the real cifar forward and the
rendered backward-chain cotangents driven by the composed softmax-CE cotangent
g = softmax(cifarCnnForward … xv) − onehot (cifarLossCot_den), denote
θ − lr·(certified ∂layer/∂θ · c). The loss-gradient form is cifar_net_lossGrad (see the
module's Scope); at the output layer cifar_W7_tied_totalloss folds W₇ to ∂CE/∂W₇.
The dense clauses are SgdNode.denseW_den/denseB_den at g, mlpCotOut1 and mlpCotOut0;
the conv clauses are convW_den/convB_den at the cotangent the backward chain delivers:
cnnChainCotW2 for conv₄ (relu mask on pool₂-back of the dense head), cnnChainCotW1 for
conv₃/conv₁ (relu mask on the next conv's input-VJP), and cifarChainCotW2 for conv₂ (relu mask
on pool₁-back of conv₃'s input-VJP). The conv backward is rendered hand-written, so the
cotangent SSA ↔ chain-cot correspondence is the per-op trust the whole suite carries.