|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +set -ex |
| 9 | + |
| 10 | +# shellcheck source=/dev/null |
| 11 | +source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" |
| 12 | + |
| 13 | +install_miniconda() { |
| 14 | + BASE_URL="https://repo.anaconda.com/miniconda" |
| 15 | + CONDA_FILE="Miniconda3-py${PYTHON_VERSION//./}_${MINICONDA_VERSION}-Linux-x86_64.sh" |
| 16 | + |
| 17 | + mkdir -p /opt/conda |
| 18 | + chown ci-user:ci-user /opt/conda |
| 19 | + |
| 20 | + pushd /tmp |
| 21 | + wget -q "${BASE_URL}/${CONDA_FILE}" |
| 22 | + # Install miniconda |
| 23 | + as_ci_user bash "${CONDA_FILE}" -b -f -p "/opt/conda" |
| 24 | + # Clean up the download file |
| 25 | + rm "${CONDA_FILE}" |
| 26 | + popd |
| 27 | + |
| 28 | + sed -e 's|PATH="\(.*\)"|PATH="/opt/conda/bin:\1"|g' -i /etc/environment |
| 29 | + export PATH="/opt/conda/bin:$PATH" |
| 30 | +} |
| 31 | + |
| 32 | +install_python() { |
| 33 | + pushd /opt/conda |
| 34 | + # Install the correct Python version |
| 35 | + as_ci_user conda create -n "py_${PYTHON_VERSION}" -y --file /opt/conda/conda-env-ci.txt python="${PYTHON_VERSION}" |
| 36 | + popd |
| 37 | +} |
| 38 | + |
| 39 | +install_pip_dependencies() { |
| 40 | + pushd /opt/conda |
| 41 | + # Install all Python dependencies |
| 42 | + pip_install -r /opt/conda/dev-requirements.txt |
| 43 | + pip_install -r /opt/conda/requirements.txt |
| 44 | + popd |
| 45 | +} |
| 46 | + |
| 47 | +fix_conda_ubuntu_libstdcxx() { |
| 48 | + cat /etc/issue |
| 49 | + # WARNING: This is a HACK from PyTorch core to be able to build PyTorch on 22.04. |
| 50 | + # Specifically, ubuntu-20+ all comes lib libstdc++ newer than 3.30+, but anaconda |
| 51 | + # is stuck with 3.29. So, remove libstdc++6.so.3.29 as installed by |
| 52 | + # https://anaconda.org/anaconda/libstdcxx-ng/files?version=11.2.0 |
| 53 | + # |
| 54 | + # PyTorch sev: https://github.com/pytorch/pytorch/issues/105248 |
| 55 | + # Ref: https://github.com/pytorch/pytorch/blob/main/.ci/docker/common/install_conda.sh |
| 56 | + if grep -e "2[02].04." /etc/issue >/dev/null; then |
| 57 | + rm "/opt/conda/envs/py_${PYTHON_VERSION}/lib/libstdc++.so.6" |
| 58 | + fi |
| 59 | +} |
| 60 | + |
| 61 | +install_miniconda |
| 62 | +install_python |
| 63 | +install_pip_dependencies |
| 64 | +fix_conda_ubuntu_libstdcxx |
0 commit comments