MobileNetV2 at batch BatchNorm — the whole net's forward and graph #
The MobileNetV2 peer of ResNet34FullB.lean. mobilenetv2ForwardBFull is the seventeen-bottleneck
net at batch BatchNorm (bnBatchLA, the proven bnBatchTensor4 at the network's left-assoc index;
reduce [0,2,3]: one mean/variance per channel across the batch, the one op that couples
examples), which is the forward MobileNetV2RenderB emits for mobilenetv2_fwd,
mobilenetv2in_fwd and the f32 train steps. mobilenetv2FwdGraphBFull is its typed graph and mobilenetv2FwdGraphBFull_faithful ties
the two.
What this file adds #
The batched relu6 stages (cbrB, dwbrB, dwbrBstrided in Batched.StageLayers, projB in
Batched.Stages), their _at VJPs and their backward-graph faithfulness are one level down, all at
bnBatchLA; MobileNetV2BackB0.lean composes them into block bodies. This file adds the
net-level ℝ forward, the net-level forward graph, and the faithfulness tying them.
The block weight records IVW / IVWNoExp come from MobileNetV2FullPaper.lean; only the
top-level bundle MNV2BWeights is declared here, generic in the class count.
Padding is XLA-SAME at all five stride-2 sites — the stem 3x3/s2 conv and the four stride-2
depthwises (b2, b4, b7, b14). These are flatConvStride2Xla / depthwiseStride2FlatXla,
not r34's symmetric flatConvStride2 peers; the two families have identical types and identical
emitted shapes, so only the certificate distinguishes them, and MobileNetV2 is the TF-origin net.
scripts/gates/convention_audit.py checks this at the artifact level.
There is no max-pool. MobileNetV2's stem is conv-BN-relu6 and downsamples once; r34's stem is
conv-BN-relu, then a 3x3/s2 pool. That is why this net needs no batchMapHasVJPAt.
Precision is a flag on the graph. Every conv and depthwise site is .convAt bf16 id … /
.convStridedXlaAt … / .depthwiseAt … / .depthwiseStridedXlaAt … (StableHLO.PrecisionSwitch,
the renderers' own switch), so one builder describes the f32 artifacts (bf16 := false) and the
bf16 ones (bf16 := true, the kinds mobilenetv2in_rmsdp64wxdols0eps0001bf16 emits); BatchNorm,
relu6, GAP and the dense carry no flag because no render switches them. The faithfulness theorems
hold at either value through Bf16Erasure (Bf16Fold.denOp_convAt_id, …: the bf16 kind at the
identity rounding is its f32 peer), so the typed graph denotes mobilenetv2ForwardBFull whichever
precision the text declares. The rounding itself is not modelled here, as it is not at f32: den
is over ℝ at both values.
Conventions this net runs at #
| depth | 17 bottlenecks, the paper [t,c,n,s] table, stem 32 to head 1280 |
| BatchNorm | batch (bnBatchLA, reduce [0,2,3], width N*h*w), 52 sites |
| activation | relu6 (TWO kinks, at 0 and at 6); 35 sites, none after a project |
| stride-2 padding | XLA-SAME at all five sites |
| stem | 3x3/s2 conv-bn-relu6, 3 to 32, 224 to 112 (NO pool) |
| head | 1x1 conv-bn-relu6 320 to 1280, then GAP and dense, generic in the class count |
| artifacts | mobilenetv2_fwd, mobilenetv2in_fwd and the train steps at either precision (bf16 selects the conv / depthwise kinds); the classifier-dropout variants mobilenetv2in_rmsdp64wxdols0* are mobilenetv2FwdGraphBFullDo below (a %do operand; at the all-ones mask this net's forward, mobilenetv2ForwardBFullDo_ones). Not this graph: the frozen-statistics evals (mobilenetv2{,in}_fwd_eval*, stated in MobileNetV2FullPaperEval) |
The head is generic in nCls, so one statement covers the 10-class Imagenette artifacts and the
1000-class mobilenetv2in ones.
N stays a variable throughout. On the data-parallel artifacts the render's N is the
per-replica batch and BatchNorm is synchronised across replicas; MobileNetV2SyncB.lean is this
file's twin for them: replica r's forward graph denotes shard r of
mobilenetv2ForwardBFull (R * N), this file's forward at the global batch.
The bias operand names are the render's default convBias := false ones — %zb{c}, the
shared zero constant each conv, depthwise and project bias is bound to once its real bias has been
folded into the BatchNorm that follows it. That is what makes the shipped parameter census 158 and
not 210. Every graph below is ∀-quantified over the bias VALUE, so it covers the
convBias := true render too; only the name would differ there.
References #
- Sandler et al. 2018, MobileNetV2: Inverted Residuals and Linear Bottlenecks. https://arxiv.org/abs/1801.04381
Every paper-spec MobileNetV2 parameter: stem (3x3/s2, 3 to 32) + the 17 bottlenecks of the
[t,c,n,s] table + the 1x1 head (320 to 1280) + the dense classifier. Generic in nCls, so
one record covers the 10-class (mobilenetv2_*) and 1000-class (mobilenetv2in_*)
artifacts.
- sW : Kernel4 32 3 3 3
- sb : Vec 32
- sε : ℝ
- sγ : Vec 32
- sβ : Vec 32
- b1 : IVWNoExp 32 16
- b2 : IVW 16 96 24
- b3 : IVW 24 144 24
- b4 : IVW 24 144 32
- b5 : IVW 32 192 32
- b6 : IVW 32 192 32
- b7 : IVW 32 192 64
- b8 : IVW 64 384 64
- b9 : IVW 64 384 64
- b10 : IVW 64 384 64
- b11 : IVW 64 384 96
- b12 : IVW 96 576 96
- b13 : IVW 96 576 96
- b14 : IVW 96 576 160
- b15 : IVW 160 960 160
- b16 : IVW 160 960 160
- b17 : IVW 160 960 320
- hW : Kernel4 1280 320 1 1
- hb : Vec 1280
- hε : ℝ
- hγ : Vec 1280
- hβ : Vec 1280
- fcW : Mat 1280 nCls
- fcb : Vec nCls
Instances For
Batched stem: 3x3/s2 XLA-SAME conv -> batch BN -> relu6. MobileNetV2 has no stem pool.
Equations
- Proofs.mnv2StemB N h w Ws bs εs γs βs = Proofs.relu6 (N * (oc * h * w)) ∘ Proofs.StableHLO.bnBatchLA N oc h w εs γs βs ∘ Proofs.StableHLO.batchMap N (Proofs.flatConvStride2Xla Ws bs)
Instances For
Batched t = 1 first bottleneck (b1): depthwise-bn-relu6 then the linear-bottleneck project.
No expand conv, no skip. The one block shape with no mnv2*BodyB lemma to delegate to.
Equations
- Proofs.mnv2NoExpB N h w p = Proofs.projB N p.pW p.pb p.pε p.pγ p.pβ ∘ Proofs.StableHLO.dwbrB N p.dW p.db p.dε p.dγ p.dβ
Instances For
Batched stride-1 inverted residual WITH the identity skip (s = 1 ∧ ic = oc). The residual
add is the block output — unlike ResNet, there is no relu after it, which is why a MobileNetV2
block carries two kink clauses and not three.
Equations
- Proofs.mnv2ResidB N h w p = Proofs.residual (Proofs.mnv2ExpOnlyB N h w p)
Instances For
Batched stride-2 downsampling bottleneck (no skip): expand at 2h x 2w, the XLA-SAME
strided depthwise halving spatial, then project at h x w.
Equations
Instances For
Batched head: 1x1 conv-bn-relu6 (ic to oc), global average pool, dense classifier.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The full batch-BN MobileNetV2 forward, N*(3*224*224) -> N*nCls, in
nested-application form, as resnet34ForwardBFull and efficientnetForwardBFull both are,
so the whole-net tie (MobileNetV2WholeBackCertifiedTieB) can peel it one block at a time.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Batched head with classifier dropout at the mask m: mnv2HeadB with dropout m on the
dense's input.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The MobileNetV2 forward with classifier dropout at the per-element mask m (the
driver's inverted mask, %do).
Equations
- One or more equations did not get rendered due to their size.
Instances For
At the all-ones mask the dropout forward is the certified forward.
Stem graph: 3x3/s2 XLA-SAME conv -> batch BN -> relu6.
Equations
- One or more equations did not get rendered due to their size.
Instances For
t = 1 bottleneck graph (b1): depthwise -> BN -> relu6 -> project 1x1 -> BN.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Stride-1 no-skip bottleneck graph (b11, b17): expand -> depthwise -> project, batch BN after each, relu6 after the first two.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Stride-1 skip bottleneck graph: the body plus the addVB identity skip, the block-input
subtree e shared between both arms as the render emits it.
Equations
- Proofs.StableHLO.mnv2ResidGraphB pfx epsStr N h w p bf16 e = (Proofs.StableHLO.mnv2ExpOnlyGraphB pfx epsStr N h w p bf16 e).addVB e
Instances For
Stride-2 downsampling bottleneck graph: expand at 2h x 2w, XLA-SAME strided depthwise,
project at h x w.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Head graph: 1x1 conv -> batch BN -> relu6 -> GAP -> dense.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The full batch-BN MobileNetV2 forward graph. Block prefixes are the render's (b1 … b17,
each parameter %b{k}{e,d,p}{W,g,bt}), so the typed graph diffs against
mobilenetv2_adam_train_step's forward half name for name. bf16 selects the conv and
depthwise kinds at every site (.convAt / .convStridedXlaAt / .depthwiseAt /
.depthwiseStridedXlaAt).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The MobileNetV2 forward graph at batch BN denotes the whole-net forward. One rw
per block over the six per-kind faithfulness lemmas.
Head graph with classifier dropout: mnv2HeadGraphB with a dropoutB on the dense's input,
its mask the input mName (the render's is doName).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The %do forward graph: mobilenetv2FwdGraphBFull with the dropout head.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The %do forward graph denotes the dropout forward, at every mask — the trunk by the same
per-block rewrites as mobilenetv2FwdGraphBFull_faithful.