All pages
Knobs, variants and sweeps
A run declares everything it may vary, in itself. Every tool selects a point before the file is read, and the selection is recorded in the setup, the metrics metadata, the status file and the run's slug.
(defvariant small (layers 2) (width 128))
(defvariant smoke (layers 2) (width 128) (seq 64))
(defknobs
(lr 0.0015 "peak learning rate") ; name, default, optional doc
(layers 4)
(optimizer :adamw)) ; any ordinary value
(defsweep seeds (seed [1 2 3]))
(defsweep deep-lr :variant small (lr [0.002 0.004]))defknobs
(defknobs (name default ["doc"]) ...) binds each knob as an ordinary top-level
variable, so the rest of the file reads lr and knows nothing about where the
number came from. A knob is declared once (E-KNOB-001) and before it is used;
a knob read before its defknobs is E-EVAL-003. A knob the file never reads
is E-KNOB-002: setting it with --set, a variant or a sweep would change
nothing, and the slug would say it did. Reading it anywhere counts, on any
branch.
defvariant
(defvariant name (knob value) ...) is a named set of overrides.
- Declare variants before the first
defknobs. Late or duplicate variants areE-KNOB-006. - Override expressions evaluate once, when the declaration executes, in the declaring lexical environment. Macros and loops may generate variants; see macros.
- A variant may only set declared knobs (
E-KNOB-003), checked after all declarations have executed. - Variants do not compose: a selection names one or none.
defsweep
(defsweep name [:variant v] [:rows rows] (knob [values...]) ...) is a cross
product. :variant names the base variant of every point. seed is a legal
axis in every file, because every run has defrun :seed.
:rows evaluates to a nonempty sequence of property lists, each setting
correlated knobs by keyword name; a knob a row omits keeps its variant value or
default, and an empty row selects that baseline. Every axis crosses every row.
Rows vary slowest, then the axes in declaration order, the last fastest.
(defknobs (width 32) (lr-scale 1.0) (data-seed 1) (seed 1))
(defsweep confirmation
:rows [[:width 32 :lr-scale 1.0 :seed 4 :data-seed 4]
[:width 64 :lr-scale 2.0 :seed 5 :data-seed 5]])
(defsweep paired ; rows are ordinary Lisp data
:rows (map (lambda (s) (list :seed s :data-seed s)) (range 4 12))
(lr-scale [0.5 1.0 2.0]))- A row names each knob at most once; rows may set different knobs. A knob is in rows or in one axis, never both. A repeated axis is an error.
- A sweep name declared twice is
E-KNOB-009. - Two equal rows, whatever their key order, or an axis listing one value twice,
is
E-KNOB-007: the two points would be one run under one slug.
Run one with sexpgpu sweep, its points one after another in one
process, or with sexpgpu rrun --sweep, every
point as its own job on its own machine.
The selection
| source | flag | wins over |
|---|---|---|
--steps N | once; only the knob steps | --set, the variant and the default |
--set knob=value | repeatable; last value for a knob wins | the variant and the default |
--variant name | once | the default |
| the declared default | — | — |
Every source is recorded per knob: default, variant, set, and override
for --steps, --eval-every, --evaluate and --diagnostics. A --variant
or --set naming something the file does not declare is E-KNOB-004 or
E-KNOB-005. In a file that declares no seed knob, --set seed=N sets
defrun :seed and takes a nonnegative integer literal (E-KNOB-008). How the
selection meets the environment and defrun is in
environment.
The knob steps
--steps N is the run's length, and a knob named steps is bound to N as
well, recorded once, source override. Anything the file computes from the
knob, a schedule's decay start or an averaging window, then agrees with the
length the run trains:
(defknobs (steps 300) (tail 0.2))
(defvar tail-start (* (- 1.0 tail) steps)) ; 4.8 under --steps 6
(defrun :steps steps)When defrun :steps does not read the knob as it is,
(defrun :steps (* 100 steps)), the knob and the run would disagree, so
--steps in such a file is E-KNOB-010; give a knob that counts something else
another name. ctx :steps is the same number inside a traced function; see
ctx.
check, explain, diff, watch, ir, eval, probe, run, variants
and bundle take the selection, and evaluate takes --set on top of its
checkpoint's; see the command line.
Seeing them
$ sexpgpu variants my-run.sx
knobs:
lr 0.0015 peak learning rate of the block matrices, the default group
layers 4 transformer blocks
width 256 model width
seq 1024 sequence length in tokens; a window holds seq + 1
seed 1 the run seed; every random stream folds it in
variants:
small layers=2 width=128
smoke layers=2 width=128 seq=64
sweeps:
seeds 3 points over seedChange a knob with --set or a variant; copy the file with
sexpgpu new only when the change is not a knob.