A Flower (flwr) extension for serverless federated learning.
Technical report (arXiv): Serverless Federated Learning with flwr-serverless.
Install
pip install flwr-serverless
or
pip install git+https://github.com/kungfuai/flwr_serverless.git
Usage for tensorflow
- Step 1: Create federated
Nodes that use a shared folder to exchange model weights and use a federated strategy (flwr.server.strategy.Strategy) to control how the weights are aggregated. - Step 2: Create and configure a callback
FlwrFederatedCallbackand use it in thekeras.Model.fit().
# Create a FL Node that has a strategy and a shared folder.
from flwr.server.strategy import FedAvg # This is a flwr federated strategy.
from flwr_serverless import AsyncFederatedNode, S3Folder
from flwr_serverless.keras import FlwrFederatedCallback
strategy = FedAvg()
shared_folder = S3Folder(directory="mybucket/experiment1")
node = AsyncFederatedNode(strategy=strategy, shared_folder=shared_folder)
# Create a keras Callback with the FL node.
num_examples_per_epoch = steps_per_epoch * batch_size # number of examples used in each epoch
callback = FlwrFederatedCallback(
node,
num_examples_per_epoch=num_examples_per_epoch,
save_model_before_aggregation=False,
save_model_after_aggregation=False,
)
# Join the federated learning, by fitting the model with the federated callback.
model = keras.Model(...)
model.compile(...)
model.fit(dataset, callbacks=[callback])
flwr_serverless uses flwr_serverless.SharedFolder to save model weights and metrics. The logic folder can be backed by a storage backend like S3.
The asynchronous FL node does not wait to sync with other nodes. It takes the latest model weights from other nodes and performs the aggregation according to the specified strategy.
Running experiments
To make it easier to experimemt with different strategies, we provide utility classes like flwr.keras.example.FederatedLearningTestRun. This allows you to configure the dataset partition, strategy and concurrency. Please use this as an example to develop your own experiments.
To reproduce some experiments reported in the paper, run
python -m experiments.experiment_scripts.exp1_mnist
python -m experiments.experiment_scripts.exp2_cifar10
python -m experiments.experiment_scripts.exp3_wikitext
Each of the above experiments run through a grid search over a large hyperparameter space, with repeated trials using different random seeds. Please edit the script to adjust the number of trials and the hyperparameter search space.
Metadata
Release files for flwr-serverless 0.2.10
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 |
|---|---|---|---|---|
| flwr_serverless-0.2.10.tar.gz | 18.3 kB | Without provenance | Details for flwr_serverless-0.2.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flwr_serverless-0.2.10-py3-none-any.whl | Python 3 | none | any | Details for flwr_serverless-0.2.10-py3-none-any.whl |
Total release size: 42.4 kB
Release files / flwr_serverless-0.2.10.tar.gz
| Download URL | flwr_serverless-0.2.10.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
93abe0040be8724197d05b1d43608167bc6443bb4da3152e7e2d9a3a192a9460
|
|
BLAKE2b-256 checksum How to use checksums |
a6f3619fb1d7acfa29bb50fd5d259d3ec32c19e2232a0a27464814247923c842
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / flwr_serverless-0.2.10-py3-none-any.whl
| Download URL | flwr_serverless-0.2.10-py3-none-any.whl |
|---|---|
| Size | 24.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b5eb8b5aa51988f2190cbcc642e24d22783cb2138ff0c7ff57575b5d3cf9e268
|
|
BLAKE2b-256 checksum How to use checksums |
58d9de271b8b8d7ff5a73505290cff48f231022427c5370fa0b87e48d8c84cde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Security for flwr-serverless 0.2.10
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.