Project name: HEFLP (Homomorphic Encryption Federated Learning (FLower) Plugin)
Heflp implements the idea of encrypting the model parameters before uploading and doing the homomorphic aggregation on the server. The aggregated model parameters can be obtained using the same cipher to decrypt the received message on each client. Heflp is based on the Flower FL framework.
Heflp now supports 4 HE schemes:
The
Flashecomponent refers the original repository: Flashe Repo
Flashev2is developed by us based on the original version of Flashe.
MWAvgis an advanced weighted averaging strategy we developed to mitigate the risk of overflowing. You can find the implementation here
CKKSandBFVare realized based on the Pyfhel module
and two ML frameworks:
.
├── data
├── heflp
│ ├── heflp
│ │ ├── app.py # Includes the start_client and start_server function
│ │ ├── info.py # Includes some meta information of Heflp, e.g. supported HEs, Log setting.
│ │ ├── client # Includes Heflp clients
│ │ ├── secureproto # The secure protocol components
│ │ │ ├── common
│ │ │ ├── homoencrypschemes # Homomorphic encryption ciphers
│ │ │ └── quantization # Quantizers
│ │ ├── strategy # Includes Heflp strategies
│ │ ├── training # Convenient tools for ML training
│ │ │ └── runner # The runners for training and testing models
│ │ └── utils # Loggers, Perf evaluation tools, etc
├── materials # Some papers/documents this project refered
├── outputs # Save the output models in this dir
├── scripts # Bash scripts for environment setup
├── src # Examples of how to conduct secure FL using Heflp
└── test # Some jupyter notebooks for practicing, drawing, testing, etc
This section gives the guideline of how to deploy and use this project.
- Python (version >= 3.8)
- Pip
- Python3-venv
- First of all clone this project to local environment:
git clone git@github.com:canarybit/canarybit-heflp.git - Run
maketo create the virtual env and prepare dependencies.
By default in this step all the dependencies (not only Heflp, but also the requirements of the examples in this project (/src)). Please look into the
requirement.txtfor more details and comment those you do not need.
- Activate venv:
source myvenv/bin/activateor runmake helpfor hints. - Run the examples in /src or develop your own programs.
- Exit venv:
deactivate
- First of all clone this project to any Linux device:
git clone git@github.com:canarybit/canarybit-heflp.git - Run command
make pack-serverto extract necessary code and pack it to a tgz file (default name is heflp-server.tgz). - Copy and paste the tgz file to the server and untar it by
tar -xvf heflp-server.tgz, then go into the dirheflp-server. - (Optional) Create virtual env:
python3 -m venv myvenv - (Optional) Activate venv:
source myvenv/bin/activate - Install dependencies:
pip install -r requirements.txt
If failed to install PyfHel, please refer to this tutorial and try it again.
- Develop and run programs.
- Exit venv:
deactivate
- Initialize a specific Heflp strategy defined in
heflp.strategy. the Heflp strategies inherit the Flower strategies. For more details about the parameters, please refer to Flower document - Start the server using
heflp.start_server. Then the server will start listening. Once receiving enough requests (the number of active clients per round is defined in the strategy) from the clients, the FL training will begin automatically.
In this project we give one example of server here.
- In the initialization, user needs to define how they are going to train the model and which HE scheme should be applied.
Modelis the model instance that is going to be trained.Runneris one kind of classes defined in Heflp, which handles the training and testing process.Cipheris the HE cipher for encryption and decryption.Quantizeris used for quantize the model parameters from float numbers to integers since some HE schemes only support integer-type data.
- After configuring the ML training and HE cipher, user should create a Heflp client matching the HE cipher they defined.
- Start the client using
heflp.start_client. If theserver_addressis correct, the client should be able to communicate with the server process automatically.
In this project we gives 2 examples of clients using pytorch: fl-client-mnist.py and fl-client-cifar.py.
