Skip to content

Commit 4262ab9

Browse files
author
Vincent Moens
committed
[Feature] Re-enable cache for specs
ghstack-source-id: 7971323 Pull Request resolved: #2730
1 parent 601483e commit 4262ab9

File tree

22 files changed

+578
-357
lines changed

22 files changed

+578
-357
lines changed

.github/unittest/linux/scripts/run_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export DISPLAY=:0
8080
export SDL_VIDEODRIVER=dummy
8181

8282
# legacy from bash scripts: remove?
83-
conda env config vars set MUJOCO_GL=$MUJOCO_GL PYOPENGL_PLATFORM=$MUJOCO_GL DISPLAY=:0 SDL_VIDEODRIVER=dummy LAZY_LEGACY_OP=False RL_LOGGING_LEVEL=DEBUG
83+
conda env config vars set MUJOCO_GL=$MUJOCO_GL PYOPENGL_PLATFORM=$MUJOCO_GL DISPLAY=:0 SDL_VIDEODRIVER=dummy LAZY_LEGACY_OP=False RL_LOGGING_LEVEL=DEBUG TOKENIZERS_PARALLELISM=true
8484

8585
pip3 install pip --upgrade
8686
pip install virtualenv

.github/unittest/linux_distributed/scripts/setup_env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ conda env config vars set MUJOCO_PY_MUJOCO_PATH=$root_dir/.mujoco/mujoco210 \
6969
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$root_dir/.mujoco/mujoco210/bin \
7070
SDL_VIDEODRIVER=dummy \
7171
MUJOCO_GL=$PRIVATE_MUJOCO_GL \
72-
PYOPENGL_PLATFORM=$PRIVATE_MUJOCO_GL
72+
PYOPENGL_PLATFORM=$PRIVATE_MUJOCO_GL \
73+
TOKENIZERS_PARALLELISM=true
7374

7475
# Software rendering requires GLX and OSMesa.
7576
if [ $PRIVATE_MUJOCO_GL == 'egl' ] || [ $PRIVATE_MUJOCO_GL == 'osmesa' ] ; then

.github/unittest/linux_libs/scripts_d4rl/setup_env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ conda env config vars set \
9292
MUJOCO_PY_MJKEY_PATH=$root_dir/.mujoco/mjkey.txt \
9393
SDL_VIDEODRIVER=dummy \
9494
MUJOCO_GL=$PRIVATE_MUJOCO_GL \
95-
PYOPENGL_PLATFORM=$PRIVATE_MUJOCO_GL
95+
PYOPENGL_PLATFORM=$PRIVATE_MUJOCO_GL \
96+
TOKENIZERS_PARALLELISM=true
9697

9798
conda env update --file "${this_dir}/environment.yml" --prune

.github/unittest/linux_libs/scripts_gym/setup_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ conda env config vars set \
8080
MUJOCO_PY_MJKEY_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/mjkey.txt \
8181
MUJOCO_PY_MUJOCO_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/linux/mujoco210 \
8282
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/pytorch/rl/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin
83+
TOKENIZERS_PARALLELISM=true
8384
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/circleci/project/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin
8485

8586
# make env variables apparent

.github/unittest/linux_libs/scripts_habitat/run_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ conda activate ./env
1010
# https://stackoverflow.com/questions/72540359/glibcxx-3-4-30-not-found-for-librosa-in-conda-virtual-environment-after-tryin
1111
#conda install -y -c conda-forge gcc=12.1.0
1212
conda install -y -c conda-forge libstdcxx-ng=12
13-
conda env config vars set LD_PRELOAD=$LD_PRELOAD:$STDC_LOC
13+
conda env config vars set LD_PRELOAD=$LD_PRELOAD:$STDC_LOC TOKENIZERS_PARALLELISM=true
1414

1515
## find libstdc
1616
STDC_LOC=$(find conda/ -name "libstdc++.so.6" | head -1)
@@ -36,7 +36,7 @@ export MKL_THREADING_LAYER=GNU
3636
#wget https://github.com/openai/mujoco-py/blob/master/vendor/10_nvidia.json
3737
#mv 10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json
3838

39-
conda env config vars set MAGNUM_LOG=quiet HABITAT_SIM_LOG=quiet
39+
conda env config vars set MAGNUM_LOG=quiet HABITAT_SIM_LOG=quiet TOKENIZERS_PARALLELISM=true
4040

4141
conda deactivate && conda activate ./env
4242

.github/unittest/linux_libs/scripts_habitat/setup_env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fi
4141
conda activate "${env_dir}"
4242

4343
# set debug variables
44-
conda env config vars set MAGNUM_LOG=debug HABITAT_SIM_LOG=debug
44+
conda env config vars set MAGNUM_LOG=debug HABITAT_SIM_LOG=debug TOKENIZERS_PARALLELISM=true
4545
conda deactivate && conda activate "${env_dir}"
4646

4747
pip3 install "cython<3"

.github/unittest/linux_libs/scripts_robohive/setup_env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ conda env config vars set \
6767
PYOPENGL_PLATFORM=egl \
6868
NVIDIA_PATH=/usr/src/nvidia-470.63.01 \
6969
sim_backend=MUJOCO \
70-
LAZY_LEGACY_OP=False
70+
LAZY_LEGACY_OP=False \
71+
TOKENIZERS_PARALLELISM=true
7172

7273
# make env variables apparent
7374
conda deactivate && conda activate "${env_dir}"

.github/unittest/linux_olddeps/scripts_gym_0_13/setup_env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ conda env config vars set \
8585
NVIDIA_PATH=/usr/src/nvidia-470.63.01 \
8686
MUJOCO_PY_MJKEY_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/mjkey.txt \
8787
MUJOCO_PY_MUJOCO_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/linux/mujoco210 \
88-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/circleci/project/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin
88+
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/circleci/project/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin \
89+
TOKENIZERS_PARALLELISM=true
8990

9091
# make env variables apparent
9192
conda deactivate && conda activate "${env_dir}"

.github/unittest/linux_sota/scripts/run_all.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ conda env config vars set MUJOCO_PY_MUJOCO_PATH=$root_dir/.mujoco/mujoco210 \
8383
SDL_VIDEODRIVER=dummy \
8484
MUJOCO_GL=egl \
8585
PYOPENGL_PLATFORM=egl \
86-
BATCHED_PIPE_TIMEOUT=60
86+
BATCHED_PIPE_TIMEOUT=60 \
87+
TOKENIZERS_PARALLELISM=true
8788

8889
pip install pip --upgrade
8990

@@ -100,7 +101,7 @@ pip install git+https://github.com/Farama-Foundation/d4rl@master#egg=d4rl
100101
conda install -y -c conda-forge libstdcxx-ng=12
101102
## find libstdc
102103
STDC_LOC=$(find conda/ -name "libstdc++.so.6" | head -1)
103-
conda env config vars set LD_PRELOAD=${root_dir}/$STDC_LOC
104+
conda env config vars set LD_PRELOAD=${root_dir}/$STDC_LOC TOKENIZERS_PARALLELISM=true
104105

105106
# compile mujoco-py (bc it's done at runtime for whatever reason someone thought it was a good idea)
106107
python -c """import gym;import d4rl"""

docs/source/reference/envs.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,35 @@ Each env will have the following attributes:
4141
the done-flag spec. See the section on trajectory termination below.
4242
- :obj:`env.input_spec`: a :class:`~torchrl.data.Composite` object containing
4343
all the input keys (:obj:`"full_action_spec"` and :obj:`"full_state_spec"`).
44-
It is locked and should not be modified directly.
4544
- :obj:`env.output_spec`: a :class:`~torchrl.data.Composite` object containing
4645
all the output keys (:obj:`"full_observation_spec"`, :obj:`"full_reward_spec"` and :obj:`"full_done_spec"`).
47-
It is locked and should not be modified directly.
4846

49-
If the environment carries non-tensor data, a :class:`~torchrl.data.NonTensorSpec`
47+
If the environment carries non-tensor data, a :class:`~torchrl.data.NonTensor`
5048
instance can be used.
5149

50+
Env specs: locks and batch size
51+
-------------------------------
52+
53+
.. _Environment-lock:
54+
55+
Environment specs are locked by default (through a ``spec_locked`` arg passed to the env constructor).
56+
Locking specs means that any modification of the spec (or its children if it is a :class:`~torchrl.data.Composite`
57+
instance) will require to unlock it. This can be done via the :meth:`~torchrl.envs.EnvBase.set_spec_lock_`.
58+
The reason specs are locked by default is that it makes it easy to cache values such as action or reset keys and the
59+
likes.
60+
Unlocking an env should only be done if it expected that the specs will be modified often (which, in principle, should
61+
be avoided).
62+
Modifications of the specs such as `env.observation_spec = new_spec` are allowed: under the hood, TorchRL will erase
63+
the cache, unlock the specs, make the modification and relock the specs if the env was previously locked.
64+
5265
Importantly, the environment spec shapes should contain the batch size, e.g.
5366
an environment with :obj:`env.batch_size == torch.Size([4])` should have
5467
an :obj:`env.action_spec` with shape :obj:`torch.Size([4, action_size])`.
5568
This is helpful when preallocation tensors, checking shape consistency etc.
5669

70+
Env methods
71+
-----------
72+
5773
With these, the following methods are implemented:
5874

5975
- :meth:`env.reset`: a reset method that may (but not necessarily requires to) take

0 commit comments

Comments
 (0)