Flower Federated Learning on Scaleway

../_images/flower-logo.png ../_images/huggingface-1.svg

In this example we will be deploying a Federated Learning (FL) experiment with the Flower FL framework. In particular we will deploy this quickstart example leveraging Hugging Face’s Transformers.

If you are not familiar with the concept of Federated Learning, you can read this quick introduction: link.

This example is an extension of the previous flower example. But this time we will be running the clients on Scaleway instances equipped with GPUs.

Here is what the topology of the experiment that we are going to deploy looks like:

graph "Grid5000 deployment graph" {

    subgraph cluster_grid5000 {
        label="Grid5000"

        subgraph cluster_cloud {
            label="Cloud"

            Superlink [
                label="cloud.server.1.1\nSuperlink"
            ]
        }
    }

    subgraph cluster_scaleway {
        label="Scaleway"

        subgraph cluster_edge {
            label="Edge"

            Supernode1 [
                label="edge.client.1.2\nSupernode"
            ]

            Supernode2 [
                label="edge.client.1.1\nSupernode"
            ]
        }

        Superlink -- Supernode1
        Superlink -- Supernode2
    }
}

Warning

This example will deploy GPU resources on Scaleway, which can be expensive, please be mindful of your usage and keep an eye on the billing.

In this example you will learn to:

  • Configure python virtual environments

  • Check end-to-end execution

  • Connect to nodes with E2Clab’s ssh command

  • Run multiprovider experiments with Grid5000 and Scaleway Instances

  • Use E2Clab’s .e2c_env env file

Experiment Artifacts

Download the experimental setup for this Flower Federated Learning experiment:

$ git clone https://gitlab.inria.fr/E2Clab/examples/flower-fl
$ cd flower-fl/

The structure of the experimental setup looks like this:

flower-fl/
├─quickstart-huggingface/   # ARTIFACTS_DIR
├─scaleway_g5k/             # SCENARIO_DIR
│   ├─.e2c_env
│   ├─layers_services.yaml
│   ├─network.yaml
│   └─workflow.yaml
├─README.md
└─...

Defining the Experimental Environment

Layers & Services Configuration

To communicate between both providers, we need to activate IPv6 and setup the firewall rules for Grid5000: https://www.grid5000.fr/w/Reconfigurable_Firewall

To setup the Scaleway provider we also need to activate IPv6 on the instances that we deploy so that we can communicate with the G5k node. We also set architecture as standalone as we don’t want to setup our instances in a private network behind a gateway but rather directly access the G5K server.

For the client nodes we request 2 nodes equipped with a single Nvidia L4 accelerator. We also need to specify that we want to deploy and OS with Nvidia drivers pre-installed: ubuntu_noble_gpu_os_13_nvidia.

You may need to spend some time to read Scaleway’s documentation to understand how to properly set those parameters.

You can explore how to change those those paramters by checking Scaleway’s API with the cli:

# List available OS image
$ scw marketplace image list
# List available commercial types
$ scw instance server-type list

Note

It is also important that you properly setup you credentials. If you used scw init to setup your credentials, E2Clab should be able to find your configuration file without the path. Also make sure to set the profile that you want to use from your configuration, if not E2Clab will default to the default profile and fail if it doesn’t exist.

You can learn more on how to configure scalewayinstances here.

 1environment:
 2  job_name: flower
 3  walltime: 01:00:00
 4  g5k:
 5    job_type: ["deploy"]
 6    cluster: parasilo
 7    env_name: "debian12-x64-big"
 8    ipv6: true
 9    # Supernode related ports
10    firewall_rules:
11      - services: ["Server"]
12        ports: [9091, 9092, 9093]
13  scalewayinstances:
14    # Scaleway profile to use
15    # config_file: path_to_config
16    # profile: profilename
17    architecture: standalone
18    ipv6: true
19layers:
20- name: cloud
21  services:
22  - name: Server
23    quantity: 1
24    environment: g5k
25- name: edge
26  services:
27  - name: Client
28    # If you change the quantity, also think to change the
29    # number of partitions in workflow.yaml edge section
30    quantity: 2
31    # Instance commercial type
32    commercial_type: l4-1-24G
33    # Deployed OS 
34    image: ubuntu_noble_gpu_os_13_nvidia
35    environment: scalewayinstances

Here we do not define new user-defined services and instead use the nodes as provided by the provider.

When the services names do not match any defined user defined services, you will see in the logs that E2Clab’s deploys Default services which basically that you get bare nodes as they were configured by the providers.

Network Configuration

In this experiment we do not define new network constraints.

1networks:

Workflow Configuration

You can go through the file to understand how it works but here are the key steps:

  • Download experiment artifacts to the nodes (the quickstart-huggingface directory)

  • Install the dependencies

  • Start the supernodes and the superlink which are flower’s servers and clients that help orchestrate the experiment, in a tmux session to make sure they keep running

  • And in the launch step we juste have to run flwr run to start the whole experiment

  • Once it’s done, we backup the logs and final model from the nodes to our experiment’s result directory ({{ working_dir }})

Notice that here we pass the address of the server deployed in Grid5000 to the clients in Scaleway with {{ server.url6 }} as Grid5000 resources are accessible from the outside only through IPv6. We also need to install cuda on the client nodes as Scaleway provides GPU OSs without it.

Note

Notice that we pass the --insecure argument to supernode and superlink, this means that we run those server without HTTPS. Of course this makes communications between the server unsafe. Here we don’t work with sensitive data or models and just provide an example workflow.

If you want to run experiments in a way that is more secure, take a look a flower’s documentation and adapt this example.

 1# Cloud
 2- hosts: cloud.server.*
 3  prepare:
 4    - name: Copy artifacts
 5      copy:
 6        src: "{{ working_dir }}/"
 7        dest: /tmp/flower_scenario/
 8    - name: Create venv
 9      shell:
10        cmd: "apt install -y python3-venv tmux && python3 -m venv venv"
11        chdir: /tmp/
12    - name: Update pip
13      command:
14        cmd: "./venv/bin/python -m pip install -U pip"
15        chdir: /tmp/
16    - name: Install dependencies
17      command:
18        cmd: "./venv/bin/python -m pip install -e ./flower_scenario"
19        chdir: /tmp/
20        creates: /tmp/venv/bin/flower-superlink
21    - name: Start flower superlink
22      shell: 
23        cmd: tmux new-session -d -s flower '. /tmp/venv/bin/activate && flower-superlink --insecure >> /tmp/superlink.log 2>&1'
24        chdir: /tmp/
25        creates: /tmp/superlink.log 
26    - name: Ensure tmux session is running
27      command: tmux has-session -t flower
28      register: result
29      failed_when: result.rc != 0
30  launch:
31    - name: Starting Flower run
32      command:
33        argv:
34          - ./venv/bin/flwr
35          - run
36          - ./flower_scenario
37          - deployment
38          - --stream
39        chdir: /tmp/
40  finalize:
41    - name: Stopping superlink
42      shell:
43        cmd: tmux kill-session -t flower
44    - name: Backing up logs
45      fetch:
46        src: "/tmp/superlink.log"
47        dest: "{{ working_dir }}/"
48    - name: Backing up model
49      fetch:
50        src: "/tmp/final_model.pt"
51        dest: "{{ working_dir }}/"
52
53# Edge
54- hosts: edge.client.*
55  depends_on:
56    - service_selector: "cloud.server.*"
57      grouping: "round_robin"
58      prefix: "server"
59  prepare:
60    - name: Install cuda
61      shell:
62        cmd: "apt-get update && apt-get -y install nvidia-cuda-toolkit"
63    - name: Install venv
64      shell:
65        cmd: "apt-get update && apt-get install -y python3-venv"
66    - name: Copy artifacts
67      copy:
68        src: "{{ working_dir }}/"
69        dest: /tmp/flower_scenario/
70    - name: Create venv
71      shell:
72        cmd: "python3 -m venv venv"
73        chdir: /tmp/
74    - name: Update pip
75      command:
76        cmd: "./venv/bin/python -m pip install -U pip"
77        chdir: /tmp/
78    - name: Install dependencies
79      command:
80        cmd: "./venv/bin/python -m pip install -e ./flower_scenario"
81        chdir: /tmp/
82        creates: /tmp/venv/bin/flower-supernode
83    - name: Run superlink
84      shell:
85        cmd: tmux new-session -d -s flower '. /tmp/venv/bin/activate && flower-supernode --insecure --superlink {{ server.url6 }}:9092 --node-config "partition-id={{ _self.machine_id | int - 1 }} num-partitions=2" >> supernode.log 2>&1'
86        chdir: /tmp/
87        creates: /tmp/supernode.log 
88    - name: Ensure tmux session is running
89      command: tmux has-session -t flower
90      register: result
91      failed_when: result.rc != 0
92  finalize:
93    - name: Stop supernode
94      shell:
95        cmd: tmux kill-session -t flower
96    - name: Backup supernode logs
97      fetch:
98        src: "/tmp/supernode.log"
99        dest: "{{ working_dir }}/"

Running & Verifying Experiment Execution

You can deploy the whole experiment with a single deploy command:

$ cd scaleway_g5k
$ e2clab deploy

This will reserver the experiment’s computing resources, deploy the artifacts and run the whole workflow:

  • prepare

  • launch

  • finalize

In that order

Note

You might notice that we did not specify the paths for ARTIFACTS_DIR or SCENARIO_DIR in the deploy command. They are actually specified in environment variables defined in the .e2c_env env file, as noted when you run e2clab –help.

1E2C_SCENARIO_DIR="./"
2E2C_ARTIFACTS_DIR="../quickstart-huggingface/"
3
4# Examples
5# E2C_DEBUG=false
6# E2C_MUTE_ANSIBLE=false
7# E2C_MUTE_ENOSLIB=false

Deployment Validation & Experiment Results

Compared to the previous example, this experiment will run in a few minutes thanks to the GPU computing power used.

While the launch step is running, you can ssh to some of the nodes to check the logs from the supernodes or the superlinks.

$ cd scaleway_g5k
$ e2clab ssh
# You can the select which host you want to ssh to
# cat the current logs
$ tail -f /tmp/super*.log | less

If you ssh to client nodes, you can check how the GPUs are used

Once the finalize step is done, logs and the finished model are downloaded to the result folder.

Free resources

Once you are absolutely done, you can free the compute nodes by killing the G5K job and terminating the Scaleway instances:

$ cd scaleway_g5k
$ e2clab destroy .