Federated Learning Simulator (FLSim) is a flexible, standalone core library that simulates FL settings with a minimal, easy-to-use API. FLSim is domain-agnostic and accommodates many use cases such as vision and text.
Project description
Federated Learning Simulator (FLSim)
Federated Learning Simulator (FLSim) is a flexible, standalone library written in PyTorch that simulates FL settings with a minimal, easy-to-use API. FLSim is domain-agnostic and accommodates many use cases such as computer vision and natural text. Currently FLSim supports cross-device FL, where millions of clients' devices (e.g. phones) train a model collaboratively together.
FLSim is scalable and fast. It supports differential privacy (DP), secure aggregation (secAgg), and a variety of compression techniques.
In FL, a model is trained collaboratively by multiple clients that each have their own local data, and a central server moderates training, e.g. by aggregating model updates from multiple clients.
In FLSim, developers only need to define a dataset, model, and metrics reporter. All other aspects of FL training are handled internally by the FLSim core library.
FLSim
Library Structure
FLSim core components follow the same semantic as FedAvg. The server comprises three main features: selector, aggregator, and optimizer at a high level. The selector selects clients for training, and the aggregator aggregates client updates until a round is complete. Then, the optimizer optimizes the server model based on the aggregated gradients. The server communicates with the clients via the channel. The channel then compresses the message between the server and the clients. Locally, the client consists of a dataset and a local optimizer. This local optimizer can be SGD, FedProx, or a custom Pytorch optimizer.
Installation
The latest release of FLSim can be installed via pip
:
pip install flsim
You can also install directly from the source for the latest features (along with its quirks and potentially occasional bugs):
git clone https://github.com/facebookresearch/FLSim.git
cd FLSim
pip install -e .
Getting started
To implement a central training loop in the FL setting using FLSim, a developer simply performs the following steps:
- Build their own data pipeline to assign individual rows of training data to client devices (to simulate data distributed across client devices)
- Create a corresponding
torch.nn.Module
model and wrap it in an FL model. - Define a custom metrics reporter that computes and collects metrics of interest (e.g. accuracy) throughout training.
- Set the desired hyperparameters in a config.
Usage Example
Tutorials
- Image classification with CIFAR-10
- Sentiment classification with LEAF's Sent140
- Compression for communication efficiency
- Adding a custom communication channel
To see the details, please refer to the tutorials that we have prepared.
Examples
We have prepared the runnable examples for 2 of the tutorials above:
Contributing
See the CONTRIBUTING for how to contribute to this library.
License
This code is released under Apache 2.0, as found in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flsim-0.1.0.tar.gz
.
File metadata
- Download URL: flsim-0.1.0.tar.gz
- Upload date:
- Size: 231.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52d5c0af0f9a32bea4704cde82e6980ecb0e8a974bf9b2d97d9683c1bbb0edd0 |
|
MD5 | ddead4af0f59b6188bd261220ac3bb06 |
|
BLAKE2b-256 | 2e33542eda6534d3e943a8bd62ba7db746a8d6ac55d3cae035d5b6ef9fe85991 |
File details
Details for the file flsim-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: flsim-0.1.0-py3-none-any.whl
- Upload date:
- Size: 340.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2afa843889b80582f2d48eaf834633bc5d36ac5ce72620a904d9eaf508b19176 |
|
MD5 | 5cd7020a58cec7192c8fc1053a1b57af |
|
BLAKE2b-256 | c0490c904a24b7d240c061d06b6bc122770468955b63fcaf7b31419b699135ca |