Skip to content

Commit

Permalink
refactor(examples) Update authentication example (#4589)
Browse files Browse the repository at this point in the history
Co-authored-by: jafermarq <[email protected]>
  • Loading branch information
chongshenng and jafermarq authored Nov 27, 2024
1 parent b909a55 commit 54ef313
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
33 changes: 11 additions & 22 deletions examples/flower-authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ framework: [torch, torchvision]
> 🧪 = This example covers experimental features that might change in future versions of Flower.
> Please consult the regular PyTorch examples ([quickstart](https://github.com/adap/flower/tree/main/examples/quickstart-pytorch), [advanced](https://github.com/adap/flower/tree/main/examples/advanced-pytorch)) to learn how to use Flower with PyTorch.
The following steps describe how to start a long-running Flower server (SuperLink+SuperExec) and a long-running Flower clients (SuperNode) with authentication enabled. The task is to train a simple CNN for image classification using PyTorch.
The following steps describe how to start a long-running Flower server (SuperLink) and a long-running Flower clients (SuperNode) with authentication enabled. The task is to train a simple CNN for image classification using PyTorch.

## Project Setup

Expand Down Expand Up @@ -65,13 +65,13 @@ The script also generates a CSV file that includes each of the generated (client
./generate.sh {your_number_of_clients}
```

## Start the long-running Flower server-side (SuperLink+SuperExec)
## Start the long-running Flower server (SuperLink)

Starting long-running Flower server-side components (SuperLink+SuperExec) and enable authentication is very easy; all you need to do is type
Starting long-running Flower server component (SuperLink) and enable authentication is very easy; all you need to do is type
`--auth-list-public-keys` containing file path to the known `client_public_keys.csv`, `--auth-superlink-private-key`
containing file path to the SuperLink's private key `server_credentials`, and `--auth-superlink-public-key` containing file path to the SuperLink's public key `server_credentials.pub`. Notice that you can only enable authentication with a secure TLS connection.

Let's first launche the `SuperLink`:
Let's first launch the `SuperLink`:

```bash
flower-superlink \
Expand All @@ -83,20 +83,9 @@ flower-superlink \
--auth-superlink-public-key keys/server_credentials.pub
```

Then launch the `SuperExec`:
At this point your server-side is idling. Next, let's connect two `SuperNode`s, and then we'll start a run.

```bash
flower-superexec \
--ssl-ca-certfile certificates/ca.crt \
--ssl-certfile certificates/server.pem \
--ssl-keyfile certificates/server.key \
--executor-config "root-certificates='certificates/ca.crt'" \
--executor flwr.superexec.deployment:executor
```

At this point your server-side is idling. First, let's connect two `SuperNodes`, and then we'll start a run.

## Start the long-running Flower client-side (SuperNode)
## Start the long-running Flower client (SuperNode)

> \[!NOTE\]
> Typically each `SuperNode` runs in a different entity/organization which has access to a dataset. In this example we are going to artificially create N dataset splits and saved them into a new directory called `datasets/`. Then, each `SuperNode` will be pointed to the dataset it should load via the `--node-config` argument. We provide a script that does the download, partition and saving of CIFAR-10.
Expand All @@ -110,21 +99,21 @@ In a new terminal window, start the first long-running Flower client (SuperNode)
```bash
flower-supernode \
--root-certificates certificates/ca.crt \
--superlink 127.0.0.1:9092 \
--auth-supernode-private-key keys/client_credentials_1 \
--auth-supernode-public-key keys/client_credentials_1.pub \
--node-config 'dataset-path="datasets/cifar10_part_1"'
--node-config 'dataset-path="datasets/cifar10_part_1"' \
--clientappio-api-address="0.0.0.0:9094"
```

In yet another new terminal window, start the second long-running Flower client:

```bash
flower-supernode \
--root-certificates certificates/ca.crt \
--superlink 127.0.0.1:9092 \
--auth-supernode-private-key keys/client_credentials_2 \
--auth-supernode-public-key keys/client_credentials_2.pub \
--node-config 'dataset-path="datasets/cifar10_part_2"'
--node-config 'dataset-path="datasets/cifar10_part_2"' \
--clientappio-api-address="0.0.0.0:9095"
```

If you generated more than 2 client credentials, you can add more clients by opening new terminal windows and running the command
Expand All @@ -142,7 +131,7 @@ above. Don't forget to specify the correct client private and public keys for ea
## Run the Flower App
With both the long-running server-side (SuperLink+SuperExec) and two SuperNodes up and running, we can now start run. Note that the command below points to a federation named `my-federation`. Its entry point is defined in the `pyproject.toml`.
With both the long-running server (SuperLink) and two SuperNodes up and running, we can now start the run. Note that the command below points to a federation named `my-federation`. Its entry point is defined in the `pyproject.toml`.
```bash
flwr run . my-federation
Expand Down
12 changes: 6 additions & 6 deletions examples/flower-authentication/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ version = "1.0.0"
description = "Federated Learning with PyTorch and authenticated Flower "
license = "Apache-2.0"
dependencies = [
"flwr==1.12.0",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
"flwr>=1.13.1",
"flwr-datasets[vision]>=0.4.0",
"torch>=2.5.0,<3.0.0",
"torchvision>=0.20.1,<0.21.0",
]

[tool.hatch.build.targets.wheel]
Expand All @@ -32,8 +32,8 @@ learning-rate = 0.1
batch-size = 32

[tool.flwr.federations]
default = "superexec"
default = "my-federation"

[tool.flwr.federations.my-federation]
address = "127.0.0.1:9093" # Address of the SuperExec
address = "127.0.0.1:9093" # Address of the Exec API
root-certificates = "certificates/ca.crt"

0 comments on commit 54ef313

Please sign in to comment.