Kaimei Training

Kaimei Training

Follow a model while it trains: install the client, add two lines, choose how runs reach Kaimei, and move over from W&B, MLflow or TensorBoard.

#Record a run

Kaimei Training follows a model while it trains: its curves, config, environment, console and hardware load, live in the dashboard, with thirty health checks on every run. It works with any Python training loop and hooks the common frameworks by itself.

  1. Install the client, 0.22.0 or later, with its training extras: pip install "kaimei[train]". They add psutil and nvidia-ml-py, for hardware load. A self-hosted API needs 1.13.0 or later.
  2. Give it an API key: kaimei login stores one for the machine, or set KAIMEI_API_KEY.
  3. Start a run with kaimei.init, and call kaimei.autolog() to hook every supported framework the program uses: plain PyTorch loops, Lightning, Hugging Face Transformers, Accelerate, Keras, XGBoost, LightGBM, CatBoost, scikit-learn, Optuna, Stable-Baselines3 and TensorBoard writers.
  4. Log what the frameworks don't with run.log, check run.stop_requested in a plain loop, and call run.finish() at the end, naming the model the run produced if it is registered.

Nothing here raises into training or waits on the network: log adds to a buffer, a background thread writes it to a journal on disk every second, and another uploads it. kaimei.init is also a context manager, and a block that raises marks the run failed. A run still open when the program exits is finished for you.

Python, OS, CPU and GPUs, installed packages, the git commit and the command line are recorded with the run; values under secret-looking names are masked before they leave the machine, and environment variables are never read. detail="full" adds per-layer gradients, weights, updates and activations; see run series.

import kaimei

run = kaimei.init(project="credit-risk", config={"lr": 3e-4, "batch_size": 256})
kaimei.autolog()                       # hooks every supported framework, now or when imported later

for epoch in range(30):
    for batch in loader:
        loss = train_step(batch)
        run.log({"train/loss": loss})  # a GPU tensor is fine: it is read off the training thread
    run.log({"val/loss": val_loss, "val/auc": val_auc}, epoch=epoch)
    if run.stop_requested:             # Stop pressed in the dashboard, or an alert rule with stop_run
        break

run.finish(model="credit-risk")        # optional: links the run to a registered model
pip install "kaimei[train]"
kaimei login                           # stores an API key for this machine
python train.py

#Live, after or offline

sync= on kaimei.init says when a run reaches Kaimei. Every mode writes the same journal first, ./kaimei-runs/<run id>/ (or dir=, or KAIMEI_DIR): append-only, checksummed and flushed every second, so a crash loses at most a second, and a live run that loses its network keeps training and catches up.

sync=During trainingWhen the run reaches KaimeiIf the process dies
"live"Journal on disk; uploads every 2 seconds or 1,000 points; a heartbeat every 30 secondsWithin secondsAlready uploaded. Kaimei marks it crashed after five missed heartbeats; kaimei sync sends any tail
"after"Journal only; one request at the start reserves the run's idAt finish() or exitkaimei sync uploads the journal
"offline"Journal only; no network at allWhen you run kaimei syncNothing is lost

live is the default, and the only mode the dashboard can follow as it happens and stop. after suits jobs whose network is busy or metered; offline, machines with none. Batches are numbered by the process that writes them, so a batch sent twice is stored once, and a quota refusal or a rate limit pauses the upload without losing anything: the journal keeps it until there is room.

shell
kaimei sync                  # upload offline runs, and whatever a crash left behind
kaimei runs ls --local       # the journals on this machine
kaimei gc --dry-run          # journals Kaimei already holds in full, which gc deletes

#Moving from W&B, MLflow and TensorBoard

  • W&B, one changed line. import kaimei.compat.wandb as wandb runs a W&B script on Kaimei: init, log (numbers, tensors, wandb.Image, wandb.Histogram, wandb.Table), config, summary, define_metric, watch, alert and finish. For a library that imports wandb itself, such as the Hugging Face trainer with report_to="wandb", call kaimei.compat.wandb.install() before it does. tee=True keeps writing to W&B as well, so a team can run both for a while.
  • MLflow, two environment variables. Kaimei answers MLflow's tracking API, so code that logs to MLflow, mlflow.autolog() included, records Kaimei runs once MLFLOW_TRACKING_URI points at Kaimei and MLFLOW_TRACKING_TOKEN holds an API key. An experiment is a project; see MLflow tracking for what maps to what.
  • TensorBoard, no change. kaimei.autolog() mirrors SummaryWriter (PyTorch and tensorboardX) and tf.summary into the run: scalars, histograms, text, images and hyperparameters. To leave the training script alone, kaimei tensorboard --follow ./runs mirrors the event files live from another process, one run per folder.
  • Past runs, one command. kaimei import copies runs from W&B, MLflow, TensorBoard, Neptune exports, Comet, ClearML, Aim, CSV and JSON Lines with their original timestamps, so they replay like native ones. Imported runs are sent after, with source: "import" and imported_from naming where each came from; they count against the runs imported each month, not the runs started, and their checkpoints record metrics only. Credentials stay on your machine, and an import resumes where it stopped and skips runs already copied.
import kaimei.compat.wandb as wandb      # was: import wandb

wandb.init(project="credit-risk", config={"lr": 3e-4})
wandb.log({"train/loss": loss})
wandb.finish()

# past runs, with their full history:
#   WANDB_API_KEY=... kaimei import wandb acme/credit-risk
export MLFLOW_TRACKING_URI=https://api.kaimei.ai/mlflow
export MLFLOW_TRACKING_TOKEN=$KAIMEI_API_KEY
python train.py                          # mlflow.start_run(), log_metric, autolog: unchanged

# past runs, from a folder or a server:
kaimei import mlflow ./mlruns
kaimei tensorboard --follow ./runs       # live, one run per subfolder, while training writes them
kaimei import tensorboard ./runs         # or copy finished ones

#Plan limits

What each plan holds for training. Contract limits can raise any of them. A refusal is 403 quota_exceeded with the limit in param, and the points a second answer 429 rate_limited; the client says so once and keeps everything in its journal.

LimitFreeStandardTeamEnterprise
training_runs101002,000none
training_imports501,00020,000none
training_live_runs1325none
training_points500,00010 million1 billionnone
training_points_per_second1,00010,000100,000none
training_storage1 GB20 GB500 GBnone
training_retention_days14180730none
training_checkpoints210200none
training_checkpoint_models202005,000none
training_landscapes110200none
probe_examples50010,000250,000none
notification_channels1550none

Runs started, runs imported and points count per month; live runs at once; checkpoints with a model and landscapes per run, checkpoint models per workspace; probe examples per set. The storage counts a run's points, files and own values (config, environment, module tree, notes, tags, summary values, the client's findings), probe sets and MLflow's tags and inputs. Once a day, runs older than the retention (counted from their last batch) are deleted, each with an entry in the audit log; a run linked to a model under a legal hold is kept. On every plan, a run holds at most 10,000 series and keeps its newest 1,000 of the client's findings, its summary values take 1 MB, and a batch holds at most 100,000 points and 8 MB.

#Going further

  • Health checks and alerts: findings on every run, rules that email you, call a webhook or post to Slack, and stop a run that has gone wrong.
  • Landscapes, checkpoints and probes: the loss surface around the model, checkpoints you open in Anatomy, and data maps of how chosen examples were learned.
  • The training record: what a run's training was, as JSON or a PDF, for the documentation the EU AI Act's Annex IV asks for.
  • Training runs and run series: every route the client calls, and the reads a script or a dashboard of your own can make.