File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # trackio
1+ # Trackio
22
3- A Python library for tracking and analytics.
3+ Trackio is a drop-in replacement for ` wandb ` that uses Hugging Face Datasets for experiment logging and Gradio for visualization.
4+
5+ ## Features
6+ - ** API compatible** with ` wandb.init ` , ` wandb.log ` , and ` wandb.finish ` (use ` trackio ` instead)
7+ - Stores logs in a Hugging Face Datasets-compatible format (Parquet)
8+ - Visualize experiments with a Gradio dashboard
9+
10+ ## Example Usage
11+ ``` python
12+ import random
13+ import math
14+ import trackio
15+
16+ # Launch 5 simulated experiments
17+ total_runs = 5
18+ for run in range (total_runs):
19+ trackio.init(
20+ project = " basic-intro" ,
21+ name = f " experiment_ { run} " ,
22+ config = {
23+ " learning_rate" : 0.02 ,
24+ " architecture" : " CNN" ,
25+ " dataset" : " CIFAR-100" ,
26+ " epochs" : 10 ,
27+ },
28+ )
29+
30+ epochs = 10
31+ offset = random.random() / 5
32+ for epoch in range (2 , epochs):
33+ acc = 1 - 2 ** - epoch - random.random() / epoch - offset
34+ loss = 2 ** - epoch + random.random() / epoch + offset
35+ trackio.log({" acc" : acc, " loss" : loss})
36+
37+ trackio.finish()
38+
39+ # To launch the Gradio UI:
40+ trackio.ui()
41+ ```
42+
43+ ## Data Storage
44+ - Logs are saved in ` ./trackio/{project}/{run_name}/run.parquet `
45+ - Config is saved as ` config.json ` in the same directory
46+
47+ ## Visualization
48+ - Run ` trackio.ui() ` to launch the Gradio dashboard and explore your experiments
449
550## Installation
651
Original file line number Diff line number Diff line change 1-
1+ datasets
2+ pandas
3+ gradio
4+ plotly
Original file line number Diff line number Diff line change 22
33
44def test_version ():
5- assert trackio .__version__ == "0.1.0 "
5+ assert trackio .__version__ == "0.0.2 "
Original file line number Diff line number Diff line change 11from pathlib import Path
2+ import os
3+ from .storage import TrackioStorage
4+ from .ui import launch_ui
25
36__version__ = Path (__file__ ).parent .joinpath ("version.txt" ).read_text ().strip ()
7+
8+ _current_run = None
9+
10+ class Run :
11+ def __init__ (self , project , name , config ):
12+ self .project = project
13+ self .name = name
14+ self .config = config
15+ self .storage = TrackioStorage (project , name , config )
16+ def log (self , metrics ):
17+ self .storage .log (metrics )
18+ def finish (self ):
19+ self .storage .finish ()
20+
21+ def init (project , name = None , config = None ):
22+ global _current_run
23+ _current_run = Run (project , name , config )
24+ return _current_run
25+
26+ def log (metrics ):
27+ if _current_run is None :
28+ raise RuntimeError ("Call trackio.init() before log()." )
29+ _current_run .log (metrics )
30+
31+ def finish ():
32+ if _current_run is None :
33+ raise RuntimeError ("Call trackio.init() before finish()." )
34+ _current_run .finish ()
35+ global _current_run
36+ _current_run = None
37+
38+ def ui ():
39+ launch_ui ()
Original file line number Diff line number Diff line change 1+ import os
2+ from datasets import Dataset
3+ import pandas as pd
4+
5+ class TrackioStorage :
6+ def __init__ (self , project , name , config ):
7+ self .project = project
8+ self .name = name or "unnamed_run"
9+ self .config = config or {}
10+ self .logs = []
11+ self .dir = os .path .join ("trackio" , project , self .name )
12+ os .makedirs (self .dir , exist_ok = True )
13+ self .run_path = os .path .join (self .dir , "run.parquet" )
14+ self .config_path = os .path .join (self .dir , "config.json" )
15+ # Save config immediately
16+ import json
17+ with open (self .config_path , "w" ) as f :
18+ json .dump (self .config , f , indent = 2 )
19+ def log (self , metrics ):
20+ self .logs .append (metrics )
21+ def finish (self ):
22+ if self .logs :
23+ df = pd .DataFrame (self .logs )
24+ ds = Dataset .from_pandas (df )
25+ ds .to_parquet (self .run_path )
Original file line number Diff line number Diff line change 1+ import gradio as gr
2+
3+ def launch_ui ():
4+ with gr .Blocks () as demo :
5+ gr .Markdown ("# Trackio Dashboard\n (Placeholder UI)" )
6+ gr .Markdown ("This will show your tracked experiments." )
7+ demo .launch ()
You can’t perform that action at this time.
0 commit comments