Skip to content

Commit

Permalink
[BugFix] Fix Examples (pytorch#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Nov 21, 2022
1 parent 40c04ef commit a3bbba0
Show file tree
Hide file tree
Showing 22 changed files with 774 additions and 51 deletions.
56 changes: 56 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,57 @@ jobs:
- store_test_results:
path: test-results


unittest_linux_examples_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-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux_examples/scripts/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_examples/scripts/setup_env.sh
- save_cache:

key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux_examples/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}

paths:
- conda
- env
- run:
name: Install torchrl
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux_examples/scripts/install.sh
- run:
name: Run tests
command: bash .circleci/unittest/linux_examples/scripts/run_test.sh
# command: docker run --env-file ./env.list -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/run_test.sh
- run:
name: Codecov upload
command: |
bash <(curl -s https://codecov.io/bash) -Z -F linux_examples-gpu
- run:
name: Post Process
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux_examples/scripts/post_process.sh
- store_test_results:
path: test-results

unittest_linux_habitat_gpu:
<<: *binary_common
machine:
Expand Down Expand Up @@ -937,3 +988,8 @@ workflows:
cu_version: cu113
name: unittest_linux_olddeps_gpu_py3.9
python_version: '3.9'

- unittest_linux_examples_gpu:
cu_version: cu113
name: unittest_linux_examples_gpu_py3.9
python_version: '3.9'
30 changes: 30 additions & 0 deletions .circleci/unittest/linux_examples/scripts/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
channels:
- pytorch
- defaults
dependencies:
- pip
- protobuf
- pip:
- hypothesis
- future
- cloudpickle
- gym
- pygame
- gym[accept-rom-license]
- gym[atari]
- moviepy
- tqdm
- pytest
- pytest-cov
- pytest-mock
- pytest-instafail
- expecttest
- pyyaml
- scipy
- hydra-core
- tensorboard
- wandb
- dm_control
- mlflow
- av
- coverage
46 changes: 46 additions & 0 deletions .circleci/unittest/linux_examples/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/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

if [ "${CU_VERSION:-}" == cpu ] ; then
version="cpu"
echo "Using cpu build"
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]))")"
fi

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

printf "Installing PyTorch with %s\n" "${CU_VERSION}"
if [ "${CU_VERSION:-}" == cpu ] ; then
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
else
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113
fi

# smoke test
python -c "import functorch"

# install snapshot
pip install git+https://github.com/pytorch/torchsnapshot

# install tensordict
pip install git+https://github.com/pytorch-labs/tensordict

printf "* Installing torchrl\n"
python setup.py develop
6 changes: 6 additions & 0 deletions .circleci/unittest/linux_examples/scripts/post_process.sh
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 a3bbba0

Please sign in to comment.