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 the hello_world notebook.

1.1. Deep Learning to Federated Learning

1.2. Workflows

1.3. 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. Step-By-Step Example Series

Step-by-Step Examples (GitHub) - Step-by-step examples series with CIFAR-10 (image data) and HIGGS (tabular data) to showcase different FLARE features, workflows, and APIs.

2.1 CIFAR-10 Image Data Examples

  • image_stats - federated statistics (histograms) of CIFAR10.

  • sag - scatter and gather (SAG) workflow with PyTorch with Client API.

  • sag_deploy_map - scatter and gather workflow with deploy_map configuration for deployment of apps to different sites using the Client API.

  • sag_model_learner - scatter and gather workflow illustrating how to write client code using the ModelLearner.

  • sag_executor - scatter and gather workflow demonstrating show to write client-side executors.

  • sag_mlflow - MLflow experiment tracking logs with the Client API in scatter & gather workflows.

  • sag_he - homomorphic encyption using Client API and POC -he mode.

  • cse - cross-site evaluation using the Client API.

  • cyclic - cyclic weight transfer workflow with server-side controller.

  • cyclic_ccwf - client-controlled cyclic weight transfer workflow with client-side controller.

  • swarm - swarm learning and client-side cross-site evaluation with Client API.

2.2 HIGGS Tabular Data Examples

  • tabular_stats- federated stats tabular histogram calculation.

  • sklearn_linear- federated linear model (logistic regression on binary classification) learning on tabular data.

  • sklearn_svm- federated SVM model learning on tabular data.

  • sklearn_kmeans- federated k-Means clustering on tabular data.

  • xgboost- federated horizontal xgboost learning on tabular data with bagging collaboration.

3. Tutorial Notebooks

4. Federated Learning Algorithms

5. 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.

6. Traditional ML examples

7. Medical Image Analysis

8. Federated Statistics

9. Federated Site Policies

10. Experiment Tracking

11. Natural Language Processing (NLP)

12. FL Hierarchical Unification Bridge (HUB)

  • FL HUB - Example for FL HUB allowing hierarchical interaction between several levels of FLARE FL systems.

13. Federated Large Language Model (LLM)

14. Graph Neural Network (GNN)

15. 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, prostate segmentation, and BraTS18 segmentation examples assume 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.