Skip to content

Commit 45cdbd1

Browse files
authored
[Feature] Multithreaded env (#734)
1 parent 336dc98 commit 45cdbd1

File tree

16 files changed

+1514
-124
lines changed

16 files changed

+1514
-124
lines changed

.circleci/config.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,51 @@ jobs:
519519
- store_test_results:
520520
path: test-results
521521

522+
unittest_linux_envpool_gpu:
523+
<<: *binary_common
524+
machine:
525+
image: ubuntu-2004-cuda-11.4:202110-01
526+
resource_class: gpu.nvidia.medium
527+
environment:
528+
image_name: "pytorch/manylinux-cuda113"
529+
TAR_OPTIONS: --no-same-owner
530+
PYTHON_VERSION: << parameters.python_version >>
531+
CU_VERSION: << parameters.cu_version >>
532+
533+
steps:
534+
- checkout
535+
- designate_upload_channel
536+
- run:
537+
name: Generate cache key
538+
# This will refresh cache on Sundays, nightly build should generate new cache.
539+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
540+
- restore_cache:
541+
keys:
542+
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux_libs/scripts_envpool/environment.yml" }}-{{ checksum ".circleci-weekly" }}
543+
- run:
544+
name: Setup
545+
command: .circleci/unittest/linux_libs/scripts_envpool/setup_env.sh
546+
- save_cache:
547+
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux_libs/scripts_envpool/environment.yml" }}-{{ checksum ".circleci-weekly" }}
548+
paths:
549+
- conda
550+
- env
551+
- run:
552+
name: Install torchrl
553+
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_libs/scripts_envpool/install.sh
554+
- run:
555+
name: Run tests
556+
command: bash .circleci/unittest/linux_libs/scripts_envpool/run_test.sh
557+
- run:
558+
name: Codecov upload
559+
command: |
560+
bash <(curl -s https://codecov.io/bash) -Z -F linux-envpool
561+
- run:
562+
name: Post Process
563+
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux_libs/scripts_envpool/post_process.sh
564+
- store_test_results:
565+
path: test-results
566+
522567
unittest_linux_brax_gpu:
523568
<<: *binary_common
524569
machine:
@@ -1182,6 +1227,10 @@ workflows:
11821227
cu_version: cu113
11831228
name: unittest_linux_jumanji_gpu_py3.8
11841229
python_version: '3.8'
1230+
- unittest_linux_envpool_gpu:
1231+
cu_version: cu113
1232+
name: unittest_linux_envpool_gpu_py3.8
1233+
python_version: '3.8'
11851234
- unittest_linux_brax_gpu:
11861235
cu_version: cu113
11871236
name: unittest_linux_brax_gpu_py3.8
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
channels:
2+
- pytorch
3+
- defaults
4+
dependencies:
5+
- pip
6+
- protobuf
7+
- pip:
8+
- hypothesis
9+
- future
10+
- cloudpickle
11+
- gym
12+
- pygame
13+
- gym[accept-rom-license]
14+
- gym[atari]
15+
- moviepy
16+
- pytest-cov
17+
- pytest-mock
18+
- pytest-instafail
19+
- expecttest
20+
- pyyaml
21+
- scipy
22+
- dm_control
23+
- coverage
24+
- envpool
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
unset PYTORCH_VERSION
4+
# For unittest, nightly PyTorch is used as the following section,
5+
# so no need to set PYTORCH_VERSION.
6+
# In fact, keeping PYTORCH_VERSION forces us to hardcode PyTorch version in config.
7+
8+
set -e
9+
10+
eval "$(./conda/bin/conda shell.bash hook)"
11+
conda activate ./env
12+
13+
if [ "${CU_VERSION:-}" == cpu ] ; then
14+
version="cpu"
15+
echo "Using cpu build"
16+
else
17+
if [[ ${#CU_VERSION} -eq 4 ]]; then
18+
CUDA_VERSION="${CU_VERSION:2:1}.${CU_VERSION:3:1}"
19+
elif [[ ${#CU_VERSION} -eq 5 ]]; then
20+
CUDA_VERSION="${CU_VERSION:2:2}.${CU_VERSION:4:1}"
21+
fi
22+
echo "Using CUDA $CUDA_VERSION as determined by CU_VERSION ($CU_VERSION)"
23+
version="$(python -c "print('.'.join(\"${CUDA_VERSION}\".split('.')[:2]))")"
24+
fi
25+
26+
# submodules
27+
git submodule sync && git submodule update --init --recursive
28+
29+
printf "Installing PyTorch with %s\n" "${CU_VERSION}"
30+
if [ "${CU_VERSION:-}" == cpu ] ; then
31+
pip3 install --pre torch --extra-index-url https://download.pytorch.org/whl/nightly/cpu
32+
else
33+
pip3 install --pre torch --extra-index-url https://download.pytorch.org/whl/nightly/cu113
34+
fi
35+
36+
# smoke test
37+
python -c "import functorch"
38+
39+
# install tensordict
40+
pip install git+https://github.com/pytorch-labs/tensordict
41+
42+
printf "* Installing torchrl\n"
43+
python setup.py develop
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
eval "$(./conda/bin/conda shell.bash hook)"
6+
conda activate ./env

0 commit comments

Comments
 (0)