Ubuntu下自动安装MindSpore1.7GPU版
https://www.mindspore.cn/install
(1)前置安装
- 确认是安装 Ubuntu 是x86架构64位操作系统。
- 安装Minicanda或者Anaconda。
- 安装Python 环境 3.7.5 或3.9.0(如何使用Conda安装可以直接创建命令即可,如果手动安装则需要配置Python环境变量)
- 安装 Cuda10.1/11.1 驱动、GCC、glibc、OpenSSL
- 查看GPU驱动
nvidia-smi
(2)自动安装
- 下载脚本
wget https://gitee.com/mindspore/mindspore/raw/r1.7/scripts/install/ubuntu-gpu-pip.sh
- 编辑脚本
vim ubuntu-gpu-pip.sh
该脚本会执行以下操作:
- 更改软件源配置为华为云源。
- 安装MindSpore所需的依赖,如GCC,gmp。
- 通过APT安装Python3和pip3,并设为默认。
- 下载CUDA和cuDNN并安装。
- 通过pip安装MindSpore GPU版本。
- 如果OPENMPI设置为
on
,则安装Open MPI。
自动安装脚本执行完成后,需要重新打开终端窗口以使环境变量生效。
- 执行脚本,完成安装
# 安装MindSpore 1.7.0,Python 3.7和CUDA 10.1
MINDSPORE_VERSION=1.7.0 CUDA_VERSION=10.1 bash -i ./ubuntu-gpu-pip.sh
- 安装完成
- 安装其他版本,修改参数
# 如需指定安装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
- 完整脚本学习
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>}]."
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>} " != *" $CUDA_VERSION "* ]]; then
echo "CUDA_VERSION is '$CUDA_VERSION', but available versions are [${available_cuda_version<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 value to environment variable if value is not in it
add_env() {
local name=$1
if [[ ":${!name}:" != *":$2:"* ]]; then
echo -e "export $1=$2:\$$1" >> ~/.bashrc
fi
}
# use huaweicloud mirror in China
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
# python
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
# pip
python -m pip install -