Backward-graph faithfulness for the VERIFIED ResNet-34 basic block #
The ResNet-34 peer of EfficientNetBackB0.lean / MobileNetV2BackB0.lean: a
backward StableHLO graph that denotes the proven VJP of the batched ResNet-34
basic block.
The basic block is relu ∘ residual(F) (identity block), with body
F = (conv-bn) ∘ (conv-bn-relu) — a 3×3 conv → bn → relu, then a 3×3 conv → bn
(no activation), and an identity skip, followed by an outer relu after the
residual add. This last fact is the structural difference from the
MobileNetV2/EfficientNet residual blocks (whose residual add is the block
output): r34 wraps the residual add in one more relu.
The relu wrinkle (vs relu6 / swish) #
r34 uses relu (one kink, at 0): its VJP is only the pointwise
relu_has_vjp_at, conditioned on the smoothness hypothesis ∀ k, x k ≠ 0 at the
pre-activation — simpler than relu6's two-sided x k ≠ 0 ∧ x k ≠ 6, but the same
_at machinery (vjp_comp_at + HasVJP.toHasVJPAt). Its per-op backward token
is .selectPos (the mask if x>0 then dy else 0), whose denotation faithfulness
is the already-proven (rfl) selectPos_faithful (StableHLO.lean:782).
Because there are TWO relu kinks (the body's mid-relu AND the outer post-residual
relu), the whole-block VJP and its backward-graph faithfulness are _at /
hypothesis-threaded: one smoothness family at the body's mid-relu pre-activation,
one at the outer relu's pre-activation residual(F)(x).
Structure #
cbReluB— batched conv → bn → relu stage (cbrBfrom MobileNetV2BackB0 with relu for relu6),_atVJP + backward-graph faithfulness (cbReluBackBatchedGraph+…_faithful), chainingselectPos_faithfulbnBatchLABack_faithful+convBackBatched_faithful.
cbB(=projB, conv → bn, no activation) backward is reused VERBATIM from EfficientNetBackB0 (projBackBatchedGraph/projBackBatchedGraph_faithful).- the body
cbB ∘ cbReluB— its backward graphr34BodyBackBatchedGraph, the two stage graphs chained at their cumulative activations, certified through the block layer. r34BasicBlockBackBatchedGraph_faithful— the CAPSTONE: the whole batched ResNet-34 identity basic block backward graph (outer-reluselectPos∘ residual-fan-in(body-back) + identity skip) denotes the provenrelu ∘ residual(F)VJP (vjp_comp_at(residual_has_vjp_at(body), relu)), threaded through both relu smoothness hypotheses.cbReluLayer/projLayer(fromMobileNetV2BackB0) /cbReluStridedLayer/projStridedLayer— the four stages asCertLayers.r34BasicBlockLayer/r34DownBlockLayercompose them withCertLayer.comp,residual/residualProjandreluOut, and each body/block VJP and capstone here is that composite's.vjp/.faithful.
The strided/downsample block (relu ∘ residualProj(proj, F_s)) #
The downsample-block capstone (r34DownBlockBackBatchedGraph_faithful) reuses the
new strided batched-conv backward primitive convStridedBackBatched
(StableHLO.lean, the stride-2 analog of convBackBatched; its _faithful lives
in EfficientNetBackB0). The body F_s = projB ∘ cbReluStridedB has a stride-2
conv1 (cbReluStridedB, the strided sibling of cbReluB) and a stride-1 conv2
(projB); the projection skip projStridedB is a stride-2 conv-bn. The whole
block composes vjp_comp_at(residualProj_has_vjp_at(proj, F_s), relu) exactly like
the identity block, but with the projection skip (residualProj, both paths
nontrivial) instead of the identity skip (residual), and the strided convs in the
body+skip.
Batched conv → bn → relu stage (ResNet basic-block first stage), at the
network layout N·(oc·h·w). The relu analogue of MobileNetV2's cbrB
(relu for relu6).
Equations
- Proofs.StableHLO.cbReluB N W b ε γ β = Proofs.relu (N * (oc * h * w)) ∘ Proofs.StableHLO.bnBatchLA N oc h w ε γ β ∘ Proofs.StableHLO.batchMap N (Proofs.flatConv W b)
Instances For
Generic relu-on-batched-bn-stage _at VJP. The relu analogue of
bnRelu6Stage_has_vjp_at (and of bnSwishStage_has_vjp, but _at — relu
only has a pointwise VJP): compose the batched-op VJP, the true-BN VJP (both
global, lifted via .toHasVJPAt), and relu's pointwise VJP at the pre-relu
activation. The smoothness hypothesis is the one-sided ≠ 0.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Differentiability of the generic relu-on-batched-bn-stage at a smooth point.
cbReluB (conv-bn-relu) _at VJP at a smooth point.
Equations
- Proofs.StableHLO.cbReluB_has_vjp_at N W b ε hε γ β x h_smooth = Proofs.StableHLO.bnReluStage_has_vjp_at N (Proofs.flatConv W b) ⋯ (Proofs.flatConv_has_vjp W b) ε hε γ β x h_smooth
Instances For
Batched conv → bn → relu stage backward graph (ResNet basic-block stage 1):
convBackBatched ∘ bnBatchLABack ∘ selectPos, each at its cumulative forward
activation. The relu analogue of MobileNetV2's cbrBackBatchedGraph —
.selectPos (the relu one-sided-kink mask) replaces .selectMid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The conv → bn → relu stage as a CertLayer, certified where its pre-relu activation misses 0.
The kernel extent is a binder, so the same layer is a 1×1 or a 3×3.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The batched ResNet-34 body backward graph: the two stage graphs chained at
their cumulative forward activations (cbReluB⁻¹ ∘ projB⁻¹).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The batched R34 identity basic block as a CertLayer: residual (cbReluLayer ; projLayer),
then reluOut. Its ok is the body's mid-relu and the OUTER post-residual relu — the extra
factor R34 has over the MBConv/inverted-residual blocks (projLayer contributes True). An
endomorphism, so chain iterates it into a stage tail.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The batched ResNet-34 identity basic block's VJP at a smooth point —
relu ∘ residual(F) with body F = projB ∘ cbReluB: the residual fan-in VJP
of the body, then the OUTER relu's pointwise VJP at the pre-relu activation
residual(F)(x) (r34BasicBlockLayer's VJP).
h_s1 is the body's mid-relu smoothness; h_out is the outer-relu smoothness
(at residual(F)(x)).
Equations
- Proofs.StableHLO.r34BasicBlockB_has_vjp_at N W₁ b₁ ε₁ hε₁ γ₁ β₁ W₂ b₂ ε₂ hε₂ γ₂ β₂ x h_s1 h_out = (Proofs.StableHLO.r34BasicBlockLayer N W₁ b₁ ε₁ hε₁ γ₁ β₁ W₂ b₂ ε₂ hε₂ γ₂ β₂).vjp x ⋯
Instances For
The whole batched ResNet-34 identity basic block backward graph:
selectPos (outer relu) ∘ residual fan-in (body backward + identity skip).
The outer relu is the LAST forward op, so its .selectPos backward is the
OUTERMOST backward op; inside, the residual addV sums the body's
input-cotangent (r34BodyBackBatchedGraph fed the relu-masked cotangent) and
the identity skip's verbatim cotangent (%dy).
Equations
- One or more equations did not get rendered due to their size.
Instances For
CAPSTONE — the whole batched ResNet-34 identity basic block: backward graph
↔ the proven VJP. The two batched stage backward graphs (cbReluB/projB)
chained at their forward activations, wrapped in the residual additive fan-in
(body cotangent + identity skip) and the OUTER post-residual relu, proven
equal to r34BasicBlockB_has_vjp_at (= vjp_comp_at(residual_has_vjp_at(F), relu)). The ResNet-34 analogue of mbResidBlockBackBatchedGraph_faithful /
mnv2ResidBlockBackBatchedGraph_faithful, with the extra outer-relu factor,
threaded through both relu smoothness hypotheses. It is r34BasicBlockLayer's
faithful.
Key fact: the outer relu's .selectPos mask is applied ONCE to the incoming
dy (giving masked = relu_has_vjp_at.backward (den ecot)), and that masked cotangent
is what the residual fan-in (r34BodyBackBatchedGraph + identity skip) sees —
exactly matching vjp_comp_at(residual, relu)'s structure: first apply relu's
backward, then residual's backward to the result.
Batched STRIDE-2 conv → bn → relu stage (downsample basic-block first
stage), at the network layout N·(oc·h·w) ← N·(ic·(2h)·(2w)). The strided
sibling of cbReluB (flatConvStride2 for flatConv); halves spatial.
Equations
- Proofs.StableHLO.cbReluStridedB N W b ε γ β = Proofs.relu (N * (oc * h * w)) ∘ Proofs.StableHLO.bnBatchLA N oc h w ε γ β ∘ Proofs.StableHLO.batchMap N (Proofs.flatConvStride2 W b)
Instances For
cbReluStridedB (strided conv-bn-relu) _at VJP at a smooth point. The strided
sibling of cbReluB_has_vjp_at (flatConvStride2 for flatConv).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Batched strided conv → bn → relu stage backward graph:
convStridedBackBatched ∘ bnBatchLABack ∘ selectPos, each at its cumulative
forward activation. The strided sibling of cbReluBackBatchedGraph —
convStridedBackBatched (the new stride-2 batched-conv VJP) replaces
convBackBatched.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The strided conv → bn → relu stage as a CertLayer — cbReluLayer with flatConvStride2.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Batched strided conv → bn projection skip (downsample basic-block skip):
bnBatchLA ∘ batchMap (flatConvStride2) — the 3×3 stride-2 projection that
matches the body's downsampled oc·h·w output. The strided sibling of projB
(flatConvStride2 for flatConv); no activation (linear bottleneck).
Equations
- Proofs.StableHLO.projStridedB N W b ε γ β = Proofs.StableHLO.bnBatchLA N oc h w ε γ β ∘ Proofs.StableHLO.batchMap N (Proofs.flatConvStride2 W b)
Instances For
Equations
- Proofs.StableHLO.projStridedB_has_vjp N W b ε hε γ β = Proofs.bnStage_has_vjp N (Proofs.flatConvStride2 W b) ⋯ (Proofs.flatConvStride2_has_vjp W b) ε hε γ β
Instances For
Batched strided conv → bn projection-skip backward graph:
convStridedBackBatched ∘ bnBatchLABack, at the skip's forward activation. The
strided sibling of projBackBatchedGraph.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The strided conv → bn projection skip as a CertLayer — projLayer with flatConvStride2,
globally certified.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The batched ResNet-34 downsample body backward graph: the two stage graphs
chained at their cumulative forward activations (cbReluStridedB⁻¹ ∘ projB⁻¹).
The strided sibling of r34BodyBackBatchedGraph.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The batched R34 downsample basic block as a CertLayer: residualProj (projStridedLayer) (cbReluStridedLayer ; projLayer), then reluOut. Halves resolution (hence the 2*h in the
input type), with a strided conv1 and a strided projection skip.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The batched ResNet-34 downsample basic block's VJP at a smooth point —
relu ∘ residualProj(proj, F_s) with body F_s = projB ∘ cbReluStridedB and
projection skip proj = projStridedB: the projected residual fan-in VJP (skip +
body), then the OUTER relu's pointwise VJP at the pre-relu activation
residualProj(proj, F_s)(x) (r34DownBlockLayer's VJP).
The strided sibling of r34BasicBlockB_has_vjp_at: residualProj (BOTH paths
nontrivial) for residual (identity skip), strided convs in body+skip.
h_s1 is the body's mid-relu smoothness; h_out is the outer-relu smoothness.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The whole batched ResNet-34 downsample basic block backward graph:
selectPos (outer relu) ∘ projected-residual fan-in (body backward +
PROJECTION skip backward). The outer relu is the LAST forward op, so its
.selectPos backward is the OUTERMOST backward op; inside, the residualProj
addV sums the projection skip's input-cotangent (projStridedBackBatchedGraph
fed the relu-masked cotangent) and the body's input-cotangent
(r34DownBodyBackBatchedGraph, same masked cotangent). Unlike the identity
block, BOTH operands are nontrivial backward subgraphs (the skip is a strided
conv-bn, not a verbatim %dy passthrough).
Equations
- One or more equations did not get rendered due to their size.
Instances For
CAPSTONE — the whole batched ResNet-34 DOWNSAMPLE basic block: backward graph
↔ the proven VJP. The two batched stage backward graphs of the body
(cbReluStridedB/projB) chained at their forward activations, wrapped in the
PROJECTED-residual additive fan-in (body cotangent + STRIDED projection-skip
cotangent) and the OUTER post-residual relu, proven equal to
r34DownBlockB_has_vjp_at (= vjp_comp_at(residualProj_has_vjp_at(proj, F_s), relu)). The strided sibling of r34BasicBlockBackBatchedGraph_faithful:
residualProj (both backward paths nontrivial) for residual (identity skip),
convStridedBackBatched in the body's conv1 and the whole projection skip. It is
r34DownBlockLayer's faithful.
Key fact: the outer relu's .selectPos mask is applied ONCE to the incoming
dy (giving masked = relu_has_vjp_at.backward (den ecot)), and that masked cotangent
is what BOTH residualProj fan-in operands see — matching
vjp_comp_at(residualProj, relu)'s structure: first relu's backward, then
residualProj's backward (= proj.backward + body.backward at the masked
cotangent).