欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python arm64_PyTorch-aarch64

发布时间:2025/4/16 python 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python arm64_PyTorch-aarch64 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

PyTorch源码编译步骤:

1、源码编译环境:

操作系统:debian 9.12

交换空间:1G

Python版本:3.5

硬件:

CPU:RK3399(aarch64)

内存:4G

2、下载依赖包:

下载pytorch及其依赖包时,默认从github上下载,如果网络不好、容易断开时,可在gitee上找到对应包克隆链接,然后修改对应配置文件,进行下载。需要细致耐心。

3、编译主要参数:

设置最大作业数:

export MAX_JOBS=3

pytorch,无cude、无MKL:

export NO_CUDA=1 export NO_DISTRIBUTED=1 export NO_MKLDNN=1 export NO_NNPACK=1 export NO_QNNPACK=1

torchvision源码编译步骤:

1、安装环境依赖:

sudo apt-get install libjpeg-dev zlib1g-dev

2、下载源代码:

git clone -b v0.5.0 https://github.com/pytorch/vision.git torchvision

或者:git clone -b v0.5.0 https://gitee.com/mirrors/vision.git torchvision

3、源码编译:

cd torchvision

python3 setup.py build

编译过程中应该出现错误,据说是python3.5的bug。参考链接:https://blog.csdn.net/Jessie_show/article/details/108280251

错误详情:

File /usr/lib/python3.5/weakref.py, line 117, in remove

TypeError: NoneType object is not callable

解决方式,修改weakref.py文件:

找到“def remove(wr, selfref=ref(self)):”这一行

并将之修改为:“def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):”

找到“_remove_dead_weakref(d, wr.key)”这一行

并将之修改为:“_atomic_removal(d, wr.key)”

4、生成wheel:

python3 setup.py bdist_wheel

此时dist/目录下得到whl包:torchvision-0.5.0a0+85b8fbf-cp35-cp35m-linux_aarch64.whl

其他:

1、PyTorch .whl for generic aarch64 platforms

Just download the file or clone the repository, and install the wheel using pip.

pip3 install torch-1.1.0a0+472be69-cp36-cp36m-linux_aarch64.whl

2、Rationale

I wanted to run some PyTorch models on my Ultra96 board for eventual use in Xilinx/Deephi's DNNDK platofrm, which allows you to tkae a trained model and speed up inference using the DPU in the programmable logic of the ZU+ device.

3、Build Instructions

In case you you have a differnt version of python, or any other reason you might have to build it yourself, ill describe the steps below.

4、Memory Considerations

The biggest challenge building a large library like this on an embeedde device is the limitaion of RAM (Ultra96 has 2GB). To combat this, you could make some extra swap space, or you could limit jobs the number of jobs used when building. I would recommned making sure you have at least 1GB swap and limiting the jobs to 1, as just using a lot of swap will slow things to a standstill if you dont have lightning fast swap.

I had a spare 2GB USB2 flash drive which would work perfectly, so I used that as my extra swap. Make sure to change the /dev/sda1 to your device, and make sure its not mounted when you start this process.

First, make the swap space sudo mkswap /dev/sda1

edit your fstab to include the new drive. nano /etc/fstab, comment out any lines you see (replace them once you are done) and add /dev/sda1 swap swap at the top of the file.

Turn on the new swap space sudo swapon -p 32767 /dev/sda1

Check it worked using cat /proc/swaps and seeing if your drive is listed.

Finally, set the max number of jobs. I did 1 to be safe, but if you want it to go faster you could try 2.

export MAX_JOBS=1

5、download dependencies and clone PyTorch

Dependencies:

sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools

Clone PyTorch:

git clone --recursive https://github.com/pytorch/pytorch and cd pytorch

Set build options for embeeded machine (no cude, no MKL, etc)

export NO_CUDA=1 export NO_DISTRIBUTED=1 export NO_MKLDNN=1 export NO_NNPACK=1 export NO_QNNPACK=1

and finally, run the build.

python3 setup.py build

Once it completes with no errors, you can run python3 setup.py install to install the files, and if you are reading this in the future with an updated version, you can also run python3 setup.py bdist_wheel to create a whl file for distribution. That command will put the generated .whl file in the newly created dist directory.

Now you can run torch!

cd python3 import torch

总结

以上是生活随笔为你收集整理的python arm64_PyTorch-aarch64的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。