-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhyperparams.py
More file actions
48 lines (45 loc) · 1.88 KB
/
hyperparams.py
File metadata and controls
48 lines (45 loc) · 1.88 KB
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
from pathlib import Path
import csv
from hydra.core.hydra_config import HydraConfig
from omegaconf import DictConfig
def get_agent_cli_args():
overrides: list[str] = HydraConfig.get().overrides.task
agent_overrides = []
overrode_offline_steps = False
for ovr in overrides:
if ovr.startswith("agent."):
agent_overrides.append(ovr[6:].split('=')[0])
elif ovr.startswith("offline_steps="):
overrode_offline_steps = True
return agent_overrides, overrode_offline_steps
def override_non_cli_args_with_default(
cfg: DictConfig,
processed_env_name: str
):
agent_name = cfg.agent.agent_name
if agent_name == "gfp" and cfg.agent.guidance_fn == "advantage":
agent_name = "gfp-advantage"
params_file = Path(__file__).parent / f"{agent_name}_params.csv"
if not params_file.exists():
return
agent_overrides,overrode_offline_steps = get_agent_cli_args()
with open(params_file,mode="r") as csvfile:
reader = csv.DictReader(csvfile)
corresponding_rows = [
row for row in reader
if (row["benchmark"] in processed_env_name
and row["env_name"] in processed_env_name)
]
n_rows = len(corresponding_rows)
if n_rows > 0:
print(f"Found {n_rows} matching hyper-param sets")
corresponding_rows.sort(key=lambda row: len(row["env_name"]))
row = corresponding_rows[-1]
for key,val in row.items():
if key == "offline_steps":
if not overrode_offline_steps:
cfg.offline_steps = int(val)
if hasattr(cfg.agent,key) and key not in agent_overrides:
setattr(cfg.agent,key,type(getattr(cfg.agent,key))(val))
print(f"Recovered hyper parameters from {params_file}->{row['env_name']}")
return