NM512 / dreamerv3-torch

Implementation of Dreamer v3 in pytorch.
MIT License
422 stars 96 forks source link

[Question] How to use parallel envs for crafter? #39

Closed darsw closed 1 year ago

darsw commented 1 year ago

Great work with this repo!

I'm getting key error log_reward when using parallel envs for crafter.

Config:

crafter: task: crafter_reward step: 1e6 parallel: True

/no eval

eval_episode_num: 0 eval_every: 1e4 action_repeat: 1 envs: 4 train_ratio: 512 video_pred_log: true dyn_hidden: 1024 dyn_deter: 4096 units: 1024 reward_layers: 5 cont_layers: 5 value_layers: 5 actor_layers: 5 encoder: {mlp_keys: '$^', cnn_keys: 'image', cnn_depth: 96, mlp_layers: 5, mlp_units: 1024} decoder: {mlp_keys: '$^', cnn_keys: 'image', cnn_depth: 96, mlp_layers: 5, mlp_units: 1024} actor_dist: 'onehot' imag_gradient: 'reinforce'

Result:

Logdir logdir/crafter Create envs. Prefill dataset (2500 steps). [0] log_reward 1.1 / log_achievement_collect_coal 0.0 / log_achievement_collect_diamond 0.0 / log_achievement_collect_drink 0.0 / log_achievement_collect_iron 0.0 / log_achievement_collect_sapling 0.0 / log_achievement_collect_stone 0.0 / log_achievement_collect_wood 97.0 / log_achievement_defeat_skeleton 0.0 / log_achievement_defeat_zombie 0.0 / log_achievement_eat_cow 0.0 / log_achievement_eat_plant 0.0 / log_achievement_make_iron_pickaxe 0.0 / log_achievement_make_iron_sword 0.0 / log_achievement_make_stone_pickaxe 0.0 / log_achievement_make_stone_sword 0.0 / log_achievement_make_wood_pickaxe 0.0 / log_achievement_make_wood_sword 0.0 / log_achievement_place_furnace 0.0 / log_achievement_place_plant 0.0 / log_achievement_place_stone 0.0 / log_achievement_place_table 0.0 / log_achievement_wake_up 39.0 / dataset_size 584.0 / train_return 1.1 / train_length 146.0 / train_episodes 4.0 Traceback (most recent call last): File "/content/drive/MyDrive/dreamerv3-torch/dreamer.py", line 396, in main(parser.parse_args(remaining)) File "/content/drive/MyDrive/dreamerv3-torch/dreamer.py", line 309, in main state = tools.simulate( File "/content/drive/MyDrive/dreamerv3-torch/tools.py", line 167, in simulate obs = {k: np.stack([o[k] for o in obs]) for k in obs[0]} File "/content/drive/MyDrive/dreamerv3-torch/tools.py", line 167, in obs = {k: np.stack([o[k] for o in obs]) for k in obs[0]} File "/content/drive/MyDrive/dreamerv3-torch/tools.py", line 167, in obs = {k: np.stack([o[k] for o in obs]) for k in obs[0]} KeyError: 'log_reward'

NM512 commented 1 year ago

Hi, Thank you for pointing out what I had overlooked. I've now updated the code at this commit so that multiple environments can be used with Crafter.