Skip to content

Writing your own training loop

You do not need to integrate with epochix. If your loop prints its metrics — and most loops already do — that is the integration.

The whole thing

for epoch in range(1, EPOCHS + 1):
    ...
    print(f"Epoch {epoch}/{EPOCHS} train_loss={loss:.4f} val_accuracy={acc:.4f}", flush=True)
python train.py | epochix

That is a complete setup. Piped input is detected automatically, the task type is inferred from your metric names, and the dashboard opens as the run progresses. Add --headless to skip the browser (useful in CI).

Use flush=True

Python buffers stdout when it is piped rather than attached to a terminal. Without flush=True your metrics arrive in one burst at the end, so the dashboard cannot draw the run while it trains. Alternatively run python -u train.py.

Shapes that are recognised

Any of these work, and they can be mixed:

Epoch 3/10 train_loss=0.4413 val_accuracy=0.8590
epoch: 3  loss: 0.4413  val_acc: 0.8590
{"epoch": 3, "train_loss": 0.4413, "val_acc": 0.8590}

A bare Epoch N/M header is understood too, so metrics printed on the following line are still attributed to the right epoch — and the /M gives the progress bar something to fill.

The epoch may appear anywhere on the line, including after the metrics.

Name your metrics conventionally

Metric names are what tell epochix which task you are training and how to grade it, so the names matter more than the format.

Use For
train_loss, val_loss, loss any run
val_accuracy / val_acc, f1, auc classification
mae, rmse, mse, r2 regression
map50, map detection
precision, recall any run — they chart, and tell the story when nothing above is logged
perplexity language modelling
lr learning-rate schedule

An unrecognised name still charts, but the run falls back to the custom task, which is graded on its improvement trajectory rather than an absolute scale.

A run that logs only a loss curve is fine — it is graded on how much the loss improved from its own starting point, not against an accuracy scale.

Which metrics get a grade from fixed bands, and which from improvement:

  • Fixed bands — accuracy; F1, on accuracy's bands; ROC AUC (0.5 is a coin toss, and the letters follow the usual rule of thumb: 0.7 acceptable, 0.8 excellent, 0.9 outstanding); R²; and each other task's main metric (mAP50, mIoU, perplexity, EER).
  • Improvement since the first reading — the number has no scale of its own: a loss, an error in the target's units (MAE, RMSE), PR AUC, and any name epochix does not recognise.

Either way the grade does not know how hard your dataset is, and the card under the grade says which of the two applied. To grade a metric on bands of your own, see Grade thresholds.

Readings that cannot be compared

Both ways of grading set one reading against something: a band, or the first reading. So do "past its best", "barely moved" and the divergence warning. That is sound when the next reading of an unchanged model would come out about the same. It is not when each reading is the loss of one batch — which is all a LoRA or DreamBooth trainer prints, and on a diffusion model moves by an order of magnitude from one step to the next with nothing wrong.

epochix measures this on the metric itself. Over its last 50 readings, once there are six: if it changes direction at half or more of them and the typical step between neighbours is a quarter or more of the larger one, the metric is unsteady. Then:

  • the run gets no letter, and the card says that is why;
  • the story gives the reading and those two measurements, and does not say the run is past its best, stalled or improving;
  • a jump in the training loss is a divergence warning only when it is more than 10 times the highest reading there has been.

The readings are charted exactly as logged. Nothing is averaged or smoothed. To get a run that can be graded, log a validation metric, or the loss averaged over many batches.

A loss that turns often but moves little beside its trend — a language model's loss per iteration, falling from 4.2 to 1.7 — is not unsteady, and is graded as before. Nor can the first five readings be: with so few, a batch's luck and a real rise look the same.

A running average is the opposite case: it moves smoothly by construction, so the measure above passes it, and it still supports none of those conclusions. kohya-ss's avr_loss averages the batches so far through the first epoch, then the last epoch's batches. Each reading shares all but one batch with the one before it, and the first readings average fewer batches than the rest. On a recorded run the first reading was one batch's loss, 0.0304, while the next eleven batches lay between 0.003 and 0.011. As that batch was averaged away, the run was graded A for an improvement it never made, and its ten end-of-epoch values, which share no batch, show no trend. A metric known to be computed this way gets no letter, no "past its best" and no "stalled": its readings are charted as logged, and the card says why.

Past its best

The story says a run is past its best, and suggests keeping the earlier checkpoint and stopping early, once three readings in a row have been more than 1% worse than the best. That is what early stopping with a patience of three would do. A single reading that far off is said as just that ("more than 1% off the best of 0.1491 at round 55"). On a converged run the metric wobbles about its best, and one wobble is not a slip. Everything else the story says about a reading's progress holds only while that reading is within 1% of the best.

What not to print

Some things look like metrics and are not, so epochix deliberately ignores them. Printing them will not enrich the dashboard:

  • Run configuration — batch_size, num_workers, epochs, precision. These are constants, and charting one draws a flat line beside your real curves as though the model were doing something.
  • print(model) layer arguments — kernel_size, in_features, stride. The architecture panel reads a model dump when one is present, but those values are shapes, not measurements.
  • tqdm and download bars. A progress bar is not a metric.

lr is the exception: a learning-rate schedule is a real curve and is charted.

Writing to a file instead

If you would rather keep a log file, epochix reads it afterwards:

python train.py | tee train.log
epochix run train.log

To watch a file that another process is still writing, use --tail. To follow one on another machine, use --ssh. Both are documented under epochix run --help.

When the dashboard is not what you expected

epochix check train.log

This reports exactly which lines were parsed, which metrics were found, what task was inferred, and what to add. It stores nothing and serves nothing — it only explains. Reach for it before assuming something is broken; an empty dashboard is nearly always a log whose metrics were not in a recognised shape.

If you would rather call an API

There is a Python SDK for logging directly from inside your code, including live reporting while a run is in progress — see the Python SDK reference. It is strictly optional; printing is the supported path and nothing about it is second class.