The MNIST-MLP train step at batch N — MlpFold with the batch stated #
MlpFold certifies the six parameter outputs of mlp_train_step.mlir for ONE example.
tests/TestSmallNetsBatchedEmit.lean pins that same text as the print of a graph at the batched
index — batchOp lifts of dense/relu/expe/softmaxDiv/dotOut, subB, selectPosB on
the whole-batch pre-activations, and the denseWeightSgdB/denseBiasSgdB nodes — so every
node's den can be read at a batch of N examples. This file does that reading:
- the batched forward's slices are the per-example forward (
preB0_slice, …); - the batched loss cotangent's slices are
softmax(logitsₖ) − onehotₖ(cotB_slice); - the batched chain cotangents' slices are the per-example
mlpCotOut1/mlpCotOut0(cot1B_slice,cot0B_slice); - each of the six parameter nodes denotes
θ − lr·Σₖ (certified per-layer Jacobian at example k · that example's chain cotangent), and the output weightW₂ − lr·Σₖ ∂CE(forwardₖ)/∂W₂(mlp_train_step_tiedB).Nis a binder; the artifact isN = 128.
The chain cotangents are node-local, as in MlpFold: each parameter node is stated with its
cotangent input as an .operand leaf carrying the den of the batched backward subgraph, which
the slice lemmas pin. Scope otherwise as MlpFold (per-op pretty lexing; ℝ → Float32).
Per-example shorthands, at example k of the batch #
Example k's input.
Equations
- Proofs.MlpFoldB.xk N xB k = Proofs.StableHLO.batchSlice N d₀ xB k
Instances For
Layer-0 pre-activation at example k.
Equations
- Proofs.MlpFoldB.p0 N W₀ b₀ xB k = Proofs.dense W₀ b₀ (Proofs.MlpFoldB.xk N xB k)
Instances For
Layer-1 pre-activation at example k.
Equations
- Proofs.MlpFoldB.p1 N W₀ b₀ W₁ b₁ xB k = Proofs.dense W₁ b₁ (Proofs.relu d₁ (Proofs.MlpFoldB.p0 N W₀ b₀ xB k))
Instances For
The softmax-CE loss cotangent at example k: softmax(logitsₖ) − onehotₖ.
Equations
- Proofs.MlpFoldB.gk N W₀ b₀ W₁ b₁ W₂ b₂ xB label k j = Proofs.softmax d₃ (Proofs.mnistLinear W₂ b₂ (Proofs.relu d₂ (Proofs.MlpFoldB.p1 N W₀ b₀ W₁ b₁ xB k))) j - Proofs.oneHot d₃ (label k) j
Instances For
The batched graph, piece by piece (the pieces mlpTrainStepText renders) #
Equations
- Proofs.MlpFoldB.preB0 N W₀ b₀ xB = Proofs.StableHLO.SHlo.batchOp (Proofs.StableHLO.BatchableOp.dense "%W0" "%b0" W₀ b₀) (Proofs.StableHLO.SHlo.operand "%x" xB)
Instances For
Equations
- Proofs.MlpFoldB.actB0 N W₀ b₀ xB = Proofs.StableHLO.SHlo.batchOp Proofs.StableHLO.BatchableOp.relu (Proofs.MlpFoldB.preB0 N W₀ b₀ xB)
Instances For
Equations
- Proofs.MlpFoldB.preB1 N W₀ b₀ W₁ b₁ xB = Proofs.StableHLO.SHlo.batchOp (Proofs.StableHLO.BatchableOp.dense "%W1" "%b1" W₁ b₁) (Proofs.MlpFoldB.actB0 N W₀ b₀ xB)
Instances For
Equations
- Proofs.MlpFoldB.actB1 N W₀ b₀ W₁ b₁ xB = Proofs.StableHLO.SHlo.batchOp Proofs.StableHLO.BatchableOp.relu (Proofs.MlpFoldB.preB1 N W₀ b₀ W₁ b₁ xB)
Instances For
Equations
- Proofs.MlpFoldB.logitsB N W₀ b₀ W₁ b₁ W₂ b₂ xB = Proofs.StableHLO.SHlo.batchOp (Proofs.StableHLO.BatchableOp.dense "%W2" "%b2" W₂ b₂) (Proofs.MlpFoldB.actB1 N W₀ b₀ W₁ b₁ xB)
Instances For
The batched loss cotangent sub(softmaxDiv(expe(logits)), onehot).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Example k's slice of the batched loss cotangent is softmax(logitsₖ) − onehotₖ.
The backward chain: selectPosB on the whole-batch pre-activation over a dotOut lift #
Layer-1 batched chain cotangent selectPosB p₁ (dotOut W₂ dy), dy the batched loss
cotangent as an operand leaf.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Its slice at example k is the per-example mlpCotOut1 at that example's cotangent.
Layer-0 batched chain cotangent selectPosB p₀ (dotOut W₁ c₁), c₁ the layer-1 chain
cotangent as an operand leaf.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The six parameter nodes at batch N #
Output weight, at the WHOLE loss, summed over the batch.
Output bias.
Hidden weight W₁, at the layer-1 chain cotangent.
Hidden bias b₁.
Input weight W₀, at the layer-0 chain cotangent.
Input bias b₀.
Whole MLP train step at batch N, tied. The output weight denotes W₂ − lr·Σₖ ∂CE/∂W₂
at the whole loss of each example; the other five denote θ − lr·Σₖ (certified per-layer Jacobian at example k · that example's rendered chain cotangent), the chain cotangents being
the slices of the emitted selectPosB/dotOut subgraphs (cot1B_slice, cot0B_slice).