Metrics and samples
Charts with no code changes, or with the workbox helper.
A job's page draws charts of what your training reports, and shows samples of what your model makes. There are two ways to get them there, and they work together.
Without changing your code
Workbox reads what your tools already print:
- the Hugging Face Trainer's log lines (
{'loss': 1.84, 'learning_rate': 3e-4, ...}); - PyTorch Lightning's progress bar;
- any line with a step and
name=valueorname: valuepairs, likestep=120 loss=1.84; - TensorBoard event files written anywhere in
~/work.
GPU use, memory, power and temperature are always read from the machine, and a job that reports steps gets a Steps per second chart.
With the workbox helper
For anything else, report it yourself. The package is in every Workbox image; on your own computer, pip install workbox.
import workbox
for step, batch in enumerate(loader):
loss = train_step(batch)
workbox.log(step=step, loss=loss, lr=scheduler.get_last_lr()[0])
if step % 500 == 0:
workbox.sample(step=step, text=generate("Once upon a time"))| Call | Records |
|---|---|
workbox.log(step=..., **metrics) | Numbers at a training step. Tensors and NumPy values work; NaN and infinite values are left out |
workbox.sample(step=..., text=...) | Text the model made at a step |
workbox.sample(step=..., image=...) | An image: a file path, or a PIL image. It is saved with the job's outputs |
workbox.describe(model, **facts) | The model, for the job's Model panel: its parameters, counted from a PyTorch module, a Keras model or JAX arrays, and what you add, such as context=1024, layers=12, vocab=50257 or tokenizer="GPT-2" |
workbox.enabled() | Whether the code is running as a Workbox job |
To chart how fast training goes in your own units, log a running total as tokens or samples: Workbox charts how fast it grows (Tokens per second, Samples per second).
seen = 0
for step, batch in enumerate(loader):
seen += batch.numel()
workbox.log(step=step, loss=loss, tokens=seen)A model saved with a config.json is described without it: Workbox reads its architecture, parameters, context window, layers and vocabulary, whether it is Hugging Face's or your own (keys such as context_length, n_layers and vocab_size, at the top or in an object inside it). Parameters and precision also come from .safetensors files, and the tokenizer from a tokenizer.json. What describe says comes first, and the Model panel shows the call that would fill in what is missing.
Outside a Workbox job every call does nothing, so the same code runs on your laptop or in Colab. The calls never raise: a training run never fails over a chart.
Next: Serve your model