-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor update to SAC: support DM_control training
- Loading branch information
1 parent
bb5525d
commit 8b2f96b
Showing
173 changed files
with
143 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import gym | ||
from gym.wrappers import FlattenDictWrapper | ||
|
||
from dm_control import suite | ||
from dm2gym import DMControlEnv | ||
|
||
from lagom.utils import pickle_dump | ||
from lagom.utils import set_global_seeds | ||
from lagom.experiment import Config | ||
from lagom.experiment import Grid | ||
from lagom.experiment import Sample | ||
from lagom.experiment import Condition | ||
from lagom.experiment import run_experiment | ||
from lagom.envs import make_vec_env | ||
from lagom.envs.wrappers import TimeLimit | ||
from lagom.envs.wrappers import NormalizeAction | ||
from lagom.envs.wrappers import VecMonitor | ||
from lagom.envs.wrappers import VecStepInfo | ||
|
||
from baselines.sac.agent import Agent | ||
from baselines.sac.engine import Engine | ||
from baselines.sac.replay_buffer import ReplayBuffer | ||
|
||
|
||
config = Config( | ||
{'log.freq': 1000, # every n timesteps | ||
'checkpoint.num': 3, | ||
|
||
'env.id': Grid([('cheetah', 'run'), ('hopper', 'hop'), ('walker', 'run'), ('fish', 'upright')]), | ||
|
||
'agent.gamma': 0.99, | ||
'agent.polyak': 0.995, # polyak averaging coefficient for targets update | ||
'agent.actor.lr': 3e-4, | ||
'agent.actor.use_lr_scheduler': False, | ||
'agent.critic.lr': 3e-4, | ||
'agent.critic.use_lr_scheduler': False, | ||
'agent.initial_temperature': 1.0, | ||
'agent.max_grad_norm': 999999, # grad clipping by norm | ||
|
||
'replay.capacity': 1000000, | ||
# number of time steps to take uniform actions initially | ||
'replay.init_size': Condition(lambda x: 1000 if x['env.id'] in ['Hopper-v3', 'Walker2d-v3'] else 10000), | ||
'replay.batch_size': 256, | ||
|
||
'train.timestep': int(1e6), # total number of training (environmental) timesteps | ||
'eval.freq': 5000, | ||
'eval.num_episode': 10 | ||
|
||
}) | ||
|
||
|
||
def make_env(config, seed): | ||
def _make_env(): | ||
domain_name, task_name = config['env.id'] | ||
env = suite.load(domain_name, task_name, environment_kwargs=dict(flat_observation=True)) | ||
env = DMControlEnv(env) | ||
env = FlattenDictWrapper(env, ['observations']) | ||
env = TimeLimit(env, env.spec.max_episode_steps) | ||
env = NormalizeAction(env) | ||
return env | ||
env = make_vec_env(_make_env, 1, seed) # single environment | ||
return env | ||
|
||
|
||
def run(config, seed, device, logdir): | ||
set_global_seeds(seed) | ||
|
||
env = make_env(config, seed) | ||
env = VecMonitor(env) | ||
env = VecStepInfo(env) | ||
|
||
eval_env = make_env(config, seed) | ||
eval_env = VecMonitor(eval_env) | ||
|
||
agent = Agent(config, env, device) | ||
replay = ReplayBuffer(env, config['replay.capacity'], device) | ||
engine = Engine(config, agent=agent, env=env, eval_env=eval_env, replay=replay, logdir=logdir) | ||
|
||
train_logs, eval_logs = engine.train() | ||
pickle_dump(obj=train_logs, f=logdir/'train_logs', ext='.pkl') | ||
pickle_dump(obj=eval_logs, f=logdir/'eval_logs', ext='.pkl') | ||
return None | ||
|
||
|
||
if __name__ == '__main__': | ||
run_experiment(run=run, | ||
config=config, | ||
seeds=[4153361530, 3503522377, 2876994566, 172236777, 3949341511, 849059707], | ||
log_dir='logs/default_dm', | ||
max_workers=os.cpu_count(), | ||
chunksize=1, | ||
use_gpu=True, # GPU much faster, note that performance differs between CPU/GPU | ||
gpu_ids=None) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/0/4153361530/anim/openaigym.episode_batch.8.2837515.stats.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/0/4153361530/anim/openaigym.manifest.8.2837515.manifest.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/0/4153361530/anim/openaigym.video.8.2837515.video000000.meta.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-1.29 MB
baselines/sac/logs/default/0/4153361530/anim/openaigym.video.8.2837515.video000000.mp4
Binary file not shown.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/0/4153361530/anim/openaigym.video.8.2837515.video000001.meta.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.53 KB
baselines/sac/logs/default/0/4153361530/anim/openaigym.video.8.2837515.video000001.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/1/4153361530/anim/openaigym.episode_batch.6.2837515.stats.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/1/4153361530/anim/openaigym.manifest.6.2837515.manifest.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/1/4153361530/anim/openaigym.video.6.2837515.video000000.meta.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-1.55 MB
baselines/sac/logs/default/1/4153361530/anim/openaigym.video.6.2837515.video000000.mp4
Binary file not shown.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/1/4153361530/anim/openaigym.video.6.2837515.video000001.meta.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.12 KB
baselines/sac/logs/default/1/4153361530/anim/openaigym.video.6.2837515.video000001.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/2/4153361530/anim/openaigym.episode_batch.7.2837515.stats.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/2/4153361530/anim/openaigym.manifest.7.2837515.manifest.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/2/4153361530/anim/openaigym.video.7.2837515.video000000.meta.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-1.29 MB
baselines/sac/logs/default/2/4153361530/anim/openaigym.video.7.2837515.video000000.mp4
Binary file not shown.
1 change: 0 additions & 1 deletion
1
baselines/sac/logs/default/2/4153361530/anim/openaigym.video.7.2837515.video000001.meta.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-4.82 KB
baselines/sac/logs/default/2/4153361530/anim/openaigym.video.7.2837515.video000001.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.