ViT scaling pass — depth-k (general-depth tower, distinct per-block params) #
The proven transformerTower_has_vjp_mat shares ONE param tuple across blocks;
the 2-block vitForward2(V) carried distinct params but fixed the depth. This
file closes general depth at the production form (vector-[D] LN + multi-head):
BlockParamsV— the 16-field per-block param structure, andvitBodyKVFlat— the depth-kblock fold (head recursion: block 0 first), withvitBodyKVFlat_has_vjpby induction onk(the chain step isvjp_comp+ the bridgedtransformerBlockV_has_vjp_mat, exactlyvitForward2V_has_vjp's step with aFin kparam function).vitForwardKV(_has_vjp[_correct])— the whole net at depthk, UNCONDITIONAL except0 < ε.vitForwardKV_two_eq: atk = 2it ISvitForward2V(definitional).vitBodyGraphKMHV— the token-level fold ofvitBlockGraphMHVwith per-block SSA prefixesb{base+i}_, andvitFwdGraphKMHV_faithful: the depth-kmulti-head vector-LN forward graph denotesvitForwardKVatheads := hm1 + 1— by induction onkchainingvitBlockGraphMHV_den_aux+vitBlockSpelledMHV_eqper block (the per-block den_aux was designed for exactly this).
Depth-12 ViT-Tiny shapes are now a config change away (the production capstone needs only the P=16/D=192/heads=3 instantiation of these).
The 16 per-block ViT parameters (vector-LN form), bundled so depth-k
signatures stay sane (params : Fin k → BlockParamsV D mlpDim).
- γ1 : Vec D
- β1 : Vec D
- Wq : Mat D D
- Wk : Mat D D
- Wv : Mat D D
- Wo : Mat D D
- bq : Vec D
- bk : Vec D
- bv : Vec D
- bo : Vec D
- γ2 : Vec D
- β2 : Vec D
- Wfc1 : Mat D mlpDim
- bfc1 : Vec mlpDim
- Wfc2 : Mat mlpDim D
- bfc2 : Vec D
Instances For
transformerBlockV at a bundled param block.
Equations
Instances For
One block at the flat index (the vitForward2V per-block spelling).
Equations
- Proofs.blockVFlat Np1 heads d_head mlpDim ε p v = (Proofs.blockV Np1 heads d_head mlpDim ε p (Proofs.Mat.unflatten v)).flatten
Instances For
Depth-k block fold (Mat level, head recursion — block 0 runs
first): body (k+1) ps = body k (ps ∘ succ) ∘ block (ps 0).
Equations
- Proofs.vitBodyKV Np1 heads d_head mlpDim ε 0 x_2 = fun (A : Proofs.Mat Np1 (heads * d_head)) => A
- Proofs.vitBodyKV Np1 heads d_head mlpDim ε k.succ ps = (Proofs.vitBodyKV Np1 heads d_head mlpDim ε k fun (i : Fin k) => ps i.succ) ∘ Proofs.blockV Np1 heads d_head mlpDim ε (ps 0)
Instances For
Depth-k block fold at the flat index — per-block flat stages (the
vitForward2V spelling, so the VJP composes block-at-a-time).
Equations
- Proofs.vitBodyKVFlat Np1 heads d_head mlpDim ε 0 x_2 = fun (v : Proofs.Vec (Np1 * (heads * d_head))) => v
- Proofs.vitBodyKVFlat Np1 heads d_head mlpDim ε k.succ ps = (Proofs.vitBodyKVFlat Np1 heads d_head mlpDim ε k fun (i : Fin k) => ps i.succ) ∘ Proofs.blockVFlat Np1 heads d_head mlpDim ε (ps 0)
Instances For
The flat fold on a flattened input is the flatten of the Mat fold (the
per-block unflatten ∘ flatten round-trips cancel, inductively).
Flat differentiability of the depth-k body, by induction on k.
Depth-k body VJP — the tower induction at distinct per-block params:
the chain step is vjp_comp gluing the bridged
transformerBlockV_has_vjp_mat onto the depth-k tail. Only 0 < ε.
Equations
- One or more equations did not get rendered due to their size.
- Proofs.vitBodyKVFlat_has_vjp Np1 heads d_head mlpDim ε hε 0 x_2 = Proofs.identity_has_vjp (Np1 * (heads * d_head))
Instances For
Depth-k distinct-param ViT forward (vector-LN): patch embed →
k blocks (Fin k → BlockParamsV) → final vector-LN → CLS slice →
dense head. vitForward2V generalized over depth.
Equations
- One or more equations did not get rendered due to their size.
Instances For
At k = 2 the depth-k net IS vitForward2V (definitional — the
fold unrolls to exactly the 2-block composition).
Whole-net VJP for the depth-k ViT (global). All-smooth, so the only
hypothesis is 0 < ε — at EVERY depth. Three vjp_comp steps gluing
patchEmbed_flat_has_vjp, the inductive vitBodyKVFlat_has_vjp, the
bridged per-token vector-LN, and classifier_flat_has_vjp.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Public correctness theorem for vitForwardKV_has_vjp — the depth-k
ViT's backward equals the pdiv-contracted Jacobian at every input.
ViT-Tiny whole-network VJP — the production capstone.
vitForwardKV_has_vjp_correct instantiated at the exact MainVitTrain.lean
vitTiny spec: a 3×224×224 image, 16×16 patches (N = 196 patch tokens
- the CLS token), embedding dim
D = 192 = 3 heads × 64, MLP dim768, 12 transformer blocks with DISTINCT per-block parameters (ps : Fin 12 → BlockParamsV 192 768), and Imagenette's10classes.
The full 12-block / 3-head ViT-Tiny's backward pass equals its Mathlib-fderiv
Jacobian-transpose contracted with the cotangent, at every input image —
UNCONDITIONAL except 0 < ε (softmax / GELU / vector-LN are kink-free, so no
smoothness witness is needed, and the statement is generic in the weights, so
it is non-degenerate by construction). The ViT peer of convNextForwardTCh_has_vjp
(18-block ConvNeXt-T) and efficientnetForwardB_full_has_vjp (16-block
EfficientNet-B0): a full-spec, real-architecture whole-network backward.
vitBlockGraphMHV at a bundled param block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Depth-k token-level block fold — block base first, SSA prefixes
b{base+1}_, b{base+2}_, … (distinct per block).
Equations
- One or more equations did not get rendered due to their size.
- Proofs.StableHLO.vitBodyGraphKMHV epsStr sStr oneStr zeroStr ε s x✝¹ 0 x_5 x✝ = x✝
Instances For
Depth-k body denotation — by induction on k, chaining
vitBlockGraphMHV_den_aux + vitBlockSpelledMHV_eq per block: the token
fold denotes the flatten of the Mat block fold at heads := hm1 + 1.
Whole depth-k multi-head vector-LN ViT forward graph: patch embed →
k spelled multi-head vector-LN blocks (b1_…b{k}_, distinct params) →
final vector-LN → CLS slice → dense head.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Depth-k multi-head vector-LN ViT forward faithfulness — the
general-depth graph denotes vitForwardKV at heads := hm1 + 1, for
EVERY depth k. The depth analogue of vitFwdGraphMHV_faithful.