trackio

0.22.0 · active · verified Sat Apr 11

Trackio is a lightweight, local-first, and free experiment tracking library built by Hugging Face. It offers an API compatible with Weights & Biases (wandb) for seamless migration, allowing users to log metrics, parameters, and artifacts. Logs are persisted locally in an SQLite database and can be optionally synced with Hugging Face Datasets and visualized on Hugging Face Spaces. It is actively developed with a focus on simplicity, extensibility, and LLM-friendly programmatic access.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a tracking run, log metrics within a simulated training loop, and finalize the run. It uses `trackio.init` to set up the project and configuration, `trackio.log` to record scalar metrics, and `trackio.finish` to conclude the experiment. To view the collected metrics, open a new terminal and run `trackio show`.

import trackio
import random
import time
import os

# Initialize a new experiment run
# For Spaces integration, add space_id='your_username/your_space_name'
run = trackio.init(project="my-awesome-project", 
                   name=f"run-{int(time.time())}",
                   config={
                       "learning_rate": 0.001,
                       "epochs": 5,
                       "batch_size": 32
                   })

print(f"Starting run: {run.name} in project: {run.project_name}")

# Simulate a training loop
for epoch in range(run.config["epochs"]):
    # Simulate metrics
    train_loss = 1.0 / (epoch + 1) + random.uniform(-0.1, 0.1)
    val_loss = 0.8 / (epoch + 1) + random.uniform(-0.05, 0.05)
    accuracy = 0.5 + (epoch / run.config["epochs"]) * 0.4 + random.uniform(-0.03, 0.03)
    
    # Log metrics
    trackio.log({"epoch": epoch, "train_loss": train_loss, "val_loss": val_loss, "accuracy": accuracy})
    print(f"Epoch {epoch}: Train Loss = {train_loss:.4f}, Val Loss = {val_loss:.4f}, Accuracy = {accuracy:.4f}")
    time.sleep(0.5)

# Finish the run
trackio.finish()
print("Run finished. To view the dashboard, run `trackio show` in your terminal.")

view raw JSON →