install.sh 1.69 KB
Newer Older
1
2
3
4
5
6
7
#!/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.

8
set -ex
9
10
11
12
13
14

this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')"
conda activate ./env

15
# TODO, refactor the below logic to make it easy to understand how to get correct cuda_version.
guyang3532's avatar
guyang3532 committed
16
if [ "${CU_VERSION:-}" == cpu ] ; then
17
    cudatoolkit="cpuonly"
18
    version="cpu"
19
else
guyang3532's avatar
guyang3532 committed
20
21
22
23
24
    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
25
26
27
28
29
30

    cuda_toolkit_pckg="cudatoolkit"
    if [[ "$CU_VERSION" == cu116 ]]; then
        cuda_toolkit_pckg="cuda"
    fi

guyang3532's avatar
guyang3532 committed
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
printf "Installing PyTorch with %s\n" "${cudatoolkit}"
37
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c nvidia "pytorch-${UPLOAD_CHANNEL}"::pytorch[build="*${version}*"] "${cudatoolkit}"
38

39
40
41
42
43
44
45
46
47
48
49
50
torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())")
echo torch.cuda.is_available is $torch_cuda

if [ ! -z "${CUDA_VERSION:-}" ] ; then
    if [ "$torch_cuda" == "False" ]; then
        echo "torch with cuda installed but torch.cuda.is_available() is False"
        exit 1
    fi
fi

source "$this_dir/set_cuda_envs.sh"

51
printf "* Installing torchvision\n"
52
"$this_dir/vc_env_helper.bat" python setup.py develop