Secure aggregation with Flower (the SecAgg+ protocol) πŸ§ͺ#

View on GitHub

πŸ§ͺ = 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 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>,
    )
)