ViT depth-k (general-depth tower, distinct per-block params) #
The proven transformerTowerHasVJPMat shares ONE param tuple across blocks. This
file builds the net with distinct per-block params at every 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), withvitBodyKVFlatHasVJPby induction onk(the chain step isvjpComp+ the bridgedtransformerBlockVHasVJPMat).vitForwardKV(HasVJP[_correct])— the whole net at depthk, UNCONDITIONAL except0 < ε.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).
The ViT-Tiny instantiation (depth 12, P=16, D=192, heads=3) of the whole-net backward is
vitTinyHasVJP_correct, in ViTWholeBackCertifiedTie.
References #
- Dosovitskiy et al. 2021, An Image is Worth 16x16 Words (ViT). https://arxiv.org/abs/2010.11929
- Touvron et al. 2021, Training data-efficient image transformers & distillation through attention (DeiT). https://arxiv.org/abs/2012.12877
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.
Equations
- Proofs.blockVFlat gf Np1 heads d_head mlpDim ε p v = (Proofs.blockV gf 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 gf Np1 heads d_head mlpDim ε 0 x_2 = fun (A : Proofs.Mat Np1 (heads * d_head)) => A
- Proofs.vitBodyKV gf Np1 heads d_head mlpDim ε k.succ ps = (Proofs.vitBodyKV gf Np1 heads d_head mlpDim ε k fun (i : Fin k) => ps i.succ) ∘ Proofs.blockV gf Np1 heads d_head mlpDim ε (ps 0)
Instances For
Depth-k block fold at the flat index — per-block flat stages, so the VJP
composes block-at-a-time.
Equations
- One or more equations did not get rendered due to their size.
- Proofs.vitBodyKVFlat gf Np1 heads d_head mlpDim ε 0 x_2 = fun (v : Proofs.Vec (Np1 * (heads * d_head))) => v
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 vjpComp gluing the bridged
transformerBlockVHasVJPMat onto the depth-k tail. Only 0 < ε.
Equations
- One or more equations did not get rendered due to their size.
- Proofs.vitBodyKVFlatHasVJP gf Np1 heads d_head mlpDim ε hε 0 x_2 = Proofs.identityHasVJP (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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Whole-net VJP for the depth-k ViT (global). All-smooth, so the only
hypothesis is 0 < ε — at EVERY depth. Three vjpComp steps gluing
patchEmbedFlatHasVJP, the inductive vitBodyKVFlatHasVJP, the
bridged per-token vector-LN, and classifierFlatHasVJP.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The .correct field of vitForwardKVHasVJP, restated: the depth-k ViT's backward is the
pdiv-contracted Jacobian of vitForwardKV at every input. The tie of the hand-written
input-gradient chain to this backward is vitInputGradK_correct.
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 gf 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.