Prérequis
- Vérifiez que votre système d'exploitation est Ubuntu x86_64 64 bits.
- Installez Miniconda ou Anaconda.
- Configurez un environnement Python 3.7.5 ou 3.9.0. Utilisez Conda pour créer un environnement spécifique si nécessaire, ou configurez manuellement les variables d'environnement Python.
- Installez les composants requis : CUDA 10.1 ou 11.1, GCC, glibc et OpenSSL.
- Vérifiez le pilote GPU NVIDIA :
nvidia-smi
Installation automatisée
- Téléchargez le script d'installation :
wget https://gitee.com/mindspore/mindspore/raw/r1.7/scripts/install/ubuntu-gpu-pip.sh
- Éditez le script pour personnaliser l’installation :
vim ubuntu-gpu-pip.sh
Le script effectue les opérations suivantes :
- Remplace le dépôt logiciel par celui de Huawei Cloud.
- Installe les dépendances nécessaries (GCC, GMP, etc.).
- Utilise APT pour installer Python 3 et pip3, puis les rend par défaut.
- Télécharge et installe CUDA et cuDNN.
- Installe via pip la version GPU de MindSpore.
- Si
OPENMPIest activé, installe Open MPI pour le traitement distribué.
Après exécution du script, redémarrez votre terminal pour charger les nouvelles variables d’environnement.
- Lancez l’installation avec les paramètres souhaités :
# Installer MindSpore 1.7.0, Python 3.7 et CUDA 10.1
MINDSPORE_VERSION=1.7.0 CUDA_VERSION=10.1 bash -i ./ubuntu-gpu-pip.sh
- Pour une installation spécifique d’une autre version :
# Exemple : Python 3.9, CUDA 10.1, MindSpore 1.6.0
PYTHON_VERSION=3.9 CUDA_VERSION=10.1 MINDSPORE_VERSION=1.6.0 bash -i ./ubuntu-gpu-pip.sh
Contenu du script d’installation
set -e
PYTHON_VERSION=${PYTHON_VERSION:-3.7}
MINDSPORE_VERSION=${MINDSPORE_VERSION:EMPTY}
CUDA_VERSION=${CUDA_VERSION:-11.1}
OPENMPI=${OPENMPI:-off}
version_less() {
test "$(echo "$@" | tr ' ' '\n' | sort -rV | head -n 1)" != "$1";
}
if [ $MINDSPORE_VERSION == "EMPTY" ] || version_less "${MINDSPORE_VERSION}" "1.6.0"; then
echo "MINDSPORE_VERSION should be >=1.6.0, please check available versions at https://www.mindspore.cn/versions."
exit 1
fi
available_py_version=(3.7 3.8 3.9)
if [[ " ${available_py_version<li>} " != *" $PYTHON_VERSION "* ]]; then
echo "PYTHON_VERSION is '$PYTHON_VERSION', but available versions are [${available_py_version</li><li>}]."
exit 1
fi
if [[ "$PYTHON_VERSION" == "3.8" && ${MINDSPORE_VERSION:0:3} == "1.6" ]]; then
echo "PYTHON_VERSION==3.8 is not compatible with MINDSPORE_VERSION==1.6.x, please use PYTHON_VERSION==3.7 or 3.9 for MINDSPORE_VERSION==1.6.x."
exit 1
fi
available_cuda_version=(10.1 11.1)
if [[ " ${available_cuda_version</li><li>} " != *" $CUDA_VERSION "* ]]; then
echo "CUDA_VERSION is '$CUDA_VERSION', but available versions are [${available_cuda_version</li><li>}]."
exit 1
fi
declare -A minimum_driver_version_map=()
minimum_driver_version_map["10.1"]="418.39"
minimum_driver_version_map["11.1"]="450.80.02"
driver_version=$(modinfo nvidia | grep ^version | awk '{printf $2}')
if [[ $driver_version < ${minimum_driver_version_map[$CUDA_VERSION]} ]]; then
echo "CUDA $CUDA_VERSION minimum required driver version is ${minimum_driver_version_map[$CUDA_VERSION]}, \
but current nvidia driver version is $driver_version, please upgrade your driver manually."
exit 1
fi
cuda_name="cuda-$CUDA_VERSION"
declare -A version_map=()
version_map["3.7"]="${MINDSPORE_VERSION/-/}-cp37-cp37m"
version_map["3.8"]="${MINDSPORE_VERSION/-/}-cp38-cp38"
version_map["3.9"]="${MINDSPORE_VERSION/-/}-cp39-cp39"
add_env() {
local name=$1
if [[ ":${!name}:" != *":$2:"* ]]; then
echo -e "export $1=$2:\$$1" >> ~/.bashrc
fi
}
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo apt-get update
sudo apt-get install curl make gcc-7 libgmp-dev linux-headers-"$(uname -r)" -y
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get install python$PYTHON_VERSION python$PYTHON_VERSION-distutils python3-pip -y
sudo update-alternatives --install /usr/bin/python python /usr/bin/python$PYTHON_VERSION 100
python -m pip install -U pip -i https://pypi.tuna.tsinghua.edu.cn/simple
echo -e "alias pip='python -m pip'" >> ~/.bashrc
python -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
echo "installing CUDA and cuDNN"
cd /tmp
declare -A cuda_url_map=()
cuda_url_map["10.1"]=https://developer.download.nvidia.cn/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_418.87.00_linux.run
cuda_url_map["11.1"]=https://developer.download.nvidia.cn/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run
cuda_url=${cuda_url_map[$CUDA_VERSION]}
wget $cuda_url
sudo sh ${cuda_url##*/} --silent --toolkit
cd -
sudo apt-key adv --fetch-keys https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo add-apt-repository "deb https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
declare -A cudnn_name_map=()
cudnn_name_map["10.1"]="libcudnn7=7.6.5.32-1+cuda10.1 libcudnn7-dev=7.6.5.32-1+cuda10.1"
cudnn_name_map["11.1"]="libcudnn8=8.0.4.30-1+cuda11.1 libcudnn8-dev=8.0.4.30-1+cuda11.1"
sudo apt-get install --no-install-recommends ${cudnn_name_map[$CUDA_VERSION]} -y
set +e && source ~/.bashrc
set -e
add_env PATH /usr/local/cuda/bin
add_env LD_LIBRARY_PATH /usr/local/cuda/lib64
add_env LD_LIBRARY_PATH /usr/lib/x86_64-linux-gnu
set +e && source ~/.bashrc
set -e
if [[ X"$OPENMPI" == "Xon" ]]; then
echo "installing openmpi"
cd /tmp
curl -O https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.3.tar.gz
tar xzf openmpi-4.0.3.tar.gz
cd openmpi-4.0.3
./configure --prefix=/usr/local/openmpi-4.0.3
make
sudo make install
add_env PATH /usr/local/openmpi-4.0.3/bin
add_env LD_LIBRARY_PATH /usr/local/openmpi-4.0.3/lib
fi
arch=`uname -m`
python -m pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MINDSPORE_VERSION}/MindSpore/gpu/${arch}/${cuda_name}/mindspore_gpu-${version_map["$PYTHON_VERSION"]}-linux_${arch}.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
python -c "import mindspore;mindspore.run_check()"
cd /tmp
cat > example.py <<end as="" cd="" context="" context.set_context="" end="" example.py="" from="" import="" mindspore="" mindspore.context="" mindspore.ops="" np="" numpy="" ops="" print="" python="" tensor="" x="Tensor(np.ones([1,3,3,4]).astype(np.float32))" y="Tensor(np.ones([1,3,3,4]).astype(np.float32))"></end></li>