Alibaba’s domestic arm architecture installs pytorch and records pitfalls once

Preface

I installed pytorch in the Alibaba Cloud docker virtual environment and went through a lot of pitfalls to record it.
This time I want to build an environment under Alibaba's domestic arm environment python3.8 + pytorch1.10.2. Since torch has been updated to 2.0, the old version of the arm environment has to be installed again.

Environmental Statement

Server environment

Ali Cloud

・实例: 1核 2G ecs.c8y ecs-7
・I/O 优化实例: I/O 优化实例
・系统盘: 增强型SSD云盘 /dev/xvda 40GB 模块属性 PL0
・操作系统: Alibaba Cloud Linux 3.2104 LTS 64位 ARM版 Linux 64位

target environment

python==3.8.16
torch==1.10.2

detailed version

The system and CPU environment are as follows

cat /proc/version
Linux version 5.10.134-13.1.al8.aarch64 ([email protected]) (gcc (GCC) 10.2.1 20200825 (Alibaba 10.2.1-3 2.32), GNU ld version 2.35-12.2.al8) #1 SMP Mon Feb 6 07:07:12 UTC 2023

uname -a
Linux 810a9ecee45c 5.10.134-13.1.al8.aarch64 #1 SMP Mon Feb 6 07:07:12 UTC 2023 aarch64 GNU/Linux

For commands to check the Linux kernel version, please refer to How to Check the Linux System Version?

1. Pull the docker image

Here select the python3.8 environment image officially provided by docker, address
Mirror version

Image pull command

docker pull python:3.8.16-buster

# 这个镜像需要手动添加yum。使用下面语句更新apt-get,安装yum
apt-get -y update
apt-get install yum

For how to use docker, please refer to the Docker Concise Usage Guide.

2. Select the corresponding version offline package.whl

Online installation

Because it is no longer possible to select the corresponding version through online installation, offline installation is used. For newer versions, you can check the online installation version first:

pip install torch==

Generates error: No version available

No corresponding version

pip install torch==

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
ERROR: Could not find a version that satisfies the requirement torch== (from versions: none)
ERROR: No matching distribution found for torch==

Pytorch officially does not provide an installation package for the arm platform,
so the installation command provided on the official page cannot be installed successfully.
As long as the CPU is an arm chip, it will not work regardless of windows, linux, maxos.
There are two solutions
: 1. Download the source code and then proceed. Manual compilation (too complicated and time-consuming)
2. Use the version compiled by others in the community. This is relatively simple.

Download offline installation package

Here we directly use doctrine and download the corresponding offline version installation package according to the system version. whl
torch download address in Tsinghua source
. Here we find the installation package from Tsinghua source torch-1.10.2-cp38-cp38-manylinux2014_aarch64.whl
, which cp38represents python 3.8, aarch64which is arm64 .
Tsinghua source torch1.10.2 all versions

3. Install offline packages

Here try to install the offline package directly

pip install XXX.whl

#如当前准备安装的 torch1.10.2 的linux安装包
pip install torch-1.10.2-cp38-cp38-manylinux2014_aarch64.whl

produces error: is not a supported wheel on this platform

The whl installation package is not supported by this platform (actually not)

pip install torch-1.10.2-cp38-cp38-manylinux2014_aarch64.whl 

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
ERROR: torch-1.10.2-cp38-cp38-manylinux2014_aarch64.whl is not a supported wheel on this platform.

But in fact, we found that Linux here only has this version of the pytorch installation package, so we have no choice.

Solution: Modify the installation package name

In fact, it’s just that the suffix of the installation package is wrong. The system determines that it recognizes the suffix of the whl file (so stupid).
First query

pip debug --verbose

(The statement is applicable to new versions of pip such as pip 20.0. You need to refer to this for previous pip versions. )
After entering this command, a large amount of information will be displayed:

$ pip debug --verbose

WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 23.0.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
sys.version: 3.8.16 (default, Mar 29 2023, 23:56:55) 
[GCC 12.2.1 20220924]
sys.executable: /usr/local/bin/python
sys.getdefaultencoding: utf-8
sys.getfilesystemencoding: utf-8
locale.getpreferredencoding: UTF-8
sys.platform: linux
sys.implementation:
  name: cpython
'cert' config value: global
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
pip._vendor.certifi.where(): /usr/local/lib/python3.8/site-packages/pip/_vendor/certifi/cacert.pem
pip._vendor.DEBUNDLED: False
vendored library versions:
  CacheControl==0.12.11
  colorama==0.4.6
  distlib==0.3.6
  distro==1.8.0
  msgpack==1.0.4
  packaging==21.3
  platformdirs==2.6.2
  pyparsing==3.0.9
  pyproject-hooks==1.0.0
  requests==2.28.2
  certifi==2022.12.07
  chardet==5.1.0
  idna==3.4
  urllib3==1.26.14
  rich==12.6.0 (Unable to locate actual module version, using vendor.txt specified version)
  pygments==2.13.0
  typing_extensions==4.4.0 (Unable to locate actual module version, using vendor.txt specified version)
  resolvelib==0.8.1
  setuptools==44.0.0 (Unable to locate actual module version, using vendor.txt specified version)
  six==1.16.0
  tenacity==8.1.0 (Unable to locate actual module version, using vendor.txt specified version)
  tomli==2.0.1
  webencodings==0.5.1 (Unable to locate actual module version, using vendor.txt specified version)
Compatible tags: 87
  cp38-cp38-musllinux_1_2_aarch64
  cp38-cp38-musllinux_1_1_aarch64
  cp38-cp38-musllinux_1_0_aarch64
  cp38-cp38-linux_aarch64
  cp38-abi3-musllinux_1_2_aarch64
  cp38-abi3-musllinux_1_1_aarch64
  cp38-abi3-musllinux_1_0_aarch64
  cp38-abi3-linux_aarch64
  cp38-none-musllinux_1_2_aarch64
  cp38-none-musllinux_1_1_aarch64
  cp38-none-musllinux_1_0_aarch64
  cp38-none-linux_aarch64
  cp37-abi3-musllinux_1_2_aarch64
  cp37-abi3-musllinux_1_1_aarch64
  cp37-abi3-musllinux_1_0_aarch64
  cp37-abi3-linux_aarch64
  cp36-abi3-musllinux_1_2_aarch64
  cp36-abi3-musllinux_1_1_aarch64
  cp36-abi3-musllinux_1_0_aarch64
  cp36-abi3-linux_aarch64
  cp35-abi3-musllinux_1_2_aarch64
  cp35-abi3-musllinux_1_1_aarch64
  cp35-abi3-musllinux_1_0_aarch64
  cp35-abi3-linux_aarch64
  cp34-abi3-musllinux_1_2_aarch64
  cp34-abi3-musllinux_1_1_aarch64
  cp34-abi3-musllinux_1_0_aarch64
  cp34-abi3-linux_aarch64
  cp33-abi3-musllinux_1_2_aarch64
  cp33-abi3-musllinux_1_1_aarch64
  cp33-abi3-musllinux_1_0_aarch64
  cp33-abi3-linux_aarch64
  cp32-abi3-musllinux_1_2_aarch64
  cp32-abi3-musllinux_1_1_aarch64
  cp32-abi3-musllinux_1_0_aarch64
  cp32-abi3-linux_aarch64
  py38-none-musllinux_1_2_aarch64
  py38-none-musllinux_1_1_aarch64
  py38-none-musllinux_1_0_aarch64
  py38-none-linux_aarch64
  py3-none-musllinux_1_2_aarch64
  py3-none-musllinux_1_1_aarch64
  py3-none-musllinux_1_0_aarch64
  py3-none-linux_aarch64
  py37-none-musllinux_1_2_aarch64
  py37-none-musllinux_1_1_aarch64
  py37-none-musllinux_1_0_aarch64
  py37-none-linux_aarch64
  py36-none-musllinux_1_2_aarch64
  py36-none-musllinux_1_1_aarch64
  py36-none-musllinux_1_0_aarch64
  py36-none-linux_aarch64
  py35-none-musllinux_1_2_aarch64
  py35-none-musllinux_1_1_aarch64
  py35-none-musllinux_1_0_aarch64
  py35-none-linux_aarch64
  py34-none-musllinux_1_2_aarch64
  py34-none-musllinux_1_1_aarch64
  py34-none-musllinux_1_0_aarch64
  py34-none-linux_aarch64
  py33-none-musllinux_1_2_aarch64
  py33-none-musllinux_1_1_aarch64
  py33-none-musllinux_1_0_aarch64
  py33-none-linux_aarch64
  py32-none-musllinux_1_2_aarch64
  py32-none-musllinux_1_1_aarch64
  py32-none-musllinux_1_0_aarch64
  py32-none-linux_aarch64
  py31-none-musllinux_1_2_aarch64
  py31-none-musllinux_1_1_aarch64
  py31-none-musllinux_1_0_aarch64
  py31-none-linux_aarch64
  py30-none-musllinux_1_2_aarch64
  py30-none-musllinux_1_1_aarch64
  py30-none-musllinux_1_0_aarch64
  py30-none-linux_aarch64
  cp38-none-any
  py38-none-any
  py3-none-any
  py37-none-any
  py36-none-any
  py35-none-any
  py34-none-any
  py33-none-any
  py32-none-any
  py31-none-any
  py30-none-any

Here we see the words Compatible tags. These are the tags that the current Python version can adapt to, that is, they can match the following file names.
It is found that there is no suffix for our existing installation package, try to modify the suffix of the installation package.
It seems that this suffix is ​​more suitable for cp38-abi3-linux_aarch64.

cp torch-1.10.2-cp38-cp38-manylinux2014_aarch64.whl torch-1.10.2-cp38-abi3-linux_aarch64.whl

Try installing again

pip install torch-1.10.2-cp38-abi3-linux_aarch64.whl

Display the following information

pip install torch-1.10.2-cp38-abi3-linux_aarch64.whl

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Processing ./torch-1.10.2-cp38-abi3-linux_aarch64.whl
Collecting typing-extensions
  Downloading http://mirrors.aliyun.com/pypi/packages/31/25/5abcd82372d3d4a3932e1fa8c3dbf9efac10cc7c0d16e78467460571b404/typing_extensions-4.5.0-py3-none-any.whl (27 kB)
Installing collected packages: typing-extensions, torch
Successfully installed torch-1.10.2 typing-extensions-4.5.0

Successful installation! scatter flowers
Successful installation

Conclusion

Although it is a pytorch installation method in the arm environment, it can actually be applied to the installation of most python libraries.

References

[1] How to check the Linux system version?
[2] Problem promotion post: Installation of pytorch, torchvision, torchaudio under arm64 and the version correspondence between them
[3] Problem ending post: [2021 new tutorial] Solving is not a supported wheel on this platform - Solving pip has no attribute pep425tags-Solve the problem that old online tutorials are not applicable

Other references:
[4] Torch, torchvision, Python version correspondence and installation of GPU or CPU version of pytorch
[5] Installing pytorch under arm
[6] Installing python's pytorch library under Arm/Linux

Guess you like

Origin blog.csdn.net/aiaidexiaji/article/details/130056643