-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_seed_fn.py
142 lines (121 loc) · 4.93 KB
/
run_seed_fn.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
import gc
import torch
import torch.distributed as dist
from omegaconf import DictConfig
from rlbench import ObservationConfig
from yarr.replay_buffer.wrappers.pytorch_replay_buffer import PyTorchReplayBuffer
from yarr.runners.offline_train_runner import OfflineTrainRunner
from yarr.utils.stat_accumulator import SimpleAccumulator
from agents import peract_bc
from agents import sgr
from agents import semantic_bc_lang
from helpers.utils import setup_logger
def run_seed(rank, cfg: DictConfig, obs_config: ObservationConfig, cams,
multi_task, seed, world_size) -> None:
dist.init_process_group('nccl', rank=rank, world_size=world_size)
torch.cuda.set_device(rank)
if rank == 0:
setup_logger(file_name='train.log',
logging_level=cfg.framework.logging_level)
task = cfg.rlbench.tasks[0]
tasks = cfg.rlbench.tasks
task_folder = task if not multi_task else tasks
replay_path = os.path.join(cfg.replay.path, str(task_folder),
f'{cfg.method.name}_{cfg.model.name}',
cfg.method.tag, 'seed%d' % seed)
if cfg.method.name == 'PERACT_BC':
replay_buffer = peract_bc.launch_utils.create_replay(
cfg.replay.batch_size, cfg.replay.timesteps,
replay_path if cfg.replay.use_disk else None, cams,
cfg.method.voxel_sizes, cfg.rlbench.camera_resolution)
peract_bc.launch_utils.fill_multi_task_replay(
cfg,
obs_config,
rank,
replay_buffer,
tasks,
cfg.rlbench.demos,
cfg.method.demo_augmentation,
cfg.method.demo_augmentation_every_n,
cams,
cfg.rlbench.scene_bounds,
cfg.method.voxel_sizes,
cfg.method.bounds_offset,
cfg.method.rotation_resolution,
cfg.method.crop_augmentation,
keypoint_method=cfg.method.keypoint_method,
variation_number=cfg.rlbench.variation_number)
agent = peract_bc.launch_utils.create_agent(cfg)
elif cfg.method.name == 'SGR':
replay_buffer = sgr.launch_utils.create_replay(
cfg.replay.batch_size, cfg.replay.timesteps,
replay_path if cfg.replay.use_disk else None, cams,
cfg.method.voxel_sizes, cfg.rlbench.camera_resolution)
sgr.launch_utils.fill_multi_task_replay(
cfg,
obs_config,
rank,
replay_buffer,
tasks,
cfg.rlbench.demos,
cfg.method.demo_augmentation,
cfg.method.demo_augmentation_every_n,
cams,
cfg.rlbench.scene_bounds,
cfg.method.voxel_sizes,
cfg.method.rotation_resolution,
keypoint_method=cfg.method.keypoint_method,
variation_number=cfg.rlbench.variation_number)
agent = sgr.launch_utils.create_agent(cfg)
elif cfg.method.name == 'SEMANTIC_BC_LANG':
replay_buffer = semantic_bc_lang.launch_utils.create_replay(
cfg.replay.batch_size, cfg.replay.timesteps,
replay_path if cfg.replay.use_disk else None, cams,
cfg.method.voxel_sizes, cfg.rlbench.camera_resolution)
semantic_bc_lang.launch_utils.fill_multi_task_replay(
cfg,
obs_config,
rank,
replay_buffer,
tasks,
cfg.rlbench.demos,
cfg.method.demo_augmentation,
cfg.method.demo_augmentation_every_n,
cams,
cfg.rlbench.scene_bounds,
cfg.method.voxel_sizes,
cfg.method.rotation_resolution,
keypoint_method=cfg.method.keypoint_method,
variation_number=cfg.rlbench.variation_number)
agent = semantic_bc_lang.launch_utils.create_agent(cfg)
else:
raise ValueError('Method %s does not exists.' % cfg.method.name)
wrapped_replay = PyTorchReplayBuffer(replay_buffer,
num_workers=cfg.framework.num_workers)
stat_accum = SimpleAccumulator(eval_video_fps=30)
cwd = os.getcwd()
weightsdir = os.path.join(cwd, 'weights')
logdir = cwd
train_runner = OfflineTrainRunner(
agent=agent,
wrapped_replay_buffer=wrapped_replay,
train_device=rank,
stat_accumulator=stat_accum,
iterations=cfg.framework.training_iterations,
logdir=logdir,
logging_level=cfg.framework.logging_level,
log_freq=cfg.framework.log_freq,
weightsdir=weightsdir,
num_weights_to_keep=cfg.framework.num_weights_to_keep,
save_freq=cfg.framework.save_freq,
tensorboard_logging=cfg.framework.tensorboard_logging,
csv_logging=cfg.framework.csv_logging,
load_existing_weights=cfg.framework.load_existing_weights,
rank=rank,
world_size=world_size)
train_runner.start()
del train_runner
del agent
gc.collect()
torch.cuda.empty_cache()