Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 163 additions & 44 deletions packaging/conda/build_vision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,204 @@ retry () {
$* || (sleep 1 && $*) || (sleep 2 && $*) || (sleep 4 && $*) || (sleep 8 && $*)
}

if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters. Pass cuda version"
echo "CUDA version should be M.m with no dot, e.g. '8.0' or 'cpu'"
exit 1
# Parse arguments and determmine version
###########################################################
if [[ -n "$DESIRED_CUDA" && -n "$TORCHVISION_BUILD_VERSION" && -n "$TORCHVISION_BUILD_NUMBER" ]]; then
desired_cuda="$DESIRED_CUDA"
build_version="$PYTORCH_BUILD_VERSION"
build_number="$PYTORCH_BUILD_NUMBER"
else
if [ "$#" -ne 3 ]; then
echo "Illegal number of parameters. Pass cuda version, pytorch version, build number"
echo "CUDA version should be Mm with no dot, e.g. '80'"
echo "DESIRED_PYTHON should be M.m, e.g. '2.7'"
exit 1
fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: this script is no longer used by the Linux/OS X binary builds (I didn't delete it because Windows still needs it), instead packaging/build_conda.sh is what is used. It would pretty awesome if we could also unify these packaging scripts, but I only really want to do it if we can keep the packaging on the shorter side. In the meantime, you can rename / simplify this script so that it is Windows only.

desired_cuda="$1"
build_version="$2"
build_number="$3"
fi
desired_cuda="$1"
if [[ "$desired_cuda" != cpu ]]; then
desired_cuda="$(echo $desired_cuda | tr -d cuda. )"
fi
echo "Building cuda version $desired_cuda and torchvision version: $build_version build_number: $build_number"

export TORCHVISION_BUILD_VERSION="0.3.0"
export TORCHVISION_BUILD_NUMBER=1
if [[ "$desired_cuda" == 'cpu' ]]; then
cpu_only=1
cuver="cpu"
else
# Switch desired_cuda to be M.m to be consistent with other scripts in
# pytorch/builder
export FORCE_CUDA=1
cuda_nodot="$desired_cuda"

if [[ ${#cuda_nodot} -eq 2 ]]; then
desired_cuda="${desired_cuda:0:1}.${desired_cuda:1:1}"
elif [[ ${#cuda_nodot} -eq 3 ]]; then
desired_cuda="${desired_cuda:0:2}.${desired_cuda:2:1}"
else
echo "unknown cuda version $cuda_nodot"
exit 1
fi

cuver="cu$cuda_nodot"
fi

export TORCHVISION_BUILD_VERSION=$build_version
export TORCHVISION_BUILD_NUMBER=$build_number

if [[ -z "$DESIRED_PYTHON" ]]; then
DESIRED_PYTHON=('3.5' '3.6' '3.7')
fi

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

if [[ -z "$WIN_PACKAGE_WORK_DIR" ]]; then
WIN_PACKAGE_WORK_DIR="$(echo $(pwd -W) | tr '/' '\\')\\tmp_conda_$(date +%H%M%S)"
fi

if [[ "$OSTYPE" == "msys" ]]; then
mkdir -p "$WIN_PACKAGE_WORK_DIR" || true
vision_rootdir="$(realpath ${WIN_PACKAGE_WORK_DIR})/torchvision-src"
git config --system core.longpaths true
else
vision_rootdir="$(pwd)/torchvision-src"
fi
mkdir -p "$WIN_PACKAGE_WORK_DIR" || true
vision_rootdir="$(realpath ${WIN_PACKAGE_WORK_DIR})/torchvision-src"
git config --system core.longpaths true

if [[ ! -d "$vision_rootdir" ]]; then
rm -rf "$vision_rootdir"
git clone "https://github.com/pytorch/vision" "$vision_rootdir"
pushd "$vision_rootdir"
git checkout v$TORCHVISION_BUILD_VERSION
git checkout $PYTORCH_BRANCH
popd
fi

cd "$SOURCE_DIR"

if [[ "$OSTYPE" == "msys" ]]; then
export tmp_conda="${WIN_PACKAGE_WORK_DIR}\\conda"
export miniconda_exe="${WIN_PACKAGE_WORK_DIR}\\miniconda.exe"
rm -rf "$tmp_conda"
rm -f "$miniconda_exe"
curl -sSk https://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe -o "$miniconda_exe"
"$SOURCE_DIR/install_conda.bat" && rm "$miniconda_exe"
pushd $tmp_conda
export PATH="$(pwd):$(pwd)/Library/usr/bin:$(pwd)/Library/bin:$(pwd)/Scripts:$(pwd)/bin:$PATH"
popd
# We have to skip 3.17 because of the following bug.
# https://github.com/conda/conda-build/issues/3285
retry conda install -yq conda-build
fi
export tmp_conda="${WIN_PACKAGE_WORK_DIR}\\conda"
export miniconda_exe="${WIN_PACKAGE_WORK_DIR}\\miniconda.exe"
rm -rf "$tmp_conda"
rm -f "$miniconda_exe"
curl -sSk https://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe -o "$miniconda_exe"
"$SOURCE_DIR/install_conda.bat" && rm "$miniconda_exe"
pushd $tmp_conda
export PATH="$(pwd):$(pwd)/Library/usr/bin:$(pwd)/Library/bin:$(pwd)/Scripts:$(pwd)/bin:$PATH"
popd
retry conda install -yq conda-build

ANACONDA_USER=pytorch
ANACONDA_USER=pytorch-nightly
conda config --set anaconda_upload no


export TORCHVISION_PACKAGE_SUFFIX=""
if [[ "$desired_cuda" == 'cpu' ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT=""
export CONDA_CPUONLY_FEATURE="- cpuonly # [not osx]"
export CUDA_VERSION="None"
if [[ "$OSTYPE" != "darwin"* ]]; then
export TORCHVISION_PACKAGE_SUFFIX="-cpu"
fi
else
export CONDA_CPUONLY_FEATURE=""
. ./switch_cuda_version.sh $desired_cuda
if [[ "$desired_cuda" == "10.0" ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT=" - cudatoolkit >=10.0,<10.1 # [not osx]"
if [[ "$desired_cuda" == "10.1" ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=10.1,<10.2 # [not osx]"
elif [[ "$desired_cuda" == "10.0" ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=10.0,<10.1 # [not osx]"
elif [[ "$desired_cuda" == "9.2" ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=9.2,<9.3 # [not osx]"
elif [[ "$desired_cuda" == "9.0" ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT=" - cudatoolkit >=9.0,<9.1 # [not osx]"
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=9.0,<9.1 # [not osx]"
elif [[ "$desired_cuda" == "8.0" ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=8.0,<8.1 # [not osx]"
else
echo "unhandled desired_cuda: $desired_cuda"
exit 1
echo "unhandled desired_cuda: $desired_cuda"
exit 1
fi
fi

if [[ "$OSTYPE" == "msys" ]]; then
time conda build -c $ANACONDA_USER --no-anaconda-upload vs2017
if [[ -z "$PYTORCH_VERSION" ]]; then
export CONDA_CHANNEL_FLAGS="-c pytorch-nightly"
export PYTORCH_VERSION="$(conda search --json 'pytorch[channel=pytorch-nightly]' | \
python -c "import os, sys, json, re; cuver = '$cuver'; \
cuver = cuver.replace('cu', 'cuda') if cuver != 'cpu' else cuver; \
print(re.sub(r'\\+.*$', '', \
[x['version'] for x in json.load(sys.stdin)['pytorch'] \
if (x['platform'] == 'darwin' or cuver in x['fn']) \
and 'py' + os.environ['DESIRED_PYTHON'] in x['fn']][-1]))")"
if [[ -z "$PYTORCH_VERSION" ]]; then
echo "PyTorch version auto detection failed"
echo "No package found for desired_cuda=$desired_cuda and DESIRED_PYTHON=$DESIRED_PYTHON"
exit 1
fi
else
export CONDA_CHANNEL_FLAGS="-c pytorch -c pytorch-nightly"
fi
if [[ "$desired_cuda" == 'cpu' ]]; then
export CONDA_PYTORCH_BUILD_CONSTRAINT="- pytorch==$PYTORCH_VERSION"
export CONDA_PYTORCH_CONSTRAINT="- pytorch==$PYTORCH_VERSION"
else
time conda build -c $ANACONDA_USER --no-anaconda-upload --python 2.7 torchvision
export CONDA_PYTORCH_BUILD_CONSTRAINT="- pytorch==${PYTORCH_VERSION}"
export CONDA_PYTORCH_CONSTRAINT="- pytorch==${PYTORCH_VERSION}"
fi
time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.5 torchvision
time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.6 torchvision
time conda build -c $ANACONDA_USER --no-anaconda-upload --python 3.7 torchvision

# Loop through all Python versions to build a package for each
for py_ver in "${DESIRED_PYTHON[@]}"; do
build_string="py${py_ver}_${build_string_suffix}"
folder_tag="${build_string}_$(date +'%Y%m%d')"

# Create the conda package into this temporary folder. This is so we can find
# the package afterwards, as there's no easy way to extract the final filename
# from conda-build
output_folder="out_$folder_tag"
rm -rf "$output_folder"
mkdir "$output_folder"

# We need to build the compiler activation scripts first on Windows
time VSDEVCMD_ARGS=${VSDEVCMD_ARGS[@]} \
conda build -c "$ANACONDA_USER" \
--no-anaconda-upload \
--output-folder "$output_folder" \
../vs2017

conda config --set anaconda_upload no
echo "Calling conda-build at $(date)"
if [[ "$desired_cuda" == "9.2" ]]; then
time CMAKE_ARGS=${CMAKE_ARGS[@]} \
BUILD_VERSION="$TORCHVISION_BUILD_VERSION" \
CU_VERSION="$cuver" \
SOURCE_ROOT_DIR="$vision_rootdir" \
conda build -c "$ANACONDA_USER" \
-c defaults \
-c conda-forge \
-c "numba/label/dev" \
--no-anaconda-upload \
--python "$py_ver" \
--output-folder "$output_folder" \
--no-verify \
--no-test \
../torchvision
else
time CMAKE_ARGS=${CMAKE_ARGS[@]} \
BUILD_VERSION="$TORCHVISION_BUILD_VERSION" \
CU_VERSION="$cuver" \
SOURCE_ROOT_DIR="$vision_rootdir" \
conda build -c "$ANACONDA_USER" \
-c defaults \
-c conda-forge \
--no-anaconda-upload \
--python "$py_ver" \
--output-folder "$output_folder" \
--no-verify \
--no-test \
../torchvision
fi
echo "Finished conda-build at $(date)"

# Extract the package for testing
ls -lah "$output_folder"
built_package="$(find $output_folder/ -name '*torchvision*.tar.bz2')"

# Copy the built package to the host machine for persistence before testing
if [[ -n "$PYTORCH_FINAL_PACKAGE_DIR" ]]; then
mkdir -p "$PYTORCH_FINAL_PACKAGE_DIR" || true
cp "$built_package" "$PYTORCH_FINAL_PACKAGE_DIR/"
fi
done


set +e
1 change: 1 addition & 0 deletions packaging/torchvision/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%desired_cuda%
set CUDA_BIN_PATH=%CUDA_PATH%\bin
set NVCC_FLAGS=-D__CUDA_NO_HALF_OPERATORS__ --expt-relaxed-constexpr
if "%desired_cuda%" == "9.0" set NVCC_FLAGS=%NVCC_FLAGS% -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_50,code=compute_50
if "%desired_cuda%" == "9.2" set NVCC_FLAGS=%NVCC_FLAGS% -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_50,code=compute_50
if "%desired_cuda%" == "10.0" set NVCC_FLAGS=%NVCC_FLAGS% -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_75,code=sm_75 -gencode=arch=compute_50,code=compute_50

:cuda_flags_end
Expand Down
3 changes: 2 additions & 1 deletion packaging/torchvision/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ requirements:
- setuptools
{{ environ.get('CONDA_PYTORCH_BUILD_CONSTRAINT') }}
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
{{ environ.get('CONDA_CPUONLY_FEATURE') }}

run:
- python
Expand All @@ -31,7 +32,7 @@ build:
- FORCE_CUDA
- NVCC_FLAGS
features:
{{ CONDA_CPUONLY_FEATURE }}
{{ environ.get('CONDA_CPUONLY_FEATURE') }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, I wonder how this ever worked lol


test:
imports:
Expand Down
44 changes: 44 additions & 0 deletions packaging/vs2017/activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
:: Set env vars that tell distutils to use the compiler that we put on path
SET DISTUTILS_USE_SDK=1
SET MSSdk=1

SET "VS_VERSION=15.0"
SET "VS_MAJOR=15"
SET "VS_YEAR=2017"

set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
set "MSYS2_ENV_CONV_EXCL=CL"

:: For Python 3.5+, ensure that we link with the dynamic runtime. See
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info
set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime140.dll"

for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do (
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
set "VSINSTALLDIR=%%i\"
goto :vswhere
)
)

:vswhere

:: Shorten PATH to avoid the `input line too long` error.
SET MyPath=%PATH%

setlocal EnableDelayedExpansion

SET TempPath="%MyPath:;=";"%"
SET var=
FOR %%a IN (%TempPath%) DO (
IF EXIST %%~sa (
SET "var=!var!;%%~sa"
)
)

set "TempPath=!var:~1!"
endlocal & set "PATH=%TempPath%"

:: Shorten current directory too
FOR %%A IN (.) DO CD "%%~sA"

:: other things added by install_activate.bat at package build time
24 changes: 24 additions & 0 deletions packaging/vs2017/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
blas_impl:
- mkl # [x86_64]
c_compiler:
- vs2017 # [win]
cxx_compiler:
- vs2017 # [win]
python:
- 3.5
- 3.6
# This differs from target_platform in that it determines what subdir the compiler
# will target, not what subdir the compiler package will be itself.
# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32
# code on win-64 miniconda.
cross_compiler_target_platform:
- win-64 # [win]
target_platform:
- win-64 # [win]
vc:
- 14
zip_keys:
- # [win]
- vc # [win]
- c_compiler # [win]
- cxx_compiler # [win]
30 changes: 30 additions & 0 deletions packaging/vs2017/install_activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
set YEAR=2017
set VER=15

mkdir "%PREFIX%\etc\conda\activate.d"
COPY "%RECIPE_DIR%\activate.bat" "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"

IF "%cross_compiler_target_platform%" == "win-64" (
set "target_platform=amd64"
echo SET "CMAKE_GENERATOR=Visual Studio %VER% %YEAR% Win64" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
IF "%VSDEVCMD_ARGS%" == "" (
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
) ELSE (
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
)
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
) else (
set "target_platform=x86"
echo SET "CMAKE_GENERATOR=Visual Studio %VER% %YEAR%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo popd
)

Loading