Federated Learning with NumPy and Flower (Quickstart Example)ΒΆ

View on GitHub

This example of Flower uses a dummy NumPy model as well as dummy training and evaluation steps in the ClientApp to showcase the core functionality of Flower apps. This app does not use a dataset.

Set up the projectΒΆ

Fetch the appΒΆ

Install Flower:

pip install flwr

Fetch the app:

flwr new @flwrlabs/quickstart-numpy
quickstart-numpy
β”œβ”€β”€ quickstart_numpy
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ client_app.py   # Defines your ClientApp
β”‚   β”œβ”€β”€ server_app.py   # Defines your ServerApp
β”‚   └── task.py         # Defines model creation
β”œβ”€β”€ 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 quickstart_numpy package.

pip install -e .

Tip: Your pyproject.toml file can define more than just the dependencies of your Flower app. You can also use it to specify hyperparameters for your runs and control which Flower Runtime is used. By default, it uses the Simulation Runtime, but you can switch to the Deployment Runtime when needed. Learn more in the TOML configuration guide.

Run with the Simulation EngineΒΆ

In the quickstart-numpy directory, use flwr run to run a local simulation:

flwr run .

Refer to the How to Run Simulations guide in the documentation for advice on how to optimize your simulations.

Run with the Deployment EngineΒΆ

Follow this how-to guide to run the same app in this example but with Flower’s Deployment Engine. After that, you might be interested in setting up secure TLS-enabled communications and SuperNode authentication in your federation.

You can run Flower on Docker too! Check out the Flower with Docker documentation.

ResourcesΒΆ