-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
68 lines (48 loc) · 1.55 KB
/
run.py
File metadata and controls
68 lines (48 loc) · 1.55 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import logging
import random
import hydra
import numpy as np
import wandb
from omegaconf import DictConfig, OmegaConf
import torch
log = logging.getLogger(__name__)
OmegaConf.register_new_resolver("add", lambda *numbers: sum(numbers))
OmegaConf.register_new_resolver("mul", lambda *numbers: np.prod(numbers))
torch.cuda.empty_cache()
def set_seed_everywhere(seed):
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
@hydra.main(
config_path="configs",
config_name="robocasa_pc_group_img_config.yaml",
version_base="1.3",
)
def main(cfg: DictConfig) -> None:
set_seed_everywhere(cfg.seed)
# init wandb logger and config from hydra path
wandb.config = OmegaConf.to_container(cfg, resolve=True, throw_on_missing=True)
wandb.init(
project=cfg.wandb.project,
entity=cfg.wandb.entity,
group=cfg.wandb.group,
mode=cfg.wandb.mode,
config=wandb.config,
)
# train the agent
agent = hydra.utils.instantiate(cfg.agents)
trainer = hydra.utils.instantiate(cfg.trainers)
if cfg.agent_name == "3da":
agent.model.set_gripper_loc_bounds(trainer.scaler.y_bounds_tensor[:, :3])
trainer.main(agent)
torch.cuda.empty_cache()
# simulate the model
env_sim = hydra.utils.instantiate(cfg.simulation)
env_sim.test_agent(agent)
log.info("Training done")
log.info("state_dict saved in {}".format(agent.working_dir))
wandb.finish()
if __name__ == "__main__":
main()