FluxGlow

How do I watch a machine learning training run on a wall screen?

Write a board file from inside the training loop, once for each epoch. The wall shows which stage the run is in, how many epochs are done and the latest loss, and it turns red if the run fails.

What it looks like

board.json
{
  "title": "Churn model",
  "tag": "run 0412",
  "nodes": [
    { "id": "data", "label": "Data", "state": "ok", "value": "1.2M", "unit": "rows", "badge": "Ready" },
    { "id": "train", "label": "Train", "state": "run", "value": "12/30", "unit": "epochs", "badge": "Loss 0.083", "after": ["data"] },
    { "id": "evaluate", "label": "Evaluate", "state": "idle", "badge": "Waiting", "after": ["train"] },
    { "id": "publish", "label": "Publish", "state": "idle", "badge": "Waiting", "after": ["evaluate"] }
  ]
}

What the states mean for a training run

StateFor a stage
run, blueIn progress. The figure is how far it has got.
ok, greenFinished.
bad, redCrashed, ran out of memory, or the loss stopped being a number.
warn, amberFinished, but below the score you wanted.
idle, greyNot started.

Writing the board from the training loop

The function train_one_epoch stands in for your own. Everything else is the board: one call for each epoch, one when training ends, and one if it fails.

training.py
"""Keeps a FluxGlow board up to date from inside a training loop."""
import json
import os

EPOCHS = 30


def write_board(epoch, loss, state="run"):
    done = state == "ok"
    board = {
        "title": "Churn model",
        "tag": "run 0412",
        "nodes": [
            {"id": "data", "label": "Data", "state": "ok", "value": "1.2M", "unit": "rows", "badge": "Ready"},
            {
                "id": "train",
                "label": "Train",
                "state": state,
                "value": f"{epoch}/{EPOCHS}",
                "unit": "epochs",
                "badge": f"Loss {loss:.3f}",
                "after": ["data"],
            },
            {"id": "evaluate", "label": "Evaluate", "state": "run" if done else "idle", "badge": "Running" if done else "Waiting", "after": ["train"]},
            {"id": "publish", "label": "Publish", "state": "idle", "badge": "Waiting", "after": ["evaluate"]},
        ],
    }
    with open("board.json.tmp", "w") as f:
        json.dump(board, f, indent=2)
    os.replace("board.json.tmp", "board.json")
    # Copy board.json to wherever the board reads it from here.


def train_one_epoch(epoch):
    return 1.0 / (epoch + 1)  # stands in for your training step; returns the loss


loss = 0.0
try:
    for epoch in range(1, EPOCHS + 1):
        loss = train_one_epoch(epoch)
        write_board(epoch, loss)
    write_board(EPOCHS, loss, state="ok")
except Exception:
    write_board(epoch, loss, state="bad")
    raise

Copy the file to where the board reads it after each write. On a rented GPU machine, a storage bucket is the easy choice, since the machine can already reach it.

How often to write

Once for each epoch is plenty. The board reads its file every 15 seconds, so writing on every step only makes work. If an epoch takes hours, write every few hundred steps and show the step count in place of the epoch.

When the process is killed

The example turns the orb red when the loop raises an error. A process that is killed outright, by the machine running out of memory or a spot instance being taken back, never gets the chance, and the board would stay blue.

To cover that, add updated and stale_after to the board, with stale_after set to two or three times as long as an epoch takes. A run that stops writing then goes grey and says when it was last heard from.

A wall of machines or experiments

Leave out after and the same format makes a grid: one orb for each GPU machine or each experiment, blue while it is working, grey while it is free, with the job's name in the badge. That answers "is anything free?" from across the lab.

What it does not do

A board has no charts. For loss curves and comparing runs, keep the experiment tracker you already use. The board is for the question people ask out loud: is it still going, and how far along is it?

  • How do I show the status of a data pipeline or ETL job on a screen?

    Make each step of the job a node, in the order they run, and rewrite the board file as each step starts and finishes. The data team can then see how far last night's load got without opening a log.

  • How often does a board update, and can it be faster?

    A board reads its file again every 15 seconds. Add &every=5 to the address to read every 5 seconds, which is as fast as it goes. Changes appear on the next read, without the page reloading.

  • Why has my board gone grey?

    A grey board has stopped trusting what it is showing. Either the file says it should have been rewritten by now and was not, or the last attempts to read it failed. A line at the bottom of the board says which.

All questions