Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(examples) Update secure aggregation example #3833

Merged
merged 46 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7101d3b
Update secure aggregation example
danielnugraha Jul 17, 2024
0d5f436
Update secure aggregation example
danielnugraha Jul 17, 2024
ed3d590
fix bugs
panh99 Jul 19, 2024
3d74f8c
update legacy_context
panh99 Jul 19, 2024
638c267
Merge branch 'fix-legacy-context' into update-sec-agg-example
panh99 Jul 19, 2024
dc1bb3e
update readme
panh99 Jul 19, 2024
8baa15b
Merge branch 'main' into update-sec-agg-example
panh99 Jul 22, 2024
b1db600
use num_server_rounds from the run_config
panh99 Jul 22, 2024
7361250
set log level to DEBUG
panh99 Jul 22, 2024
e39efb4
Merge branch 'main' into update-sec-agg-example
panh99 Jul 22, 2024
604ec32
Merge remote-tracking branch 'origin/main' into update-sec-agg-example
panh99 Jul 22, 2024
9de8ef5
Merge branch 'main' into update-sec-agg-example
panh99 Jul 24, 2024
ce12fd9
Merge branch 'main' into update-sec-agg-example
panh99 Jul 24, 2024
22efc92
Add note
danielnugraha Jul 26, 2024
3912547
Merge branch 'main' into update-sec-agg-example
panh99 Jul 31, 2024
0afa73b
Merge branch 'main' into update-sec-agg-example
danielnugraha Aug 5, 2024
09a10ab
Merge branch 'main' into update-sec-agg-example
panh99 Aug 6, 2024
ed24cb1
use real datasets/models for the SA example
panh99 Aug 6, 2024
fd3ed8b
update metadata in README.md
panh99 Aug 6, 2024
8a31a9a
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
b09bb0f
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
c90ddfb
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
79e5fdd
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
1629725
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
80a97a9
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
ec30523
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
e90d6eb
Update examples/flower-secure-aggregation/secaggexample/server_app.py
panh99 Aug 7, 2024
3efad28
Update examples/flower-secure-aggregation/secaggexample/workflow_with…
panh99 Aug 7, 2024
061d27c
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
2e4a239
Update examples/flower-secure-aggregation/README.md
panh99 Aug 7, 2024
abdc144
Update examples/flower-secure-aggregation/pyproject.toml
panh99 Aug 7, 2024
92b710d
Update examples/flower-secure-aggregation/pyproject.toml
panh99 Aug 7, 2024
3068378
Update examples/flower-secure-aggregation/secaggexample/server_app.py
panh99 Aug 7, 2024
292723a
Update examples/flower-secure-aggregation/secaggexample/client_app.py
panh99 Aug 7, 2024
636aa6f
Update examples/flower-secure-aggregation/secaggexample/task.py
panh99 Aug 7, 2024
73cadec
Update examples/flower-secure-aggregation/secaggexample/__init__.py
panh99 Aug 7, 2024
d6f200a
move init params
panh99 Aug 7, 2024
d6ece3f
make is_demo a run config
panh99 Aug 7, 2024
0df1b48
Merge branch 'main' into update-sec-agg-example
panh99 Aug 7, 2024
30bd275
format README.md
panh99 Aug 7, 2024
e0d98e1
Update examples/flower-secure-aggregation/secaggexample/task.py
panh99 Aug 7, 2024
4ccd30b
update based on comments
panh99 Aug 7, 2024
341c681
minor updates
jafermarq Aug 7, 2024
c30cf4d
updating logging and readme
jafermarq Aug 7, 2024
e356f44
update top part of readme
jafermarq Aug 7, 2024
be9d0cb
format
jafermarq Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions examples/app-secure-aggregation/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions examples/app-secure-aggregation/client.py

This file was deleted.

14 changes: 0 additions & 14 deletions examples/app-secure-aggregation/pyproject.toml

This file was deleted.

1 change: 0 additions & 1 deletion examples/app-secure-aggregation/requirements.txt

This file was deleted.

34 changes: 0 additions & 34 deletions examples/app-secure-aggregation/run.sh

This file was deleted.

45 changes: 0 additions & 45 deletions examples/app-secure-aggregation/server.py

This file was deleted.

72 changes: 72 additions & 0 deletions examples/flower-secure-aggregation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
tags: [advanced, secure_aggregation, privacy]
dataset: [CIFAR-10]
framework: [torch, torchvision]
---

# Secure aggregation with Flower (the SecAgg+ protocol)

The following steps describe how to use Flower's built-in Secure Aggregation components. This example demonstrates how to apply `SecAgg+` to the same federated learning workload as in the [quickstart-pytorch](https:/adap/flower/tree/main/examples/quickstart-pytorch) example. The `ServerApp` uses the [`SecAggPlusWorkflow`](https://flower.ai/docs/framework/ref-api/flwr.server.workflow.SecAggPlusWorkflow.html#secaggplusworkflow) while `ClientApp` uses the [`secaggplus_mod`](https://flower.ai/docs/framework/ref-api/flwr.client.mod.secaggplus_mod.html#flwr.client.mod.secaggplus_mod). To introduce the various steps involved in `SecAgg+`, this example introduces as a sub-class of `SecAggPlusWorkflow` the `SecAggPlusWorkflowWithLogs`. It is enabled by default, but you can disable (see later in this readme).

## Set up the project

### Clone the project

Start by cloning the example project:

```shell
git clone --depth=1 https:/adap/flower.git _tmp \
&& mv _tmp/examples/flower-secure-aggregation . \
&& rm -rf _tmp && cd flower-secure-aggregation
```

This will create a new directory called `flower-secure-aggregation` containing the
following files:

```shell
flower-secure-aggregation
|
├── secaggexample
| ├── __init__.py
| ├── client_app.py # Defines your ClientApp
| ├── server_app.py # Defines your ServerApp
| ├── task.py # Defines your model, training and data loading
| └── workflow_with_log.py # Defines a workflow used when `is-demo=true`
├── pyproject.toml # Project metadata like dependencies and configs
└── README.md
```

### Install dependencies and project

Install the dependencies defined in `pyproject.toml` as well as the `secaggexample` package.

```bash
pip install -e .
```

## Run the project

You can run your Flower project in both _simulation_ and _deployment_ mode without making changes to the code. If you are starting with Flower, we recommend you using the _simulation_ mode as it requires fewer components to be launched manually. By default, `flwr run` will make use of the Simulation Engine.

### Run with the Simulation Engine

```bash
flwr run .
```

You can also override some of the settings for your `ClientApp` and `ServerApp` defined in `pyproject.toml`. For example

```bash
flwr run . --run-config num-server-rounds=5,learning-rate=0.25
```

To adapt the example for a practial usage, set `is-demo=false` like shown below. You might want to adjust the `num-shares` and `reconstruction-threshold` settings to suit your requirements. You can override those via `--run-config` as well.

```bash
flwr run . --run-config is-demo=false
```

### Run with the Deployment Engine

> \[!NOTE\]
> An update to this example will show how to run this Flower project with the Deployment Engine and TLS certificates, or with Docker.
46 changes: 46 additions & 0 deletions examples/flower-secure-aggregation/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "secaggexample"
version = "1.0.0"
description = "Secure Aggregation in Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
]

[tool.hatch.build.targets.wheel]
packages = ["."]

[tool.flwr.app]
publisher = "flwrlabs"

[tool.flwr.app.components]
serverapp = "secaggexample.server_app:app"
clientapp = "secaggexample.client_app:app"


[tool.flwr.app.config]
num-server-rounds = 3
fraction-evaluate = 0.5
local-epochs = 1
learning-rate = 0.1
batch-size = 32
# Parameters for the SecAgg+ protocol
num-shares = 3
reconstruction-threshold = 2
max-weight = 9000
timeout = 15.0
# Demo flag
is-demo = true

[tool.flwr.federations]
default = "local-simulation"

[tool.flwr.federations.local-simulation]
options.num-supernodes = 5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""secaggexample: A Flower with SecAgg+ app."""
Loading