/reactantnitro-jl:reactantnitro-checkpoint-resumefrom reactantnitro-jl
Configures checkpointing and resume for ReactantNitro runs: Checkpointer selectors (Best, Last, Epochs, Every), scope, checkpoint averaging, resume modes, and debugging refused resumes.
Ships in reactantnitro-jl. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
resume = false is the default: a fresh Nitro does not resume. Resuming is opt in.
resume = :auto is exactly resume = :latest => :latest, the newest record of the most recent run
in the run directory, and logs what it resolved to (resume = :auto: continuing :latest => :latest, run <id>, epoch <n>). The one difference: in a directory with nothing to resume it warns and
starts a fresh run, where :latest => :latest raises. The default used to be :auto, and it was
changed because run_dir defaults to a name derived from the experiment type, so a second
Nitro(MyExp()) in the same working directory silently continued the previous run. Picking up
weights nobody named is not something a constructor should do on its own.
When driving from a Kaimon session, the tools pass this through unchanged (reactantnitro-kaimon):
nitro_train(..., run_dir = ..., resume = ...) accepts "auto", "false", a checkpoint path, or
a source string such as "latest => latest" or "<run id> => best", and the same default applies:
a reused run_dir does NOT resume unless asked. The tools' run registry is process-local, so a
session restart loses in-flight runs and resume = "auto" is the recovery path, not a convenience.
Ask for it explicitly after a restart.
ReactantNitro.monitor(::MyExp) = :acc => :max # what Best ranks by; default :loss => :min
Checkpointer(; keep = (Best(3), Last(1)), metric = nothing, mode = nothing, dir = nothing,
scope = :run)
Set monitor once; the checkpointer, EarlyStopping and every Plateau follow it unless
given both their own metric and mode (one alone is refused). The metric is a key your
finalize_metrics returns, never the backend's display name (:acc, not :validate_acc).
Names carry no split: the framework's validation loss is :loss, which exists only when the
experiment defines no metrics; :val_loss still works as :loss with a warning until 1.0.0. A checkpointer used without setup
(average_checkpoints) ranks by what the run's newest scored entry was written under.
TopKCheckpointer follows the same rule.
checkpointer = nothing writes nothing.
It must also be FINITE, and that is checked, because the checkpointer compares it against the
retained set and a NaN compares false against everything. The way this arrives is not exotic: a
metric whose count was zero on a split reduces to 0 / 0. See reactantnitro-metrics for the scrub.
Under resume = :auto, a second train! into a directory that already holds checkpoints
continues rather than starting over. That is the point of it, and it has one trap worth knowing
before you opt in: a seed sweep that varies the seed and not the run directory resumes into itself
and runs one seed N times. Vary run_dir too.
Retention is the union of the selectors in keep. Each selector answers "which entries of this
run's manifest":
| Selector | Keeps |
|---|---|
Best(k) | the k best by metric and mode (under scope = :dir, across every run) |
Last(n) | this run's latest n, whatever they scored |
Epochs(r) | this run's entries whose epoch is in r |
Every(n) | this run's entries whose epoch is a multiple of n |
The default, (Best(3), Last(1)), is the old top-K-plus-latest rule: K+1 files when the latest is
not among the best, K when it is. Resuming from the best checkpoint is not resuming from where
you were, which is why both exist. keep = (Best(3), Last(10)) keeps a window for averaging (next
section); keep = Last(5) is a rolling window. A custom selector defines select(sel, entries, ckpt) and optionally admits.
An epoch is written only when some selector would keep it. With a Last every epoch is
written. Without one (keep = Best(3), the escape hatch when a record is large and the filesystem
slow) an epoch that cannot enter the top K is never written at all (it must beat the K-th best
strictly), so there is no per-epoch write-then-delete. The final stop_reason rewrite follows the
same rule. What it costs: the state training ended in is saved only if a selector keeps the last
epoch, weights = :latest => :latest and resume = :auto resolve to the run's latest kept
record (its most recent improvement, not where it stopped), a resume from it continues the same
run id and retrains the epochs after it, and a crash loses every epoch since that improvement.
Setup warns once about this for a handle that trains, and refuses a keep of only Best for a
training run with no val split, since no epoch would have a score to be kept by.
TopKCheckpointer(; k, keep_latest, ...) is deprecated (warns once per session, supported until
at least 1.0.0). It builds Checkpointer(; keep = (Best(k), Last(1))), or keep = Best(k) for
keep_latest = false, and writes identical files. ckpt.k and ckpt.keep_latest stay readable on
a Checkpointer.
latest is a retained file, not a symlink into the top-K set: top-K rotation deletes its target
during entirely normal operation, and checkpoint directories get copied between paths where tools
handle symlinks inconsistently.
A small manifest sits alongside with file, epoch, score, stop reason, and the run, metric and mode that wrote each entry, so resume can find the newest without reading every file.
Retention is per run, and one directory can hold several. The default run_dir is the
experiment's type name, so two fresh runs routinely share one. Setup gives every run an id
(n.checkpointer.run, and run on each read_manifest entry), and the rule above applies to a
run's own entries only: a second run never ranks, rotates, deletes or overwrites the first run's
checkpoints, and a name that would land on another run's file (same seed and config, same epoch,
step and score) is written as ...-run-<id>.jld2 instead. Within a run, top-K ranks only entries
scored under the checkpointer's current metric and mode. A manifest written before runs were
recorded reads as one unnamed run (run === nothing, listed by runs() as "legacy"), the
oldest, and a new run leaves it alone. A fresh run into an occupied directory says so at setup.
scope = :dir is the space-saving alternative. The whole directory keeps only its top K by the
current metric across every run, plus what this run's other selectors keep (Last by write time
under this scope); every other entry scored the same way is deleted, another run's and legacy ones
included. Ranking is by score alone. With keep = Best(k) alone, at most K such files remain in
the directory. Names still never collide: a file another run owns gets the -run-<id>
suffix rather than being overwritten. Setup of a training handle warns how many checkpoints of
other runs the directory already holds and that they may be deleted as this run beats them.
Selection only ever uses the CURRENT metric and mode, and never prunes the others. Every
selection (retention under either scope, :best, :all => :best, Average(Best(k))) ranks
the entries scored under the checkpointer's metric and mode and nothing else. Entries scored
under another pair, written by an earlier run or by this run before a resume changed the selection,
are disjoint: never ranked against current ones and never deleted. When the entries being
considered are mixed, setup of a training handle (over its retention scope) and every :best
lookup @warn, naming the other metrics and modes with counts and saying they are kept. A run with
no entry under the current metric cannot answer run => :best: it raises, listing the metrics the
run does have; set the checkpointer's metric and mode to match, or pass the path. Legacy entries
with no recorded metric count as matching. The manifest records a metric's name and mode, not its
definition: a metric whose name stays the same while what it computes changes (a new
finalize_metrics, a different split) cannot be detected, and old and new scores will be ranked
together as if comparable. Rename the metric when its definition changes.
Resuming is always exact continuation, of a run or as a branch from it. A resume restores
parameters, layer state, optimizer state, step, epoch and schedule position, under the refusals
below. Resuming a run's newest record (:auto, :latest => :latest, "<id>" => :latest,
other => :latest, or that record's path) adopts that run's id, so its later checkpoints join the
same run. Anything else, an earlier record (=> :best, :all => :best) or a file this manifest
does not list, starts a new run and logs that it branched, and from which run and epoch. That is
what keeps a resume from epoch 5 of a run that reached epoch 12 from rewriting epochs 6 to 12 and
rotating the originals away. The branch's entries carry the source path as parent.
resume = other and other => :current are refused as not supported yet; use weights = other
for the parameters.
train!(e; early_stop = EarlyStopping(; patience = 5, min_delta = 1f-4)) # watches `monitor`
early_stop defaults to nothing, so a bare experiment does not early-stop. EarlyStopping is a
small dedicated component, separate from the checkpointer: both watch monitor by default, and
either can be given its own metric and mode (checkpoint on mae, stop on loss).
A metric nothing emits is an error naming the ones available, checked before training when the
framework can know the key set. patience counts epochs without improvement and min_delta
is absolute, both matching Keras and Lightning: an epoch improves when it beats the best seen
by more than min_delta, and anything else, including an equal or slightly better value, counts
against patience.
Stopping is graceful and recorded. The epoch finishes, validation runs, the checkpoint is
written, the logger finalizes, and the run exits through the normal Done path. stop_reason in
the checkpoint record says :early_stop rather than :completed, which is what makes resume
comprehensible: a run that early-stopped and is resumed with :auto would immediately re-satisfy
the condition, and with the reason stored it says so instead of exiting silently.
A custom metrics key cannot be checked before validation runs, so a misspelled monitor costs
one epoch before it raises.
The early-stopping counters, and each Plateau schedule's counters (the record's
schedule_state), are updated before the epoch's checkpoint is written, so a resume from any
record continues exactly; a stored plateau resumes only when its key, metric and mode match, and a
weights load starts both fresh.
request_stop! sets the same flag imperatively, from a REPL or a phase monitor. Both are checked
once per epoch after validation. Custom policies implement should_stop(es, epoch, metrics) for
their own type; a ::Nothing method returns false, which is how "no early stopping" stays the
default with no branch in the driver.
^C in the REPL is the same stop. The entry points run on a worker thread, and ^C is delivered
to the parked caller, which converts it into request_stop!: the epoch finishes, the checkpoint is
written, and the record's stop_reason reads :requested, so a ^C'd run resumes cleanly, exactly
like one that stopped on patience.
A "checkpoint" is full training state; "weights" are parameters alone. Optimizer state is saved on every checkpoint including top-K ones, not only on a dedicated resume checkpoint, because an API that says checkpoint and hands back something unresumable has picked the wrong word. Anything producing parameters alone for export or serving is named for weights.
Checkpoint sources: one grammar for weights and resume. Either keyword takes a path, or
run => checkpoint:
| Run (left) | Means |
|---|---|
:latest | the most recent run in run_dir (the run of the entry written last; legacy entries count as oldest) |
"<run id>" | that run; "legacy" is the unnamed run of a manifest written before runs were recorded |
:all | every run in run_dir; only :all => :best |
other::Nitro | that handle's own run, read in its own run directory through its own checkpointer |
| Checkpoint (right) | Means |
|---|---|
:best | the run's best record by the CURRENT checkpointer's metric and mode |
:latest | the run's newest retained record |
:current | a live handle's in-memory parameters; only weights = other => :current |
Average(sel) | the average of the run's checkpoints sel picks; only for weights (next section) |
Best(1) and Last(1) are the same as :best and :latest. Any other selector may pick several
checkpoints, so a source refuses it outside Average.
weights = other (a bare handle) is the same as other => :current. Bare :best and :latest are
refused with the pair to use (weights = :latest => :best), :all => :latest is refused in favour
of :latest => :latest, and :all => :current is invalid. A source that cannot be found raises,
naming the directory, the run ids it holds, and runs(run_dir); nothing asked for is silently
replaced by fresh weights. The pair is resolved to the actual file at setup, so
checkpoint_source and an exported bundle's provenance name the file, not the words.
n = Nitro(MyExp, :baseline; run_dir = "runs/my_run", weights = :latest => :best, logger = nothing)
n = Nitro(MyExp, :baseline; run_dir = "runs/my_run", weights = "a1b2c3d4" => :best) # a named run
n = Nitro(MyExp, :baseline; run_dir = "runs/my_run", weights = :all => :best) # best of all
That is the construction for evaluation, mining and export. With the handle that trained still in
hand, weights = trained => :best names the record of THAT handle's run, whatever else has written
to its directory since. The gate tools take the same sources as strings (weights = "latest => best").
Averaging checkpoints. Average(sel; weight = :uniform, state = nothing) averages the
parameters of the checkpoints sel picks from ONE run, streamed one record at a time into a
Float64 accumulator:
n = Nitro(MyExp(); run_dir = "runs/my_run", weights = :latest => Average(Last(10)))
n = Nitro(MyExp(); run_dir = "runs/my_run", weights = "a1b2c3d4" => Average(Best(5; among = Last(20))))
average_checkpoints("runs/my_run", :latest => Average(Last(10)); save = "runs/my_run/avg10.jld2")
Best(k; among = sel) ranks only what sel picks: the best 5 of the latest 20 (the LAWA-style
recipe). among is for loading only; keep refuses itBest) and the latest otherwise, or as state = :best | :latest says. Exact without running
statistics; an approximation with BatchNormkeep = (Best(3), Last(10))); when it does not, the error lists the retained epochs and the
keep that would have held them. other => Average(...) also checks other's keep first:uniform is the only weighting so far. Refused: averaging across runs (:all => Average),
Average in resume, and restore_optimizer = true with an Average (no optimizer state)averaged_from (spec, run, directory, files, epochs, weights, state file):
checkpoint_info(path) shows it, nitro.averaged_from holds it, and an export's provenance
includes it. average_checkpoints(...; save) writes it outside the manifest, so retention never
deletes it, and refuses to overwrite; weights = path then loads it like any recordFinding run ids. runs(run_dir) lists the runs a directory's manifest holds, most recent
first: id, checkpoints kept and their epochs, best score with its metric and mode, last write, and
the parent of a branch. checkpoint_run(nitro) is a handle's own id (not run_id, which is the
logger's), and show(nitro) prints it beside run_dir and on the selected checkpoint.
read_manifest(dir) is the per-entry view.
restore_optimizer = true: a record's parameters and its optimizer state, under a new schedule.
With weights naming a record (a path or any run => :best | :latest), the record's optimizer
state is restored as well, normalized to device residency exactly as a resume normalizes it and
checked against the optimizer this run builds: a different rule or group layout refuses. Step,
epoch and schedule start fresh: it is a new run with its own max_epochs. It is refused with no
record to take the state from (no weights, a bare handle, other => :current; restoring a live
handle's optimizer is not supported yet), with resume (which always restores it), and on a handle
with no train split.
| You want | Write |
|---|---|
| the exact training state of a record (a branch unless it is the newest) | resume = run => :best |
| a record's parameters and optimizer state, fresh step and schedule | weights = run => :best, restore_optimizer = true |
| a record's parameters, fresh optimizer | weights = run => :best |
| a changed model (a new head, a dropped layer), loading what fits | weights = run => :best, strict = false |
strict = false: a partial load, as in PyTorch's load_state_dict. Leaves of ps and st
are matched by keypath; one the source lacks keeps its fresh initialization, one this model lacks
is dropped, and both always warn with the list. A parameter size mismatch refuses regardless. A
layer-state leaf that does not fit only warns and keeps the fresh leaf, under either setting. Only weights
takes it; resume and restore_optimizer refuse a partial load.
restore_best = true: end train! holding the run's best weights. When training completes,
stops early or is stopped on request (not on error), the handle loads ps and st from its OWN
run's best checkpoint under the current metric. Step, epoch, history and the last metrics stay as
training ended; checkpoint_source becomes the best file, so an export names it, and show says
the handle holds that checkpoint's weights and which epoch. A run that saved no scored checkpoint
warns and keeps its final weights. A handle restored this way refuses a later train!: the best
weights beside the optimizer state and step training ended in are not a state any run was in. The
error prints the three real ones, filled in with the handle's experiment, preset, run directory
and run id (the table above, with "<id>" => :best). train!(e; restore_best = true) and the
nitro_train tool's restore_best argument reach the same keyword.
restore_best = Average(sel) ends train! holding the average of the run's own checkpoints
instead, exactly as weights = run => Average(sel) would load them, with averaged_from set.
Setup refuses a keep that cannot hold the selection; a run that ends before it has enough (an
early stop) warns and keeps its final weights. A later train! is refused, and the error gives the
weights = "<id>" => Average(...) construction. The nitro_train tool takes only the Bool form.
This is a correctness requirement, not tidiness, and it is the single most expensive class of bug this framework has had.
A device array survives serialization: it is written field by field, raw pointer included, and read back without complaint. The pointer means nothing in the reading process, so the failure surfaces much later, in a different process, as an assertion from inside an unrelated read-back that names neither the field nor serialization.
The framework converts on the way out and asserts at write time, naming the path of any leaf that survived. If you see that error, it is telling you a walker has a gap, not that you did something wrong. A type that genuinely cannot hold a host value needs a surrogate plus a method to turn it back; that is how the layer-state RNG is handled.
The flow is uniform and has exactly one normalization point per path: write host, read host, normalize on the way in.
Restored: parameters, layer state, optimizer state including its moments, the step and epoch counters,
the seed, derived-value bookkeeping, and the EarlyStopping counters when the resumed policy watches
the same metric and mode. The logger reattaches so a resumed run extends one history
rather than opening a second.
Recomputed, not restored: derived values. derive runs again, so resuming against changed data
picks up new values. They are recorded in the record so a change is visible after the fact.
The seed is restored from the record and overrides a seed keyword, with a warning when they
differ. Restoring is what makes the initialization reproducible, so the override is right; only its
silence was wrong. Watch for this if you are sweeping seeds: vary the run directory too, or the sweep
resumes into itself and runs the same seed N times.
resume = :auto is safe to reach for only because the compatibility check lives in the framework
rather than in your harness. It refuses, with a diff, when:
Host fields are excluded, since raising max_epochs on
resume is the normal case. A changed derived GraphConst field is an error; a changed derived
Device value is fine and is logged.:w0, the anchor is
re-captured from a fresh initialization and checked against the record. A match proves you are
anchored to the same tensor the original run used.Do not resume into a run directory containing a wedged temporary file. A checkpoint write killed
mid-flight can leave a partial .tmp; resuming in place walks the new run into the same path and
wedges it identically. Move or delete the fragment first.
A long run's log may be empty and the run perfectly healthy. Julia's stderr is block-buffered when
redirected to a file, so nothing appears until the process exits, and a hard kill discards the buffer
entirely. Use the checkpoint files as the progress signal, not the log. If you need live progress,
write it yourself with an explicit open, append, and close per epoch from a phase monitor
(register_phase_monitor!).
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
reactantnitro, checkpointing, resume, model-training, early-stopping
11 skills in this plugin
/reactantnitro-acceleratorsChoosing and configuring the accelerator a ReactantNitro run executes on: CPU, CUDA, ROCm, TPU, and how many devices it shards over. The one-process-one-XLA model, `setup_devices!` (REPL) and its tool form `nitro_setup` (Kaimon) as one shared code path, the `n_devs` pin and its precedence, and `CUDA_VISIBLE_DEVICES` for restricting GPUs. Invoke when starting a run on a specific accelerator, when a run unexpectedly uses the wrong backend or the wrong number of devices, or when deciding what `n_devs` means for a session.
/reactantnitro-device-boundaryDebug and prevent CPU/GPU divergence in ReactantNitro: why a fully green CPU test suite can pass while code has never once worked on a device, what a model author must and must not do at the boundary, what scalar indexing does differently on each backend, how to read a residency assertion, and the rule to apply to any new contract ("would this raise on CPU?"). Invoke when code that passes on CPU fails on a GPU; when anything raises "Scalar indexing is disallowed" or "still holds DEVICE-resident values"; when a resume dies on `buffer.buffer !== C_NULL`; or when adding a contract that promises host or device residency.
npx claudepluginhub enzymead/reactantnitro.jl --plugin reactantnitro-jlOther plugins' skills for the same job