Path: blob/master/cloud/notebooks/python_sdk/experiments/federated_learning/Federated Learning Demo Part I - for Admin.ipynb
6405 views
WML Federated Learning with MNIST for Admin using ibm-watsonx-ai
.
With IBM Federated Learning, you can combine data from multiple sources to train a model from the collective data without having to actually share them. This allows enterprises to train data with other companies without delegating resources for security. Another advantage is the remote data does not have to be centralized in one location, eliminates the needs to move potentially large datasets. This notebook demonstrates how to start Federated Learning with the Python client.
Learning Goals
After completing this notebook, you should know how to:
Load an untrained model
Create a Remote Training System
Start a training job
1. Set up the environment
Before you use the sample code in this notebook, you must perform the following setup tasks:
Create a watsonx.ai Runtime Service instance (a free plan is offered and information about how to create the instance can be found here).
Install and import the ibm-watsonx-ai
and dependecies
Note: ibm-watsonx-ai
documentation can be found here.
Connection to watsonx.ai Runtime
Authenticate the watsonx.ai Runtime service on IBM Cloud. You need to provide platform api_key
and instance location
.
You can use IBM Cloud CLI to retrieve platform API Key and instance location.
API Key can be generated in the following way:
In result, get the value of api_key
from the output.
Location of your watsonx.ai Runtime instance can be retrieved in the following way:
In result, get the value of location
from the output.
Tip: Your Cloud API key
can be generated by going to the Users section of the Cloud console. From that page, click your name, scroll down to the API Keys section, and click Create an IBM Cloud API key. Give your key a name and click Create, then copy the created key and paste it below. You can also get a service specific url by going to the Endpoint URLs section of the watsonx.ai Runtime docs. You can check your instance location in your watsonx.ai Runtime Service instance details.
You can also get service specific apikey by going to the Service IDs section of the Cloud Console. From that page, click Create, then copy the created key and paste it below.
Action: Enter your api_key
and location
in the following cell.
Action: Assign project ID below
You need an untrained model asset for Federated Learning to work with. In this tutorial, an untrained Tensorflow 2 Keras model is provided for you. Federated Learning supports Scikit-learn and Tensorflow 2, which are free machine learning packages with tutorials. Additionally IBM docs provide some details on how to configure an untrained model for Federated Learning. See:
Creates an untrained model asset in your project.
Now you will learn to create a Remote Training System (RTS). An RTS handles receiving your multiple parties' call to the aggregator to run the training.
allowed_identities
are users permitted to connect to the Federated Learning experiment. In this tutorial, only your user ID is permitted to connect but you can update the template and add additional users as required.An Admin in
remote_admin
. The template for the admin is the same as the user. In this tutorial, a template Admin is created. It is also the same as the user ID, however generally in application, the admin does not have to be one of the users.
If you want to clean up all created assets:
experiments
trainings
pipelines
model definitions
models
functions
deployments
please follow up this sample notebook.
You successfully completed this notebook! Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Get Variables And Paste Into Party Notebook
Run the following cell and copy the output.
As the Admin, you have now launched a Federated Learning experiment. Copy the output from the previous cell. Open Part II - WML Federated Learning with MNIST for Party and paste the output into the first code cell.
Author
Rinay Shah, Software Developer at IBM.
Copyright © 2020-2025 IBM. This notebook and its source code are released under the terms of the MIT License.