Skip to main content

Part 2: Federated Training

Now that we have our aggregator running and experiment configured, let's set up the Client API. As a client in a federated learning computation, you'll be training the model on your local MNIST data and sharing only the model updates while keeping your training data private.

Step 1: Install the Client API

There are two ways in which you can install your fl_client SyftBox API:

  1. Downloading and copying the fl_client into your SyftBox API directory (similarly to what we did in Part 1)
  2. Using the built-in installation widget automatically added to the metrics dashboard (described below)

Install the Client API using the installation widget

  1. Navigate to your FL Monitoring dashboard:
https://syftbox.openmined.org/datasites/your.datasite/fl/[YOUR_CREATIVE_NAME]_MNIST_FL/
  1. Look for the FL Client API installation widget. You'll see a blue button like this:
Install FL Client Button - Blue version showing 'fl_client 0.0.1 Install'
  1. Click the Install button. Once installation is complete, the button will turn green:
Installed FL Client Button - Green version showing 'fl_client 0.0.1 Installed'
  1. Check your SyftBox API Directory

You should now see a new fl_client folder into your SyftBox API Directory

Step 2: Prepare Your Training Data

  1. Create a new fl_client folder into your SyftBox private data directory:
mkdir -p $HOME/SyftBox/private/fl_client
  1. Copy the MNIST samples from the FL Client API mnist_samples directory:
cp $HOME/SyftBox/apis/fl_client/mnist_samples/mnist_label_*.pt $HOME/SyftBox/private/fl_client/
info

🎲 Data Distribution: The MNIST samples have been organized by digit - each file mnist_label_X.pt contains training samples for digit X. Feel free to select any combination of digits for your training! This simulates a real-world scenario where different clients have different kinds of data. For example, you might choose to train on digits 0, 1, and 2, while another participant might train on digits 3, 4, and 5. This non-uniform data distribution is actually beneficial, as it helps demonstrate how federated learning works with non-IID (non-independent and identically distributed) data.

Step 3: Process FL Requests

When the FL Aggregator launches a new federated learning experiment, all nominated participants receive a computation request in their datasite. To join the federated model training, each client must actively accept this request.

When you receive a computation request:

  1. Navigate to your API data directory:
cd $HOME/SyftBox/datasites/your.datasite/api_data/fl_client

The should be two distinc folders: request and running.

  1. To accept a computation, move the project folder received in request to running:
mv -r ./request/[YOUR_CREATIVE_NAME]_MNIST_FL ./running/

🎉 Congratulations! You've successfully completed the setup of your federated learning client! You're now ready to move on to Part 3, where we'll monitor the training process and watch your federated learning experiment in action.