metaflow-traincard
See your training run live — loss curves, GPU usage, and checkpoints — without leaving Metaflow.
The problem
LLM fine-tuning jobs run for hours with zero visibility. By the time you know your loss is diverging or your GPU is idle, the run has been wasting compute for hours. TensorBoard requires a separate server; W&B requires credentials and an account — and neither result is versioned with the run itself.
Quick start
pip install metaflow-traincard
from metaflow import FlowSpec, step, card
from metaflow_traincard import Reporter
class MyFlow(FlowSpec):
@card(type="traincard")
@step
def train(self):
reporter = Reporter()
for step_num, batch in enumerate(loader):
loss = train_step(batch)
reporter.metric("loss", loss, step_num)
reporter.finish()
self.traincard_state = reporter.get_state()
self.next(self.end)
Open the card in the Metaflow UI — live loss curves, GPU bars, and checkpoint history are waiting.
Install
# Core
pip install metaflow-traincard
# With HuggingFace Trainer integration
pip install "metaflow-traincard[hf]"
Usage
Raw PyTorch
reporter = Reporter(
output_dir="/tmp/traincard", # where metrics are buffered
flush_interval=5, # seconds between background flushes
rank=0, # distributed rank (non-zero ranks are silent)
world_size=1,
)
reporter.metric("train/loss", loss, step=global_step)
reporter.metric("train/learning_rate", lr, step=global_step)
reporter.system({
"gpu_utilization": [88.0, 83.0],
"gpu_memory_used_gb": [18.5, 18.2],
"gpu_memory_total_gb": [24.0, 24.0],
"cpu_percent": 35.0,
"ram_used_gb": 42.1,
"ram_total_gb": 64.0,
})
reporter.checkpoint("/tmp/ckpt-100", metadata={"eval_loss": 1.38, "epoch": 2})
reporter.finish()
self.traincard_state = reporter.get_state()
HuggingFace Trainer
from metaflow_traincard import HFTrainCardCallback
trainer = Trainer(
model=model,
args=training_args,
callbacks=[HFTrainCardCallback()],
)
trainer.train()
self.traincard_state = HFTrainCardCallback().reporter.get_state()
HFTrainCardCallback maps all Trainer events automatically — on_log → metrics, on_save → checkpoints, on_evaluate → eval phase, on_train_end → finish. GPU/CPU telemetry is sampled every 10 seconds via pynvml + psutil (both optional).
Preview the card locally
from metaflow import Flow, namespace
from metaflow_traincard import render_state
namespace(None)
state = Flow("MyFlow").latest_run["train"].task["traincard_state"].data
open("card.html", "w").write(render_state(state))
# open card.html
How it works
The Reporter writes metrics and telemetry to a local events.jsonl log via a background thread, flushing an atomic latest.json snapshot every few seconds. On step completion, get_state() returns the full in-memory state dict, which is stored as the traincard_state artifact. The TrainCard renderer reads that artifact and produces a self-contained HTML page — Chart.js charts, GPU utilization bars, checkpoint table, and log viewer — served by Metaflow's card system.
Crash safety: latest.json is written via tmp-then-rename, and a SIGTERM handler flushes state before the process exits. Resume detection: if the same output_dir exists from a prior run, metric history is loaded and a visual discontinuity marker is inserted in each chart.
Card sections
| Section | What it shows |
|---|---|
| Status header | Phase badge (TRAINING / EVALUATING / SAVING / DONE), step, epoch, elapsed time |
| Training Metrics | Live Chart.js line charts — loss, eval loss, LR, grad norm, tokens/sec, any custom metric |
| System Telemetry | Per-GPU utilization bars, VRAM used/total, temperature, CPU %, RAM, disk throughput |
| Checkpoints | Table of saved checkpoints — step, size, age, metadata; BEST badge on lowest eval loss |
| Logs | Searchable tail of recent log lines; errors and warnings highlighted |
| Failure Summary | Exception type, message, traceback toggle, OOM warning (shown only on crash) |
Full card (system telemetry · checkpoints · logs)
Development
git clone https://github.com/npow/metaflow-traincard
cd metaflow-traincard
pip install -e ".[dev]"
pytest tests/ -v
License
Metadata
Release files for metaflow-traincard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| metaflow_traincard-0.1.0.tar.gz | 29.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| metaflow_traincard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.2 kB
Release files / metaflow_traincard-0.1.0.tar.gz
| Download URL | metaflow_traincard-0.1.0.tar.gz |
|---|---|
| Size | 29.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f564173d52924a578eb4ed22e377cc7859e070da7cf435801998e3ca96d5ce65
|
|
BLAKE2b-256 checksum How to use checksums |
599cdba244dd2709beb9521d9001871d0b5cc2b41771930276dbb946a502aa14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2026.
Transparency logRelease files / metaflow_traincard-0.1.0-py3-none-any.whl
| Download URL | metaflow_traincard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6309114cdc4763c8ad93f5fa33424921a22d7ce13892f608adce034dc12f8c65
|
|
BLAKE2b-256 checksum How to use checksums |
77e095564e357e25f69160fff8fc4756ffab0d88439803b501df6675eaba804c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2026.
Transparency logSecurity for metaflow-traincard 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for metaflow_traincard-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.