大體流程
1. 重裝系統
先重裝了系統,避免混亂的舊系統所帶來的不必要麻煩。
安裝依賴包
sudo apt-get install python3-pip cmake
pip3 install numpy pyyaml mkl mkl-include setuptools cffi typing
# 各大教程裏面還推薦了安裝其他的一些包,我也不知道有沒有用。
下載Pytorch源碼
# 如果你想安裝歷史版本,可下載對應版本的源碼,或者git checkout
git clone --recursive http://github.com/pytorch/pytorch
cd pytorch
安裝源碼中要求的Python依賴包
sudo pip3 install -r requirements.txt
安裝
# 直接安裝
sudo python3 setup.py install
# 生成whl
python3 setup.py bdist_wheel
附安裝的參考鏈接:
- https://gist.github.com/dusty-nv/ef2b372301c00c0a9d3203e42fd83426
- https://github.com/andrewadare/jetson-tx2-pytorch
- PyTorch for Jetson Nano - NVIDIA Developer Forums
- https://github.com/dusty-nv/jetson-reinforcement/blob/master/CMakePreBuild.sh
可能遇到的問題:
- 內存不足
# 顯示的錯誤信息沒保存下來
# 好像是什麼內部錯誤
解決辦法:添加交換分區
附添加分區的參考鏈接:
https://help.ubuntu.com/community/SwapFaq#How_do_I_add_or_modify_a_swap_partition.3F
https://www.jetsonhacks.com/2016/12/21/jetson-tx1-swap-file-and-development-preparation/
- NCCL編譯報錯
Makefile:68: recipe for target '/home/ubuntu/software/pytorch/build/nccl/obj/collectives/device/devlink.o' failed
make[5]: *** [/home/ubuntu/software/pytorch/build/nccl/obj/collectives/device/devlink.o] Error 255
Makefile:44: recipe for target '/home/ubuntu/software/pytorch/build/nccl/obj/collectives/device/colldevice.a' failed
make[4]: *** [/home/ubuntu/software/pytorch/build/nccl/obj/collectives/device/colldevice.a] Error 2
Makefile:25: recipe for target 'src.build' failed
make[3]: *** [src.build] Error 2
CMakeFiles/nccl_external.dir/build.make:110: recipe for target 'nccl_external-prefix/src/nccl_external-stamp/nccl_external-build' failed
make[2]: *** [nccl_external-prefix/src/nccl_external-stamp/nccl_external-build] Error 2
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/nccl_external.dir/all' failed
make[1]: *** [CMakeFiles/nccl_external.dir/all] Error 2
由於TX1默認情況並沒有安裝NCCL,因此爲了避免報錯,可對CMakeLists.txt
和setup.py
進行如下更改:
# append to setup.py
USE_NCCL = False
# USE_DISTRIBUTED = False
# change the option in the CMakeLists.txt
option(USE_NCCL "Use NCCL" OFF)
修改參數之後,建議clean
一下!!!