Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetBackChains

The MobileNetV2 / MobileNetV4 backward chains — the ℝ maps the MobileNet ties are about #

The hand-composed reverse of the committed MobileNet forwards, as plain defs on the cotangent: the batched chains mnv2InputGradB (seventeen bottlenecks, the reverse of mobilenetv2ForwardBFull) and mnv4InputGradB (MobileNetV4-Conv-M: the fused stage, twenty-one UIB blocks and two head convs, the reverse of mobilenetv4ForwardBFull), both at a variable batch N and class count. Each chain keeps its block backwards and its BatchNorm backwards as supplied maps and spells only the endpoints, so that the certified tie (MobileNetV2WholeBackCertifiedTieB, MobileNetV4WholeBackCertifiedTieB) is a statement about a NAMED chain of the forward's shape.

Padding: MobileNetV2 is XLA-SAME at its stem (flatConvStride2XlaBack, the odd-phase scatter decimateOddBack) and its strided depthwises (depthwiseStride2FlatXlaBack), the TF-origin convention. MobileNetV4 follows timm's mobilenetv4_conv_medium and is SYMMETRIC at every strided site — its stem is ResNet's flatConvStride2Back.

Neither net has a stem pool, so every batched endpoint is StableHLO.batchMap N of a per-example leaf; none of ResNet's row-indexed batchMapAux lift is needed here.

Note: mnv4InputGradB is stated to the image, one step past the artifact: MobileNetV4's committed backward stops at the stem conv's WEIGHT gradient (no render emits a gradient into %x), so this chain runs one flatConvStride2Back past that point, as EfficientNet-B0's does at its stem.

No number is stated about either chain.

noncomputable def Proofs.mnv2InputGradB (N : ℕ) {nCls : ℕ} (Ws : Kernel4 32 3 3 3) (Wh : Kernel4 1280 320 1 1) (Wfc : Mat 1280 nCls) (bnBs : Vec (N * (32 * 112 * 112)) → Vec (N * (32 * 112 * 112))) (bnBh : Vec (N * (1280 * 7 * 7)) → Vec (N * (1280 * 7 * 7))) (b1B : Vec (N * (16 * 112 * 112)) → Vec (N * (32 * 112 * 112))) (b2B : Vec (N * (24 * 56 * 56)) → Vec (N * (16 * 112 * 112))) (b3B : Vec (N * (24 * 56 * 56)) → Vec (N * (24 * 56 * 56))) (b4B : Vec (N * (32 * 28 * 28)) → Vec (N * (24 * 56 * 56))) (b5B b6B : Vec (N * (32 * 28 * 28)) → Vec (N * (32 * 28 * 28))) (b7B : Vec (N * (64 * 14 * 14)) → Vec (N * (32 * 28 * 28))) (b8B b9B b10B : Vec (N * (64 * 14 * 14)) → Vec (N * (64 * 14 * 14))) (b11B : Vec (N * (96 * 14 * 14)) → Vec (N * (64 * 14 * 14))) (b12B b13B : Vec (N * (96 * 14 * 14)) → Vec (N * (96 * 14 * 14))) (b14B : Vec (N * (160 * 7 * 7)) → Vec (N * (96 * 14 * 14))) (b15B b16B : Vec (N * (160 * 7 * 7)) → Vec (N * (160 * 7 * 7))) (b17B : Vec (N * (320 * 7 * 7)) → Vec (N * (160 * 7 * 7))) (m_stem : Fin (N * (32 * 112 * 112)) → Prop) [DecidablePred m_stem] (m_head : Fin (N * (1280 * 7 * 7)) → Prop) [DecidablePred m_head] :
Vec (N * nCls) → Vec (N * (3 * (2 * 112) * (2 * 112)))

The batched whole-net input-gradient backward of the seventeen-bottleneck MobileNetV2 — the exact reverse of mobilenetv2ForwardBFull = head ∘ b17 ∘ … ∘ b1 ∘ stem: dense-back → GAP-back → the head's relu6 mask, BatchNorm back and 1×1 conv back → the seventeen bottleneck backwards → the stem's relu6 mask, BatchNorm back and XLA-SAME 3×3/s2 conv back. The block backwards, the two BatchNorm backs and the two relu6 masks' predicates are supplied; the conv, GAP and dense leaves are concrete and lifted over the N examples.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    noncomputable def Proofs.mnv4InputGradB (N f : ℕ) {nCls : ℕ} (Ws : Kernel4 32 3 3 3) (Wh1 : Kernel4 960 256 1 1) (Wh : Kernel4 1280 960 1 1) (Wd : Mat 1280 nCls) (bnBs : Vec (N * (32 * (16 * f) * (16 * f))) → Vec (N * (32 * (16 * f) * (16 * f)))) (bnBh1 : Vec (N * (960 * f * f)) → Vec (N * (960 * f * f))) (bnBh : Vec (N * (1280 * 1 * 1)) → Vec (N * (1280 * 1 * 1))) (fB : Vec (N * (48 * (8 * f) * (8 * f))) → Vec (N * (32 * (16 * f) * (16 * f)))) (b1B : Vec (N * (80 * (4 * f) * (4 * f))) → Vec (N * (48 * (8 * f) * (8 * f)))) (b2B : Vec (N * (80 * (4 * f) * (4 * f))) → Vec (N * (80 * (4 * f) * (4 * f)))) (b3B : Vec (N * (160 * (2 * f) * (2 * f))) → Vec (N * (80 * (4 * f) * (4 * f)))) (b4B b5B b6B b7B b8B b9B b10B : Vec (N * (160 * (2 * f) * (2 * f))) → Vec (N * (160 * (2 * f) * (2 * f)))) (b11B : Vec (N * (256 * f * f)) → Vec (N * (160 * (2 * f) * (2 * f)))) (b12B b13B b14B b15B b16B b17B b18B b19B b20B b21B : Vec (N * (256 * f * f)) → Vec (N * (256 * f * f))) (m_stem : Fin (N * (32 * (16 * f) * (16 * f))) → Prop) [DecidablePred m_stem] (m_h1 : Fin (N * (960 * f * f)) → Prop) [DecidablePred m_h1] (m_h : Fin (N * (1280 * 1 * 1)) → Prop) [DecidablePred m_h] :
    Vec (N * nCls) → Vec (N * (3 * (2 * (16 * f)) * (2 * (16 * f))))

    The batched whole-net input-gradient backward of MobileNetV4-Conv-M — the exact reverse of mobilenetv4ForwardBFull (timm's mobilenetv4_conv_medium): dense-back, relabelled to [N, 1280, 1, 1] → conv_head's relu mask, BatchNorm back and 1×1 conv back at 1×1 → relabelled to [N, 960], GAP-back → the first head conv's relu mask, BatchNorm back and 1×1 conv back at 7×7 → the twenty-one UIB block backwards → the fused stage's → the stem's relu mask, BatchNorm back and symmetric 3×3/s2 conv back.

    The fused stage's and the twenty-one blocks' backwards are supplied, as are the three BatchNorm backs and the three relu masks' predicates; the conv, GAP, relabel and dense leaves are concrete and lifted over the N examples. The two relabellings are the head's [N, c] ↔ [N, c, 1, 1] (castIdx in the graph, no text in the render).

    f is the final feature side — the render's own knob (mobilenetv4AdamTrainStepText's f): 7 at the 224 input, 8 at the paper tier's 256 (mnv4in256), the other sides its multiples (stem 16f, fused 8f, then 4f, 2f, f; the input 2·16f). Added 2026-10-12 so the whole-net tie covers both renders; every earlier statement is the instance f := 7, and 16 * 7 IS 112 to the kernel.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For