The renderers' shared optimizer tail #
Every batched train-step renderer ends the same way: fold a per-parameter optimizer step over the parameter list, so the θ/m/v outputs come out in signature order. This file holds that step once.
| step | used by | ops per parameter |
|---|---|---|
adamOne | MobileNetV2, MobileNetV4, EfficientNet | all-reduce (DP only) + the AdamW triple |
rmsOne | MobileNetV2, EfficientNet | all-reduce + coupled L2 + mean-square + buffer + SGD |
adamOneEma | ViT, ConvNeXt | adamOne + the model-EMA shadow, with the clip's preAvg |
and the train step's packed interface — the one positional contract the driver's blob walks:
packedTrainSig (arguments) and packedTrainRetTys (results), used by every batched renderer.
Last, the precision-switched constructors XAt bf16 rnd … (convAt, convBackBatchedAt, …): one
if bf16 then .XBf16 rnd … else .X … per op instead of one per call site.
ResNet34RenderB.optOne is the multi-optimizer step (AdamW / LAMB / heavy-ball / accumulation /
EMA) that ResNet-34 and ResNet-50 fold; it reads the same PGrad.
At replicas ≤ 1 the all-reduce emits nothing and threads the raw gradient, so a single-device
render is unchanged by it. The AdamW triple consumes the averaged gradient as an .operand,
exactly as it consumed the raw one, so the den side does not shift.
Equations
(θ', m', v') for one parameter under AdamW: the replica mean of its gradient
(prettyAllReduceMean, pretty of the allReduceMeanF node) and then the proven
adamMNextF/adamVNextF/adamWParamF triple (prettyAdamW).
Equations
- One or more equations did not get rendered due to their size.
Instances For
(θ', b', s') for one parameter under RMSProp with momentum — the adamOne peer. Only ONE
of the four ops is new. Reading the reference
(jax/Jax/Codegen.lean, the .rmsprop branch) top to bottom:
| reference line | emitted here |
|---|---|
grads = g + WD * p | momVNextF at (μ := wd, v := θ) — Proofs.momVNext_as_coupled_l2 |
sq = RHO*s + (1-RHO)*g*g | adamVNextF at β₂ := ρ — Proofs.rmsSqNext_eq_adamVNext |
buf = MOMENTUM*b + g/sqrt(sq+EPS) | rmsBufNextF — the new op, ε INSIDE the root |
params = p - lr*buf | sgdParamF on the buffer's SSA |
⚠ The weight decay is COUPLED and goes FIRST, so the accumulator sees the decayed gradient. Reversing that order — decaying after the accumulator, AdamW-style — is a different optimizer and would not show up as an arity or type error anywhere.
⚠ EfficientNet's ε is 1e-3, where MobileNetV2's is 1.0 — the placement's sensitive end: at a
collapsed mean-square the textbook spelling takes a step 31.6× larger
(Proofs.rmsBufNext_eps_placement_at_zero). A green MobileNetV2 tie does not license the
EfficientNet render; rms-tie efficientnet is its own gate.
Slot mapping: the packed [θ|m|v] signature is reused verbatim with m carrying the
momentum buffer and v the running mean-square, the same slot reinterpretation the Nesterov
render does for its velocity. That is why the driver and the interface do not move.
Equations
- One or more equations did not get rendered due to their size.
Instances For
(θ', m', v', e') for one parameter under AdamW with the model-EMA shadow — ViT's and
ConvNeXt's step. e' is "" at ema := false.
wdName—"%wd", or the zero constant for timm'sno_weight_decayparameters. The AdamW ops take the decay as an OPERAND NAME, so excluding a parameter binds that name to a zero.preAvg— the caller has ALREADY averaged (and clipped) this gradient, so the collective is not emitted a second time. Under data parallelism the clip must come AFTER theall_reduce(the reference clips the combined gradient; clipping per replica clips PARTIAL gradients — a different function that still trains and descends), and the clip needs every gradient at once while this step is per parameter, so atclip := truethe caller hoists both (planning/archive/grad_clip.md§4).ema— the shadowe' = d·e + (1−d)·θ'isadamMNextFat(β₁ := d, m := e, g := θ'):Proofs.adamMNextIS the reference'sema_update(ema_updateinjax/Jax/Codegen.lean), so it needs no new op andadamMNextF_faithfulcloses thedenside byrfl. ⚠ It readsnT, the UPDATED parameter — the shadow averages weights after the optimizer moves them. ⚠%emad/%oemadare function ARGS, not constants: the reference's decay is warmup-corrected,d = min(decay, (1+t)/(10+t))(planning/archive/ema.md§2 — without it a shadow held 12.8% of the random init and scored 0.00%). Atema := falsenoprettycall happens, so the fresh-name counter does not move and the non-EMA renders are unchanged by the flag.
⚠ The shadow's SSA name is %{nm}e here; ResNet34RenderB.optOne uses %{nm}ema because at
suffix e the stem BN gamma %sg collides with select_and_scatter's block-local %sge.
ViT and ConvNeXt have no max-pool, so e is safe for them.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The packed train step's argument list after %x: the parameter regions in the order the
driver packs them — θ, m, v, then the accumulator G (<p>a, only under gradient
accumulation) and the model-EMA shadow E (<p>{emaSuf}, only under ema) — followed by the
runtime scalars %lr, %bc1, %bc2, %aup, %akeep (accumulation) and %emad, %oemad (EMA).
ps is (%name, type) per parameter, in signature order.
⚠ G precedes E and never follows it: [θ|m|v|G|E] is the order that leaves both single-axis
layouts at the index they already occupy. ⚠ emaSuf is "e" except on the ResNet family, whose
stem BN gamma %sg + e would be %sge — select_and_scatter's block-local name in the
max-pool backward — so there it is "ema" (ResNet34RenderB.optOne).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The packed train step's leading result types, in packedTrainSig's order: the updated
regions θ', m', v'[, G'][, E'], then %loss, %bc1, %bc2, then the handed-back
accumulation / EMA scalars. pTy is the parameter types in signature order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The stochastic-depth mask arguments , %dp<i>: tensor<Bxf32> for the sites idxs, in the
order given — the order the driver's dropScales writes them into the blob. Empty when sd is
off, which keeps every non-SD render byte-identical. Each net passes its own site list
(vitDropSig, cnxDropSig, enetDropSig, r50DropSig).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Every bf16 op is its f32 peer with one extra leading argument, the rounding rnd, and every
renderer used to spell the choice out
(if bf16 then .convBf16 (h := h) zrnd … else .conv (h := h) …, 248 times). XAt bf16 rnd …
is that if, once per constructor. pretty evaluates it, so the emitted text is exactly the
chosen branch's — every artifact renders byte-identically.
conv, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convBackBatched, or its bf16 peer at rounding rnd when bf16.
Equations
- Proofs.StableHLO.SHlo.convBackBatchedAt bf16 rnd wName W b = if bf16 = true then Proofs.StableHLO.SHlo.convBackBatchedBf16 rnd wName W b else Proofs.StableHLO.SHlo.convBackBatched wName W b
Instances For
convStride4, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convStride4WeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convStrided, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convStridedBackBatched, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convStridedWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convStridedXla, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convStridedXlaWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
convWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- Proofs.StableHLO.SHlo.convWeightGradBAt bf16 rnd xName b x W = if bf16 = true then Proofs.StableHLO.SHlo.convWeightGradBBf16 rnd xName b x W else Proofs.StableHLO.SHlo.convWeightGradB xName b x W
Instances For
denseRow, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
denseRowBack, or its bf16 peer at rounding rnd when bf16.
Equations
- Proofs.StableHLO.BatchableOp.denseRowBackAt bf16 rnd wName W = if bf16 = true then Proofs.StableHLO.BatchableOp.denseRowBackBf16 rnd wName W else Proofs.StableHLO.BatchableOp.denseRowBack wName W
Instances For
depthwise, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseBackBatched, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseStrided, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseStridedBackBatched, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseStridedWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseStridedXla, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseStridedXlaBackBatched, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseStridedXlaWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
depthwiseWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- One or more equations did not get rendered due to their size.
Instances For
flatConvF, or its bf16 peer at rounding rnd when bf16.
Equations
- Proofs.StableHLO.SHlo.flatConvFAt bf16 rnd wName bName W b = if bf16 = true then Proofs.StableHLO.SHlo.flatConvFBf16 rnd wName bName W b else Proofs.StableHLO.SHlo.flatConvF wName bName W b
Instances For
matmulFB, or its bf16 peer at rounding rnd when bf16.
Equations
Instances For
rowDenseWeightGradB, or its bf16 peer at rounding rnd when bf16.
Equations
- Proofs.StableHLO.SHlo.rowDenseWeightGradBAt bf16 rnd xName x = if bf16 = true then Proofs.StableHLO.SHlo.rowDenseWeightGradBBf16 rnd xName x else Proofs.StableHLO.SHlo.rowDenseWeightGradB xName x
Instances For
One frozen-statistic BN site at the per-example index — bnPerChannelEvalF on xin, with
the running statistics arriving as graph inputs %{statP}mu / %{statP}var. The BN site of the
per-example eval chains (r34FwdChain, r50FwdChain, mnv2FwdChain), which write
@resnet34_fwd_eval, @resnet50in_fwd_eval and @mobilenetv2_fwd_eval: frozen-stat affine BN
performs no reduction, so these forwards are class-batch-independent and partner the batch-BN
train steps whose EMA'd μ/σ² they read. There is deliberately no training arm — the per-example
training BN those chains once also emitted (bnPerChannelF) is not the BN any shipped train
step uses.
Equations
- One or more equations did not get rendered due to their size.