334 Star 1.5K Fork 863

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mindspore_ascend310_install_pip_en.md 15.38 KB
一键复制 编辑 原始数据 按行查看 历史
俞涵 提交于 2023-11-16 14:09 . update obs links

Installing MindSpore in Ascend 310 by pip

View Source On Gitee

The following describes how to quickly install MindSpore by pip on Linux in the Ascend 310 environment, MindSpore in Ascend 310 only supports inference.

  • If you want to install MindSpore by pip on an EulerOS 2.8 with Ascend AI processor software package installed, you may use automatic installation script for one-click installation, see Automatic Installation section. The automatic installation script will install MindSpore and its required dependencies.

  • If your system is one of Ubuntu 18.04/CentOS 7.6, or some dependencies, such as Python and GCC, have been installed in your system, it is recommended to install manually by referring to the installation steps in the Manual Installation section.

Automatic Installation

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 automatic installation script only supports the installation of MindSpore>=1.6.0.

wget https://gitee.com/mindspore/mindspore/raw/r1.8/scripts/install/euleros-ascend310-pip.sh
# install MindSpore 1.8.1 and Python 3.7
# the default value of LOCAL_ASCEND is /usr/local/Ascend
MINDSPORE_VERSION=1.8.1 bash -i ./euleros-ascend310-pip.sh
# to specify Python and MindSpore version, taking Python 3.9 and MindSpore 1.6.0 as examples
# and set LOCAL_ASCEND to /home/xxx/Ascend, use the following manners
# LOCAL_ASCEND=/home/xxx/Ascend MINDSPORE_VERSION=1.6.0 bash -i ./euleros-ascend310-pip.sh

This script performs the following operations:

  • Install the dependencies required by MindSpore, such as GCC and gmp.
  • Install Python3 and pip3 and set them as default.
  • Install MindSpore Ascend 310 by pip.

After the 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

Take Python 3.7 as an example, run the following command to activate the virtual environment.

conda activate mindspore_py37

Now you can jump to the Configuring Environment Variables section to set the relevant environment variables.

For more usage, see the script header description.

Manual Installation

The following table lists the system environment and third-party dependencies required for installing MindSpore.

software version description
Ubuntu 18.04/CentOS 7.6/EulerOS 2.8 - OS for running and compiling MindSpore
Python 3.7-3.9 Python environment that MindSpore depends
Ascend AI processor software package - Ascend platform AI computing library used by MindSpore
GCC 7.3.0 C++ compiler for compiling MindSpore
gmp 6.1.2 Multiple precision arithmetic library used by MindSpore
CMake 3.18.3 or later Compilation tool that builds MindSpore

The following describes how to install the third-party dependencies.

Installing Python

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

If you are using an ARM architecture system, please ensure that pip installed for current Python has a version >= 19.3. If not, upgrade pip with the following command.

python -m pip install -U pip

Installing Ascend AI processor software package

Ascend software package provides two distributions, commercial edition and community edition:

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 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 if the Ascend AI package has been installed in 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/topi-*-py3-none-any.whl
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/loacl/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.

Installing GCC

  • 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, run the following commands to install.

    sudo yum install gcc -y

Installing gmp

  • On Ubuntu 18.04, run the following commands to install.

    sudo apt-get install libgmp-dev -y
  • On CentOS 7 and EulerOS, run the following commands to install.

    sudo yum install gmp-devel -y

Installing CMake

  • 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, and other installation path need to be modified accordingly.

    echo -e "export PATH=/usr/local/cmake-3.19.8/bin:\$PATH" >> ~/.bashrc
    source ~/.bashrc

Installing MindSpore

First, refer to Version List to select the version of MindSpore you want to install, and perform SHA-256 integrity check. Taking version 1.8.1 as an example, execute the following commands.

export MS_VERSION=1.8.1

Then run the following commands to install MindSpore according to the system architecture and Python version.

# x86_64 + Python3.7
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/ascend/x86_64/mindspore_ascend-${MS_VERSION/-/}-cp37-cp37m-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# x86_64 + Python3.8
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/ascend/x86_64/mindspore_ascend-${MS_VERSION/-/}-cp38-cp38-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# x86_64 + Python3.9
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/ascend/x86_64/mindspore_ascend-${MS_VERSION/-/}-cp39-cp39-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# aarch64 + Python3.7
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/ascend/aarch64/mindspore_ascend-${MS_VERSION/-/}-cp37-cp37m-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# aarch64 + Python3.8
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/ascend/aarch64/mindspore_ascend-${MS_VERSION/-/}-cp38-cp38-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# aarch64 + Python3.9
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/ascend/aarch64/mindspore_ascend-${MS_VERSION/-/}-cp39-cp39-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -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 dependencies, see required_package in the setup.py. In other cases, install the dependencies by yourself. When running a model, you need to install additional dependencies based on the requirements.txt file specified by different models in the ModelZoo. For details about common dependencies, see requirements.txt.

Configuring Environment Variables

After MindSpore is installed, export runtime environment variables. In the following command, /usr/local/Ascend in LOCAL_ASCEND=/usr/local/Ascend indicates the installation path of the software package. Change it to the actual installation path.

# 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/op_impl/built-in/ai_core/tbe/op_tiling:${LD_LIBRARY_PATH}

# lib libraries that the mindspore depends on, modify "pip3" according to the actual situation
export LD_LIBRARY_PATH=`pip3 show mindspore-ascend | grep Location | awk '{print $2"/mindspore/lib"}' | xargs realpath`:${LD_LIBRARY_PATH}

# Environment variables that must be configured
## TBE operator implementation tool path
export TBE_IMPL_PATH=${LOCAL_ASCEND}/ascend-toolkit/latest/opp/op_impl/built-in/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}

Verifying the Installation

Create a directory to store the sample code project, for example, /home/HwHiAiUser/Ascend/ascend-toolkit/20.0.RC1/acllib_linux.arm64/sample/acl_execute_model/ascend310_single_op_sample. You can obtain the code from the official website. A simple example of adding [1, 2, 3, 4] to [2, 3, 4, 5] is used and the code project directory structure is as follows:


└─ascend310_single_op_sample
    ├── CMakeLists.txt                    // Build script
    ├── README.md                         // Usage description
    ├── main.cc                           // Main function
    └── tensor_add.mindir                 // MindIR model file

Go to the directory of the sample project and change the path based on the actual requirements.

cd /home/HwHiAiUser/Ascend/ascend-toolkit/20.0.RC1/acllib_linux.arm64/sample/acl_execute_model/ascend310_single_op_sample

Build a project by referring to README.md, and modify pip3 according to the actual situation.

cmake . -DMINDSPORE_PATH=`pip3 show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`
make

After the build is successful, execute the case.

./tensor_add_sample

The following information is displayed:

3
5
7
9

The preceding information indicates that MindSpore is successfully installed.

1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r1.8

搜索帮助