Skip to content

Commit 439216d

Browse files
committed
changes
1 parent 3950bfa commit 439216d

6 files changed

Lines changed: 241 additions & 39 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
notebooks/
2+
trackio/__pycache__/

trackio/__init__.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,28 @@
1+
import logging
12
from pathlib import Path
23

3-
from .storage import TrackioStorage
4-
from .ui import launch_ui
4+
from trackio.run import Run, current_run
5+
from trackio.ui import launch_ui
56

67
__version__ = Path(__file__).parent.joinpath("version.txt").read_text().strip()
78

8-
_current_run = None
9-
10-
11-
class Run:
12-
def __init__(self, project, name, config):
13-
self.project = project
14-
self.name = name
15-
self.config = config
16-
self.storage = TrackioStorage(project, name, config)
17-
18-
def log(self, metrics):
19-
self.storage.log(metrics)
20-
21-
def finish(self):
22-
self.storage.finish()
23-
249

2510
def init(project, name=None, config=None):
26-
global _current_run
27-
_current_run = Run(project, name, config)
28-
return _current_run
11+
logging.info(f"Initializing run | Project: {project} | Name: {name}")
12+
current_run.set(Run(project, name, config))
2913

3014

3115
def log(metrics):
32-
if _current_run is None:
16+
if current_run.get() is None:
3317
raise RuntimeError("Call trackio.init() before log().")
34-
_current_run.log(metrics)
18+
current_run.get().log(metrics)
3519

3620

3721
def finish():
38-
if _current_run is None:
22+
if current_run.get() is None:
3923
raise RuntimeError("Call trackio.init() before finish().")
40-
_current_run.finish()
41-
global _current_run
42-
_current_run = None
24+
current_run.get().finish()
25+
current_run.set(None)
4326

4427

4528
def ui():

trackio/run.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import contextvars
2+
3+
from trackio.storage import TrackioStorage
4+
from trackio.utils import generate_readable_name
5+
6+
7+
class Run:
8+
def __init__(
9+
self, project: str, name: str | None = None, config: dict | None = None
10+
):
11+
self.project = project
12+
self.name = name or generate_readable_name()
13+
self.config = config or {}
14+
self.storage = TrackioStorage(project, name, config)
15+
16+
def log(self, metrics: dict):
17+
self.storage.log(metrics)
18+
19+
def finish(self):
20+
self.storage.finish()
21+
22+
23+
current_run: contextvars.ContextVar[Run | None] = contextvars.ContextVar("current_run", default=None)

trackio/storage.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1+
import json
12
import os
2-
from datasets import Dataset
3+
34
import pandas as pd
5+
from datasets import Dataset
46

57

68
class TrackioStorage:
7-
def __init__(self, project, name, config):
9+
def __init__(self, project: str, name: str, config: dict):
810
self.project = project
9-
self.name = name or "unnamed_run"
10-
self.config = config or {}
11-
self.logs = []
11+
self.name = name
12+
self.config = config
13+
self.logs: list[dict] = []
1214
self.dir = os.path.join("trackio", project, self.name)
1315
os.makedirs(self.dir, exist_ok=True)
1416
self.run_path = os.path.join(self.dir, "run.parquet")
1517
self.config_path = os.path.join(self.dir, "config.json")
16-
# Save config immediately
17-
import json
1818

1919
with open(self.config_path, "w") as f:
2020
json.dump(self.config, f, indent=2)
2121

22-
def log(self, metrics):
22+
def log(self, metrics: dict):
2323
self.logs.append(metrics)
2424

2525
def finish(self):

trackio/ui.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def plot_metrics(df):
5555

5656

5757
def update_runs(project):
58-
return gr.Dropdown.update(choices=get_runs(project), value=None)
58+
return gr.Dropdown(choices=get_runs(project), value=None)
5959

6060

6161
def update_dashboard(project, run):
@@ -67,8 +67,7 @@ def update_dashboard(project, run):
6767
)
6868
df, config = load_run_data(project, run)
6969
plots = plot_metrics(df)
70-
config_str = json.dumps(config, indent=2)
71-
return plots, gr.JSON.update(value=config), gr.update(visible=True)
70+
return plots, gr.JSON(value=config), gr.update(visible=True)
7271

7372

7473
def launch_ui():
@@ -78,7 +77,7 @@ def launch_ui():
7877
project_dd = gr.Dropdown(label="Project", choices=get_projects())
7978
run_dd = gr.Dropdown(label="Run", choices=[])
8079
with gr.Row():
81-
plot_output = gr.Plot(
80+
plot_output = gr.LinePlot(
8281
label="Metrics",
8382
visible=False,
8483
show_label=True,

trackio/utils.py

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import random
2+
3+
4+
def generate_readable_name():
5+
"""
6+
Generates a random, readable name like "dainty-sunset-1"
7+
"""
8+
adjectives = [
9+
"dainty",
10+
"brave",
11+
"calm",
12+
"eager",
13+
"fancy",
14+
"gentle",
15+
"happy",
16+
"jolly",
17+
"kind",
18+
"lively",
19+
"merry",
20+
"nice",
21+
"proud",
22+
"quick",
23+
"silly",
24+
"tidy",
25+
"witty",
26+
"zealous",
27+
"bright",
28+
"shy",
29+
"bold",
30+
"clever",
31+
"daring",
32+
"elegant",
33+
"faithful",
34+
"graceful",
35+
"honest",
36+
"inventive",
37+
"jovial",
38+
"keen",
39+
"lucky",
40+
"modest",
41+
"noble",
42+
"optimistic",
43+
"patient",
44+
"quirky",
45+
"resourceful",
46+
"sincere",
47+
"thoughtful",
48+
"upbeat",
49+
"valiant",
50+
"warm",
51+
"youthful",
52+
"zesty",
53+
"adventurous",
54+
"breezy",
55+
"cheerful",
56+
"delightful",
57+
"energetic",
58+
"fearless",
59+
"glad",
60+
"hopeful",
61+
"imaginative",
62+
"joyful",
63+
"kindly",
64+
"luminous",
65+
"mysterious",
66+
"neat",
67+
"outgoing",
68+
"playful",
69+
"radiant",
70+
"spirited",
71+
"tranquil",
72+
"unique",
73+
"vivid",
74+
"wise",
75+
"zany",
76+
"artful",
77+
"bubbly",
78+
"charming",
79+
"dazzling",
80+
"earnest",
81+
"festive",
82+
"gentlemanly",
83+
"hearty",
84+
"intrepid",
85+
"jubilant",
86+
"knightly",
87+
"lively",
88+
"magnetic",
89+
"nimble",
90+
"orderly",
91+
"peaceful",
92+
"quick-witted",
93+
"robust",
94+
"sturdy",
95+
"trusty",
96+
"upstanding",
97+
"vibrant",
98+
"whimsical",
99+
]
100+
nouns = [
101+
"sunset",
102+
"forest",
103+
"river",
104+
"mountain",
105+
"breeze",
106+
"meadow",
107+
"ocean",
108+
"valley",
109+
"sky",
110+
"field",
111+
"cloud",
112+
"star",
113+
"rain",
114+
"leaf",
115+
"stone",
116+
"flower",
117+
"bird",
118+
"tree",
119+
"wave",
120+
"trail",
121+
"island",
122+
"desert",
123+
"hill",
124+
"lake",
125+
"pond",
126+
"grove",
127+
"canyon",
128+
"reef",
129+
"bay",
130+
"peak",
131+
"glade",
132+
"marsh",
133+
"cliff",
134+
"dune",
135+
"spring",
136+
"brook",
137+
"cave",
138+
"plain",
139+
"ridge",
140+
"wood",
141+
"blossom",
142+
"petal",
143+
"root",
144+
"branch",
145+
"seed",
146+
"acorn",
147+
"pine",
148+
"willow",
149+
"cedar",
150+
"elm",
151+
"falcon",
152+
"eagle",
153+
"sparrow",
154+
"robin",
155+
"owl",
156+
"finch",
157+
"heron",
158+
"crane",
159+
"duck",
160+
"swan",
161+
"fox",
162+
"wolf",
163+
"bear",
164+
"deer",
165+
"moose",
166+
"otter",
167+
"beaver",
168+
"lynx",
169+
"hare",
170+
"badger",
171+
"butterfly",
172+
"bee",
173+
"ant",
174+
"beetle",
175+
"dragonfly",
176+
"firefly",
177+
"ladybug",
178+
"moth",
179+
"spider",
180+
"worm",
181+
"coral",
182+
"kelp",
183+
"shell",
184+
"pebble",
185+
"boulder",
186+
"cobble",
187+
"sand",
188+
"wavelet",
189+
"tide",
190+
"current",
191+
]
192+
adjective = random.choice(adjectives)
193+
noun = random.choice(nouns)
194+
number = random.randint(1, 99)
195+
return f"{adjective}-{noun}-{number}"

0 commit comments

Comments
 (0)