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.
- Install the client, 0.22.0 or later, with its training extras:
pip install "kaimei[train]". They addpsutilandnvidia-ml-py, for hardware load. A self-hosted API needs 1.13.0 or later. - Give it an API key:
kaimei loginstores one for the machine, or setKAIMEI_API_KEY. - Start a run with
kaimei.init, and callkaimei.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. - Log what the frameworks don't with
run.log, checkrun.stop_requestedin a plain loop, and callrun.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 modelpip 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 training | When the run reaches Kaimei | If the process dies |
|---|---|---|---|
"live" | Journal on disk; uploads every 2 seconds or 1,000 points; a heartbeat every 30 seconds | Within seconds | Already 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 id | At finish() or exit | kaimei sync uploads the journal |
"offline" | Journal only; no network at all | When you run kaimei sync | Nothing 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.
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 wandbruns a W&B script on Kaimei:init,log(numbers, tensors,wandb.Image,wandb.Histogram,wandb.Table),config,summary,define_metric,watch,alertandfinish. For a library that importswandbitself, such as the Hugging Face trainer withreport_to="wandb", callkaimei.compat.wandb.install()before it does.tee=Truekeeps 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 onceMLFLOW_TRACKING_URIpoints at Kaimei andMLFLOW_TRACKING_TOKENholds an API key. An experiment is a project; see MLflow tracking for what maps to what. - TensorBoard, no change.
kaimei.autolog()mirrorsSummaryWriter(PyTorch and tensorboardX) andtf.summaryinto the run: scalars, histograms, text, images and hyperparameters. To leave the training script alone,kaimei tensorboard --follow ./runsmirrors the event files live from another process, one run per folder. - Past runs, one command.
kaimei importcopies 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 sentafter, withsource: "import"andimported_fromnaming 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-riskexport 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 ./mlrunskaimei 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.
| Limit | Free | Standard | Team | Enterprise |
|---|---|---|---|---|
training_runs | 10 | 100 | 2,000 | none |
training_imports | 50 | 1,000 | 20,000 | none |
training_live_runs | 1 | 3 | 25 | none |
training_points | 500,000 | 10 million | 1 billion | none |
training_points_per_second | 1,000 | 10,000 | 100,000 | none |
training_storage | 1 GB | 20 GB | 500 GB | none |
training_retention_days | 14 | 180 | 730 | none |
training_checkpoints | 2 | 10 | 200 | none |
training_checkpoint_models | 20 | 200 | 5,000 | none |
training_landscapes | 1 | 10 | 200 | none |
probe_examples | 500 | 10,000 | 250,000 | none |
notification_channels | 1 | 5 | 50 | none |
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.