Skip to content

londonaicentre/flip-fl-base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

317 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

FLIP-FL-base-FLARE

flip-flare-logo

codecov PyPI version Docker - flare-fl-base Docker - flare-fl-server Docker - flare-fl-client Python 3.12+ Documentation StatusLicense

This repository contains the FLIP (Federated Learning and Interoperability Platform) federated learning base application utilities. It is a monorepo that includes:

  • flip — pip-installable Python package with platform logic, NVFLARE components, and utilities
  • tutorials/ — example applications you can run on the FLIP platform
  • fl_services/ — Docker services for running FL networks (server, clients, admin API)

Table of Contents


flip Python Package

The flip package is the core pip-installable library for the FLIP federated learning platform. It provides all platform logic core to training and evaluating FL applications.

Installation

uv sync
# or
pip install .

To build a distributable package:

uv build

Package Structure

flip/
├── core/         # FLIPBase, FLIPStandardProd/Dev implementations, FLIP() factory
├── constants/    # FlipConstants (pydantic-settings), enums, PTConstants
├── utils/        # General utilities: Utils, model weight helpers
└── nvflare/      # NVFLARE-specific logic and components
    ├── executors/    # RUN_TRAINER, RUN_VALIDATOR, RUN_EVALUATOR wrappers
    ├── controllers/  # Workflow controllers (ScatterAndGather, CrossSiteModelEval, …)
    └── components/   # Event handlers, persistors, privacy filters, locators, …

The FLIP() factory selects FLIPStandardDev (local CSV/filesystem) or FLIPStandardProd (FLIP platform APIs) based on the LOCAL_DEV environment variable.

User Application Requirements

User-provided files go in the job's custom/ directory and are dynamically imported by the executor wrappers:

File Description
trainer.py Training logic — must export FLIP_TRAINER class
validator.py Validation logic — must export FLIP_VALIDATOR class
models.py Model definitions — must export get_model() function
config.json Hyperparameters — must include LOCAL_ROUNDS and LEARNING_RATE
transforms.py Data transforms (optional)

Job Types

Set via the JOB_TYPE environment variable:

Type Description
standard Federated training with FedAvg aggregation (default)
evaluation Distributed model evaluation without training
diffusion_model Two-stage training (VAE encoder + diffusion)
fed_opt Custom federated optimization

The corresponding configs live in src/<job_type>/app/config/.

Development Mode

DEV mode lets you test FL applications locally before deploying to production.

  1. Edit .env.development:

    LOCAL_DEV=true
    DEV_IMAGES_DIR=../data/accession-resources
    DEV_DATAFRAME=../data/sample_get_dataframe.csv
    JOB_TYPE=standard
  2. Place your application files in src/<JOB_TYPE>/app/custom/.

  3. Run the simulator in Docker:

    make run-container

Unit Tests

make unit-test
# or
uv run pytest -s -vv

Tutorials

The tutorials/ directory contains ready-to-use example applications that can be uploaded to the FLIP platform UI. Each tutorial is designed to work with a specific app type from src/.

FL app structure

App / Tutorial Compatibility

App Tutorial
standard image_segmentation/3d_spleen_segmentation
standard image_classification/xray_classification
diffusion_model image_synthesis/latent_diffusion_model
fed_opt image_segmentation/3d_spleen_segmentation
evaluation image_evaluation/3d_spleen_segmentation

FL Services API

The fl_services/ directory contains Docker-based NVFLARE services. See the FL services README and the FL API README for full details on provisioning and the API endpoints.

Prerequisites

  • Docker and Docker Compose
  • uv (Python package manager)
  • AWS CLI configured (for downloading test data)

Provisioning the 2 Networks

Generate the certificates, keys, and configuration for the 2 FL networks:

make nvflare-provision-2-nets

This uses the network-specific provisioning project files (net-1_project.yml and net-2_project.yml) and provisions the network files in workspace/net-1 and workspace/net-2 (gitignored) using the scripts/provision-network.sh script.

⚠️ Warning: Provisioned files contain cryptographic signatures. Any modification will cause errors. Always re-run provisioning if changes are needed.

Provisioning Networks for Staging/Production

Note the provisioning project file net-1_project_stag.yml changes the name of the FL server to the full domain name i.e. stag.flip.aicentre.co.uk instead of fl-server-net-1, since the FL clients won't be on the same Docker network as the FL server (as they are in development) and won't be able to resolve internal Docker hostnames.

Run:

make nvflare-provision-stag

Creating a New Network

Create a provisioning project file (e.g. net-3_project.yml) based on the template (net-1_project.yml) (you'll likely need to change fed_learn_port) and run:

NET_NUMBER=3 make nvflare-provision

Running a Network

make build NET_NUMBER=1   # Build Docker images
make up NET_NUMBER=1      # Start the network (server, 2 clients, API)
make down NET_NUMBER=1    # Stop the network
make clean NET_NUMBER=1   # Remove containers and images

Integration Testing

Download test data (requires AWS S3 access) then run the relevant target:

make download-test-data
make test   # Run all integration tests

CI/CD

GitHub Actions workflows use OIDC to authenticate to AWS (no long-lived keys).

Trigger Target
PR to any branch s3://flipdev/base-application-dev/nvflare/pull-requests/<PR_NUMBER>
Merge to develop s3://flipdev/base-application/nvflare and s3://flipstag/base-application/nvflare
Merge to main s3://flipprod/base-application/nvflare

Warning: Never manually sync to the production bucket.

To test a PR on the FLIP platform, update FL_APP_BASE_BUCKET in the flip repo environment variables to point to your PR's S3 path.

Makefile Reference

Network Management

Command Description
make nvflare-provision NET_NUMBER=X Provision FL network X
make build NET_NUMBER=X Build Docker images for network X
make up NET_NUMBER=X Start FL network X
make down NET_NUMBER=X Stop FL network X
make clean NET_NUMBER=X Remove containers and images

Development

Command Description
make run-container Run NVFLARE simulator in Docker

Data Management

Command Description
make download-test-data Download all test data (x-ray and spleen images, model checkpoints) from S3

Testing

Command Description
make unit-test Run pytest unit tests for flip python package
make test-xrays-standard Test standard job with x-ray data
make test-spleen-standard Test standard job with spleen data
make test-spleen-evaluation Test evaluation job with spleen data
make test-spleen-diffusion Test diffusion model with spleen data
make test Run all integration tests

Security

Please report security vulnerabilities responsibly. For details on how to report a vulnerability, see SECURITY.md.

⚠️ Do not open a public GitHub issue for security bugs; instead, use the private GitHub Security Advisory feature.


Contributing

For information on how to contribute to this project, see CONTRIBUTING.md.

About

Federated Learning Interoperability Platform Base Federated Learning Utilities

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors