This document describes how to install MindSpore by compiling source code on Linux in an Ascend environment.
If you want to configure an environment that can compile MindSpore on EulerOS 2.8 with Ascend AI processor software package installed, you may use an automatic installation script for one-click configuration, see Environment Preparation -automatic, recommended section. The script will automatically install the dependencies required to compile MindSpore.
If your system is Ubuntu 18.04, CentOS 7.6, openEuler 20.03, or KylinV10 SP1, or some dependencies, such as Python and GCC, have been installed, it is advised to manually install MindSpore by referring to Environment Preparation-manual section.
Before running the automatic installation script, you need to make sure that the Ascend AI processor software package is correctly installed on your system. If it is not installed, please refer to the section Installing Ascend AI processor software package to install it.
Run the following command to obtain and run the automatic installation script. The environment configured by the automatic installation script only supports compiling MindSpore>=1.6.0.
wget https://gitee.com/mindspore/mindspore/raw/master/scripts/install/euleros-ascend-source.sh
# install Python 3.7 by default
# the default value of LOCAL_ASCEND is /usr/local/Ascend
bash -i ./euleros-ascend-source.sh
# to specify the Python 3.9 installation and install the optional dependencies Open MPI
# and set LOCAL_ASCEND to /home/xxx/Ascend, use the following manners
# LOCAL_ASCEND=/home/xxx/Ascend PYTHON_VERSION=3.9 OPENMPI=on bash -i ./euleros-ascend-source.sh
This script performs the following operations:
on
.After the automatic installation script is executed, you need to reopen the terminal window to make the environment variables take effect.
The automatic installation script creates a virtual environment named mindspore_pyXX
for MindSpore. Where XX
is the Python version, such as Python 3.7, the virtual environment name is mindspore_py37
. Run the following command to show all virtual environments.
conda env list
To activate the virtual environment, take Python 3.7 as an example, execute the following command.
conda activate mindspore_py37
Now you can jump to the Downloading the Source Code from the Code Repository section to downloading and compiling MindSpore.
For more usage, see the script header description.
The following table lists the system environment and third-party dependencies required for building and installing MindSpore.
Software | Version | Description |
---|---|---|
Ubuntu 18.04/CentOS 7.6/EulerOS 2.8/openEuler 20.03/KylinV10 SP1 | - | OS for running MindSpore |
Python | 3.7-3.9 | Python environment that MindSpore depends on |
Ascend AI processor software package | - | Ascend platform AI computing library used by MindSpore |
wheel | 0.32.0 or later | Python packaging tool used by MindSpore |
setuptools | 44.0 or later | Python package management tool used by MindSpore |
GCC | 7.3.0 | C++ compiler for compiling MindSpore |
git | - | Source code management tool used by MindSpore |
git-lfs | - | Source code management tool used by MindSpore |
CMake | 3.18.3 or later | Build tool for MindSpore |
Flex | 2.5.35 or later | lexical analyzer used by MindSpore |
tclsh | - | MindSpore SQLite build dependency |
patch | 2.5 or later | Source code patching tool used by MindSpore |
NUMA | 2.0.11 or later | Non-uniform memory access library used by MindSpore |
The following describes how to install the third-party dependencies.
Python can be installed by Conda.
Install Miniconda:
cd /tmp
curl -O https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py37_4.10.3-Linux-$(arch).sh
bash Miniconda3-py37_4.10.3-Linux-$(arch).sh -b
cd -
. ~/miniconda3/etc/profile.d/conda.sh
conda init bash
After the installation is complete, you can set up Tsinghua source acceleration download for Conda, and see here.
Create a virtual environment, taking Python 3.7.5 as an example:
conda create -n mindspore_py37 python=3.7.5 -y
conda activate mindspore_py37
Run the following command to check the Python version.
python --version
Ascend software package provides two distributions, commercial edition and community edition:
Commercial edition needs approval from Ascend to download, for detailed installation guide, please refer to Ascend Training Solution 23.0.RC3.
Community edition has no restrictions, choose 7.0.RC1.beta1
in CANN community edition, then choose relevant driver and firmware packages in firmware and driver. Please refer to the abovementioned commercial edition installation guide to choose which packages are to be installed and how to install them.
The default installation path of the installation package is /usr/local/Ascend
. Ensure that the current user has the right to access the installation path /usr/local/Ascend
of Ascend AI processor software package. If not, the root user needs to add the current user to the user group where /usr/local/Ascend
is located.
Install the .whl packages provided in Ascend AI processor software package. If the .whl packages have been installed before, you should uninstall the .whl packages by running the following command.
pip uninstall te topi hccl -y
Run the following command to install the .whl packages in the default path. If the installation path is not the default path, you need to replace the path in the command with the installation path.
pip install sympy
pip install /usr/local/Ascend/ascend-toolkit/latest/lib64/te-*-py3-none-any.whl
pip install /usr/local/Ascend/ascend-toolkit/latest/lib64/hccl-*-py3-none-any.whl
The LD_LIBRARY_PATH environment variable does not work when the installation package exists in the default path. The default path priority is: /usr/local/Ascend/nnae is higher than /usr/local/Ascend/ascend-toolkit. The reason is that MindSpore uses DT_RPATH to support startup without environment variables, reducing user settings. DT_RPATH has a higher priority than the LD_LIBRARY_PATH environment variable.
After installing Python, use the following command to install it.
pip install wheel
pip install -U setuptools
On Ubuntu 18.04, run the following commands to install.
sudo apt-get install gcc-7 -y
On CentOS 7, run the following commands to install.
sudo yum install centos-release-scl
sudo yum install devtoolset-7
After installation, run the following commands to switch to GCC 7.
scl enable devtoolset-7 bash
On EulerOS and openEuler, run the following commands to install.
sudo yum install gcc -y
On Ubuntu 18.04, run the following commands to install.
sudo apt-get install git tcl patch libnuma-dev flex -y
On CentOS 7, EulerOS and openEuler, run the following commands to install.
sudo yum install git tcl patch numactl-devel flex -y
On Ubuntu, run the following commands to install.
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs -y
git lfs install
On CentOS 7, run the following commands to install.
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
sudo yum install git-lfs -y
git lfs install
On EulerOS and openEuler, run the following commands to install.
Select the appropriate version to download according to the system architecture.
# x64
curl -OL https://github.com/git-lfs/git-lfs/releases/download/v3.1.2/git-lfs-linux-amd64-v3.1.2.tar.gz
# arm64
curl -OL https://github.com/git-lfs/git-lfs/releases/download/v3.1.2/git-lfs-linux-arm64-v3.1.2.tar.gz
Unzip and install.
mkdir git-lfs
tar xf git-lfs-linux-*-v3.1.2.tar.gz -C git-lfs
cd git-lfs
sudo bash install.sh
On Ubuntu 18.04, run the following commands to install CMake.
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"
sudo apt-get install cmake -y
Other Linux systems can be installed with the following commands.
Choose different download links based on the system architecture.
# x86 run
curl -O https://cmake.org/files/v3.19/cmake-3.19.8-Linux-x86_64.sh
# aarch64 run
curl -O https://cmake.org/files/v3.19/cmake-3.19.8-Linux-aarch64.sh
Run the script to install CMake, which is installed in the /usr/local
by default.
sudo mkdir /usr/local/cmake-3.19.8
sudo bash cmake-3.19.8-Linux-*.sh --prefix=/usr/local/cmake-3.19.8 --exclude-subdir
Finally, add CMake to the PATH
environment variable. Run the following commands if it is installed in the default path, other installation paths need to be modified accordingly.
echo -e "export PATH=/usr/local/cmake-3.19.8/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
git clone https://gitee.com/mindspore/mindspore.git
Go to the root directory of mindspore, then run the build script.
cd mindspore
bash build.sh -e ascend -S on
Where:
build.sh
script, the default number of compilation threads is 8. If the compiler performance is poor, compilation errors may occur. You can add -j{Number of threads} in to script to reduce the number of threads, for example, bash build.sh -e ascend -j4
.on
, the source code is downloaded from the corresponding gitee image.build.sh
, see the script header description.pip install output/mindspore-*.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
When the network is connected, dependencies of MindSpore are automatically downloaded during the .whl package installation. (For details about the dependency, see required_package in setup.py.) In other cases, you need to install it by yourself. When running models, you need to install additional dependencies based on requirements.txt specified for different models in ModelZoo. For details about common dependencies, see requirements.txt.
If Ascend AI processor software is installed in a non-default path, after MindSpore is installed, export Runtime-related environment variables. /usr/local/Ascend
in the following command LOCAL_ASCEND=/usr/local/Ascend
denotes the installation path of the software package, and you need to replace it as the actual installation path of the software package.
# control log level. 0-DEBUG, 1-INFO, 2-WARNING, 3-ERROR, 4-CRITICAL, default level is WARNING.
export GLOG_v=2
# Conda environmental options
LOCAL_ASCEND=/usr/local/Ascend # the root directory of run package
# lib libraries that the run package depends on
export LD_LIBRARY_PATH=${LOCAL_ASCEND}/ascend-toolkit/latest/lib64:${LOCAL_ASCEND}/driver/lib64:${LOCAL_ASCEND}/ascend-toolkit/latest/opp/built-in/op_impl/ai_core/tbe/op_tiling:${LD_LIBRARY_PATH}
# Environment variables that must be configured
## TBE operator implementation tool path
export TBE_IMPL_PATH=${LOCAL_ASCEND}/ascend-toolkit/latest/opp/built-in/op_impl/ai_core/tbe
## OPP path
export ASCEND_OPP_PATH=${LOCAL_ASCEND}/ascend-toolkit/latest/opp
## AICPU path
export ASCEND_AICPU_PATH=${ASCEND_OPP_PATH}/..
## TBE operator compilation tool path
export PATH=${LOCAL_ASCEND}/ascend-toolkit/latest/compiler/ccec_compiler/bin/:${PATH}
## Python library that TBE implementation depends on
export PYTHONPATH=${TBE_IMPL_PATH}:${PYTHONPATH}
i:
python -c "import mindspore;mindspore.set_context(device_target='Ascend');mindspore.run_check()"
The outputs should be the same as:
MindSpore version: __version__
The result of multiplication calculation is correct, MindSpore has been installed on platform [Ascend] successfully!
It means MindSpore has been installed successfully.
ii:
import numpy as np
import mindspore as ms
import mindspore.ops as ops
ms.set_context(device_target="Ascend")
x = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
y = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
print(ops.add(x, y))
The outputs should be the same as:
[[[[2. 2. 2. 2.]
[2. 2. 2. 2.]
[2. 2. 2. 2.]]
[[2. 2. 2. 2.]
[2. 2. 2. 2.]
[2. 2. 2. 2.]]
[[2. 2. 2. 2.]
[2. 2. 2. 2.]
[2. 2. 2. 2.]]]]
It means MindSpore has been installed successfully.
After successfully executing the compile script build.sh
in the root path of the source code, find the whl package in path output
, and use the following command to update your version.
When upgrading from MindSpore 1.x to MindSpore 2.x, you need to manually uninstall the old version first:
pip uninstall mindspore-ascend
Then install MindSpore 2.x:
pip install mindspore*.whl
When upgrading from MindSpore 2.x:
pip install --upgrade mindspore*.whl
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。