VeryFL is a simple federated learning framework embedded with blockchain (Etherenum). Federated Learning side uses PyTorch while blockchain-side use Solidity deployed on Ethereum to implement on-chain mechanism. The main propose of VeryFL is to provide the blockchain-based FL algorithm with a real execution environment. However you can use VeryFL for:
- Understanding basic workflow of the federated learning.
- Verifying centralized federated learning algorithm.
- Verifying blockchain-based federated learning algorithm running on real Ethereum environment.
Ethereum Environment
Node.js >= 16.0.0 and npm >= 7.10.0
- Ganache
npm install ganache --global
Python Environment
- Anaconda
-
Python: 3.6 ~ 3.9
-
PyTorch: 1.13
- Brownie
pip install eth-brownie
VeryFL can simulate the federated learning experiment with both centralized/de-centralized paradigm. VeryFL contains many image classification datasets and classic federated learning algorithms.
One of the main propose of VeryFL is to provide experiment environment for blockchain-based federated learning. With the embedded Ethereum network, on-chain mechanism can be implemented in Solidity and can be deployed in VeryFL.
By inject watermark into model through model watermarking technology, VeryFL implement a demo framework which can protect model copyright and execute model transaction by managing watermark on the blockchain.(Detail of this function can refer to our article below [2])
python test.py --benchmark FashionMNIST
#test.py
import argparse
from task import Task
import config.benchmark
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--benchmark', type=str, default="FashionMNIST", help="Running Benchmark(See ./config/benchmark.py)")
args = parser.parse_args()
benchmark = config.benchmark.get_benchmark(args.benchmark)
global_args, train_args, algorithm = benchmark.get_args()
classification_task = Task(global_args=global_args, train_args=train_args, algorithm=algorithm)
classification_task.run()
In ./config/benchmark.py, each Benchmark contains three parts
- global_args: global FL parameters like client number, dataset, model.
- train_args: training parameters like learning rate, weight decay.
- Algorithm: federated learning algorithm (Aggregator, Client, Trainer)
- Client side algoritm need to implement Trainer (./client/trainer)
- Server side algorithm need to implement aggregator (./server/aggregation_alg)
- Implement algorim with Solidity (./chainEnv/contracts)
- Deploy smart contract when network start (./chainfl/interact)
- Wrap the function call with Brownie SDK in class chainProxy (./chainfl/interact)
- Interact with blockchain when training through chainProxy.
[1] [VeryFL Design] VeryFL: A Verify Federated Learning Framework Embedded with Blockchain(Arxiv)
[2] [Model Copyright] Tokenized Model: A Blockchain-Empowered Decentralized Model Ownership Verification Platform(Arxiv)
[3] [Overall Background] Towards Reliable Utilization of AIGC: Blockchain-Empowered Ownership Verification Mechanism(OJCS 2023)
[4] [Using VeryFL] A decentralized federated learning framework via committee mechanism with convergence guarantee(TPDS 2022)