Updated version of gist.github.com/fgolemo/b973a3fa1aaa67ac61c480ae8440e754 for my personal build.
Baseline configuration:
$ cat /etc/debian_version
10.1
$ uname -a
Linux pi 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux
$ cat /proc/cpuinfo
processor : 0
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 1
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 2
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 3
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
Hardware : BCM2835
Revision : a22082
Serial : 000000000b91277e
Model : Raspberry Pi 3 Model B Rev 1.2
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 59G 4.2G 52G 8% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 6.5M 482M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 52M 201M 21% /boot
tmpfs 98M 0 98M 0% /run/user/1001
$ cat /etc/dphys-swapfile
# ...
CONF_SWAPSIZE=4096 # increased swap size for PyTorch installation
CONF_MAXSWAP=4096 # increased swap size for PyTorch installation
$ free -h
total used free shared buff/cache available
Mem: 975Mi 102Mi 693Mi 6.0Mi 179Mi 816Mi
Swap: 4.0Gi 0B 4.0Gi
sudo apt install libopenblas-dev cython m4 python3-dev cmake python3-yaml libatomic-ops-dev libatlas3-base
For PyTorch 1.3.0:
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
git fetch && git fetch --tags
git checkout v1.3.0
# or
git checkout origin/v1.3.0 -b v1.3.0
Modify CMakeLists.txt
, add -latomic
to CMAKE_CXX_FLAGS
:
# somewhere in CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -latomic")
Compilation steps, set required environment flags and run the setup.py function:
export USE_MKLDNN=0 # disable using MKL-DNN (https://github.com/intel/mkl-dnn)
export USE_CUDA=0 # disable compiling CUDA
export USE_DISTRIBUTED=0 # disable distributed (c10d, gloo, mpi, etc.) build
export USE_FBGEMM=1 # enable using FBGEMM (https://github.com/pytorch/FBGEMM)
export USE_NNPACK=1 # enable compiling with NNPACK
export USE_QNNPACK=1 # enable QNNPACK build (quantized 8-bit operators)
export MAX_JOBS=1 # limit to 1 concurrent compiler job
python3 setup.py build
sudo -E python3 setup.py install
python3
>>> import torch
>>> x = torch.rand(5, 3)
>>> print(x)
My entire PyTorch directory, for successful setup.py installation.
$ sha256sum pytorch_v1.3.0_rpi3B.tar.gz
7a9d85f1620e39e37d5c8f36874002f73bd40e9685e8271ffef389ac6d65940b pytorch_v1.3.0_rpi3B.tar.gz
Hi, this gist is quite out of date as Pytorch is now running version
1.13
. Maybe follow the official docs? https://pytorch.org/tutorials/intermediate/realtime_rpi.html#installing-pytorch-and-opencv