FederatedScope
An easy-to-use federated learning platform
Install / Use
/learn @alibaba/FederatedScopeREADME
FederatedScope is a comprehensive federated learning platform that provides convenient usage and flexible customization for various federated learning tasks in both academia and industry. Based on an event-driven architecture, FederatedScope integrates rich collections of functionalities to satisfy the burgeoning demands from federated learning, and aims to build up an easy-to-use platform for promoting learning safely and effectively.
A detailed tutorial is provided on our website: federatedscope.io
You can try FederatedScope via FederatedScope Playground or Google Colab.
| Code Structure | Quick Start | Advanced | Documentation | Publications | Contributing |
News
[05-17-2023] Our paper FS-REAL has been accepted by KDD'2023!
[05-17-2023] Our benchmark paper for FL backdoor attacks Backdoor Attacks Bench has been accepted by KDD'2023!
[05-17-2023] Our paper Communication Efficient and Differentially Private Logistic Regression under the Distributed Setting has been accepted by KDD'2023!
[04-25-2023] Our paper pFedGate has been accepted by ICML'2023!
[04-25-2023] Our benchmark paper for FedHPO FedHPO-Bench has been accepted by ICML'2023!
[04-03-2023] We release FederatedScope v0.3.0!- [02-10-2022] Our paper elaborating on FederatedScope is accepted by VLDB'23!
- [10-05-2022] Our benchmark paper for personalized FL, pFL-Bench has been accepted by NeurIPS'22, Dataset and Benchmark Track!
- [08-18-2022] Our KDD 2022 paper on federated graph learning receives the KDD Best Paper Award for ADS track!
- [07-30-2022] We release FederatedScope v0.2.0!
- [06-17-2022] We release pFL-Bench, a comprehensive benchmark for personalized Federated Learning (pFL), containing 10+ datasets and 20+ baselines. [code, pdf]
- [06-17-2022] We release FedHPO-Bench, a benchmark suite for studying federated hyperparameter optimization. [code, pdf]
- [06-17-2022] We release B-FHTL, a benchmark suit for studying federated hetero-task learning. [code, pdf]
- [06-13-2022] Our project was receiving an attack, which has been resolved. More details.
- [05-25-2022] Our paper FederatedScope-GNN has been accepted by KDD'2022!
- [05-06-2022] We release FederatedScope v0.1.0!
Code Structure
FederatedScope
├── federatedscope
│ ├── core
│ | ├── workers # Behaviors of participants (i.e., server and clients)
│ | ├── trainers # Details of local training
│ | ├── aggregators # Details of federated aggregation
│ | ├── configs # Customizable configurations
│ | ├── monitors # The monitor module for logging and demonstrating
│ | ├── communication.py # Implementation of communication among participants
│ | ├── fed_runner.py # The runner for building and running an FL course
│ | ├── ... ..
│ ├── cv # Federated learning in CV
│ ├── nlp # Federated learning in NLP
│ ├── gfl # Graph federated learning
│ ├── autotune # Auto-tunning for federated learning
│ ├── vertical_fl # Vertical federated learning
│ ├── contrib
│ ├── main.py
│ ├── ... ...
├── scripts # Scripts for reproducing existing algorithms
├── benchmark # We release several benchmarks for convenient and fair comparisons
├── doc # For automatic documentation
├── environment # Installation requirements and provided docker files
├── materials # Materials of related topics (e.g., paper lists)
│ ├── notebook
│ ├── paper_list
│ ├── tutorial
│ ├── ... ...
├── tests # Unittest modules for continuous integration
├── LICENSE
└── setup.py
Quick Start
We provide an end-to-end example for users to start running a standard FL course with FederatedScope.
Step 1. Installation
First of all, users need to clone the source code and install the required packages (we suggest python version >= 3.9). You can choose between the following two installation methods (via docker or conda) to install FederatedScope.
git clone https://github.com/alibaba/FederatedScope.git
cd FederatedScope
Use Docker
You can build docker image and run with docker env (cuda 11 and torch 1.10):
docker build -f environment/docker_files/federatedscope-torch1.10.Dockerfile -t alibaba/federatedscope:base-env-torch1.10 .
docker run --gpus device=all --rm -it --name "fedscope" -w $(pwd) alibaba/federatedscope:base-env-torch1.10 /bin/bash
If you need to run with down-stream tasks such as graph FL, change the requirement/docker file name into another one when executing the above commands:
# environment/requirements-torch1.10.txt ->
environment/requirements-torch1.10-application.txt
# environment/docker_files/federatedscope-torch1.10.Dockerfile ->
environment/docker_files/federatedscope-torch1.10-application.Dockerfile
Note: You can choose to use cuda 10 and torch 1.8 via changing torch1.10 to torch1.8.
The docker images are based on the nvidia-docker. Please pre-install the NVIDIA drivers and nvidia-docker2 in the host machine. See more details here.
Use Conda
We recommend using a new virtual environment to install FederatedScope:
conda create -n fs python=3.9
conda activate fs
If your backend is torch, please install torch in advance (torch-get-started). For example, if your cuda version is 11.3 please execute the following command:
conda install -y pytorch=1.10.1 torchvision=0.11.2 torchaudio=0.10.1 torchtext=0.11.1 cudatoolkit=11.3 -c pytorch -c conda-forge
For users with Apple M1 chips:
conda install pytorch torchvision torchaudio -c pytorch
# Downgrade torchvision to avoid segmentation fault
python -m pip install torchvision==0.11.3
Finally, after the backend is installed, you can install FederatedScope from source:
From source
# Editable mode
pip install -e .
# Or (developers for dev mode)
pip install -e .[dev]
pre-commit install
Now, you have successfully installed the minimal version of FederatedScope. (Optinal) For application version including graph, nlp and speech, run:
bash environment/extra_dependencies_torch1.10-application.sh
Step 2. Prepare datasets
To run an FL task, users should prepare a dataset.
The DataZoo provided in FederatedScope can help to automatically download and preprocess widely-used public datasets for various FL applications, including CV, NLP, graph learning, recommendation, etc. Users can directly specify cfg.data.type = DATASET_NAMEin the configuration. For example,
cfg.data.type = 'femnist'
To use customized datasets, you need to prepare the datasets following a certain format and register it. Please refer to Customized Datasets for more details.
Step 3. Prepare models
Then, users should specify the model architecture that will be trained in the FL course.
FederatedScope provides a ModelZoo that contains the implementation of widely adopted model architectures for various FL applications. Users can set up cfg.model.type = MODEL_NAME to apply a specific model architecture in FL tasks. For example,
cfg.model.type = 'convnet2'
FederatedScope allows users to use custo
