Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3c62cb0
Code working modulo action wrappers
decodyng Feb 11, 2021
5804df7
Initial changes to get Minecraft non-obfuscated working, modulo strin…
decodyng Feb 16, 2021
bbdc991
Remove unused pdb
decodyng Feb 22, 2021
33ffce6
Basic working with flat action distribution
decodyng Mar 3, 2021
d3de350
Fix obs mapping error
decodyng Mar 4, 2021
75d3a10
Get full pipeline working with FindCaves
decodyng Mar 11, 2021
488aa49
Get tests passing
decodyng Mar 11, 2021
c8be72c
Remove unused import
decodyng Mar 11, 2021
bd1fb54
Fix merge conflicts with master
decodyng Mar 11, 2021
ec46c3d
Remove typo and get tests running
decodyng Mar 11, 2021
858ded8
Update requirements
decodyng Mar 11, 2021
66364cc
Remove minerl from requirements since it currently doesn't work in th…
decodyng Mar 11, 2021
fabf11d
Remove RB from requirements
decodyng Mar 11, 2021
e810bd8
Fully remove RB from requirements
decodyng Mar 12, 2021
d4cef19
Turn warning into info if RB isn't installed
decodyng Mar 12, 2021
98cbc46
New data to fit with new wrappers
decodyng Mar 15, 2021
c08b99f
Get tests passing
decodyng Mar 15, 2021
c89ed13
Remove breakpoint
decodyng Mar 15, 2021
29e4c74
Turn RB fail-to-import into print rather than warning
decodyng Mar 15, 2021
e8e03c1
Turn print into info()
decodyng Mar 15, 2021
f51817a
Add RB to requirements now that CircleCI has access
decodyng Mar 16, 2021
667078c
Increase wrapper limit to 2500
decodyng Mar 18, 2021
8843122
Put config in il_train where it should be
decodyng Mar 18, 2021
dbe0139
Local changes for basalt baselines
decodyng Apr 7, 2021
9adaf16
Remove RB from requirements.txt
decodyng Apr 7, 2021
64d948e
Get full chain working on Minecraft envs
decodyng Apr 15, 2021
f7bf3c8
Merge in current master
decodyng Apr 15, 2021
d512112
Maybe don't use 5x the memory you need to use
decodyng Apr 16, 2021
fab188b
Add frames_per_traj parameter
decodyng Apr 16, 2021
65bbe46
Make wrapper named configs clearer
decodyng Apr 16, 2021
9449752
Update Minecraft data loading to work on a per-trajectory basis
decodyng Apr 16, 2021
6e89786
Add support for saving out encoders to facilitate il pretraining
decodyng Apr 19, 2021
acd8978
Make new chain configs
decodyng Apr 19, 2021
7be4262
Make multicallback training work
decodyng Apr 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
docker:
# this is also used in gcp_cluster_template.yaml (if you change this file,
# remember to update all your cluster configs too)
- image: humancompatibleai/il-representations:2021.02.22
- image: humancompatibleai/il-representations:2021.03.16
steps:
- checkout
- run:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RUN apt-get update -q \
wget \
xpra \
xserver-xorg-dev \
libopenmpi-dev \
libxrandr2 \
libxss1 \
libxcursor1 \
Expand Down
2 changes: 1 addition & 1 deletion cloud/gcp_cluster_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker:
# the image below is taken from .circleci/config.yml
# (if you change this file or that file, then remember to change the other
# too)
image: "humancompatibleai/il-representations:2021.02.22"
image: "humancompatibleai/il-representations:2021.03.16"
container_name: "il-rep-ray-tune"
# Set to true if to always force-pull the latest image version (no cache).
pull_before_run: False
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ git+git://github.com/HumanCompatibleAI/stable-baselines3@ad902dd5f9d4afeef347897
magical-il~=0.0.1a4
dm_control~=0.0.319497192
git+git://github.com/denisyarats/dmc2gym@6e34d8acf18e92f0ea0a38ecee9564bdf2549076#egg=dmc2gym

# # NOTE TO SELF: Developing locally with updated RB, need to change that here once that PR is merged
# # Target RB branch: ilr_wrappers
# # [Also need to make branch un-private somehow, possibly giving CircleCI a checkout key?...]
# git+ssh://git@github.com/HumanCompatibleAI/realistic-benchmarks@master#egg=realistic-benchmarks
5 changes: 3 additions & 2 deletions src/il_representations/algos/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from gym import spaces
from il_representations.algos.utils import independent_multivariate_normal
from il_representations.utils import ForkedPdb
import functools

"""
Expand Down Expand Up @@ -407,7 +408,6 @@ def infer_action_shape_info(action_space, action_embedding_dim):
and the action_embedding_dim
"""
# Machinery for turning raw actions into vectors.

if isinstance(action_space, spaces.Discrete):
# If actions are discrete, this is done via an Embedding.
action_processor = nn.Embedding(num_embeddings=action_space.n, embedding_dim=action_embedding_dim)
Expand Down Expand Up @@ -439,6 +439,7 @@ def __init__(self, obs_space, representation_dim, action_space, learn_scale=Fals

super().__init__(obs_space, representation_dim, obs_encoder_cls, learn_scale=learn_scale)

# TODO make this work better for more complex action types like those in Minecraft
self.processed_action_dim, self.action_shape, self.action_processor = infer_action_shape_info(action_space,
action_embedding_dim)
# Machinery for aggregating information from an arbitrary number of actions into a single vector,
Expand Down Expand Up @@ -476,7 +477,7 @@ def forward(self, x, traj_info, action=False):
if self.action_encoder is not None:
output, (hidden, cell) = self.action_encoder(processed_actions)
else:
hidden = torch.mean(processed_actions, dim=1)
hidden = torch.mean(processed_actions.float(), dim=1)

action_encoding_vector = torch.squeeze(hidden)
assert action_encoding_vector.shape[0] == batch_dim, \
Expand Down
1 change: 0 additions & 1 deletion src/il_representations/algos/representation_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def learn(self, datasets, batches_per_epoch, n_epochs, n_trajs=None, callbacks=(
for step, batch in enumerate(dataloader):
# Construct batch (currently just using Torch's default batch-creator)
contexts, targets, traj_ts_info, extra_context = self.unpack_batch(batch)

# Use an algorithm-specific augmentation strategy to augment either
# just context, or both context and targets
contexts, targets = self._prep_tensors(contexts), self._prep_tensors(targets)
Expand Down
1 change: 1 addition & 0 deletions src/il_representations/data/write_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def write_frames(out_file_path, meta_dict, frame_dicts, n_traj=None):
with wds.TarWriter(out_file_path, keep_meta=True, compress=True) \
as writer: # noqa: E207
# first write _metadata.meta.pickle containing the benchmark config
meta_dict['frames'] = len(frame_dicts)
writer.dwrite(key='_metadata', meta_pickle=meta_dict)
# now write each frame in each trajectory
for frame_num, frame_dict in enumerate(frame_dicts):
Expand Down
15 changes: 9 additions & 6 deletions src/il_representations/envs/auto.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Code for automatically loading data, creating vecenvs, etc. based on
Sacred configuration."""

from functools import partial
import glob
import logging
import os
Expand All @@ -18,10 +19,10 @@
from il_representations.envs.dm_control_envs import load_dataset_dm_control
from il_representations.envs.magical_envs import (get_env_name_magical,
load_dataset_magical)
from il_representations.envs.minecraft_envs import (MinecraftVectorWrapper,
get_env_name_minecraft,
from il_representations.envs.minecraft_envs import (get_env_name_minecraft,
load_dataset_minecraft)
from il_representations.scripts.utils import update as dict_update
from il_representations.envs.utils import wrap_env

ERROR_MESSAGE = "no support for benchmark_name={benchmark_name!r}"

Expand Down Expand Up @@ -53,6 +54,7 @@ def benchmark_is_available(benchmark_name):
# we check whether minecraft is installed by importing minerl
try:
import minerl # noqa: F401
import realistic_benchmarks
return True, None
except ImportError as ex:
return False, "MineRL not installed, cannot use Minecraft " \
Expand All @@ -62,7 +64,7 @@ def benchmark_is_available(benchmark_name):


@env_cfg_ingredient.capture
def load_dict_dataset(benchmark_name, n_traj=None):
def load_dict_dataset(benchmark_name, n_traj, frames_per_traj):
"""Load a dict-type dataset. Also see load_wds_datasets, which instead
lods a set of datasets that have been stored in a webdataset-compatible
format."""
Expand All @@ -73,7 +75,7 @@ def load_dict_dataset(benchmark_name, n_traj=None):
elif benchmark_name == 'atari':
dataset_dict = load_dataset_atari(n_traj=n_traj)
elif benchmark_name == 'minecraft':
dataset_dict = load_dataset_minecraft(n_traj=n_traj)
dataset_dict = load_dataset_minecraft(n_traj=n_traj, frames_per_traj=frames_per_traj)
else:
raise NotImplementedError(ERROR_MESSAGE.format(**locals()))

Expand Down Expand Up @@ -110,9 +112,10 @@ def _get_venv_opts(n_envs, venv_parallel, parallel_workers):
return n_envs, venv_parallel, parallel_workers



@env_cfg_ingredient.capture
def load_vec_env(benchmark_name, dm_control_full_env_names,
dm_control_frame_stack, minecraft_max_env_steps):
dm_control_frame_stack, minecraft_max_env_steps, minecraft_wrappers):
"""Create a vec env for the selected benchmark task and wrap it with any
necessary wrappers."""
n_envs, venv_parallel, parallel_workers = _get_venv_opts()
Expand Down Expand Up @@ -161,7 +164,7 @@ def load_vec_env(benchmark_name, dm_control_full_env_names,
n_envs=1, # TODO fix this eventually; currently hitting error
# noted here: https://github.com/minerllabs/minerl/issues/177
parallel=venv_parallel,
wrapper_class=MinecraftVectorWrapper,
wrapper_class=partial(wrap_env, wrappers=minecraft_wrappers),
max_episode_steps=minecraft_max_env_steps)
raise NotImplementedError(ERROR_MESSAGE.format(**locals()))

Expand Down
47 changes: 46 additions & 1 deletion src/il_representations/envs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
vecenvs (`venv_opts_ingredient`), and for loading data
(`env_data_ingredient`)."""
import os

import logging
from sacred import Ingredient
from il_representations.envs.utils import MinecraftPOVWrapper, Testing2500StepLimitWrapper
try:
import realistic_benchmarks.wrappers as rb_wrappers
except ImportError as e:
print(f"Hit error: {e}")
logging.info("Realistic Benchmarks is not installed; as a result much Minecraft functionality will not work")


ALL_BENCHMARK_NAMES = {"atari", "magical", "dm_control", "minecraft"}

Expand Down Expand Up @@ -69,11 +76,49 @@ def env_cfg_defaults():
# Minecraft-specific config variables
# ###############################
minecraft_max_env_steps = None
minecraft_wrappers = list()
_ = locals()
del _

@env_cfg_ingredient.named_config
def wrappers_frames_only_camera_disc_no_limit():
minecraft_wrappers = [rb_wrappers.CameraDiscretizationWrapper, rb_wrappers.ActionFlatteningWrapper,
MinecraftPOVWrapper] #
_ = locals()
del _

@env_cfg_ingredient.named_config
def wrappers_frames_only_camera_disc():
minecraft_wrappers = [rb_wrappers.CameraDiscretizationWrapper, rb_wrappers.ActionFlatteningWrapper,
MinecraftPOVWrapper, Testing2500StepLimitWrapper] #
_ = locals()
del _

@env_cfg_ingredient.named_config
def treechop_wrappers_with_frameskip():
minecraft_wrappers = [rb_wrappers.CameraDiscretizationWrapper, rb_wrappers.ActionFlatteningWrapper,
MinecraftPOVWrapper, rb_wrappers.FrameSkip] #
_ = locals()
del _


@env_cfg_ingredient.named_config
def wrappers_frames_only_obfuscated():
minecraft_wrappers = [rb_wrappers.ActionFlatteningWrapper,
MinecraftPOVWrapper, Testing2500StepLimitWrapper] #
_ = locals()
del _

@env_cfg_ingredient.named_config
def wrappers_obs_flatten_camera_disc():
minecraft_wrappers = [rb_wrappers.CameraDiscretizationWrapper, rb_wrappers.ActionFlatteningWrapper,
rb_wrappers.ObservationFlatteningWrapper, Testing2500StepLimitWrapper]
_ = locals()
del _




# see venv_opts_defaults docstring for description of this ingredient
venv_opts_ingredient = Ingredient('venv_opts')

Expand Down
Loading