horrible_train — the training helper
import horrible_train as ht — the dependency-free helper every generated training notebook uses: ht.callback() for metrics that work offline, ht.finish() to close a run. See training.
Also browsable, with search, in the Python reference pane (/pydoc) under Dashboard SDKs.
horrible_train
callback
callback(name=None, log_every=1, graph=True, weights=False)
A Hugging Face `TrainerCallback` that mirrors every logged metric here.
This is what makes "local metrics are authoritative" true rather than a
slogan: it is installed on every generated recipe regardless of
`report_to`, so the chart pane works offline, works with `report_to=["none"]`,
and keeps working when a tracker's API key expires mid-run.
`transformers` is imported **inside** this function. The helper package has
zero dependencies by design — importing a trainer at module scope would make
`import horrible_train` fail in a plain script or a gym rollout, which is
most of what this package is used for.
**`graph=True` publishes the architecture too.** The Trainer hands `model=` to
every callback hook, and this one used to drop it on the floor — so running a
generated recipe to completion left the Architecture pane saying "no model
yet, call `horrible_train.watch(model)`", naming a call the recipe does not
make and, for the trl path, could not make (the trainer is given the model's
*name*, so there is no model object in the notebook namespace until it is
constructed). It is on by default because it is nearly free: `_extract_graph`
falls back from `torch.fx` — which will not trace an HF decoder — to a walk of
`named_modules()`.
`weights` is the one that costs, and stays off: it norms every parameter on
every `log()`, per step, for the life of the run.
finish
finish(status: str='finished', **summary: Any) -> None
Declare the current run over, with a terminal status.
Without this a run has **no end**. The backend's only other end-of-run signal
is "a different run started for the same project", which leaves the last run
of a session `running` forever and makes a sweep of twelve runs show twelve
live ones. That was tolerable while runs were things you watched; it is not
tolerable once runs are things you compare.
Emitted by `ht.callback()` on `on_train_end`, so a generated recipe gets it
for free. Call it yourself in a hand-written loop, or let the supervising
process close the run when it exits (a crashed script is marked `crashed`,
a non-zero exit `failed` — the distinction the localtrack schema already
carries and nothing had ever written).
Safe to call twice; the second one is dropped by the backend.
frame
frame(img: Any, source: str='gym') -> None
Stream one rendered frame (HxWx3 uint8 array, PIL image, or encoded bytes)
to the rollout pane.
log
log(step: int | None=None, **values: float) -> None
Log scalar metrics for the current run: `ht.log(step=i, loss=0.4, acc=0.9)`.
run
run(name: str | None=None) -> str
Start (or rename) the current run; returns its id. Called implicitly by the
first `log()` if you don't call it yourself.
watch
watch(model: Any, example: Any=None, weights: bool=False) -> None
Publish a torch model's architecture to the model-graph pane. With
`weights=True`, per-layer weight/grad norms ride along with every `log()`.