Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetV2BackB0

Backward-graph faithfulness for the batched MobileNetV2 inverted-residual block #

The MobileNetV2 peer of EfficientNetBackB0.lean: a backward StableHLO graph that denotes the proven VJP of the batched MobileNetV2 inverted-residual block — project ∘ depthwise-bn-relu6 ∘ expand-bn-relu6 with the linear-bottleneck skip.

The block is the EfficientNet MBConv body minus the squeeze-excite stage, with relu6 in place of swish and the same linear-bottleneck projB (1×1 conv → bn, no activation). The stages come from Batched.StageLayers (cbrB, dwbrB, dwbrBstrided and their CertLayers cbrLayer, dwbrLayer, dwbrStridedLayer, projLayer) and Batched.Stages (projB); the residual fan-in's backward graph is residualBackGraph (Batched.BackLinks). The project stage and the fan-in need no smoothness hypothesis.

The relu6 wrinkle #

Unlike swish (smooth everywhere, GLOBAL swishHasVJP), relu6 has a TWO-SIDED kink (at 0 and at 6), so its VJP is only the pointwise relu6HasVJPAt, conditioned on the smoothness hypothesis ∀ k, x k ≠ 0 ∧ x k ≠ 6 at the pre-activation. Its per-op backward token is .selectMid (the mask if 0<x<6 then dy else 0), whose denotation faithfulness is the already-proven (rfl) StableHLO.selectMid_faithful.

Because relu6's VJP is _at, the whole MobileNetV2 stage/body VJP and its backward- graph faithfulness are stated in the _at / hypothesis-threaded form (via vjpCompAt, lifting the global bnBatchLA/batchMap/conv/depthwise VJPs through HasVJP.toHasVJPAt), NOT the EfficientNet global form. The relu6 smoothness hypothesis at the pre-relu6 activation bnBatchLA(…)(batchMap(conv)(x)) is threaded through; the bn/conv/depthwise pieces stay activation-independent (linear) or global.

Structure #

noncomputable def Proofs.StableHLO.mnv2BodyLayer (N : ℕ) {ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) :
CertLayer (N * (ic * h * w)) (N * (oc * h * w))

The SE-less body as a CertLayer: cbrLayer ; dwbrLayer ; projLayer, left-nested so its fwd is projB ∘ (dwbrB ∘ cbrB), the association the stated types use. Its ok is the expand and depthwise relu6 clauses; projLayer contributes True.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    noncomputable def Proofs.StableHLO.mnv2BodyBHasVJPAt (N : ℕ) {ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (x : Vec (N * (ic * h * w))) (h_se : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
    HasVJPAt (projB N Wp bp εp γp βp ∘ dwbrB N Wd bd εd γd βd ∘ cbrB N We be εe γe βe) x

    The batched MobileNetV2 inverted-residual body's VJP at a smooth point — projB ∘ dwbrB ∘ cbrB (the EfficientNet MBConv body MINUS seB, with relu6 for swish), mnv2BodyLayer's VJP.

    h_se is the expand relu6 smoothness (at the cbrB pre-relu6 activation); h_sd is the depthwise relu6 smoothness (at the dwbrB pre-relu6 activation, fed the cbrB output).

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.mnv2BodyB_differentiableAt (N : ℕ) {ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (x : Vec (N * (ic * h * w))) (h_se : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
      DifferentiableAt ℝ (projB N Wp bp εp γp βp ∘ dwbrB N Wd bd εd γd βd ∘ cbrB N We be εe γe βe) x
      noncomputable def Proofs.StableHLO.mnv2BodyBackBatchedGraph {N ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (γp βp : Vec oc) (x : Vec (N * (ic * h * w))) (e : SHlo (N * (oc * h * w))) :
      SHlo (N * (ic * h * w))

      The batched MobileNetV2 body backward graph: the three stage graphs chained at their cumulative forward activations (cbrB⁻¹ ∘ dwbrB⁻¹ ∘ projB⁻¹).

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Proofs.StableHLO.mnv2BodyBackBatchedGraph_faithful {N ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (x : Vec (N * (ic * h * w))) (e : SHlo (N * (oc * h * w))) (h_se : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
        den (mnv2BodyBackBatchedGraph We be εe γe βe Wd bd εd γd βd Wp bp εp γp βp x e) = (mnv2BodyBHasVJPAt N We be εe hεe γe βe Wd bd εd hεd γd βd Wp bp εp hεp γp βp x h_se h_sd).backward (den e)
        noncomputable def Proofs.StableHLO.mnv2DownBodyLayer (N : ℕ) {ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) :
        CertLayer (N * (ic * (2 * h) * (2 * w))) (N * (oc * h * w))

        The downsample body as a CertLayer: cbrLayer at 2h × 2w, then dwbrStridedLayer and projLayer at h × w.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          noncomputable def Proofs.StableHLO.mnv2DownBodyBHasVJPAt (N : ℕ) {ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (h_se : ∀ (k : Fin (N * (mid * (2 * h) * (2 * w)))), bnBatchLA N mid (2 * h) (2 * w) εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid (2 * h) (2 * w) εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseStride2FlatXla Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseStride2FlatXla Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
          HasVJPAt (projB N Wp bp εp γp βp ∘ dwbrBstrided N Wd bd εd γd βd ∘ cbrB N We be εe γe βe) x

          The batched MobileNetV2 DOWNSAMPLE inverted-residual body's VJP at a smooth point — projB ∘ dwbrBstrided ∘ cbrB, the stride-2 analogue of mnv2BodyBHasVJPAt (swaps the stride-1 dwbrB depthwise stage for the STRIDED dwbrBstrided). The expand cbrB runs at the larger 2h×2w (1×1 conv keeps spatial), the strided depthwise then halves spatial to h×w; project runs at h×w. NO residual (spatial/channels change), so this is the body alone: mnv2DownBodyLayer's VJP.

          h_se is the expand relu6 smoothness (at the cbrB pre-relu6 activation, at 2h×2w); h_sd is the strided-depthwise relu6 smoothness (at the dwbrBstrided pre-relu6 activation, fed the cbrB output).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Proofs.StableHLO.mnv2DownBodyB_differentiableAt (N : ℕ) {ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (h_se : ∀ (k : Fin (N * (mid * (2 * h) * (2 * w)))), bnBatchLA N mid (2 * h) (2 * w) εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid (2 * h) (2 * w) εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseStride2FlatXla Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseStride2FlatXla Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
            DifferentiableAt ℝ (projB N Wp bp εp γp βp ∘ dwbrBstrided N Wd bd εd γd βd ∘ cbrB N We be εe γe βe) x
            noncomputable def Proofs.StableHLO.mnv2DownBodyBackBatchedGraph {N ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (γp βp : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (e : SHlo (N * (oc * h * w))) :
            SHlo (N * (ic * (2 * h) * (2 * w)))

            The batched MobileNetV2 downsample body backward graph: the three stage graphs chained at their cumulative forward activations (cbrB⁻¹ ∘ dwbrBstrided⁻¹ ∘ projB⁻¹). Stride-2 analogue of mnv2BodyBackBatchedGraph (strided depthwise stage graph, no residual).

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Proofs.StableHLO.mnv2DownBodyBackBatchedGraph_faithful {N ic mid oc h w kHd kWd : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (e : SHlo (N * (oc * h * w))) (h_se : ∀ (k : Fin (N * (mid * (2 * h) * (2 * w)))), bnBatchLA N mid (2 * h) (2 * w) εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid (2 * h) (2 * w) εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseStride2FlatXla Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseStride2FlatXla Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
              den (mnv2DownBodyBackBatchedGraph We be εe γe βe Wd bd εd γd βd Wp bp εp γp βp x e) = (mnv2DownBodyBHasVJPAt N We be εe hεe γe βe Wd bd εd hεd γd βd Wp bp εp hεp γp βp x h_se h_sd).backward (den e)

              CAPSTONE — the batched MobileNetV2 DOWNSAMPLE inverted-residual body: backward graph ↔ the proven mnv2DownBodyBHasVJPAt. The three batched stage backward graphs (cbrB/dwbrBstrided/projB) chained at their forward activations, proven equal to the downsample-body VJP. The stride-2 analogue of mnv2BodyBackBatchedGraph_faithful (no residual skip — the downsample block changes spatial/channels, so the body alone is the block), threaded through the two relu6 smoothness hypotheses (relu6's VJP is only _at). The MobileNetV2 relu6 peer of the EfficientNet mbDownBodyBackBatchedGraph_faithful; it is mnv2DownBodyLayer's faithful.

              noncomputable def Proofs.StableHLO.mnv2ResidBlockBackBatchedGraph {N c mid h w kHd kWd : ℕ} (We : Kernel4 mid c 1 1) (be : Vec mid) (εe : ℝ) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (γd βd : Vec mid) (Wp : Kernel4 c mid 1 1) (bp : Vec c) (εp : ℝ) (γp βp : Vec c) (x : Vec (N * (c * h * w))) (ecot : SHlo (N * (c * h * w))) :
              SHlo (N * (c * h * w))

              The whole batched MobileNetV2 inverted-residual block backward graph (body + identity skip).

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem Proofs.StableHLO.mnv2ResidBlockBackBatchedGraph_faithful {N c mid h w kHd kWd : ℕ} (We : Kernel4 mid c 1 1) (be : Vec mid) (εe : ℝ) (hεe : 0 < εe) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (hεd : 0 < εd) (γd βd : Vec mid) (Wp : Kernel4 c mid 1 1) (bp : Vec c) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec c) (x : Vec (N * (c * h * w))) (ecot : SHlo (N * (c * h * w))) (h_se : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 0 ∧ bnBatchLA N mid h w εe γe βe (batchMap N (flatConv We be) x) k ≠ 6) (h_sd : ∀ (k : Fin (N * (mid * h * w))), bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 0 ∧ bnBatchLA N mid h w εd γd βd (batchMap N (depthwiseFlat Wd bd) (cbrB N We be εe γe βe x)) k ≠ 6) :
                den (mnv2ResidBlockBackBatchedGraph We be εe γe βe Wd bd εd γd βd Wp bp εp γp βp x ecot) = (residualHasVJPAt (projB N Wp bp εp γp βp ∘ dwbrB N Wd bd εd γd βd ∘ cbrB N We be εe γe βe) x ⋯ (mnv2BodyBHasVJPAt N We be εe hεe γe βe Wd bd εd hεd γd βd Wp bp εp hεp γp βp x h_se h_sd)).backward (den ecot)

                CAPSTONE — the whole batched MobileNetV2 inverted-residual block: backward graph ↔ the proven VJP. The three batched stage backward graphs (cbrB/dwbrB/projB) chained at their forward activations + the identity skip, proven equal to residualHasVJPAt of the SE-less body projB ∘ dwbrB ∘ cbrB. The MobileNetV2 analogue of the EfficientNet mbResidBlockBackBatchedGraph_faithful, without the seB factor, threaded through the relu6 smoothness hypotheses (relu6's VJP is only _at).

                It is CertLayer.residual mnv2BodyLayer's faithful: the residual fan-in backward (body cotangent + the identity skip's verbatim %dy).