Example Applications

NVIDIA FLARE has several tutorials and examples to help you get started with federated learning and to explore certain features in the examples directory.

1. Hello World Examples

Can be run from hello_world notebook.

1.1. Workflows

1.2. Deep Learning

  • Hello PyTorch - Example image classifier using FedAvg and PyTorch as the deep learning training framework

  • Hello TensorFlow - Example image classifier using FedAvg and TensorFlow as the deep learning training frameworks

2. Tutorial Notebooks

  • Intro to the FL Simulator - Shows how to use the NVIDIA FLARE FL Simulator to run a local simulation of an NVFLARE deployment to test and debug an application without provisioning a real FL project.

  • Hello FLARE API - Goes through the different commands of the FLARE API to show the syntax and usage of each.

  • NVFLARE in POC Mode - Shows how to use POC mode to test the features of a full FLARE deployment on a single machine.

  • NVFlare CLI Tutorial - Walks through the current nvflare command groups for local setup, recipes, jobs, systems, studies, provisioning, and deployment.

  • Job Recipe - Introduces Job Recipes to simplify federated learning job creation and execution with a high-level API.

  • FLARE Logging - Covers how to configure logging in FLARE for different use cases and modes.

3. Federated Learning Algorithms

4. Privacy Preserving Algorithms

Privacy preserving algorithms in NVIDIA FLARE are implemented as filters that can be applied as data is sent or received between peers.

5. Traditional ML examples

6. Medical Image Analysis

  • MONAI Integration (GitHub) - For an example of using NVIDIA FLARE to train a 3D medical image analysis model using federated averaging (FedAvg) and MONAI Bundle MONAI

7. Federated Statistics

8. Federated Site Policies

9. Experiment Tracking

10. Natural Language Processing (NLP)

11. Federated Large Language Model (LLM)

12. Graph Neural Network (GNN)

13. Financial Applications

Setting up a virtual environment for examples and notebooks

It is recommended to set up a virtual environment before installing the dependencies for the examples. Install dependencies for a virtual environment with:

python3 -m pip install --user --upgrade pip
python3 -m pip install --user virtualenv

Once venv is installed, you can use it to create a virtual environment with:

$ python3 -m venv nvflare_example

This will create the nvflare_example directory in current working directory if it doesn’t exist, and also create directories inside it containing a copy of the Python interpreter, the standard library, and various supporting files.

Activate the virtualenv by running the following command:

$ source nvflare_example/bin/activate

Installing required packages

In each example folder, install required packages for training:

pip install --upgrade pip
pip install -r requirements.txt

(optional) some examples contain scripts for plotting the TensorBoard event files, if needed, please also install the additional requirements in the example folder:

pip install -r plot-requirements.txt

JupyterLab with your virtual environment for Notebooks

To run examples including notebooks, we recommend using JupyterLab.

After activating your virtual environment, install JupyterLab.

pip install jupyterlab

If you need to register the virtual environment you created so it is usable in JupyterLab, you can register the kernel with:

python -m ipykernel install --user --name="nvflare_example"

Start a Jupyter Lab:

jupyter lab .

When you open a notebook, select the kernel you registered, “nvflare_example”, using the dropdown menu at the top right.

Custom Code in Example Apps

There are several ways to make custom code available to clients when using NVIDIA FLARE. Most hello-* examples use a custom folder within the FL application. Note that using a custom folder in the app needs to be allowed when using secure provisioning. By default, this option is disabled in the secure mode. POC mode, however, will work with custom code by default.

In contrast, the CIFAR-10 example assumes that the learner code is already installed on the client’s system and available in the PYTHONPATH. Hence, the app folders do not include the custom code there. The PYTHONPATH is set in the run_poc.sh or run_secure.sh scripts of the example. Running these scripts as described in the README will make the learner code available to the clients.