Flower AI Summit 2026·April 15–16·London

@dianyo/vitpoultry

0
0
flwr new @dianyo/vitpoultry

Federated Finetuning of a Vision Transformer on Poultry Health

This example shows how to use Flower to federate the finetuning of a ViT-Base-16 pretrained on ImageNet. It finetunes just the classification head on a binary poultry health dataset (Dianyo/poultry-health) using Flower Datasets for on-the-fly IID partitioning across 10 clients. Because only the head is trained, each client needs minimal VRAM (~1 GB at batch size 32).

Set up the project

Fetch the app

flwr new @dianyo/vitpoultry

This will create a new directory called flowertune-vit-poultry with the following structure:

flowertune-vit-poultry
├── vitpoultry
│   ├── __init__.py
│   ├── client_app.py   # Defines your ClientApp
│   ├── server_app.py   # Defines your ServerApp
│   └── task.py         # Defines your model, training and data loading
├── pyproject.toml      # Project metadata like dependencies and configs
└── README.md

Install dependencies and project

Install the dependencies defined in pyproject.toml as well as the vitpoultry package.

pip install -e .

Run the project

You can run your Flower project in both simulation and deployment mode without making changes to the code. If you are starting with Flower, we recommend you using the simulation mode as it requires fewer components to be launched manually. By default, flwr run will make use of the Simulation Engine.

Run with the Simulation Engine

Tip: Check the Simulation Engine documentation to learn more about Flower simulations, how to use more virtual SuperNodes, and how to configure CPU/GPU usage in your ClientApp.

flwr run .

You can also override some of the settings for your ClientApp and ServerApp defined in pyproject.toml. For example:

flwr run . --run-config "num-server-rounds=5 batch-size=64"

If your system has a GPU you can make use of it:

flwr run .

Run with the Deployment Engine

To run this app using Flower's Deployment Engine we recommend first creating some demo data using Flower Datasets. For example:

# Install Flower Datasets
pip install "flwr-datasets[vision]"

# Create dataset partitions and save them to disk
flwr-datasets create Dianyo/poultry-health --num-partitions 2 --out-dir demo_data

The above command will create two IID partitions of the poultry health dataset and save them in a demo_data directory. Next, you can pass one partition to each of your SuperNodes like this:

flower-supernode \
    --insecure \
    --superlink <SUPERLINK-FLEET-API> \
    --node-config="data-path=/path/to/demo_data/partition_0"

Finally, ensure the environment of each SuperNode has all dependencies installed. Then, launch the run via flwr run but pointing to a SuperLink connection that specifies the SuperLink your SuperNode is connected to:

flwr run . <SUPERLINK-CONNECTION> --stream

Tip: Follow this how-to guide to run the same app in this example but with Flower's Deployment Engine. After that, you might be interested in setting up secure TLS-enabled communications and SuperNode authentication in your federation.