- Install PySyft
- Testing the environment
The PySyft framework enables practitioners and stakeholders in the AI domain to leverage the potential of Federated Learning. This method is part of privacy preserving machine learning and allows data scientists to work with remote data, without revealing it. This approach is especially interesting in the context of high demand for big data to train AI models on the one side and data privacy regulations on the other side. Some examples of such regulations are the General Data Protection Regulation in the European Union , the California Consumer Privacy Act in the USA  or the Personal Data Protection (Amendment) Act in Singapore .
Federated Learning systems can either be tested with virtual nodes on the same machine or with physically separated nodes. Running experiments with the data scientist and data owner being on separate devices is important to account for possible hardware constraints. A Raspberry Pi can be a good choice for simulating the data owner’s device. It is a Single-Board-Computer (SBC), which can handle data acquisition and control, data processing and storage, connectivity and power management. The CPU architecture is ARM based and some Python packages are not instantly available over pip install <package_name> for example. This is especially the case for older PySyft versions like v0.2.9 and v0.3.0. To reduce complexity, we focus therefore on the latest version of syft, at the time of writing this post. At the end you'll find a dockerfile capturing all mentioned steps. The image is also hosted on Docker Hub with the image name rene36/pysyft050rc1.
The numbers you will see in brackets give the execution time of a specific command. They should help giving an order of magnitude about the required installation time for syft. Our setup for installing PySyft 0.5.0rc1 is as follows:
- Raspberry Pi 4B with 8 GB of memory
- 32 GB SSD card (erased)
- Image (Ubuntu Server 20.04 LTS 64bit) flashed with Raspberry Pi Imager v1.3.
- Using a fresh Ubuntu 20.04 LTS 64bit installation.
- Connecting to the Raspberry Pi via SSH, which is connected with a LAN.
Some characteristics of the system are:
|lsb_release -a||Distributor ID: Ubuntu Description: Ubuntu 20.10 Release: 20.10 Codename: groovy|
|uname -a||Linux raspi28 5.8.0-1015-raspi #18-Ubuntu SMP PREEMPT Fri Feb 5 06:09:58 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux|
|gcc --version||gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0|
|python --version||Python 3.8.5|
2.1 PyTorch v1.8.0 (1 min)
Based on the GitHub repository of PySyft the latest supported torch version is 1.8. Note that numpy is already pre-installed on the system. If this is not the case, the installation cantake much longer.
pip3 install torch==1.8.0 # Successfully installed torch-1.8.0 typing-extensions-22.214.171.124
2.2 Install torchvision v0.9.0 (11 min)
The requirements.torch.txt states a torchvision version of >=0.5,<=0.9. Version 0.9.1 is readily available via pip3 install torchvision==0.9.1, however syft complains about that down the road. Feel free to adjust the version in the requirements.torch.txt to check if any issues come up with a slightly more up-to-date torchvision version. Otherwise build the officially required version from source.
cd ~ && git clone https://github.com/pytorch/vision.git --branch=v0.9.0 && cd vision # (1 min) sudo -E python3 setup.py install # (10 min) # Finished processing dependencies for torchvision==0.9.0a0+01dfa8e
2.3 Install aiortc (7 min)
After installing these two major requirements (torch and torchvision) for syft, we can go the last step. This is split into two steps. First we build the aiortc package from source and then install syft with pip3. Starting withthe latter throws an error with respect to aiortc.
The aiortc package has some dependencies. Let’s install them and check if we fulfill its requirements.
sudo apt install -y libavdevice-dev libavfilter-dev libopus-dev libvpx-dev pkg-config # (2 min) openssl version # should be >= v1.0.2, I have 1.1.1f ffmpeg -version sudo apt install -y ffmpeg # installed version 4.3.1-4ubuntu1 for me. sudo apt install -y libvpx-dev libopus-dev libffi-dev # Installed libvpx-dev:v1.8.2-1build1, libopus-dev:v1.3.1-0.1, libffi-dev: 3.4~20200819gead65ca871-0ubuntu3.
Finally, lets get the source code of aiortc from GitHub and build it from source.
cd ~ && git clone https://github.com/aiortc/aiortc.git && cd aiortc sudo -E python3 setup.py install # (5 min) # This installed aiortc==1.2.0
2.4 Install syft 0.5.0rc1 (6 min)
Now we are ready to install syft version 0.5.0rc1 with
pip3 install syft==0.5.0rc1 # (6 min) # Successfully installed PyNaCl-1.4.0 Werkzeug-1.0.1 dataclasses-0.6 dpcontracts-0.6.0 flask-1.1.2 # forbiddenfruit-0.1.4 itsdangerous-1.1.0 loguru-0.5.3 nest-asyncio-1.5.1 packaging-20.9 protobuf-3.15.8 # pyparsing-2.4.7 sqlitedict-1.7.0 syft-0.5.0rc1 syft-proto-0.5.3 typeguard-2.12.0 websocket-client-0.58.0
Testing the environment
Let’s check if the installation worked as expected. Open Python in a console, import the three major packages and check the exact version of them.
python3 import syft import torch import torchvision # Check package verions print(syft.__version__) # two under scores print(torch.__version__) print(torchvision.__version__)
The docker image is either available over Docker Hub (rene36/pysyft050rc1) or you adjust and build it yourself. Feel free to use the below dockerfile as a starting point.
FROM ubuntu:20.04 RUN apt-get update && \ apt-get upgrade --yes ENV DEBIAN_FRONTEND=noninteractive RUN apt-get install --yes software-properties-common python3 python3-pip && \ apt-get install --yes git && \ apt-get install --yes libavdevice-dev libavfilter-dev libopus-dev libvpx-dev pkg-config ffmpeg && \ apt-get install --yes libvpx-dev libopus-dev libffi-dev # Install torch RUN pip3 install torch==1.8.0 # Build torchvision from source RUN git clone https://github.com/pytorch/vision.git --branch=v0.9.0 WORKDIR /vision RUN python3 setup.py install # Build aiortc from source WORKDIR / RUN git clone https://github.com/aiortc/aiortc.git WORKDIR /aiortc RUN python3 setup.py install # Install syft RUN pip3 install syft==0.5.0rc1 CMD ["/bin/sh"]
 European Union, REGULATION (EU) 2016/679 OF THE EUROPEAN PARLIAMENT AND OF THE COUNCIL of 27 April 2016 on the protection of natural persons with regard to the processing of personal data and on the free movement of such data, and repealing Directive 95/46/EC (General Data Protection Regulation), 2016
 State of California Department of Justice , California Consumer Privacy Act of 2018 [1798.100 – 1798.199.100], 2018
 Personal Data Protection Commission Singapore, Personal Data Protection Act, 2014