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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java公网对讲_【对讲机的那点事】选择
- 下一篇: python open ascii co