All pages
defrun
defrun is the run configuration the file owns: how many steps, how a step is
split, the precision, the seed, and how often to checkpoint and sample
diagnostics. It is required, once.
(defrun :steps 300 :microbatches 4 :checkpoint-every 100 :precision :f32 :seed 1)| keyword | default | meaning |
|---|---|---|
:steps | 1 | target number of completed optimizer updates; nonnegative. 0 skips training and runs the final inline evaluation passes |
:microbatches | 1 | microbatches per optimizer step; 1 to 4294967295. Gradients accumulate over them. Under several GPUs the count must divide by the device count; see devices |
:checkpoint-every | none | steps between checkpoints, at least 1; without a checkpoint location nothing is written. See checkpoints |
:precision | :f32 | :f32 or :bf16; anything else is E-CONTRACT-003. See numerics |
:gradient | :reverse | :reverse differentiates the objective; :forward-query estimates it from two evaluations; :forward-credit uses forward-computed local scores; see forward-query training and forward-credit training |
:query-radius | 1e-3 | with :gradient :forward-query, how far each evaluation moves every parameter element; positive, and large enough for f32 to hold |
:seed | 0 | nonnegative; mixed into every random stream when the run executes the graphs; see determinism |
:diagnostics | none | globs over diagnostic names, ["attention/*" "logits/*"]; only these ever compute |
:diagnose-every | 1 | a sampled step is a multiple of this; at least 1 |
:diagnose-first | 0 | nonnegative; the first this many steps are sampled too, and so is the last |
:guard-finite | false | stop, committing nothing, when a proposed parameter or state is not finite; see the finite guard |
:clip-grad-norm | none | positive finite number; limit the global L2 norm of the step's gradients before optimizer updates; see below |
:evaluate | :inline | where the passes run: :inline in the loop, :offline from the checkpoints with sexpgpu evaluate; see evaluation |
:ema | none | a decay, at least 0 and below 1: the passes read an exponential moving average of the trained weights; see below |
:ema-debias | false | with :ema, true averages only the trained weights after each step, leaving out the initial weights; see below |
Overrides
| file key | replaced by | recorded as |
|---|---|---|
:steps | --steps N | knob steps, source override |
every pass's :every | --eval-every N | knob eval-every, source override |
:diagnostics | --diagnostics, then SEXPGPU_DIAGNOSTICS | knob diagnostics, source override |
:evaluate | --evaluate inline|offline | knob evaluate, source override |
:seed | --set seed=N, when the file declares no seed knob | knob seed, source set |
Everything else, :microbatches, :checkpoint-every, :precision, is the
file's alone. There is no defrun key for the device, the metrics target, the
checkpoint location or the resume; those are the environment's. See
environment.
Values can be knobs: (defrun :steps steps :microbatches microbatches).
--steps binds a knob named steps too, so the file reads the length it runs;
see the knob steps.
:microbatches, :precision, :gradient, :query-radius, :diagnostics,
:guard-finite, :clip-grad-norm, :ema and :ema-debias change the compiled
graphs. The other keys are recorded in the setup beside them
(how it works), so another seed or another
length of run compiles to the same IR.
Global gradient clipping
:clip-grad-norm c limits the L2 norm over all trainable parameters' gradients
to c. Omit it to disable clipping.
(defrun :steps 50000
:clip-grad-norm 1.0
:diagnostics ["optimizer/grad-norm"]
:diagnose-every 200)The norm is computed once per optimizer step, after microbatch accumulation and
distributed gradient reduction, before any optimizer reads the gradients. Every
gradient is multiplied by min(1, c / norm); zero gradients stay zero. Tied
parameters count once, frozen parameters do not contribute, and all optimizer
groups share one limit. The optimizer's moments receive the clipped gradients.
Weight decay and the optimizer's final update are not norm-limited.
While clipping is enabled, select optimizer/grad-norm to report the norm
before clipping as diagnostics/optimizer/grad-norm on sampled steps. It is one
global value, tagged split=train, without an optimizer-group param tag.
Changing diagnostic selection or sampling does not change clipping.
The norm sums squares in f32, or f64 when a gradient is declared f64; the
scaled gradients retain their declared dtypes. Clipping does not repair
non-finite gradients. Use :guard-finite true to stop on non-finite proposals.
Weight averaging
:ema decay keeps an exponential moving average of every trainable parameter,
the ones a library model declares included, and evaluates it in place of the
trained weights:
(defeval test :loader test-loader :every 500)
(defeval test-raw :loader test-loader :every 500 :ema false)
(defrun :steps 50000 :ema 0.999)- Each average is a model buffer at
ema.followed by its parameter's path, somodel.head.weightis averaged atema.model.head.weight. It starts at the parameter's initial value, loaded or not, and after every optimizer step becomesdecay * average + (1 - decay) * parameter. The average of a parameter declaredbf16is computed inf32and stored asbf16, so with a decay near 1 it moves only when the parameter is far from it; declare a parameterf32to average it finely. Under:precision :bf16trained parameters stayf32. - Frozen parameters and
defbufferbuffers are not averaged. Training, optimizers and buffer updates read the trained weights; only evaluation and the model run alone read the averages. - Every pass reads the averages, inline and with
sexpgpu evaluate. A pass declared with:ema falsereads the trained weights, so one file can report both. A generator reads the weights of the call it runs for: the trained weights before a training call, and before a pass the weights that pass reads. - A checkpoint's model, which
exportwrites andserveruns, reads the averages, so it is the model the passes scored. Both take--trainedfor the trained weights instead. - The averages take as much memory as the trainable parameters. A checkpoint
stores them with the parameters, and a resume restores them. A resume that
turns
:emaon or off is refused, since the averages would be new or gone; a resume with another decay continues from the stored averages. :emacan be a knob. A decay of 1 or more, or below 0, isE-CONTRACT-003, and so is a top-level model bound toema, whose paths the averages would take, and:ema-debiaswithout:ema.
Early steps
After n steps the initial weights still make up decay^n of each average, so
early passes read mostly the initialization: with :ema 0.999, 61% at step 500,
37% at step 1,000 and 5% at step 3,000. A pass reading the averages can then
score far below an :ema false pass of the same step without anything being
wrong with training. As a rule, the averages say little before about
3 / (1 - decay) steps.
:ema-debias true leaves the initial weights out:
(defrun :steps 50000 :ema 0.999 :ema-debias true)- After step
neach average is the decay-weighted mean of the parameter after steps 1 ton,sum((1 - decay) * decay^(n - k) * parameter_k) / (1 - decay^n). The update at stepniskeep * average + take * parameter, withtake = (1 - decay) / (1 - decay^n)andkeep = 1 - take, so after step 1 the average is the trained parameter, and from about3 / (1 - decay)steps on it updates as plain:emadoes. The initial weights, zero or not, have no share after the first step; before it, as at step-zero evaluation, the averages are the initial weights. nis the run's optimizer step, which a resume and a fork from a checkpoint continue together with the stored averages. A run that loads its weights starts again from step 0, and averages what it trains from them.- The averages are still buffers holding weights: passes,
export,serveand--trainedread them as before, and abf16parameter's average is stored asbf16as above. - A resume may turn
:ema-debiason or off, or change the decay; it continues from the stored averages with the new update. Late in a run the two updates are the same.
Zero steps
:steps 0 and --steps 0 perform no optimizer update but still need the full
run contract: the training graphs, the optimizer states and the training loader
are prepared. On a fresh run each inline pass runs once at step 0, subject to
signals and the time budget; the curriculum does not run,
training counters stay at zero, and a configured checkpoint location receives
step-00000000. Offline runs evaluate nothing, as usual. To evaluate an
existing checkpoint without the training setup, use
sexpgpu evaluate.
The step target counts updates already completed in a resumed checkpoint, so a
zero-step resume keeps the checkpoint's step and counters, runs no update, and
evaluates at that step. Negative :steps are E-CONTRACT-003.
Step numbering
A training step's number is the update being computed, so the first training
step is step 0, and an evaluation or a checkpoint at step n has n completed
updates behind it. A loop that numbers training metrics by completed updates
would call step 0 update 1.
Related: diagnostics sampling, run.
Select evaluation values
:evals is a list or vector of
eval-pass values, evaluated after all
top-level definitions. Nil items are omitted. Selected passes follow legacy
defeval declarations. :drop-evals ["name"] removes declared passes after
selection. Names must be unique before removal. Both lists accumulate when a run
extends a base; other defrun settings replace the
inherited setting only when written.