Skip to main content

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 FlwrFederatedCallback and use it in the keras.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)

Source distribution for flwr-serverless 0.2.10
File Size Uploaded
flwr_serverless-0.2.10.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flwr-serverless 0.2.10
File Interpreter ABI Platform
flwr_serverless-0.2.10-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.2.10 This release

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page