Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetV4FullBSeal

MobileNetV4-Conv-M's non-degeneracy seal, on the full-width batched net (levels 2 and 3) #

planning/full_width_seals.md §4.4, the last of four. MobileNetV4FullBVJP.lean proves mobilenetv4ForwardB_full_has_vjp_at: the whole-net VJP at any (w, x) satisfying eight clause bundles — the stem's relu, the fused stage's (vacuous), one per resolution group and the head's, 54 relu sites in all (the #guard below counts them off the block table). That statement is pointwise, so it could in principle be vacuous. This file exhibits a (w, x) that discharges every clause with genuinely nonzero weights, shows the forward is not constant there, and seals the Jacobian nonzero — hence, through Training/JacobianSeal.lean, the proven backward is not the zero map at that point. MobileNetV4 had no witness at any depth before this; with it, every kinked net in the book is sealed on the forward its artifacts run.

⭐⭐ All 54 clauses are weight-only — and generic in the table row #

Every kink in this net is a relu sitting directly on a bnBatchLA output, in four spellings (Mnv4StemSmoothAtB, cbReluLayer.ok, mnv4DWReluLayer.ok, mnv4DWReluStridedLayer.ok); projLayer.ok, mnv4FusedConvLayer.ok and CertLayer.id'.ok are True. bnBatchLA_pos bounds a BatchNorm output above β − |γ|√(N·h·w) > 0 at EVERY input, so with γ = 1, β = 160, ε = 1 the whole bundle is discharged without the activation ever being read. ⭐ Better still, the discharge is proved generically in the UibSpec row (sealUib_ok, sealUibStrided_ok): the k = 0 depthwise slots contribute True and the rest are the same BatchNorm fact, so 21 blocks cost two lemmas.

⭐⭐ The swish is the one thing that is not MobileNetV2 again #

planning/full_width_seals.md §4.4 called the clause bundle the package's remaining uncertainty and the CertLayer peel its real work. Both turned out cheap — CertLayer.comp_fwd_apply and the group *_fwd_apply lemmas in MobileNetV4FullB.lean already peel at variables. What was missed is the fused stage's swish, and it changes the witness:

The readout along the ray is therefore swishGap 160 (uF t 0) · Rr t, not t · Rr t, and the seal closes with hasDerivAt_mul_of_zero rather than hasDerivAt_mul_self_zero. ⚠ No BatchNorm variance derivative is taken anywhere: the two pre-swish factors enter through t · Q0 t and the fifteen after it through a continuous Rr; the swish's slope at β is the one honest derivative in the chain, and it is positive for every β ≥ 0.

The carrier threads seventeen BatchNorms #

The stem's, the fused stage's two, four in each of rows 1, 3 and 11 — the only rows that change channels, hence the only ones without a skip — and the head's two. ⛔ Counted from the net, not from prose: the other eighteen rows are CertLayer.residual, so the carrier goes round their bodies. With the project BatchNorm's β = 0 a zeroed body is the constant 0, so those rows are the EXACT identity and two of the seven groups collapse to nothing at all.

⚠⚠ Every collapse, every clause bundle and every block lemma here is proved at variable shapes and instantiated at the witness's numerals afterwards, never proved at them (planning/full_width_seals.md §3.5). ⚠ And a lemma whose spatial dims are only reachable through a Vec (… (2*h) …) argument needs them passed explicitly — 2 * ?h =?= 56 is nonlinear, and BUnif_convS2 without (h := 56) (w := 56) is a maxHeartbeats timeout in isDefEq.

noncomputable def Proofs.Mnv4FullBSeal.sealP (s : StableHLO.UibSpec) (Wq : DepthwiseKernel s.ic s.preDWk s.preDWk) (We : Kernel4 (s.ic * s.expand) s.ic 1 1) (Wd : DepthwiseKernel (s.ic * s.expand) s.postDWk s.postDWk) (Wz : Kernel4 s.oc (s.ic * s.expand) 1 1) :
Equations
  • One or more equations did not get rendered due to their size.
Instances For

    a carrier row: every kernel a centre tap.

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

      a skipped row: every kernel zero, so the body is the constant 0.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        noncomputable def Proofs.Mnv4FullBSeal.sealW (nCls : ) :
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[reducible, inline]
          abbrev Proofs.Mnv4FullBSeal.Mg (N h w : ) :
          Equations
          Instances For
            theorem Proofs.Mnv4FullBSeal.bpos (N oc h w : ) (hm : Mg N h w) (v : Vec (N * (oc * h * w))) (k : Fin (N * (oc * h * w))) :
            0 < StableHLO.bnBatchLA N oc h w 1 (BatchSeal.kv oc 1) (BatchSeal.kv oc 160) v k
            theorem Proofs.Mnv4FullBSeal.bne (N oc h w : ) (hm : Mg N h w) (v : Vec (N * (oc * h * w))) (k : Fin (N * (oc * h * w))) :
            StableHLO.bnBatchLA N oc h w 1 (BatchSeal.kv oc 1) (BatchSeal.kv oc 160) v k 0
            theorem Proofs.Mnv4FullBSeal.cbReluB_eq {N ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (hm : Mg N h w) (x : Vec (N * (ic * h * w))) :
            theorem Proofs.Mnv4FullBSeal.dwbReluB_eq {N c h w kH kW : } (W : DepthwiseKernel c kH kW) (b : Vec c) (hm : Mg N h w) (x : Vec (N * (c * h * w))) :
            theorem Proofs.Mnv4FullBSeal.dwbReluBstrided_eq {N c h w kH kW : } (W : DepthwiseKernel c kH kW) (b : Vec c) (hm : Mg N h w) (x : Vec (N * (c * (2 * h) * (2 * w)))) :
            theorem Proofs.Mnv4FullBSeal.mnv4StemB_eq {N h w ic oc kH kW : } (Ws : Kernel4 oc ic kH kW) (bs : Vec oc) (hm : Mg N h w) (x : Vec (N * (ic * (2 * h) * (2 * w)))) :
            theorem Proofs.Mnv4FullBSeal.sealZBody_eq (N : ) (s : StableHLO.UibSpec) (hn : 0 < N * (s.h * s.h)) (v : Vec (N * (s.ic * s.h * s.h))) :
            (StableHLO.mnv4BodyOfRow N s (sealZ s)).fwd v = fun (x : Fin (N * (s.oc * s.h * s.h))) => 0

            A zeroed UIB body is the constant 0, whatever its slots are. The project conv's kernel is zero, so projB_zero_const closes the block without any stage inside it being analysed — the k = 0 dispatch never has to be read.

            theorem Proofs.Mnv4FullBSeal.resid_id {n : } (L : StableHLO.CertLayer n n) (v : Vec n) (hL : L.fwd v = fun (x : Fin n) => 0) :
            L.residual.fwd v = v

            and so a skipped row is the exact IDENTITY, not ResNet's a ↦ a + 1.

            A carrier row (all three are pre-strided ExtraDW) collapses to four BatchNorms.

            theorem Proofs.Mnv4FullBSeal.comp_ok {m n p : } (L₁ : StableHLO.CertLayer m n) (L₂ : StableHLO.CertLayer n p) (v : Vec m) (h₁ : L₁.ok v) (h₂ : L₂.ok (L₁.fwd v)) :
            (L₁.comp L₂).ok v
            theorem Proofs.Mnv4FullBSeal.sealUib_ok (N : ) (s : StableHLO.UibSpec) (hm : Mg N s.h s.h) (Wq : DepthwiseKernel s.ic s.preDWk s.preDWk) (We : Kernel4 (s.ic * s.expand) s.ic 1 1) (Wd : DepthwiseKernel (s.ic * s.expand) s.postDWk s.postDWk) (Wz : Kernel4 s.oc (s.ic * s.expand) 1 1) (x : Vec (N * (s.ic * s.h * s.h))) :
            (StableHLO.mnv4BodyOfRow N s (sealP s Wq We Wd Wz)).ok x

            Every clause of a UIB body, at every input. The k = 0 slots contribute True and the rest are relus on BatchNorm outputs, so the discharge never looks at the activation and holds for the centre-tap rows and the zeroed rows alike.

            theorem Proofs.Mnv4FullBSeal.sealUibStrided_ok (N : ) (s : StableHLO.UibSpec) (hm : Mg N s.h s.h) (Wq : DepthwiseKernel s.ic s.preDWk s.preDWk) (We : Kernel4 (s.ic * s.expand) s.ic 1 1) (Wd : DepthwiseKernel (s.ic * s.expand) s.postDWk s.postDWk) (Wz : Kernel4 s.oc (s.ic * s.expand) 1 1) (x : Vec (N * (s.ic * (2 * s.h) * (2 * s.h)))) :

            the pre-strided peer: the leading depthwise carries the stride, so it is not a slot.

            noncomputable def Proofs.Mnv4FullBSeal.sealV :
            Vec (2 * (3 * (2 * 112) * (2 * 112)))
            Equations
            Instances For
              noncomputable def Proofs.Mnv4FullBSeal.sealX (t : ) :
              Vec (2 * (3 * (2 * 112) * (2 * 112)))
              Equations
              Instances For
                theorem Proofs.Mnv4FullBSeal.BUnif_sealX (t : ) :
                BatchSeal.BUnif (fun (n : Fin 2) (ci : Fin 3) => if n = 0 ci = 0 then t else 0) (sealX t)

                ⭐ the witness input is per-(example, channel) CONSTANT: t on example 0's channel 0, zero everywhere else.

                theorem Proofs.Mnv4FullBSeal.scStem (nCls : ) (t : ) :
                StableHLO.Mnv4StemSmoothAtB 2 112 112 (sealW nCls).sW (sealW nCls).sb (sealW nCls).sE (sealW nCls).sg (sealW nCls).sbt (sealX t)

                ⭐⭐ The whole-net VJP at the witness — all eight bundles discharged.

                Equations
                Instances For
                  noncomputable def Proofs.Mnv4FullBSeal.As (t : ) :
                  Vec (2 * (32 * 112 * 112))
                  Equations
                  Instances For
                    noncomputable def Proofs.Mnv4FullBSeal.iS (t : ) (o : Fin 32) :

                    the stem BatchNorm's istd, channel by channel.

                    Equations
                    Instances For
                      noncomputable def Proofs.Mnv4FullBSeal.aS (t : ) :
                      Fin 2Fin 32
                      Equations
                      Instances For
                        theorem Proofs.Mnv4FullBSeal.bu_Zs (t : ) :
                        BatchSeal.BUnif (fun (n : Fin 2) (x : Fin 32) => if n = 0 then t else 0) (Zs t)

                        ⭐ the stem BatchNorm puts the two examples at 160 ± t/2 · istd — symmetrically about β, which is the fact the swish needs and a difference alone cannot give.

                        theorem Proofs.Mnv4FullBSeal.pc0 (nCls : ) (t : ) :

                        the stem's relu is the identity here, so mnv4Pre0 IS the stem BatchNorm.

                        noncomputable def Proofs.Mnv4FullBSeal.Af (t : ) :
                        Vec (2 * (128 * 56 * 56))
                        Equations
                        Instances For
                          noncomputable def Proofs.Mnv4FullBSeal.iF (t : ) (o : Fin 128) :

                          the fused conv's BatchNorm istd, channel by channel.

                          Equations
                          Instances For
                            noncomputable def Proofs.Mnv4FullBSeal.uF (t : ) (o : Fin 128) :

                            the half-gap at the swish's inputt times the two pre-swish BatchNorm factors.

                            Equations
                            Instances For
                              noncomputable def Proofs.Mnv4FullBSeal.aF (t : ) :
                              Fin 2Fin 128
                              Equations
                              Instances For
                                theorem Proofs.Mnv4FullBSeal.bu_Zf (t : ) :
                                BatchSeal.BUnif (fun (n : Fin 2) (x : Fin 128) => 160 + (if n = 0 then t / 2 else -(t / 2)) * iS t 0) (Zf t)
                                noncomputable def Proofs.Mnv4FullBSeal.Sw (t : ) :
                                Vec (2 * (128 * 56 * 56))

                                the fused stage's swish output.

                                Equations
                                Instances For
                                  theorem Proofs.Mnv4FullBSeal.ed_Sw (t : ) :
                                  BatchSeal.EDiff (fun (o : Fin 128) => BatchSeal.swishGap 160 (uF t o)) (Sw t)

                                  ⭐⭐ the carrier crosses the swish. The two examples straddle β = 160, so their outputs differ by swishGap 160 of the half-gap — and from here on the carrier is an EDiff and every stage multiplies it.

                                  noncomputable def Proofs.Mnv4FullBSeal.A1p (t : ) :
                                  Vec (2 * (48 * 56 * 56))
                                  Equations
                                  Instances For
                                    noncomputable def Proofs.Mnv4FullBSeal.Aaq (t : ) :
                                    Vec (2 * (48 * 28 * 28))
                                    Equations
                                    Instances For
                                      noncomputable def Proofs.Mnv4FullBSeal.Aae (t : ) :
                                      Vec (2 * (192 * 28 * 28))
                                      Equations
                                      Instances For
                                        noncomputable def Proofs.Mnv4FullBSeal.Aad (t : ) :
                                        Vec (2 * (192 * 28 * 28))
                                        Equations
                                        Instances For
                                          noncomputable def Proofs.Mnv4FullBSeal.Aaz (t : ) :
                                          Vec (2 * (80 * 28 * 28))
                                          Equations
                                          Instances For
                                            noncomputable def Proofs.Mnv4FullBSeal.Abq (t : ) :
                                            Vec (2 * (80 * 14 * 14))
                                            Equations
                                            Instances For
                                              noncomputable def Proofs.Mnv4FullBSeal.Abe (t : ) :
                                              Vec (2 * (480 * 14 * 14))
                                              Equations
                                              Instances For
                                                noncomputable def Proofs.Mnv4FullBSeal.Abd (t : ) :
                                                Vec (2 * (480 * 14 * 14))
                                                Equations
                                                Instances For
                                                  noncomputable def Proofs.Mnv4FullBSeal.Abz (t : ) :
                                                  Vec (2 * (160 * 14 * 14))
                                                  Equations
                                                  Instances For
                                                    noncomputable def Proofs.Mnv4FullBSeal.Acq (t : ) :
                                                    Vec (2 * (160 * 7 * 7))
                                                    Equations
                                                    Instances For
                                                      noncomputable def Proofs.Mnv4FullBSeal.Ace (t : ) :
                                                      Vec (2 * (960 * 7 * 7))
                                                      Equations
                                                      Instances For
                                                        noncomputable def Proofs.Mnv4FullBSeal.Acd (t : ) :
                                                        Vec (2 * (960 * 7 * 7))
                                                        Equations
                                                        Instances For
                                                          noncomputable def Proofs.Mnv4FullBSeal.Acz (t : ) :
                                                          Vec (2 * (256 * 7 * 7))
                                                          Equations
                                                          Instances For
                                                            noncomputable def Proofs.Mnv4FullBSeal.Ah1 (t : ) :
                                                            Vec (2 * (960 * 7 * 7))
                                                            Equations
                                                            Instances For
                                                              noncomputable def Proofs.Mnv4FullBSeal.Ah2 (t : ) :
                                                              Vec (2 * (1280 * 7 * 7))
                                                              Equations
                                                              Instances For
                                                                noncomputable def Proofs.Mnv4FullBSeal.rf (n : ) (z : Vec n) :

                                                                one carrier BatchNorm's whole contribution: γ · istd at γ = 1.

                                                                Equations
                                                                Instances For
                                                                  theorem Proofs.Mnv4FullBSeal.rf_pos (n : ) (z : Vec n) :
                                                                  0 < rf n z
                                                                  theorem Proofs.Mnv4FullBSeal.rf_cont (n : ) (k : Fin n) :
                                                                  Continuous fun (z : Vec n) => rf n z
                                                                  theorem Proofs.Mnv4FullBSeal.rfac_cont (oc h w : ) (k : Fin (2 * (h * w))) (c : Fin oc) (Z : Vec (2 * (oc * h * w))) (hZ : Continuous Z) :
                                                                  Continuous fun (t : ) => rf (2 * (h * w)) (BatchSeal.bnRowLA 2 oc h w (Z t) c)
                                                                  noncomputable def Proofs.Mnv4FullBSeal.dSw (t : ) :
                                                                  Fin 128

                                                                  the carrier at the swish's output — ⭐⭐ the one step of the whole chain that is NOT a multiple of the step before it.

                                                                  Equations
                                                                  Instances For
                                                                    noncomputable def Proofs.Mnv4FullBSeal.dad (t : ) :
                                                                    Fin 192
                                                                    Equations
                                                                    Instances For
                                                                      noncomputable def Proofs.Mnv4FullBSeal.dbd (t : ) :
                                                                      Fin 480
                                                                      Equations
                                                                      Instances For
                                                                        noncomputable def Proofs.Mnv4FullBSeal.Rr (t : ) :
                                                                        Equations
                                                                        • One or more equations did not get rendered due to their size.
                                                                        Instances For
                                                                          theorem Proofs.Mnv4FullBSeal.pc1 (nCls : ) (t : ) :
                                                                          theorem Proofs.Mnv4FullBSeal.pc2 (nCls : ) (t : ) :
                                                                          theorem Proofs.Mnv4FullBSeal.pc3 (nCls : ) (t : ) :
                                                                          theorem Proofs.Mnv4FullBSeal.pc4 (nCls : ) (t : ) :
                                                                          theorem Proofs.Mnv4FullBSeal.pc5 (nCls : ) (t : ) :
                                                                          theorem Proofs.Mnv4FullBSeal.pc6 (nCls : ) (t : ) :
                                                                          theorem Proofs.Mnv4FullBSeal.sealW_Wd (nCls : ) :
                                                                          (sealW nCls).Wd = fun (i : Fin 1280) (j : Fin nCls) => if i = 0 j = 0 then 1 else 0

                                                                          the head, peeled: two 1×1 conv-bn-relus, then GAP and the classifier. ⚠ Proved at variables (CertLayer.comp_fwd_apply) and applied at the net's literals — peeling a CertLayer.comp here is a kernel timeout, which is why MobileNetV4FullB.lean keeps the group peels generic too.

                                                                          theorem Proofs.Mnv4FullBSeal.head_diff (nCls : ) (hn : 0 < nCls) (v : Vec (2 * (1280 * 7 * 7))) (δ : Fin 1280) (hv : BatchSeal.EDiff δ v) :

                                                                          ⭐⭐ The class-0 difference between the two examples, along the ray: the swish's gap times the fifteen BatchNorm factors below it. ⚠ NOT t · Rr t — the swish is not affine, and that is exactly what swishGap carries.

                                                                          noncomputable def Proofs.Mnv4FullBSeal.Q0 (t : ) :

                                                                          the two pre-swish BatchNorm factors, as uF t 0 = t · Q0 t.

                                                                          Equations
                                                                          Instances For
                                                                            theorem Proofs.Mnv4FullBSeal.uF_eq (t : ) :
                                                                            uF t 0 = t * Q0 t
                                                                            theorem Proofs.Mnv4FullBSeal.hasDerivAt_uF :
                                                                            HasDerivAt (fun (t : ) => uF t 0) (Q0 0) 0

                                                                            ⭐⭐ the swish's contribution: swishGap is differentiable at 0 with slope 2 · swish' β, and that is the whole reason this net's readout is not t · Rr t.

                                                                            at t = 1 the readout is strictly positive: the half-gap is inside (0, 160] because ε = 1 caps every istd at 1, and the swish is strictly increasing there.

                                                                            ⭐⭐ Level 2 — the witness is non-degenerate: the full-width batch-BN MobileNetV4-Conv-M at the structural weights is NOT constant in its input.

                                                                            ⭐⭐ Level 3 — the whole-net Jacobian is nonzero at the witness.

                                                                            theorem Proofs.Mnv4FullBSeal.sealX_backward_nontrivial (nCls : ) (hn : 0 < nCls) :
                                                                            ∃ (j₀ : Fin (2 * nCls)) (i₀ : Fin (2 * (3 * (2 * 112) * (2 * 112)))), (sealVJP nCls 0).backward (basisVec j₀) i₀ 0

                                                                            ⭐⭐ The seal: the proven whole-network backward of the full-width, batch-BatchNorm, 21-block, 224×224 MobileNetV4-Conv-M — mobilenetv4ForwardB_full, the forward every MobileNetV4 artifact runs — is not the zero map at the witness.