All pages
Working as an agent
Every verb answers in a form a program reads (JSON with --json where there is
structure; a run's progress goes to standard error, its numbers to the metrics
target), fails with a stable exit code, and never asks anything interactively.
The loop
sexpgpu new my-run.sx --from base.sx --knob width=512 # a new experiment starts from a run, never from nothing
sexpgpu fmt my-run.sx
sexpgpu variants my-run.sx # discover declared selections
sexpgpu check my-run.sx --variant smoke --steps 3 --json
sexpgpu explain my-run.sx --variant smoke --steps 3 --json
sexpgpu diff base.sx my-run.sx # the intended change and nothing else
sexpgpu rrun my-run.sx --variant smoke --steps 3 --gpu A100 --spot --checkpoint-dir o41://my-team/my-smoke
sexpgpu sweep my-run.sx lr-scan --dry-run # the points of a declared grid
sexpgpu rrun my-run.sx --sweep lr-scan --gpu A100 --spot --queue none --checkpoint-dir o41://my-team/lr-scan- Plan in the file. Every quantity the experiment may vary is a knob, and
so is every choice of structure: a knob holds any value, and a compile-time
condon it selects a block, a loss or an optimizer. Named configurations are variants; grids are sweeps. Change a knob with--setrather than editing the file, and add a knob rather than copying the file: one file that answers many questions is the unit of work, and a second file is for a change no knob expresses. See knobs. - Check until clean.
check --jsonreturns an array of diagnostics, each withcode, message, resolvedfile:line:col, notes and call trace. Look the code up in diagnostic codes; most carry a fix. See check. - Verify the science.
explainstates what will run: the selection with each knob's source, every parameter with its shape and update group, the optimizer's constants, records and counters per step, the evaluation cadence, precision and peak memory. Compare it with the plan before paying for a GPU. See explain. - Verify the change.
diffprints only what differs between two runs, or two selections of one, by section. A diff with more rows than the intended change is a mistake. - Smoke on an allowed machine. Follow the workspace's execution rules; use
a short
rrunjob on shared development machines. Where local execution is allowed, a deliberately tiny interpreter smoke can userun my-run.sx --variant smoke --steps 3 --device cpu. A small step count alone does not shrink model shapes or evaluation work. See devices. - Launch the checked selection. Keep the same
--variant,--setand--stepsoncheck,explainand the smoke. Check and explain the full selection separately before launching it.rrunbundles the run and launches it on rrun, which picks the cheapest GPU and runs it again elsewhere after a preemption, the run continuing from its checkpoints. It prints the job's id (--jsonas JSON), ando41-rrun logs <id> -ffollows the job. See run on rrun. - Run a grid on many machines at once. Declare the grid as a
defsweepand launch it withrrun --sweep <name>: one bundle is uploaded once, and every point is its own job on its own machine, with its own slug and its own checkpoints.--dry-runlists the jobs first;--jsonlists each point with its job id. The same command given again launches only the points without a job that is still queued or running, so it also finishes a launch that failed midway.sexpgpu sweeptrains the same points one after another in one process. Explore with many short runs, then confirm the best with long ones. See a sweep on rrun.
Reuse a run and its passes
Before: generate a second full run file and substitute (grid false) with
(grid true). After: keep the base and write only:
(extends "./base.sx")
(defknobs (grid true))Use defvariant for knob combinations in one file, defsweep for a grid, and
extends for a separate file that inherits declarations. Defaults do not force
overrides of checkpoint-recorded knobs. Compare the effective program and each
declaration's origin with sexpgpu diff base.sx grid-read.sx --json.
Before: one defeval per split, written out or generated. After: a function
returns (eval-pass name :loader (dev-loader split) :batches 2), and
defrun :evals selects a list built with map or filter. Attach a
generator value to the pass when it makes records. Building a value schedules
nothing until selected. See the run file and
evaluation values.
Macros are the preferred way to generate code: a table of arms that expands to
defvariant forms, a family of defmodel or defoptimizer definitions, a
protocol several run files share. Wherever declarations repeat or follow a
pattern, write the macro that generates them; the table or rule is the readable
source, and its expansion is not. Functions are for computing the values the
generated code runs on — the evaluation passes above are values, so they are
built by functions, and a macro may still generate or assemble them. See
generated declarations.
Before inventing an API
Use sexpgpu docs search "<operation or diagnostic>" to find the relevant page
before translating an API from another tensor library or Lisp:
| task | SexpGPU form or reference |
|---|---|
| call a function held in a variable | (f x); one namespace, no funcall or #'; use true, false and nil for literals (Lisp) |
use mean, argmax, softmax or logsumexp | import the names from sexpgpu/nn; remove imports no longer used (require) |
| pairwise tensor extrema | (maximum a b) or (minimum a b); one-tensor max and min reduce (tensors) |
| slice a tensor | (slice x axis start stop) with an exclusive stop; shapes broadcast from the right (tensors) |
| declare a variant or string override | (defvariant smoke (width 32)) before defknobs; --set 'data="s3://bucket/manifest.json"' keeps a string a string (knobs) |
| contract tensor axes | (einsum "bhqd,bhkd->bhqk" q k), not transpose and matmul plumbing; ellipses broadcast; a label occurs once per operand (einsum) |
| combine boolean masks | (logical-and (>= c 0) (< c cc)), logical-or, logical-not, logical-xor; and, or, not and if run at compile time and reject tensors (boolean tensors) |
| infer, add, remove or reverse dimensions | (reshape x [batch -1]), (unsqueeze x :axis -1), (squeeze x :axis 1), (stack [a b] :axis 0), (flip x :axes [0 1]) (tensors) |
| split, permute or merge named axes | (require "sexpgpu/axes" rearrange), then (rearrange x [batch time (heads depth)] [batch heads time depth] :sizes ((heads 8))) (axes) |
repeat a weight-tied tensor cell n times | (scan (lambda (state unused index) (cell state)) initial nil :length n) traces the cell once and shares its parameters, where dotimes unrolls it; keep dotimes when the index decides shapes or forms (scan) |
Tensor kinds promote upward, so a mask can multiply a float tensor directly:
(* (cast mask :float) x) ; explicit spelling
(* mask x) ; the same kind conversion, inserted automaticallyThe same applies to integer counts mixed with floats and to where branches.
Same-kind width differences still need an explicit cast; see
promotion.
Choose the smallest command that answers the question. eval --expr FORM checks
compile-time values; probe --expr FORM computes small tensors and
derivatives without a training contract. check expects a complete experiment:
validate a library through a run that imports it, rather than adding a fake
training contract to the library. A missing model, train-loader or defrun
is often a sign that the wrong file was checked.
A local require path starts with ./ or ../ and resolves relative to the
file containing it. See require.
Static check does not open dataset records. After changing loaders or data
preparation, use check --data with the same
selection and storage credentials to catch missing files and malformed sample
records before a remote launch. It samples data; it does not validate every row.
Reading a running or finished run
| want | read | never |
|---|---|---|
| where is it now | the status file, SEXPGPU_STATUS | grep the log for a step number |
| every number | the JSONL events, filter "kind":"metric" | parse the progress lines |
| the final result | run --json, one summary object on standard output | parse the done: block |
| did it fail | the exit code, then state and error in the status file | look for "error" in text |
The progress lines and the done: block are for humans and are not a contract.
Those sources describe one run. To compare runs, send every run's numbers to one metrics target and compare them there, rather than collecting summaries from each run's output.
Exit codes
0 worked, 1 the thing failed (diagnostics, a run that died, a doctor that
says no), 2 the command line was wrong, 128 + n stopped by signal n. See
the command line.
Rules that keep a run honest
- One selection names one run: the slug is the file stem, the variant and every
--set, so metrics never mix two experiments. Past 200 characters it ends in a hash of the whole;checkprints it. See run. --stepsand--eval-everyare recorded as overrides; a shortened run says so everywhere.--stepsalso binds a knob namedsteps, so what the file computes from it follows the shortened run; see the knobsteps.- Diagnostics never change a training number. Turn them on freely; see diagnostics.
- Format every file you write:
sexpgpu fmt file.sx. See fmt. - Put
--resume lateston a remote command line from the first launch, with a checkpoint location;latestneeds one. - A checkpoint location holds one run. Running again into a location that has
checkpoints, for example by reusing one
SEXPGPU_CHECKPOINT_DIR, is refused (E-CKPT-001): give a new--checkpoint-dir, or continue with--resume latest. A fork given again, the same--resume <location>/step-<n>into the location it wrote, continues there; see resume.
Reporting a problem
When a verb does what its page says it should not, or a diagnostic or a page
leaves you guessing, report it:
sexpgpu feedback --bug "<what you ran, what happened, what you expected>", or
sexpgpu feedback --bug - with the report and its log on standard input. The
report carries only the binary's version and the system, so say the command, the
settings it ran with (never a key) and the error; see feedback.
Reading these docs
Read only the pages you need: the index lists every page with one
line each. Before reading pages whole, run sexpgpu docs search "<question>"
for the pages that answer it; see docs search. On the
website, fetch /docs/<page>.md for markdown, or send Accept: text/markdown
to any page; /llms.txt is the index and /llms-full.txt is every page in one
file.
Related: how it works, the command line.