Skip to content

Commit

Permalink
Merge branch 'main' into add-llm-code-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-gao-GY authored Sep 6, 2024
2 parents cce8537 + ceb3903 commit f9d2fdf
Show file tree
Hide file tree
Showing 32 changed files with 769 additions and 488 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ README.md @jafermarq @tanertopal @danieljanes
/.devcontainer @Robert-Steiner @Moep90
**/Dockerfile @Robert-Steiner @Moep90
**/*.Dockerfile @Robert-Steiner @Moep90
src/docker @Robert-Steiner @Moep90
16 changes: 4 additions & 12 deletions .github/workflows/_docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ permissions:
jobs:
build:
name: Build image
runs-on: ubuntu-22.04
runs-on: ${{ matrix.platform.runner-os }}
timeout-minutes: 180
outputs:
build-id: ${{ steps.build-id.outputs.id }}
strategy:
fail-fast: true
matrix:
platform: [
# build-push action and qemu use different platform names
# therefore we create a map
{ name: "amd64", qemu: "", docker: "linux/amd64" },
{ name: "arm64", qemu: "arm64", docker: "linux/arm64" },
{ name: "amd64", docker: "linux/amd64", runner-os: "ubuntu-22.04" },
{ name: "arm64", docker: "linux/arm64", runner-os: "ubuntu-4-core-arm64" },
]
steps:
- name: Create build id
Expand Down Expand Up @@ -79,12 +77,6 @@ jobs:
print(build_args, file=fh)
print("EOF", file=fh)
- name: Set up QEMU
if: matrix.platform.qemu != ''
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: ${{ matrix.platform.qemu }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
Expand All @@ -104,7 +96,7 @@ jobs:
uses: Wandalen/wretry.action@6feedb7dedadeb826de0f45ff482b53b379a7844 # v3.5.0
id: build
with:
action: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
action: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
attempt_limit: 60 # 60 attempts * (9 secs delay + 1 sec retry) = ~10 mins
attempt_delay: 9000 # 9 secs
with: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
run: ./../test_superlink.sh bare sqlite
- name: Run driver test with client authentication
if: ${{ matrix.directory == 'e2e-bare-auth' }}
run: ./../test_superlink.sh bare client-auth
run: ./../test_superlink.sh "${{ matrix.directory }}" client-auth
- name: Run reconnection test with SQLite database
if: ${{ matrix.directory == 'e2e-bare' }}
run: ./../test_reconnection.sh sqlite
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/framework-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
if: ${{ github.repository == 'adap/flower' }}
name: Publish release
runs-on: ubuntu-22.04
outputs:
flwr-version: ${{ steps.publish.outputs.flwr-version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -26,10 +28,12 @@ jobs:
uses: ./.github/actions/bootstrap

- name: Get artifacts and publish
id: publish
env:
GITHUB_REF: ${{ github.ref }}
run: |
TAG_NAME=$(echo "${GITHUB_REF_NAME}" | cut -c2-)
echo "flwr-version=$TAG_NAME" >> "$GITHUB_OUTPUT"
wheel_name="flwr-${TAG_NAME}-py3-none-any.whl"
tar_name="flwr-${TAG_NAME}.tar.gz"
Expand Down Expand Up @@ -67,8 +71,7 @@ jobs:
- id: matrix
run: |
FLWR_VERSION=$(poetry version -s)
python dev/build-docker-image-matrix.py --flwr-version "${FLWR_VERSION}" > matrix.json
python dev/build-docker-image-matrix.py --flwr-version "${{ needs.publish.outputs.flwr-version }}" > matrix.json
echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
build-base-images:
Expand Down
2 changes: 2 additions & 0 deletions doc/source/contributor-explanation-architecture.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Flower Architecture
===================

This document provides an overview of the Flower architecture. The architecture is designed to be modular and flexible, and can use two different types of engines: Deployment Engine and Simulation Engine.

Edge Client Engine
------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial-quickstart-mlx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ You can also override the parameters defined in
.. code:: shell
# Override some arguments
$ flwr run . --run-config num-server-rounds=5,lr=0.05
$ flwr run . --run-config "num-server-rounds=5 lr=0.05"
What follows is an explanation of each component in the project you just
created: dataset partition, the model, defining the ``ClientApp`` and
Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial-quickstart-pytorch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ You can also override the parameters defined in the
.. code:: shell
# Override some arguments
$ flwr run . --run-config num-server-rounds=5,local-epochs=3
$ flwr run . --run-config "num-server-rounds=5 local-epochs=3"
What follows is an explanation of each component in the project you just
created: dataset partition, the model, defining the ``ClientApp`` and
Expand Down
5 changes: 1 addition & 4 deletions e2e/test_superlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

case "$1" in
e2e-bare-https)
e2e-bare-https | e2e-bare-auth)
./generate.sh
server_arg="--ssl-ca-certfile certificates/ca.crt --ssl-certfile certificates/server.pem --ssl-keyfile certificates/server.key"
client_arg="--root-certificates certificates/ca.crt"
Expand Down Expand Up @@ -37,14 +37,11 @@ case "$2" in
client_auth_2=""
;;
client-auth)
./generate.sh
rest_arg_superlink=""
rest_arg_supernode=""
server_address="127.0.0.1:9092"
server_app_address="127.0.0.1:9091"
db_arg="--database :flwr-in-memory-state:"
server_arg="--ssl-ca-certfile certificates/ca.crt --ssl-certfile certificates/server.pem --ssl-keyfile certificates/server.key"
client_arg="--root-certificates certificates/ca.crt"
server_auth="--auth-list-public-keys keys/client_public_keys.csv --auth-superlink-private-key keys/server_credentials --auth-superlink-public-key keys/server_credentials.pub"
client_auth_1="--auth-supernode-private-key keys/client_credentials_1 --auth-supernode-public-key keys/client_credentials_1.pub"
client_auth_2="--auth-supernode-private-key keys/client_credentials_2 --auth-supernode-public-key keys/client_credentials_2.pub"
Expand Down
61 changes: 48 additions & 13 deletions examples/fl-dp-sa/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,63 @@
---
tags: [basic, vision, fds]
tags: [DP, SecAgg, vision, fds]
dataset: [MNIST]
framework: [torch, torchvision]
---

# Example of Flower App with DP and SA
# Flower Example on MNIST with Differential Privacy and Secure Aggregation

This is a simple example that utilizes central differential privacy with client-side fixed clipping and secure aggregation.
Note: This example is designed for a small number of rounds and is intended for demonstration purposes.
This example demonstrates a federated learning setup using the Flower, incorporating central differential privacy (DP) with client-side fixed clipping and secure aggregation (SA). It is intended for a small number of rounds for demonstration purposes.

## Install dependencies
This example is similar to the [quickstart-pytorch example](https://github.com/adap/flower/tree/main/examples/quickstart-pytorch) and extends it by integrating central differential privacy and secure aggregation. For more details on differential privacy and secure aggregation in Flower, please refer to the documentation [here](https://flower.ai/docs/framework/how-to-use-differential-privacy.html) and [here](https://flower.ai/docs/framework/contributor-ref-secure-aggregation-protocols.html).

```bash
# Using pip
pip install .
## Set up the project

### Clone the project

Start by cloning the example project:

```shell
git clone --depth=1 https://github.com/adap/flower.git && mv flower/examples/fl-dp-sa . && rm -rf flower && cd fl-dp-sa
```

This will create a new directory called `fl-dp-sa` containing the following files:

# Or using Poetry
poetry install
```shell
fl-dp-sa
├── fl_dp_sa
│ ├── client_app.py # Defines your ClientApp
│ ├── server_app.py # Defines your ServerApp
│ └── task.py # Defines your model, training, and data loading
├── pyproject.toml # Project metadata like dependencies and configs
└── README.md
```

## Run
### Install dependencies and project

The example uses the MNIST dataset with a total of 100 clients, with 20 clients sampled in each round. The hyperparameters for DP and SecAgg are specified in `server.py`.
Install the dependencies defined in `pyproject.toml` as well as the `fl_dp_sa` package.

```shell
flower-simulation --server-app fl_dp_sa.server:app --client-app fl_dp_sa.client:app --num-supernodes 100
# From a new python environment, run:
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 "noise-multiplier=0.1 clipping-norm=5"
```

### 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.
2 changes: 1 addition & 1 deletion examples/fl-dp-sa/fl_dp_sa/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""fl_dp_sa: A Flower / PyTorch app."""
"""fl_dp_sa: Flower Example using Differential Privacy and Secure Aggregation."""
42 changes: 0 additions & 42 deletions examples/fl-dp-sa/fl_dp_sa/client.py

This file was deleted.

50 changes: 50 additions & 0 deletions examples/fl-dp-sa/fl_dp_sa/client_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""fl_dp_sa: Flower Example using Differential Privacy and Secure Aggregation."""

import torch
from flwr.client import ClientApp, NumPyClient
from flwr.common import Context
from flwr.client.mod import fixedclipping_mod, secaggplus_mod

from fl_dp_sa.task import Net, get_weights, load_data, set_weights, test, train


class FlowerClient(NumPyClient):
def __init__(self, trainloader, testloader) -> None:
self.net = Net()
self.trainloader = trainloader
self.testloader = testloader
self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

def fit(self, parameters, config):
set_weights(self.net, parameters)
results = train(
self.net,
self.trainloader,
self.testloader,
epochs=1,
device=self.device,
)
return get_weights(self.net), len(self.trainloader.dataset), results

def evaluate(self, parameters, config):
set_weights(self.net, parameters)
loss, accuracy = test(self.net, self.testloader, self.device)
return loss, len(self.testloader.dataset), {"accuracy": accuracy}


def client_fn(context: Context):
partition_id = context.node_config["partition-id"]
trainloader, testloader = load_data(
partition_id=partition_id, num_partitions=context.node_config["num-partitions"]
)
return FlowerClient(trainloader, testloader).to_client()


# Flower ClientApp
app = ClientApp(
client_fn=client_fn,
mods=[
secaggplus_mod,
fixedclipping_mod,
],
)
Loading

0 comments on commit f9d2fdf

Please sign in to comment.