forked from meta-llama/llama-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracker_utils.py
62 lines (51 loc) · 1.97 KB
/
tracker_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import importlib
from llama_recipes.configs import aim_config
class Tracker:
def initialize(self, tracker_config):
pass
def load_params(self, params, context):
pass
def track(self, metric, name, stage):
pass
class Aim(Tracker):
run: None
config: None
def initialize(self, tracker_config):
self.config = tracker_config
assert isinstance(tracker_config, aim_config), f"config passed to AIM tracker is unknown: {type(tracker_config)}"
try:
AIM = importlib.import_module("aim")
Run = AIM.Run
except Exception:
raise ImportError("Failed to import modules from pkg 'aim'.\n"
"Please run 'pip install aim==3.17.5' to install Aim before proceeding.")
exp = self.config.experiment
repo = self.config.repo
if (self.config.remote_server_ip is not None) and (self.config.remote_server_port is not None):
repo = f"aim://{self.config.remote_server_ip}:{self.config.remote_server_port}/"
try:
if repo is not None:
print("Aimstack trying to connect to the repo "+repo)
self.run = Run(repo=repo, experiment=exp)
else:
print("Aimstack using the default repo `.run`")
self.run = Run(experiment=exp)
except Exception:
print("Failed to start Aim stack tracker")
def load_params(self, params, context):
run_params = {}
for k, v in params.items():
run_params[k] = v
self.run[context] = run_params
def track(self, metric, name, stage):
if self.run is not None:
self.run.track(metric, name=name, context={'subset':stage})
def get_tracker_by_name(name):
if name is None:
return None
elif name == "aim":
return Aim()
else :
print("Unknown Tracker "+str(name)+" Please check the name of the tracker passed. ")
return None