|
1 | 1 | #!/usr/bin/env bash
|
2 |
| -. /remote/anaconda_token || true |
| 2 | +if [[ -x "/remote/anaconda_token" ]]; then |
| 3 | + . /remote/anaconda_token || true |
| 4 | +fi |
| 5 | + |
| 6 | +set -ex |
3 | 7 |
|
4 |
| -set -e |
| 8 | +# Defined a portable sed that should work on both mac and linux |
| 9 | +if [ "$(uname)" == 'Darwin' ]; then |
| 10 | + portable_sed="sed -E -i ''" |
| 11 | +else |
| 12 | + portable_sed='sed --regexp-extended -i' |
| 13 | +fi |
5 | 14 |
|
6 | 15 | echo "Building cuda version $1 and pytorch version: $2 build_number: $3"
|
| 16 | +desired_cuda="$1" |
| 17 | +build_version="$2" |
| 18 | +build_number="$3" |
7 | 19 |
|
| 20 | +# setup.py is hardcoded to use these variables |
| 21 | +export PYTORCH_BUILD_VERSION=$build_version |
| 22 | +export PYTORCH_BUILD_NUMBER=$build_number |
| 23 | + |
| 24 | +if [[ "$build_version" == "nightly" ]]; then |
| 25 | + export PYTORCH_BUILD_VERSION="$(date +"%Y.%m.%d")" |
| 26 | +fi |
| 27 | + |
| 28 | + |
| 29 | +# This is the channel that finished packages will be uploaded to |
| 30 | +if [[ -z "$ANACONDA_USER" ]]; then |
| 31 | + ANACONDA_USER=soumith |
| 32 | +fi |
| 33 | + |
| 34 | +# Token needed to upload to the conda channel above |
8 | 35 | if [ -z "$ANACONDA_TOKEN" ]; then
|
9 | 36 | echo "ANACONDA_TOKEN is unset. Please set it in your environment before running this script";
|
10 |
| - exit 1 |
11 | 37 | fi
|
12 | 38 |
|
13 |
| -ANACONDA_USER=soumith |
| 39 | +# Don't upload the packages until we've verified that they're correct |
| 40 | +conda config --set anaconda_upload no |
14 | 41 |
|
15 |
| -BUILD_VERSION="$2" |
16 |
| -BUILD_NUMBER="$3" |
| 42 | +# Build for a specified Python, or if none were given then all of them |
| 43 | +if [[ -z "$DESIRED_PYTHON" ]]; then |
| 44 | + DESIRED_PYTHON=('2.7' '3.5' '3.6' '3.7') |
| 45 | +fi |
| 46 | +echo "Will build for all Pythons: ${DESIRED_PYTHON[@]}" |
| 47 | +echo "Will build for all CUDA versions: ${desired_cuda[@]}" |
17 | 48 |
|
18 |
| -export PYTORCH_BUILD_VERSION=$BUILD_VERSION |
19 |
| -export PYTORCH_BUILD_NUMBER=$BUILD_NUMBER |
20 | 49 |
|
21 |
| -if [[ "$BUILD_VERSION" == "nightly" ]]; then |
22 |
| - export PYTORCH_BUILD_VERSION="$(date +"%Y.%m.%d")" |
| 50 | +# Determine which build folder to use, if not given it directly |
| 51 | +if [[ -n "$TORCH_CONDA_BUILD_FOLDER" ]]; then |
| 52 | + build_folder="$TORCH_CONDA_BUILD_FOLDER" |
| 53 | +else |
| 54 | + if [[ "$OSTYPE" == 'darwin'* || "$desired_cuda" == '90' ]]; then |
| 55 | + build_folder='pytorch' |
| 56 | + elif [[ "$desired_cuda" == 'cpu' ]]; then |
| 57 | + build_folder='pytorch-cpu' |
| 58 | + else |
| 59 | + build_folder="pytorch-$desired_cuda" |
| 60 | + fi |
| 61 | + build_folder="$build_folder-$build_version" |
23 | 62 | fi
|
| 63 | +echo "Using conda-build folder $build_folder" |
24 | 64 |
|
25 |
| -conda config --set anaconda_upload no |
26 |
| - |
| 65 | +# Switch the CUDA version that /usr/local/cuda points to |
27 | 66 | if [[ "$OSTYPE" == "darwin"* ]]; then
|
28 | 67 | export CUDA_VERSION="0.0"
|
29 | 68 | export CUDNN_VERSION="0.0"
|
30 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 2.7 pytorch-$BUILD_VERSION |
31 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.5 pytorch-$BUILD_VERSION |
32 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.6 pytorch-$BUILD_VERSION |
33 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.7 pytorch-$BUILD_VERSION |
34 |
| -else |
35 |
| - if [[ "$1" == "80" ]]; then |
36 |
| - . ./switch_cuda_version.sh 8.0 |
37 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 2.7 pytorch-cuda80-$BUILD_VERSION |
38 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.5 pytorch-cuda80-$BUILD_VERSION |
39 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.6 pytorch-cuda80-$BUILD_VERSION |
40 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.7 pytorch-cuda80-$BUILD_VERSION |
41 |
| - elif [[ "$1" == "90" ]]; then |
42 |
| - . ./switch_cuda_version.sh 9.0 |
43 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 2.7 pytorch-$BUILD_VERSION |
44 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.5 pytorch-$BUILD_VERSION |
45 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.6 pytorch-$BUILD_VERSION |
46 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.7 pytorch-$BUILD_VERSION |
47 |
| - elif [[ "$1" == "92" ]]; then |
48 |
| - . ./switch_cuda_version.sh 9.2 |
49 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 2.7 pytorch-cuda92-$BUILD_VERSION |
50 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.5 pytorch-cuda92-$BUILD_VERSION |
51 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.6 pytorch-cuda92-$BUILD_VERSION |
52 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.7 pytorch-cuda92-$BUILD_VERSION |
53 |
| - elif [[ "$1" == "cpu" ]]; then |
54 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 2.7 pytorch-cpu-$BUILD_VERSION |
55 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.5 pytorch-cpu-$BUILD_VERSION |
56 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.6 pytorch-cpu-$BUILD_VERSION |
57 |
| - time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.7 pytorch-cpu-$BUILD_VERSION |
58 |
| - else |
59 |
| - echo "Error, unknown argument $1" |
60 |
| - exit 1 |
61 |
| - fi |
| 69 | +elif [[ "$desired_cuda" != 'cpu' ]]; then |
| 70 | + echo "Switching to CUDA version ${desired_cuda:0:1}.${desired_cuda:1:1}" |
| 71 | + . ./switch_cuda_version.sh "${desired_cuda:0:1}.${desired_cuda:1:1}" |
| 72 | + $portable_sed "s/cudatoolkit =[0-9]/cudatoolkit =${desired_cuda:0:1}/g" "$build_folder/meta.yaml" |
| 73 | +fi |
| 74 | + |
| 75 | +# Alter the meta.yaml to use passed in Github repo/branch |
| 76 | +if [[ -n "$GITHUB_ORG" ]]; then |
| 77 | + $portable_sed "s#git_url:.*#git_url: https://github.com/$GITHUB_ORG/pytorch#g" "$build_folder/meta.yaml" |
| 78 | +fi |
| 79 | +if [[ -n "$PYTORCH_BRANCH" ]]; then |
| 80 | + $portable_sed "s#git_rev:.*#git_rev: $PYTORCH_BRANCH#g" "$build_folder/meta.yaml" |
62 | 81 | fi
|
63 | 82 |
|
| 83 | +# Loop through all Python versions to build a package for each |
| 84 | +for py_ver in "${DESIRED_PYTHON[@]}"; do |
| 85 | + echo "Build $build_folder for Python version $py_ver" |
| 86 | + time conda build -c "$ANACONDA_USER" \ |
| 87 | + --no-anaconda-upload \ |
| 88 | + --python "$py_ver" \ |
| 89 | + "$build_folder" |
| 90 | +done |
| 91 | + |
64 | 92 | echo "All builds succeeded, uploading binaries"
|
65 | 93 |
|
66 | 94 | set +e
|
67 | 95 |
|
68 |
| -# anaconda -t $ANACONDA_TOKEN upload --user $ANACONDA_USER $(conda build -c $ANACONDA_USER --python 2.7 pytorch-$BUILD_VERSION --output) |
69 |
| -# anaconda -t $ANACONDA_TOKEN upload --user $ANACONDA_USER $(conda build -c $ANACONDA_USER --python 3.5 pytorch-$BUILD_VERSION --output) |
70 |
| -# anaconda -t $ANACONDA_TOKEN upload --user $ANACONDA_USER $(conda build -c $ANACONDA_USER --python 3.6 pytorch-$BUILD_VERSION --output) |
| 96 | +# anaconda -t $ANACONDA_TOKEN upload --user $ANACONDA_USER $(conda build -c $ANACONDA_USER --python 2.7 pytorch-$build_version --output) |
| 97 | +# anaconda -t $ANACONDA_TOKEN upload --user $ANACONDA_USER $(conda build -c $ANACONDA_USER --python 3.5 pytorch-$build_version --output) |
| 98 | +# anaconda -t $ANACONDA_TOKEN upload --user $ANACONDA_USER $(conda build -c $ANACONDA_USER --python 3.6 pytorch-$build_version --output) |
71 | 99 |
|
72 | 100 | unset PYTORCH_BUILD_VERSION
|
73 | 101 | unset PYTORCH_BUILD_NUMBER
|
0 commit comments