ViT forward graph — ch10 close Item A (planning/archive/vit_close.md) #
Two halves, both living here because StableHLO.lean cannot import
Attention.lean (Attention is the proof capstone; StableHLO is the token
layer — the ViT den helpers there are local re-spellings, tied back to the
proven Attention forms in THIS file):
vitForward2— the representative distinct-param 2-block ViT forward at theVeclevel:classifier ∘ finalLN ∘ block₂ ∘ block₁ ∘ patchEmbed. The proventransformerTower/vit_fullshare ONE param tuple across blocks; a train step needs distinct per-block params, so the 2-block forward is composed here fromtransformerBlockdirectly (the tower proof does exactly this composition — with shared params).vitForward2_has_vjpis the whole-net VJP:vjp_compchainspatchEmbed_flat_has_vjp, two bridgedtransformerBlock_has_vjp_matwitnesses, the bridged per-token final-LN, andclassifier_flat_has_vjp. UNCONDITIONAL except0 < ε(all-smooth — softmax/GELU/LN have no kinks).vitFwdGraph— the typedSHloforward graph over the ch10 token vocabulary (patchEmbedF/lnRowF/denseRowF/matmulF/transposeF/scaleF/softmaxRowF/geluF/addV/clsSliceF), heads = 1 (SDPA = three matmuls + a row-softmax — the representative granularity trade, like ConvNeXt's 2-block/1×1-stem).vitFwdGraph_faithful: its denotation ISvitForward2atheads := 1— the ViT analogue ofconvNextFwdGraph_faithful.
Distinct-param 2-block ViT forward (the ch10 representative):
patchEmbed (stride-P conv + CLS + pos) → block₁ → block₂ → final-LN (per-token, scalar γ/β) → CLS slice → dense head
Generic dims; the two transformerBlocks carry distinct parameter
sets (…₁/…₂) — beyond the shared-param transformerTower witness,
composed from the same proven block VJP. One shared LN ε across all
five LN sites (the proof convention, as in vit_full).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Whole-net VJP for the distinct-param 2-block ViT (global). All-smooth,
so the only hypothesis is the LayerNorm positivity 0 < ε — joins
vit_full_has_vjp/convnext_has_vjp as an unconditional whole-network
VJP holding at every input. Four vjp_comp steps glueing
patchEmbed_flat_has_vjp, two bridged distinct-param
transformerBlock_has_vjp_mat witnesses, the bridged per-token final-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 vitForward2_has_vjp — the
distinct-param 2-block ViT's backward equals the pdiv-contracted
Jacobian (Jacobian-transpose applied to the cotangent), at every
input. The ch10 analogue of convnext_has_vjp_correct.
MHSA at heads = 1 is three matmuls + a row-softmax. The per-head
slice/concat plumbing of mhsa_layer collapses (the head axis is
Fin 1), leaving exactly the ch10 graph spelling: Q/K/V per-token
dense → Q·Kᵀ → ·1/√d → row-softmax → P·V → output dense.
This is the load-bearing tie for vitFwdGraph_faithful.
The ch10 spelled pre-norm transformer block at heads = 1 (Mat level) —
the exact op sequence vitBlockGraph denotes: LN₁ → Q/K/V per-token
dense → Q·Kᵀ → ·1/√d → row-softmax → P·V → output dense → +res →
LN₂ → fc1 → GELU → fc2 → +res. Equals transformerBlock at one head
(vitBlockSpelled_eq).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The spelled block IS transformerBlock at one head. The
sublayer/residual structure matches definitionally once
mhsa_layer_one_head collapses the per-head plumbing.
One spelled pre-norm transformer block over the ch10 tokens (heads = 1):
lnRowF → Q/K/V denseRowF → matmulF(Q, transposeF K) → scaleF →
softmaxRowF → matmulF(P, V) → output denseRowF → addV residual →
lnRowF → fc1 → geluF → fc2 → addV residual. Generic D; the
faithfulness theorem instantiates D := 1 * d, s := sdpa_scale d.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Flat ↔ Mat commutation bridges #
Each ch10 den helper applied to a Mat.flatten is the flatten of the
corresponding Mat-level op (the Mat.unflatten_flatten round-trip
cancels); the pointwise ops (scaleF/geluF/addV) commute with
flattening definitionally. Public — ViTChainClose reuses them to tie
the matmul-spelled SDPA backward to the proven closed forms.
Whole ViT forward graph (the ch10 representative, peer of
convNextFwdGraph): patch embed (stride-P conv + CLS + pos-embed) →
2 spelled transformer blocks (distinct params) → final per-token LN →
CLS slice → dense head. Generic D/s; faithful at D := 1 * d,
s := sdpa_scale d (heads = 1).
Equations
- One or more equations did not get rendered due to their size.
Instances For
ViT forward faithfulness — the ch10 close's Item A apex: the
representative forward graph denotes the proven distinct-param 2-block
vitForward2 at one head (heads := 1, D := 1 * d,
s := sdpa_scale d). The ViT analogue of convNextFwdGraph_faithful:
per-block vitBlockGraph_den_aux + vitBlockSpelled_eq
(mhsa_layer_one_head under the hood), then the patch-embed / CLS-slice
den helpers are the proven Attention forms verbatim.