aayushdewangan11 / Blockchain_Enabled_Federated_learning

A Proof-of-Stake (PoS) blockchain-based Federated Learning framework with a validation scheme robust against the distorted local model updates. This repo hosts an simulated implementation for described model written in Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blockchain Enabled Federated learning

Introduction

A Proof-of-Stake (PoS) blockchain-based Federated Learning framework with a validation scheme robust against the distorted local model updates. This repo hosts an simulated implementation for VBFL written in Python.

Instructions to Run

Suggested Environments Setup

python 3.7.6
pytorch 1.4.0

(1) Clone the repo

$ git clone https://github.com/aayushdewangan11/Bloackchain_Enabled_Federated-learning.git

(2) Create a new conda environment with python 3.7.6

$ conda create -n VBFL python=3.7.6
$ conda activate VBFL

(3) Head to https://pytorch.org/ for instructions to install PyTorch

$ # If using CUDA, first check its version
$ nvidia-smi
$ # Install the correct CUDA version for PyTorch. 
$ # The code was tested on CUDA 10.1 and PyTorch 1.4.0
$ conda install pytorch=1.4.0 torchvision torchaudio cudatoolkit=10.1 -c pytorch

(4) Install pycryptodome 3.9.9 and matplotlib

$ conda install pycryptodome=3.9.9
$ conda install matplotlib

Run VBFL Simulation

Sample running command

$ python main.py -nd 20 -max_ncomm 100 -ha 12,5,3 -aio 1 -pow 0 -ko 6 -nm 3 -vh 0.08 -cs 0 -B 10 -mn mnist_cnn -iid 0 -lr 0.01 -dtx 1

VBFL arguments

(1) -nd 20: 20 devices.

(2) -max_ncomm 100: maximum 100 communication rounds.

(3) -ha 12,5,3: role assignment hard-assigned to 12 workers, 5 validators and 3 miners for each communication round. A * in -ha means the corresponding number of roles are not limited. e.g., -ha *,5,* means at least 5 validators would be assigned in each communication round, and the rest of the devices are dynamically and randomly assigned to any role. -ha *,*,* means the role-assigning in each communication round is completely dynamic and random.

(4) -aio 1: aio means "all in one network", namely, every device in the emulation has every other device in its peer list. This is to simulate that VBFL runs on a permissioned blockchain. If using -aio 0, the emulation will let a device (registrant) randomly register with another device (register) and copy the register's peer list.

(5) -pow 0: the argument of -pow specifies the proof-of-work difficulty. When using 0, VBFL runs with VBFL-PoS consensus to select the winning miner.

(6) -ko 6: this argument means a device is blacklisted after it is identified as malicious after 6 consecutive rounds as a worker.

(7) -nm 3: exactly 3 devices will be malicious nodes.

(8) -vh 0.08: validator-threshold is set to 0.08 for all communication rounds. This value may be adaptively learned by validators in a future version.

(9) -cs 0: as the emulation does not include mechanisms to disturb digital signature of the transactions, this argument turns off signature checking to speed up the execution.

Federated Learning arguments (inherited from https://github.com/WHDY/FedAvg)

(10) -B 10: batch size set to 10.

(11) -mn mnist_cnn: use mnist_cnn model. Another choice is mnist_2nn, or you may put your own network inside of Models.py and specify it.

(12) -iid 0: shard the training data set in Non-IID way.

(13) -lr 0.01: learning rate set to 0.01.

Other arguments

(14) -dtx 1: see Known Issue.

Please see main.py for other argument options.

Please raise other issues and concerns you found. Thank you!

image

About

A Proof-of-Stake (PoS) blockchain-based Federated Learning framework with a validation scheme robust against the distorted local model updates. This repo hosts an simulated implementation for described model written in Python.


Languages

Language:Python 100.0%