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
reluHasVJPAt, 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 (vjpCompAt + 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) StableHLO.selectPos_faithful.
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 #
The stages are defined in Foundation, not here: cbReluB (batched conv → bn → relu, the
relu sibling of cbrB), cbReluStridedB and projStridedB, with their _at VJPs, the backward
graph cbReluBackBatchedGraph + cbReluBackBatchedGraph_faithful (chaining
selectPos_faithful + bnBatchLABack_faithful + convBackBatched_faithful), and the four
CertLayers cbReluLayer / projLayer / cbReluStridedLayer / projStridedLayer, are in
Foundation/Batched/StageLayers.lean; projB (conv → bn, no activation, the body's cbB) is in
Foundation/Batched/Stages.lean; projBackBatchedGraph / projBackBatchedGraph_faithful are in
Foundation/Batched/BackLinks.lean. This file holds the ResNet-34 assemblies:
- 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 (vjpCompAt(residualHasVJPAt(body), relu)), threaded through both relu smoothness hypotheses.r34BasicBlockLayer/r34DownBlockLayercompose the stage layers 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
strided batched-conv backward primitive convStridedBackBatched
(StableHLO.Basic, the stride-2 analog of convBackBatched; convStridedBackBatched_faithful
is in Foundation/Batched/BackLinks.lean). 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 vjpCompAt(residualProjHasVJPAt(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.
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.r34BasicBlockBHasVJPAt 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 r34BasicBlockBHasVJPAt (= vjpCompAt(residualHasVJPAt(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 = reluHasVJPAt.backward (den ecot)), and that masked cotangent
is what the residual fan-in (r34BodyBackBatchedGraph + identity skip) sees —
exactly matching vjpCompAt(residual, relu)'s structure: first apply relu's
backward, then residual's backward to the result.
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 r34BasicBlockBHasVJPAt: 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
r34DownBlockBHasVJPAt (= vjpCompAt(residualProjHasVJPAt(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 = reluHasVJPAt.backward (den ecot)), and that masked cotangent
is what BOTH residualProj fan-in operands see — matching
vjpCompAt(residualProj, relu)'s structure: first relu's backward, then
residualProj's backward (= proj.backward + body.backward at the masked
cotangent).