All pages
Checkpoints and resume
A run checkpoints to a location, and continues from its newest checkpoint with
--resume latest. A signal stops it at a step boundary with a checkpoint of
that step, so a preempted run loses nothing.
sexpgpu run my-run.sx --checkpoint-dir o41://my-team/my-run --resume latestLocations
--checkpoint-dir or SEXPGPU_CHECKPOINT_DIR is one of:
| location | where | credentials |
|---|---|---|
/path/run | a directory on this machine | none |
s3://bucket/prefix | an S3-compatible bucket | S3 credentials |
gs://bucket/prefix, az://account/container/prefix | a GCS or Azure bucket | the usual GOOGLE_*, AZURE_* variables |
o41://<artifact> | an artifact of 041 Artifacts, placed in your bucket nearest the machine | O41_ARTIFACTS_API_KEY; see environment |
Every kind of location holds the same layout. Credentials are checked, and the location opened, before the first step, so a run never finds out hours in that it cannot write.
Checkpoints
- One checkpoint per step,
<location>/step-<8 digits>/and its files. - Written every
defrun :checkpoint-everysteps and once more after the last step; without a location nothing is written. - A periodic checkpoint is the step as it ended. One due where an evaluation is
due too is written before that evaluation and any curriculum move it makes, so
an evaluation that fails leaves the step saved, and a resume from it runs the
evaluation and the move again. A failure inside a step writes no checkpoint of
it; the resume repeats the steps after the last one. The last step's
checkpoint is written before the final passes, which move no curriculum, so a
final pass that fails leaves the trained parameters saved;
--resume latestthen runs the final passes again without a step, andsexpgpu evaluateruns the ones you pick. - The files go up first, then
_manifest.json, which lists them and makes the checkpoint count: one cut off by a machine going away has none and is passed over for the one before it. - The run copies a checkpoint off the device and trains on while its files go up. The next checkpoint, the end of the run and a stop by a signal wait for them to be stored.
- Every checkpoint is an
annotationin the metrics stream once it is stored, at the step it holds, with thesecondsfrom the first tensor leaving the device to the last byte stored, and from then on the status file'scheckpoint. Ono41://it also says where the checkpoint was placed,checkpoint <path> in aws us-east-1 (region match), withplacement(locationid,cloud,region, andmatch:region,cloudorfallback) in its metadata, and a second line andwarningwhen it went somewhere other than where the run is.
Resume
A location holds one run. --resume or SEXPGPU_RESUME says how this run
relates to it, all of it checked before the first step:
| value | the run | with a location that has checkpoints |
|---|---|---|
| none | starts fresh | refused, E-CKPT-001 |
latest | continues the location's newest checkpoint, or starts fresh when it has none; needs a location | continues it |
<location>/step-<n>, any kind of location | starts from that checkpoint, a fork; its first checkpoint records the path it came from | continues it when it holds this fork, otherwise refused, E-CKPT-001 |
sexpgpu run: E-CKPT-001: /tmp/my-run has checkpoints already: continue them with --resume latest, or start or fork into a new, empty --checkpoint-dirA location holds a fork when its first checkpoint records that same
<location>/step-<n>, as written, as the path it came from. The fork given
again, with the same --resume and --checkpoint-dir, continues the newest
checkpoint there as --resume latest would, so a restarted fork goes on where
it stopped. A location with any other checkpoints, another run's or a fork of
another checkpoint, is refused, and so is the location the checkpoint itself is
in.
A fork may add, drop, reorder or change training loaders. Each loader of the run
continues the checkpoint's loader that reads the same fields (name, column,
dtype, shape, pad) in the same batch size, from that loader's saved position and
sources. A loader with no match starts fresh at the run's current stage. Field
names are unique across a run's loaders, so one loader never continues another's
cursor. The resumed from annotation reports each loader that starts fresh,
continues a loader at another index, or is dropped:
resumed from o41://my-team/my-run/step-00007000
knob reward-share 0 -> 0.5
training loader 1 starts freshThe fork's checkpoints record that path and what each loader took, under fork
in experiment.json. Weights, optimizer states, step, stage, records and
counters carry over as on any resume. A run with
persistent generator slots forks only
with the checkpoint's loaders unchanged (E-GEN-008), since its slots hold
their rows. Once the fork has written a checkpoint, continuing it takes its
loaders as written.
A <location>/step-<n> without a checkpoint location continues from it and
writes no checkpoint. One that is not there is an error, and so is a location
that cannot be read, never a fresh start. Put --resume latest, or the fork's
--resume <location>/step-<n>, on the command line from the first launch; the
same command then starts, restarts and continues.
On o41:// opening the location takes it over: a run still writing there, such
as the one a preempted VM left behind, stops at its next checkpoint and exits
1, without saving it:
sexpgpu run: E-CKPT-002: another run opened o41://my-team/my-run and continues it (...); this run stops without saving step 510A directory or a raw bucket has no such fence: two runs given one location with
--resume latest both write to it.
On several nodes node 0 alone writes checkpoints and, on a resume, reads the tensors and sends them to the other nodes, so a resume across clouds moves the bytes across once. The other nodes read the small files themselves.
-
Refused: a parameter that is new, gone, or another shape or dtype, or that trains where it was frozen or the reverse; a different device or node count (
E-DP-002); when continuing a location, training loaders of another number, or one whose fields (name, column, dtype, shape, pad) or batch size moved, since each loader continues from its checkpoint with the sources it was reading (a fork starts such a loader fresh instead); a recorded choice this run cannot take (E-CHOICE-001); a:loadfile whose bytes are not the ones the checkpoint's run read (E-LOAD-001), told by the tensor and the file's size and version, its ETag on S3 or the SHA-256 of a local file:E-LOAD-001: a loaded parameter's file is not the one the checkpoint's run read: model.teacher.q: q_proj.weight in s3://my-bucket/llama/model-00001-of-00002.safetensors, 4976698672 bytes, "9b2cf535f27731c974343645a3985328-149" -> ... restore that file, or start the run again -
Pinned: a resume takes the choices its checkpoint recorded, the stacking, the convolution engines and the recompute budget, instead of choosing again, so a run that moved to another machine keeps its summation order.
--choices freshlets it choose, and--choices missinglets it choose only what the checkpoint does not record; see determinism. -
Allowed, and recorded: edited sources or other knobs. The
resumed fromannotation names each file and knob that moved, one line each. A run resumed after a comment was added to its file, with--set lr=0.25 --steps 6:resumed from /tmp/my-run/step-00000004 source my-run.sx 91d77bdc76be -> b05c928e631c knob lr 0.5 -> 0.25 knob steps 4 -> 6The same bytes at another path, a bundle's copy of a
:loadfile, sayload <param path> <old> -> <new>. A bundle's sources are its own paths and rewritten files, so resuming a bundled run's checkpoint from the unbundled file lists each of them.
A resumed run reports into the same metrics experiment; see events.
A resume notes the first training loader whose file list or recorded manifest selection differs. It continues the saved sources and cursor; current source changes are ignored. The notice appears on standard error and in Metrics. This check does not inspect data bytes or reload manifests.
What a checkpoint holds
A checkpoint promises three things: the run continues from it, its weights load into the same model somewhere else, and the model runs from it without the sources. It holds exactly that:
params.safetensors one tensor per parameter but a frozen one read from a
file, keyed by its dotted path
states.safetensors one tensor per optimizer state, "<param path>/<state>"
state.json step, stage, records, counters, each training loader's
position, seed
experiment.json the setup: the source files and their sha256, the
variant, every knob with its value and source, and
what the run was bound to, its steps, seed, cadences,
each loader's stages and each `:load`; each
parameter's path, shape, dtype, trainable and tags, and
for a `:load` parameter the file it was read from,
pinned; each parameter's state names, the counters,
precision, device count, the sexpgpu version, the
executable's SHA-256 and the program's digest, and the
choices the run made, the run's slug, and whether it
is the checkpoint of the run's last step (`finished`)
model.json the model alone, compiled, which `sexpgpu serve` runs
with these weightsmodel.json is there when the model runs alone; see
running a trained model.
The rule for frozen parameters:
one made by its initializer is in params.safetensors like any other, so its
random features load elsewhere and a resume takes them back. One read from a
file with :load is not copied: its experiment.json entry has a load object
naming the file (the shard, for an index), the tensor, and the file's size and
version, its ETag on S3 or sha256:<hex> of a local file, and a resume reads
that file again and refuses another one (E-LOAD-001). A trainable parameter
that started from a file has a load too, and is in params.safetensors with
what it has learned, as is a buffer loaded by with-loaded ... :buffers true
with what its updates made of it:
{
"path": "model.teacher.q",
"shape": [4096, 4096],
"dtype": "f32",
"trainable": false,
"tags": [],
"load": {
"uri": "s3://my-bucket/llama/model-00001-of-00002.safetensors",
"tensor": "model.layers.0.self_attn.q_proj.weight",
"size": 4976698672,
"version": "\"9b2cf535f27731c974343645a3985328-149\""
}
}Every parameter root is in a checkpoint by the same rule,
under its own name: model.* first, then a second root such as a with-loaded
teacher as teacher.*, in experiment.json's params and, when it trains or
was made by its initializer, in params.safetensors. A frozen teacher read from
a file is named, not copied: each of its parameters is under loaded with the
tensor its name function produced.
loaded
teacher.embed teacher.embed.weight in teacher.safetensors, 2216 bytes, sha256:f2fb0b73...
teacher.head teacher.head.weight in teacher.safetensors, 2216 bytes, sha256:f2fb0b73...
params.safetensors 2 tensors
model.embed F32 [32, 8]
model.head F32 [8, 32]F64 parameters and optimizer states are stored as safetensors F64, every bit
preserved; a checkpoint's dtype must match the declared one, and loading never
narrows F64 values. Model buffers declared with
defbuffer are stored with the parameters under their model paths, marked as
buffers, and a resume refuses to change that. Their updates commit after the
optimizer and before a checkpoint, so the next step reads the same state after a
resume as without one. The averages of
defrun :ema are buffers too, at ema. and their
parameter's path.
experiment.json is a few kilobytes for any model. The compiled graphs and
kernels are not in a checkpoint: a resume compiles them again from the sources.
A bundle carries the binary, sources and local data to another
machine. It does not guarantee identical numerical results.
What evaluate reads
sexpgpu evaluate reads a checkpoint as a
resume does, less: experiment.json, to compile the file under its selection
and any --set, verify the parameters and the :load files, take its choices
and find the Metrics experiment by slug; state.json, for the step, the stage
and the counters a pass reads; and params.safetensors. It never reads
states.safetensors, never opens the training loader, and writes nothing into a
checkpoint. A frozen :load parameter is read from its pinned file, and buffers
are restored, never updated.
evaluate --follow keeps one note of its own beside the step-<n> checkpoints,
evaluated.json: each pass's evaluated steps, a pass under a --set by its
name and set, rewritten whole after each pass
once its numbers have reached the metrics target. latest and --resume never
read it; delete it to evaluate again. A step a
--from-step bound skipped is never
in it. The passes' record tables go under records/
beside the checkpoints too, unless --records says where; nothing reads them
back.
{
"eval": [250, 500],
"probe": [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]
}A follower that dies after its numbers are delivered and before the file is rewritten evaluates that step again when restarted, and Metrics keeps both points. Repeated evaluations need not produce identical values. A step is never marked without its numbers delivered.
A follower stops after the checkpoint whose experiment.json has
"finished": true. It says training reached its last step (step equal to
:steps), nothing about what metrics were delivered.
Inspecting one
sexpgpu checkpoint <location>/step-<n> prints what a checkpoint is without
loading it: the identity from experiment.json, the step from state.json, and
every tensor's name, dtype and shape from the two safetensors headers, read by
range, so a bucket or o41:// costs a few small reads. A path without a
manifest is not a complete checkpoint and is an error.
$ sexpgpu checkpoint /tmp/my-run/step-00000004 | head -12
checkpoint /tmp/my-run/step-00000004
step 4
sexpgpu 0.1.0
variant -
devices 1
precision f32
seed 7
counters tokens
sources
<core> e4f1b2681fd7e21aa5cfe45f6f1b42618f70206f8af4becbf5adb1472edd09d9
my-run.sx 1a74f5546c852533510ab69ca07859527eb813001fc991db683c1ed1013f1117
...Then the knobs, the choices, loaded with each :load parameter's file,
tensor, size and version, and each tensor file with one line per tensor; a
parameter's line ends with frozen when it does not train and with its tags. A
frozen parameter read from a file is under loaded and in no tensor file.
loaded
model.teacher.q model.layers.0.self_attn.q_proj.weight in s3://my-bucket/llama/model-00001-of-00002.safetensors, 4976698672 bytes, "9b2cf535f27731c974343645a3985328-149"
params.safetensors 33 tensors
...
model.noise F32 [32] frozenLoading one elsewhere
The safetensors files are the interchange format. A bf16 parameter is stored
as f32, and experiment.json's dtype says what it means:
import json
from safetensors.numpy import load_file # safetensors.torch.load_file for tensors
step = "/tmp/my-run/step-00000004"
identity = json.load(open(f"{step}/experiment.json"))
params = load_file(f"{step}/params.safetensors") # {"model.net.embed.table": array, ...}
states = load_file(f"{step}/states.safetensors") # {"model.net.embed.table/m": array, ...}
for declared in identity["params"]:
if declared["path"] not in params: # frozen and read from a file
source = declared["load"] # {"uri", "tensor", "size", "version"}
continue
assert list(params[declared["path"]].shape) == declared["shape"]From a bucket, the same keys under the location; an o41:// artifact is a
prefix of a bucket of yours too, and its versions/read API signs a URL for
each file. Read the bytes and give them to safetensors.numpy.load:
import boto3
from safetensors.numpy import load
body = boto3.client("s3").get_object(
Bucket="my-bucket", Key="runs/my-run/step-00000004/params.safetensors"
)["Body"].read()
params = load(body)Checkpoints of other versions
A version reads the checkpoints earlier versions wrote, so a run resumes, evaluates and forks on a newer version than the one that trained it. A checkpoint of a format this version does not read is refused by every verb that reads one, with the version that wrote it and the line that installs that version beside this one:
sexpgpu run: E-CKPT-003: o41://my-team/my-run/step-00011000 was written by sexpgpu 0.1.1 in a checkpoint format this version does not read; resume or evaluate it with sexpgpu 0.1.1, installed beside this one:
curl -fsSL https://sx.041.io/install.sh | SEXPGPU_VERSION=0.1.1 SEXPGPU_INSTALL_DIR="$HOME/.local/sexpgpu-0.1.1" sh
or train the run againThe installed binary resumes, evaluates and prints the checkpoint, given a run
file it compiles. Run it with SEXPGPU_AUTO_UPDATE=0: otherwise a version that
updates itself replaces itself with the newest
release after its first command.
SEXPGPU_AUTO_UPDATE=0 $HOME/.local/sexpgpu-0.1.1/sexpgpu run my-run.sx --resume o41://my-team/my-run/step-00011000Signals
SIGTERM, SIGINT (Ctrl-C) or SIGHUP (the terminal went away) stops a run at
the next step boundary:
- the step in flight finishes; no further step is taken. An evaluation pass in flight stops at its next batch, reports nothing and is run again by the resume (on several GPUs it finishes). A step whose generator is still making its records is abandoned before its next trip (on several GPUs it finishes): no parameter has changed, its batches are given back and its counters undone, and the resume takes the abandoned step again;
- the metrics get
interrupted by <signal> at step <n>, withwhile generatingafter an abandoned step or pass; - a checkpoint of that step is written when there is a location;
- the stream is drained without
done, and the status file readsinterrupted; - the process prints
sexpgpu run: interrupted by <signal> at step <n>and exits128 + n:129,130,143.
A second SIGTERM or SIGINT ends the process at once, without any of it. A
SIGHUP never does, because a machine shutting down sends SIGTERM and
SIGHUP together. A run killed outright (SIGKILL, a second signal, the
machine gone) writes nothing more: its status file keeps reading running, and
its resume repeats the steps after its last checkpoint.
A spot VM's shutdown or a job runner's cancel gives the process a SIGTERM and
some seconds; a checkpoint larger than that allows is passed over. See
preemptible jobs.
The finite guard
(defrun ... :guard-finite true) checks every proposed parameter and optimizer
state for NaN and infinity on the device before any of the step is committed.
When one is not finite the run stops with the step, the parameter and the state
in the error, which the status file and a last failed: <error> annotation
repeat. Nothing of that step is committed, so the last checkpoint is intact and
a resume from it replays the step.
sexpgpu run: step 2: the proposed parameter of model.b has 1 values that are not finite; nothing was committedIt is off by default because it adds a reduction per parameter per step and a read of every result. A guard in an optimizer body is read with it, before anything is committed.
Session time budgets
A time budget stops at complete optimizer steps and writes their state when there is a checkpoint location. The checkpoint holds no deadline: a resume starts a new session, compilation and restore included, and its summary counts only that session's work.
Related: run, bundle, the status file.