Secure aggregation with Flower (the SecAgg+ protocol) π§ͺ#
π§ͺ = This example covers experimental features that might change in future versions of Flower Please consult the regular PyTorch code examples (quickstart, advanced) to learn how to use Flower with PyTorch.
The following steps describe how to use Secure Aggregation in flower, with ClientApp
using secaggplus_mod
and ServerApp
using SecAggPlusWorkflow
.
Preconditions#
Letβs assume the following project structure:
$ tree .
.
βββ client.py # Client application using `secaggplus_mod`
βββ server.py # Server application using `SecAggPlusWorkflow`
βββ workflow_with_log.py # Augmented `SecAggPlusWorkflow`
βββ run.sh # Quick start script
βββ pyproject.toml # Project dependencies (poetry)
βββ requirements.txt # Project dependencies (pip)
Installing dependencies#
Project dependencies (such as and flwr
) are defined in pyproject.toml
. We recommend Poetry to install those dependencies and manage your virtual environment (Poetry installation), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences.
Poetry#
poetry install
poetry shell
Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command:
poetry run python3 -c "import flwr"
pip#
Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt.
pip install -r requirements.txt
If you donβt see any errors youβre good to go!
Run the example with one command (recommended)#
./run.sh
Run the example with the simulation engine#
flower-simulation --server-app server:app --client-app client:app --num-supernodes 5
Alternatively, run the example (in 7 terminal windows)#
Start the Flower Superlink in one terminal window:
flower-superlink --insecure
Start 5 Flower ClientApp
in 5 separate terminal windows:
flower-client-app client:app --insecure
Start the Flower ServerApp
:
flower-server-app server:app --insecure --verbose
Amend the example for practical usage#
For real-world applications, modify the workflow
in server.py
as follows:
workflow = fl.server.workflow.DefaultWorkflow(
fit_workflow=SecAggPlusWorkflow(
num_shares=<number of shares>,
reconstruction_threshold=<reconstruction threshold>,
)
)