The label-smoothed loss cotangent, at a GENERAL target #
Every whole-net T3 tie in the repo pins its top-of-chain cotangent to
softmax(logits) − oneHot label — the gradient of plain cross-entropy at a hard label. That is
what the SGD-inline per-example renders emit, and it is not what the batched ImageNet renders emit.
ResNet34RenderB.lean composes the head cotangent from six kit ops:
%sm = softmaxRow(logits) %d0 = %sm − %onehot %lsa = α · %onehot
%d1 = %d0 + %lsa %d2 = %d1 − α/K %dy = %d2 / B
so dy = (softmax(z) − t + α·t − α/K) / B, with α = 0.1 baked (the ls0 variants set it to 0)
and t arriving as the graph INPUT %onehot — which under mixup or cutmix is a soft vector drawn
on the host, not a one-hot. ConvNeXtRenderB and ViTRenderB compose the same six ops. This file
is the cotangent lemma those ties need: at a general target and at the smoothed form.
What is proved #
softCE K t z = Σ_k t_k · crossEntropy K z k— cross-entropy against a target distribution, not a label.softCE_gradis its gradient,(Σ_k t_k)·softmax(z)_j − t_j, with no hypothesis ontat all: it issoftmaxCE_gradunderpdiv_finset_sum, and the familiarsoftmax − tis theΣ t = 1case.smoothTarget K α t = (1−α)·t + α/Kis label smoothing as a map on targets, and it preservesΣ = 1(smoothTarget_sum, the one place0 < Kis needed).- ⭐
smoothedCE_grad: the gradient ofsoftCEat the SMOOTHED target is exactly the expression the render emits —softmax(z)_j − t_j + α·t_j − α/K. So the six-op chain is not an approximation of the smoothed loss's gradient; it is that gradient, rearranged so that the smoothing is two extra elementwise ops on the target rather than a change to the target itself. smoothedLossCotGraph/smoothedLossCotGraph_den/smoothedLossCotGraph_row: the emitted graph, its denotation, and the per-example row of that denotation as the smoothed gradient divided by the batch.
What is NOT claimed #
⚠ The / B is the batch mean, and it is a convention, not a theorem here. smoothedLossCotGraph_row
states the row IS (1/B)·∂softCE/∂z at that example's logits; that the sum of B such rows is the
gradient of the mean loss is the linearity step, and a tie against a *dp* artifact needs the
replica mean on top of it (planning/archive/proofs_tier_to_paper_nets.md 4d).
⚠ α is a free real. The committed renders bake 0.1, and the ls0 twins bake 0; both are
instances. ⚠ Nothing here says t is a probability vector — only Σ t = 1 is ever used, which is
what mixup's convex combination of two one-hots satisfies.
Soft-target cross-entropy −Σ_k t_k log softmax(z)_k, written as the t-weighted sum of
the per-class crossEntropy. At t = oneHot label it IS crossEntropy K z label
(softCE_oneHot).
Equations
- Proofs.softCE K t z = ∑ k : Fin K, t k * Proofs.crossEntropy K z k
Instances For
At a one-hot target, soft-target CE is the ordinary cross-entropy.
The soft-target CE gradient, with NO hypothesis on t:
∂/∂z_j (−Σ_k t_k log p_k) = (Σ_k t_k)·p_j − t_j. Each summand is softmaxCE_grad; the sum
comes out by pdiv_finset_sum, and each t_k factor by pdiv_mul against a constant.
⭐ The emitted expression IS the smoothed loss's gradient. ∂/∂z_j of soft-target CE at
the SMOOTHED target (1−α)t + α/K equals softmax(z)_j − t_j + α·t_j − α/K, which is exactly
what the render's softmaxRow → subB → scaleB → addVB → shiftB chain computes, before the
batch divide.
The six-op label-smoothed cotangent chain the batched renders emit, at one row per example
(m = 1, n = K) and batch N. logits is the head's output and t the graph input
%onehot; α is the smoothing and B the batch divisor (the render bakes B = N).
Equations
- One or more equations did not get rendered due to their size.
Instances For
What the chain denotes, coordinatewise: (rowSoftmax(logits) − t + α·t − α/K) / B.
⭐ Each row of the emitted cotangent is the smoothed loss's gradient at that example's
logits, divided by the batch. Mat.unflatten splits the flat N·(1·K) activation into its
N per-example rows; smoothedCE_grad supplies the gradient. The hypothesis is only that the
example's target sums to 1 — a one-hot, a mixup convex combination, or any distribution.
The six-op chain as ConvNeXtRenderB and ViTRenderB emit it. Those two renders spell the
row softmax as batchOp expe then batchOp softmaxDiv — the per-example
softmaxDiv (expe ·) pair the SGD-inline files tie (cnxLossCot_den), lifted — and run the
whole chain at the plain width N·K rather than N·(1·K), so there is no row index and no
rowB/unrowB cast at the head. Same six functions, different AST;
smoothedLossCotGraphDiv_den says the denotation is smoothedLossCotGraph's, and
smoothedLossCotGraphDiv_row is the per-example statement at batchSlice.
Equations
- One or more equations did not get rendered due to their size.
Instances For
What the chain denotes, coordinatewise: (softmax(logits_n) − t + α·t − α/K) / B, the
per-example softmax lifted by batchMap — the same function smoothedLossCotGraph_den reads
off the softmaxRow spelling.
⭐ Each example's row of the emitted cotangent is the smoothed loss's gradient at that
example's logits, divided by the batch — smoothedLossCotGraph_row at the softmaxDiv
spelling and the plain N·K index, where the example is batchSlice N K · n with no
Mat.unflatten. The hypothesis is only that the example's target sums to 1.