vitInputGradK is the certified whole-net ViT gradient #
The per-example whole-net backward tie for ViT, the peer of ConvNeXt-T's
convnextInputGrad_eq_convNextForwardTCh_vjp and EfficientNet-B0's
efficientnetInputGradBFull_eq_efficientnetForwardB_full_vjp; the batched ties of the other nets
are r34InputGradB_eq_r34B_full_vjp and mnv2InputGradB_eq_mobilenetv2B_full_vjp, and ViT's own
batched form is ViTWholeBackCertifiedTieB.lean. It is stated generically and instantiated at
ViT-Tiny's configuration: depth 12 with distinct per-block parameters, D = 192 = 3 × 64,
197 tokens, vector-[D] LayerNorm.
Four things assemble it, and only the second is a proof rather than an enumeration:
- The three endpoint leaf ties. The classifier head's backward is the transposed dense
(
dense Wclsᵀ 0) then the CLS scatter (vitHeadBack_eq_classifier_vjp); the final LayerNorm's isrowLNVecFlatBackat the tower's output (rowLNVecFlatHasVJP_backward_eq, ConvNeXt's, sincevitForwardKV's final-LN witness ISHasVJPMat.toHasVJP (layerNormVecPerTokenHasVJPMat …)); and the patch embed's ispatchEmbedInputGradFormula, whichpatchEmbedFlatHasVJPgives as its backward definitionally — so that endpoint isrfland needs no lemma at all. - The depth-
ktower fold (vitTowerBackK_eq_vjp), the one real proof.vitBodyKVFlat'sHasVJPis built head-first (block0runs first), so the backward composes the block backwards in the opposite order, each at its own saved activation, and the tail's saved input is block0's forward output.cnxStageChKBack_eq_vjp's induction verbatim: one rewrite of the block tie and one of the inductive hypothesis. - The apex witness.
vitApexVJPnames the committedvitForwardKVHasVJP; its.backwardreduces through the fourvjpCompfactors byrfl. - A shape check.
vitForwardKV_eq_chainsays the four-factor composition the apex is stated at IS the committedvitForwardKV, byrfl.
The only hypothesis is 0 < ε; the result holds at every input and every cotangent. ViT has no
kink anywhere — softmax, GELU and LayerNorm are all smooth — so, like ConvNeXt-T and
EfficientNet-B0 and unlike ResNet-34 / MobileNetV2, this is a global HasVJP and not a
smooth-point HasVJPAt, with no smoothness witness. The forward vitForwardKV has no drop-path
and is in exact arithmetic.
The classifier-head backward tie. clsScatter ∘ dense Wclsᵀ 0 — the head dense's free
input-VJP, then the CLS-slice scatter — IS (classifierFlatHasVJP …).backward x, at every
saved input (the head is linear, so the backward does not depend on x).
The final-LayerNorm backward tie. vitForwardKV's final-LN witness is
HasVJPMat.toHasVJP (layerNormVecPerTokenHasVJPMat …), which is exactly
rowLNVecFlatHasVJP — so ConvNeXt's rowLNVecFlatHasVJP_backward_eq is this tie, read
at the ViT token layout.
The tower-fold tie. The hand-composed depth-k encoder-tower backward is
(vitBodyKVFlatHasVJP k ps).backward. Induction on k: the base is identityHasVJP's
fun _ dy => dy, and the step is one rewrite of the inductive hypothesis at the shifted saved
activation (blockVFlat (ps 0) v, block 0's OUTPUT) and one of the block tie at v.
The whole-net witness the apex is stated at — the committed vitForwardKVHasVJP, whose
.backward is the four-factor vjpComp chain by rfl.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The four-factor composition the apex is stated at is the committed vitForwardKV, by rfl.
vitInputGradK IS the apex witness's backward. Four rewrites, one per factor: the
tower fold, the final-LN tie, the head tie, and the patch-embed endpoint (rfl).
The apex. vitInputGradK — the whole-net ViT-Tiny input gradient, every slot pinned
to the certified per-op backward at its own saved activation — IS
(vitForwardKVHasVJP …).backward x, the committed depth-12 witness — vitApexVJP by name.
The apex, read as the Jacobian. vitInputGradK is the pdiv-contracted Jacobian
transpose of the committed vitForwardKV, at EVERY image and EVERY cotangent — the ViT peer
of efficientnetInputGradBFull_correct. Only 0 < ε.
ViT-Tiny's whole-net backward tie.
vitInputGradK_eq_vitForwardKV_vjp instantiated at the exact ViT-Tiny
spec: a 3×224×224 image, 16×16 patches (196 patch tokens + CLS), D = 192 = 3 heads × 64,
MLP dim 768, 12 transformer blocks with DISTINCT per-block parameters, vector-[D]
LayerNorm at all 25 sites, and any number of classes nCls (10 on Imagenette, 1000 on
ImageNet).
So the hand-written input-gradient chain IS the certified gradient of the committed depth-12
forward, at every image. vitTinyHasVJP_correct reads it as the Jacobian. The peer of
convnextInputGrad_eq_convNextForwardTCh_vjp and
efficientnetInputGradBFull_eq_efficientnetForwardB_full_vjp.
ViT-Tiny's whole-net backward, read as the Jacobian. vitInputGradK_correct at the
ViT-Tiny spec of vitTinyInputGrad_eq_vitTiny_vjp: the hand-written input-gradient chain
vitInputGradK, every slot the certified per-op backward at its own saved activation, is the
pdiv-contracted Jacobian transpose of the committed depth-12 forward vitForwardKV, at every
image, every cotangent and every class count nCls. The only hypothesis is 0 < ε: softmax,
GELU and vector LayerNorm are smooth, so no smoothness witness is needed, and the weights are
free. The peer of efficientnetInputGradBFull_correct.