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.Modulemodel 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.
Metadata
Release files for flsim 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flsim-0.1.0.tar.gz | 231.8 kB | Without provenance | Details for flsim-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flsim-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for flsim-0.1.0-py3-none-any.whl |
Total release size: 572.2 kB
Release files / flsim-0.1.0.tar.gz
| Download URL | flsim-0.1.0.tar.gz |
|---|---|
| Size | 231.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52d5c0af0f9a32bea4704cde82e6980ecb0e8a974bf9b2d97d9683c1bbb0edd0
|
|
BLAKE2b-256 checksum How to use checksums |
2e33542eda6534d3e943a8bd62ba7db746a8d6ac55d3cae035d5b6ef9fe85991
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / flsim-0.1.0-py3-none-any.whl
| Download URL | flsim-0.1.0-py3-none-any.whl |
|---|---|
| Size | 340.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2afa843889b80582f2d48eaf834633bc5d36ac5ce72620a904d9eaf508b19176
|
|
BLAKE2b-256 checksum How to use checksums |
c0490c904a24b7d240c061d06b6bc122770468955b63fcaf7b31419b699135ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for flsim 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.