tags | dataset | framework | ||||||
---|---|---|---|---|---|---|---|---|
|
|
|
In this example, we demonstrate how to train a model with differential privacy (DP) using Flower. We employ PyTorch and integrate the Opacus Privacy Engine to achieve sample-level differential privacy. This setup ensures robust privacy guarantees during the client training phase. The code is adapted from the PyTorch Quickstart example.
For more information about DP in Flower please refer to the tutorial. For additional information about Opacus, visit the official website.
Start by cloning the example. We prepared a single-line command that you can copy into your shell which will checkout the example for you:
git clone --depth=1 https://github.com/adap/flower.git && mv flower/examples/opacus . && rm -rf flower && cd opacus
This will create a new directory called opacus
containing the following files:
-- pyproject.toml
-- client.py
-- server.py
-- README.md
Project dependencies are defined in pyproject.toml
. Install them with:
pip install .
flower-superlink --insecure
Start 2 Flower SuperNodes
in 2 separate terminal windows, using:
flower-client-app client:appA --insecure
flower-client-app client:appB --insecure
Opacus hyperparameters can be passed for each client in ClientApp
instantiation (in client.py
). In this example, noise_multiplier=1.5
and noise_multiplier=1
are used for the first and second client respectively.
With both the long-running server (SuperLink) and two clients (SuperNode) up and running, we can now run the actual Flower App:
flower-server-app server:app --insecure