setup-env.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env bash
  2. set -euxo pipefail
  3. # Prepare conda
  4. set +x && eval "$($(which conda) shell.bash hook)" && set -x
  5. # Setup the OS_TYPE environment variable that should be used for conditions involving the OS below.
  6. case $(uname) in
  7. Linux)
  8. OS_TYPE=linux
  9. ;;
  10. Darwin)
  11. OS_TYPE=macos
  12. ;;
  13. MSYS*)
  14. OS_TYPE=windows
  15. ;;
  16. *)
  17. echo "Unknown OS type:" $(uname)
  18. exit 1
  19. ;;
  20. esac
  21. if [[ "${OS_TYPE}" == "macos" && $(uname -m) == x86_64 ]]; then
  22. echo '::group::Uninstall system JPEG libraries on macOS'
  23. # The x86 macOS runners, e.g. the GitHub Actions native "macos-12" runner, has some JPEG and PNG libraries
  24. # installed by default that interfere with our build. We uninstall them here and use the one from conda below.
  25. IMAGE_LIBS=$(brew list | grep -E "jpeg|png")
  26. for lib in $IMAGE_LIBS; do
  27. brew uninstall --ignore-dependencies --force "${lib}"
  28. done
  29. echo '::endgroup::'
  30. fi
  31. echo '::group::Create build environment'
  32. # See https://github.com/pytorch/vision/issues/7296 for ffmpeg
  33. conda create \
  34. --name ci \
  35. --quiet --yes \
  36. python="${PYTHON_VERSION}" pip \
  37. ninja cmake \
  38. libpng \
  39. 'ffmpeg<4.3'
  40. conda activate ci
  41. conda install --quiet --yes libjpeg-turbo -c pytorch
  42. pip install --progress-bar=off --upgrade setuptools
  43. # See https://github.com/pytorch/vision/issues/6790
  44. if [[ "${PYTHON_VERSION}" != "3.11" ]]; then
  45. pip install --progress-bar=off av!=10.0.0
  46. fi
  47. echo '::endgroup::'
  48. if [[ "${OS_TYPE}" == windows && "${GPU_ARCH_TYPE}" == cuda ]]; then
  49. echo '::group::Install VisualStudio CUDA extensions on Windows'
  50. if [[ "${VC_YEAR:-}" == "2022" ]]; then
  51. TARGET_DIR="/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Microsoft/VC/v170/BuildCustomizations"
  52. else
  53. TARGET_DIR="/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Microsoft/VC/v160/BuildCustomizations"
  54. fi
  55. mkdir -p "${TARGET_DIR}"
  56. cp -r "${CUDA_HOME}/MSBuildExtensions/"* "${TARGET_DIR}"
  57. echo '::endgroup::'
  58. fi
  59. echo '::group::Install PyTorch'
  60. # TODO: Can we maybe have this as environment variable in the job template? For example, `IS_RELEASE`.
  61. if [[ (${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
  62. CHANNEL=test
  63. else
  64. CHANNEL=nightly
  65. fi
  66. case $GPU_ARCH_TYPE in
  67. cpu)
  68. GPU_ARCH_ID="cpu"
  69. ;;
  70. cuda)
  71. VERSION_WITHOUT_DOT=$(echo "${GPU_ARCH_VERSION}" | sed 's/\.//')
  72. GPU_ARCH_ID="cu${VERSION_WITHOUT_DOT}"
  73. ;;
  74. *)
  75. echo "Unknown GPU_ARCH_TYPE=${GPU_ARCH_TYPE}"
  76. exit 1
  77. ;;
  78. esac
  79. PYTORCH_WHEEL_INDEX="https://download.pytorch.org/whl/${CHANNEL}/${GPU_ARCH_ID}"
  80. pip install --progress-bar=off --pre torch --index-url="${PYTORCH_WHEEL_INDEX}"
  81. if [[ $GPU_ARCH_TYPE == 'cuda' ]]; then
  82. python -c "import torch; exit(not torch.cuda.is_available())"
  83. fi
  84. echo '::endgroup::'
  85. echo '::group::Install third party dependencies prior to TorchVision install'
  86. # Installing with `easy_install`, e.g. `python setup.py install` or `python setup.py develop`, has some quirks when
  87. # when pulling in third-party dependencies. For example:
  88. # - On Windows, we often hit an SSL error although `pip` can install just fine.
  89. # - It happily pulls in pre-releases, which can lead to more problems down the line.
  90. # `pip` does not unless explicitly told to do so.
  91. # Thus, we use `easy_install` to extract the third-party dependencies here and install them upfront with `pip`.
  92. python setup.py egg_info
  93. # The requires.txt cannot be used with `pip install -r` directly. The requirements are listed at the top and the
  94. # optional dependencies come in non-standard syntax after a blank line. Thus, we just extract the header.
  95. sed -e '/^$/,$d' *.egg-info/requires.txt | tee requirements.txt
  96. pip install --progress-bar=off -r requirements.txt
  97. echo '::endgroup::'
  98. echo '::group::Install TorchVision'
  99. python setup.py develop
  100. echo '::endgroup::'
  101. echo '::group::Collect environment information'
  102. conda list
  103. python -m torch.utils.collect_env
  104. echo '::endgroup::'