Skip to content

Commit

Permalink
[Feature] Make torchrl runnable without functorch and with gym==0.13 (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Oct 28, 2022
1 parent 6f9faaa commit af104c3
Show file tree
Hide file tree
Showing 38 changed files with 2,063 additions and 356 deletions.
54 changes: 53 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ jobs:
- run:
name: Install torchrl
# command: bash .circleci/unittest/linux_stable/scripts/install.sh
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux/scripts/install.sh
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_stable/scripts/install.sh
- run:
name: Run tests
command: bash .circleci/unittest/linux_stable/scripts/run_test.sh
Expand All @@ -516,6 +516,53 @@ jobs:
- store_test_results:
path: test-results

unittest_linux_olddeps_gpu:
<<: *binary_common
machine:
image: ubuntu-2004-cuda-11.4:202110-01
resource_class: gpu.nvidia.medium
environment:
image_name: "pytorch/manylinux-cuda113"
TAR_OPTIONS: --no-same-owner
PYTHON_VERSION: << parameters.python_version >>
CU_VERSION: << parameters.cu_version >>

steps:
- checkout
- designate_upload_channel
- run:
name: Generate cache key
# This will refresh cache on Sundays, nightly build should generate new cache.
command: echo "$(date +"%Y-%U")" > .circleci-weekly
- restore_cache:
keys:
- env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux_olddeps/scripts_gym_0_13/environment.yml" }}-{{ checksum ".circleci-weekly" }}
- run:
name: Setup
command: docker run -e PYTHON_VERSION -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux_olddeps/scripts_gym_0_13/setup_env.sh
- save_cache:
key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux_olddeps/scripts_gym_0_13/environment.yml" }}-{{ checksum ".circleci-weekly" }}
paths:
- conda
- env
- run:
name: Install torchrl, run tests, upload codecov
command: |
docker run -t --env=CUDA_VISIBLE_DEVICES="" --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_olddeps/scripts_gym_0_13/batch_scripts.sh
# docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_olddeps/scripts_gym_0_13/batch_scripts.sh
# - run:
# name: Run tests
# command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_olddeps/scripts_gym_0_13/run_test.sh
# - run:
# name: Codecov upload
# command: |
# docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" <(curl -s https://codecov.io/bash) -Z -F linux-stable-cpu
# - run:
# name: Post process
# command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_olddeps/scripts_gym_0_13/post_process.sh
- store_test_results:
path: test-results

unittest_macos_cpu:
<<: *binary_common
macos:
Expand Down Expand Up @@ -787,3 +834,8 @@ workflows:
cu_version: cu113
name: unittest_linux_stable_gpu_py3.10
python_version: '3.10'

- unittest_linux_olddeps_gpu:
cu_version: cu113
name: unittest_linux_olddeps_gpu_py3.9
python_version: '3.9'
8 changes: 7 additions & 1 deletion .circleci/unittest/linux/scripts/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash

# this code is supposed to run on CPU
# rendering with the combination of packages we have here in headless mode
# is hard to nail.
# IMPORTANT: As a consequence, we can't guarantee TorchRL compatibility with
# rendering with this version of gym / mujoco-py.

set -e

eval "$(./conda/bin/conda shell.bash hook)"
Expand All @@ -19,6 +25,6 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$lib_dir
export MKL_THREADING_LAYER=GNU

coverage run -m pytest test/smoke_test.py -v --durations 20
coverage run -m pytest test/smoke_test_deps.py -v --durations 20
coverage run -m pytest test/smoke_test_deps.py -v --durations 20 -k 'test_gym or test_dm_control_pixels or test_dm_control or test_tb'
coverage run -m pytest --instafail -v --durations 20
coverage xml
10 changes: 10 additions & 0 deletions .circleci/unittest/linux_olddeps/scripts_gym_0_13/batch_scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Runs a batch of scripts in a row to allow docker run to keep installed libraries
# and env variables across runs.

DIR="$(cd "$(dirname "$0")" && pwd)"

$DIR/install.sh
$DIR/run_test.sh
$DIR/post_process.sh
26 changes: 26 additions & 0 deletions .circleci/unittest/linux_olddeps/scripts_gym_0_13/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
channels:
- pytorch
- defaults
dependencies:
- pip
- protobuf
- pip:
- hypothesis
- future
- cloudpickle
- gym==0.13
- pygame
- gym[atari]
- moviepy
- tqdm
- pytest
- pytest-cov
- pytest-mock
- pytest-instafail
- expecttest
- pyyaml
- scipy
- hydra-core
- dm_control -e git+https://github.com/deepmind/dm_control.git@c053360edea6170acfd9c8f65446703307d9d352#egg={dm_control}
- patchelf
- pyopengl==3.1.4
45 changes: 45 additions & 0 deletions .circleci/unittest/linux_olddeps/scripts_gym_0_13/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

unset PYTORCH_VERSION
# For unittest, nightly PyTorch is used as the following section,
# so no need to set PYTORCH_VERSION.
# In fact, keeping PYTORCH_VERSION forces us to hardcode PyTorch version in config.

set -e

eval "$(./conda/bin/conda shell.bash hook)"
conda activate ./env

#apt-get update -y && apt-get install git wget gcc g++ -y

if [ "${CU_VERSION:-}" == cpu ] ; then
cudatoolkit="cpuonly"
version="cpu"
else
if [[ ${#CU_VERSION} -eq 4 ]]; then
CUDA_VERSION="${CU_VERSION:2:1}.${CU_VERSION:3:1}"
elif [[ ${#CU_VERSION} -eq 5 ]]; then
CUDA_VERSION="${CU_VERSION:2:2}.${CU_VERSION:4:1}"
fi
echo "Using CUDA $CUDA_VERSION as determined by CU_VERSION ($CU_VERSION)"
version="$(python -c "print('.'.join(\"${CUDA_VERSION}\".split('.')[:2]))")"
cudatoolkit="cudatoolkit=${version}"
fi

case "$(uname -s)" in
Darwin*) os=MacOSX;;
*) os=Linux
esac

# submodules
git submodule sync && git submodule update --init --recursive

printf "Installing PyTorch with %s\n" "${CU_VERSION}"
if [ "${CU_VERSION:-}" == cpu ] ; then
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cpuonly -c pytorch -y
else
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge -y
fi

printf "* Installing torchrl\n"
python setup.py develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e

eval "$(./conda/bin/conda shell.bash hook)"
conda activate ./env
Loading

0 comments on commit af104c3

Please sign in to comment.