Skip to content

Commit ebce3c7

Browse files
[CI] Add unit test workflows for Windows (#804)
Co-authored-by: Yohann Benchetrit <[email protected]>
1 parent b845cf2 commit ebce3c7

File tree

16 files changed

+422
-1
lines changed

16 files changed

+422
-1
lines changed

.circleci/config.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,88 @@ jobs:
913913
- store_test_results:
914914
path: test-results
915915

916+
unittest_windows_optdepts_cpu:
917+
<<: *binary_common
918+
executor:
919+
name: windows-cpu
920+
steps:
921+
- checkout
922+
- designate_upload_channel
923+
- run:
924+
name: Generate cache key
925+
# This will refresh cache on Sundays, nightly build should generate new cache.
926+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
927+
- restore_cache:
928+
keys:
929+
- env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows_optdepts/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
930+
931+
- run:
932+
name: Setup
933+
command: .circleci/unittest/windows_optdepts/scripts/setup_env.sh
934+
- save_cache:
935+
key: env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows_optdepts/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
936+
937+
paths:
938+
- conda
939+
- env
940+
- run:
941+
name: Install torchrl
942+
command: .circleci/unittest/windows_optdepts/scripts/install.sh
943+
- run:
944+
name: Run tests
945+
command: .circleci/unittest/windows_optdepts/scripts/run_test.sh
946+
- run:
947+
name: Post process
948+
command: .circleci/unittest/windows_optdepts/scripts/post_process.sh
949+
- store_test_results:
950+
path: test-results
951+
952+
unittest_windows_optdepts_gpu:
953+
<<: *binary_common
954+
executor:
955+
name: windows-gpu
956+
environment:
957+
CUDA_VERSION: "11.6"
958+
PYTHON_VERSION: << parameters.python_version >>
959+
steps:
960+
- checkout
961+
- designate_upload_channel
962+
- run:
963+
name: Generate cache key
964+
# This will refresh cache on Sundays, nightly build should generate new cache.
965+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
966+
- restore_cache:
967+
keys:
968+
- env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows_optdepts/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
969+
970+
- run:
971+
name: Setup
972+
command: .circleci/unittest/windows_optdepts/scripts/setup_env.sh
973+
- save_cache:
974+
key: env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows_optdepts/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
975+
976+
paths:
977+
- conda
978+
- env
979+
- run:
980+
name: Install CUDA
981+
command: packaging/windows/internal/cuda_install.bat
982+
- run:
983+
name: Update CUDA driver
984+
command: packaging/windows/internal/driver_update.bat
985+
- run:
986+
name: Install torchrl
987+
command: .circleci/unittest/windows_optdepts/scripts/install.sh
988+
- run:
989+
name: Run tests
990+
command: .circleci/unittest/windows_optdepts/scripts/run_test.sh
991+
- run:
992+
name: Post process
993+
command: .circleci/unittest/windows_optdepts/scripts/post_process.sh
994+
- store_test_results:
995+
path: test-results
996+
997+
916998
workflows:
917999
lint:
9181000
jobs:
@@ -1173,3 +1255,36 @@ workflows:
11731255
cu_version: cu113
11741256
name: unittest_linux_examples_gpu_py3.9
11751257
python_version: '3.9'
1258+
1259+
- unittest_windows_optdepts_cpu:
1260+
cu_version: cpu
1261+
name: unittest_windows_optdepts_cpu_py3.7
1262+
python_version: '3.7'
1263+
- unittest_windows_optdepts_cpu:
1264+
cu_version: cpu
1265+
name: unittest_windows_optdepts_cpu_py3.8
1266+
python_version: '3.8'
1267+
- unittest_windows_optdepts_cpu:
1268+
cu_version: cpu
1269+
name: unittest_windows_optdepts_cpu_py3.9
1270+
python_version: '3.9'
1271+
- unittest_windows_optdepts_cpu:
1272+
cu_version: cpu
1273+
name: unittest_windows_optdepts_cpu_py3.10
1274+
python_version: '3.10'
1275+
- unittest_windows_optdepts_gpu:
1276+
cu_version: cu116
1277+
name: unittest_windows_optdepts_gpu_py3.7
1278+
python_version: '3.7'
1279+
- unittest_windows_optdepts_gpu:
1280+
cu_version: cu116
1281+
name: unittest_windows_optdepts_gpu_py3.8
1282+
python_version: '3.8'
1283+
- unittest_windows_optdepts_gpu:
1284+
cu_version: cu116
1285+
name: unittest_windows_optdepts_gpu_py3.9
1286+
python_version: '3.9'
1287+
- unittest_windows_optdepts_gpu:
1288+
cu_version: cu116
1289+
name: unittest_windows_optdepts_gpu_py3.10
1290+
python_version: '3.10'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
channels:
2+
- pytorch
3+
- defaults
4+
dependencies:
5+
- pip
6+
- pip:
7+
- hypothesis
8+
- future
9+
- cloudpickle
10+
- pytest
11+
- pytest-cov
12+
- pytest-mock
13+
- pytest-instafail
14+
- expecttest
15+
- pyyaml
16+
- scipy
17+
- coverage
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 -ex
9+
10+
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11+
12+
eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')"
13+
conda activate ./env
14+
15+
# TODO, refactor the below logic to make it easy to understand how to get correct cuda_version.
16+
if [ "${CU_VERSION:-}" == cpu ] ; then
17+
cudatoolkit="cpuonly"
18+
version="cpu"
19+
else
20+
if [[ ${#CU_VERSION} -eq 4 ]]; then
21+
CUDA_VERSION="${CU_VERSION:2:1}.${CU_VERSION:3:1}"
22+
elif [[ ${#CU_VERSION} -eq 5 ]]; then
23+
CUDA_VERSION="${CU_VERSION:2:2}.${CU_VERSION:4:1}"
24+
fi
25+
26+
cuda_toolkit_pckg="cudatoolkit"
27+
if [[ $CUDA_VERSION == 11.6 || $CUDA_VERSION == 11.7 ]]; then
28+
cuda_toolkit_pckg="pytorch-cuda"
29+
fi
30+
31+
echo "Using CUDA $CUDA_VERSION as determined by CU_VERSION"
32+
version="$(python -c "print('.'.join(\"${CUDA_VERSION}\".split('.')[:2]))")"
33+
cudatoolkit="${cuda_toolkit_pckg}=${version}"
34+
fi
35+
36+
37+
# submodules
38+
git submodule sync && git submodule update --init --recursive
39+
40+
printf "Installing PyTorch with %s\n" "${cudatoolkit}"
41+
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c nvidia "pytorch-${UPLOAD_CHANNEL}"::pytorch[build="*${version}*"] "${cudatoolkit}"
42+
43+
torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())")
44+
echo torch.cuda.is_available is $torch_cuda
45+
46+
if [ ! -z "${CUDA_VERSION:-}" ] ; then
47+
if [ "$torch_cuda" == "False" ]; then
48+
echo "torch with cuda installed but torch.cuda.is_available() is False"
49+
exit 1
50+
fi
51+
fi
52+
53+
pip install pip --upgrade
54+
55+
# install tensordict
56+
pip3 install git+https://github.com/pytorch-labs/tensordict
57+
58+
source "$this_dir/set_cuda_envs.sh"
59+
60+
printf "* Installing torchrl\n"
61+
pip3 install -e .
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda%
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/Scripts/conda.exe 'shell.bash' 'hook')"
6+
conda activate ./env
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')"
6+
conda activate ./env
7+
8+
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
9+
source "$this_dir/set_cuda_envs.sh"
10+
11+
python -m torch.utils.collect_env
12+
pytest --junitxml=test-results/junit.xml -v --durations 20
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
echo CU_VERSION is "${CU_VERSION}"
5+
echo CUDA_VERSION is "${CUDA_VERSION}"
6+
7+
# Currenly, CU_VERSION and CUDA_VERSION are not consistent.
8+
# to understand this code, see https://github.com/pytorch/vision/issues/4443
9+
version="cpu"
10+
if [[ ! -z "${CUDA_VERSION}" ]] ; then
11+
version="$CUDA_VERSION"
12+
else
13+
if [[ ${#CU_VERSION} -eq 5 ]]; then
14+
version="${CU_VERSION:2:2}.${CU_VERSION:4:1}"
15+
fi
16+
fi
17+
18+
# Don't use if [[ "$version" == "cpu" ]]; then exit 0 fi.
19+
# It would exit the shell. One result is cpu tests would not run if the shell exit.
20+
# Unless there's an error, Don't exit.
21+
if [[ "$version" != "cpu" ]]; then
22+
# set cuda envs
23+
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${version}/bin:/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${version}/libnvvp:$PATH"
24+
export CUDA_PATH_V${version/./_}="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${version}"
25+
export CUDA_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${version}"
26+
27+
if [ ! -d "$CUDA_PATH" ]; then
28+
echo "$CUDA_PATH" does not exist
29+
exit 1
30+
fi
31+
32+
if [ ! -f "${CUDA_PATH}\include\nvjpeg.h" ]; then
33+
echo "nvjpeg does not exist"
34+
exit 1
35+
fi
36+
37+
# check cuda driver version
38+
for path in '/c/Program Files/NVIDIA Corporation/NVSMI/nvidia-smi.exe' /c/Windows/System32/nvidia-smi.exe; do
39+
if [[ -x "$path" ]]; then
40+
"$path" || echo "true";
41+
break
42+
fi
43+
done
44+
45+
which nvcc
46+
nvcc --version
47+
env | grep CUDA
48+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is for setting up environment in which unit test is ran.
4+
# To speed up the CI time, the resulting environment is cached.
5+
#
6+
# Do not install PyTorch and torchvision here, otherwise they also get cached.
7+
8+
set -e
9+
10+
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11+
root_dir="$(git rev-parse --show-toplevel)"
12+
conda_dir="${root_dir}/conda"
13+
env_dir="${root_dir}/env"
14+
15+
cd "${root_dir}"
16+
17+
# 1. Install conda at ./conda
18+
if [ ! -d "${conda_dir}" ]; then
19+
printf "* Installing conda\n"
20+
export tmp_conda="$(echo $conda_dir | tr '/' '\\')"
21+
export miniconda_exe="$(echo $root_dir | tr '/' '\\')\\miniconda.exe"
22+
curl --output miniconda.exe https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -O
23+
"$this_dir/install_conda.bat"
24+
unset tmp_conda
25+
unset miniconda_exe
26+
fi
27+
28+
eval "$(${conda_dir}/Scripts/conda.exe 'shell.bash' 'hook')"
29+
30+
# 2. Create test environment at ./env
31+
if [ ! -d "${env_dir}" ]; then
32+
printf "* Creating a test environment\n"
33+
conda create --prefix "${env_dir}" -y python="$PYTHON_VERSION"
34+
fi
35+
conda activate "${env_dir}"
36+
37+
# 3. Install Conda dependencies
38+
printf "* Installing dependencies (except PyTorch)\n"
39+
conda env update --file "${this_dir}/environment.yml" --prune
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@echo on
2+
3+
set VC_VERSION_LOWER=16
4+
set VC_VERSION_UPPER=17
5+
6+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
7+
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
8+
set "VS15INSTALLDIR=%%i"
9+
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
10+
goto vswhere
11+
)
12+
)
13+
14+
:vswhere
15+
if "%VSDEVCMD_ARGS%" == "" (
16+
call "%VS15VCVARSALL%" x64 || exit /b 1
17+
) else (
18+
call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS% || exit /b 1
19+
)
20+
21+
@echo on
22+
23+
set DISTUTILS_USE_SDK=1
24+
25+
set args=%1
26+
shift
27+
:start
28+
if [%1] == [] goto done
29+
set args=%args% %1
30+
shift
31+
goto start
32+
33+
:done
34+
if "%args%" == "" (
35+
echo Usage: vc_env_helper.bat [command] [args]
36+
echo e.g. vc_env_helper.bat cl /c test.cpp
37+
)
38+
39+
%args% || exit /b 1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
set "DRIVER_DOWNLOAD_LINK=https://ossci-windows.s3.amazonaws.com/461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe"
2+
curl --retry 3 -kL %DRIVER_DOWNLOAD_LINK% --output 461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe
3+
if errorlevel 1 exit /b 1
4+
5+
start /wait 461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe -s -noreboot
6+
if errorlevel 1 exit /b 1
7+
8+
del 461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe || ver > NUL
9+
10+
setlocal EnableDelayedExpansion
11+
set NVIDIA_GPU_EXISTS=0
12+
for /F "delims=" %%i in ('wmic path win32_VideoController get name') do (
13+
set GPUS=%%i
14+
if not "x!GPUS:NVIDIA=!" == "x!GPUS!" (
15+
SET NVIDIA_GPU_EXISTS=1
16+
goto gpu_check_end
17+
)
18+
)
19+
:gpu_check_end
20+
endlocal & set NVIDIA_GPU_EXISTS=%NVIDIA_GPU_EXISTS%
21+
22+
if "%NVIDIA_GPU_EXISTS%" == "0" (
23+
echo "CUDA Driver installation Failed"
24+
exit /b 1
25+
)

0 commit comments

Comments
 (0)