A simple and easy-to-extend asynchronous federated learning (AFL) simulation framework.
The asynchronous simulation is based on a prior queue.
- Insert training-finished clients into the prior queue based on supposed finished time
- Pop the first item in the prior queue
- Update the simulated wall-clock time based on the item
We also provide simulation of synchronous federated learning like FedAvg.
- Key directories overview: see
docs/PROJECT_STRUCTURE.md - If you use the Streamlit GUI (
gui/front.py), you can open the 项目结构 page to browse the key folders interactively.
- Download this project
git clone https://github.com/boyi-liu/Asynchronous-Federated-Learning-Simulation.git
- Install required packages
- Partition datasets
cd dataset
python generate_cifar10.py noniid balance dir
- Run evaluation
cd script
bash run.sh {your_suffix}
Create a new {your_algorithm}.py file inside trainer.alg
If you are working on a synchronous FL algorithm, just extend the Client and Server class in trainer.base
from trainer.base import BaseServer, BaseClient
class Client(BaseClient):
def __init__(self, id, args, dataset):
super().__init__(id, args, dataset)
class Server(BaseServer):
def __init__(self, id, args, dataset, clients):
super().__init__(id, args, dataset, clients)
Otherwise, you may extend the Client and Server in trainer.asyncbase
from trainer.asyncbase import AsyncBaseServer, AsyncBaseClient
class Client(AsyncBaseClient):
def __init__(self, id, args, dataset):
super().__init__(id, args, dataset)
class Server(AsyncBaseServer):
def __init__(self, id, args, dataset, clients):
super().__init__(id, args, dataset, clients)
For algorithm-specific hyperparameters,
it is recommended to add a add_args() function inside your file
def add_args(parser):
parser.add_argument('--{your_param}', type=int, default=1)
return parser.parse_args()
And all general args could be found in utils/options.py
We claim that each algorithm should overwrite the function run(),
because it stands for the main workflow of your algorithm.
You can overwrite or add any function as you want then.
The data partitioning module is adopted from PFLlib.