Skip to content

Commit 3a72c98

Browse files
kminhtateoparvanov
andauthored
[Task Runner API] [Flower Interoperability] Pull ConnectorFlower, FlowerTaskRunner/FlowerDataLoader, and FlowerInteropServer/FlowerInteropClient into core OpenFL (#1633)
* integrate flower collaborator into core collaborator Signed-off-by: kta-intel <[email protected]> * formatting Signed-off-by: kta-intel <[email protected]> * change task name interop -> prepare_for_interop, change references to local_grpc_server to interop_server Signed-off-by: kta-intel <[email protected]> * add prepare_interop_server as callback to run on_experiment_begin Signed-off-by: kta-intel <[email protected]> * fix typo Signed-off-by: kta-intel <[email protected]> * change to on_round_begin() Signed-off-by: kta-intel <[email protected]> * return empty dict Signed-off-by: kta-intel <[email protected]> * set self.prepare_interop_server() to run on experiment begin Signed-off-by: kta-intel <[email protected]> * remove self-explanatory comment, added another comment for clarity Signed-off-by: kta-intel <[email protected]> * fix plan parsing and automatic assignment of grpc ports Signed-off-by: kta-intel <[email protected]> * move taskrunner and dataloader to core openfl.federated Signed-off-by: kta-intel <[email protected]> * move connector and interop components to core openfl Signed-off-by: kta-intel <[email protected]> * remove comments about patch Signed-off-by: kta-intel <[email protected]> * remove collaborator number setting, it is not being used Signed-off-by: kta-intel <[email protected]> * adjust handling of flower directory. enabling user configuration with default location and use openfl's directory traversal check Signed-off-by: kta-intel <[email protected]> * exit system if error Signed-off-by: kta-intel <[email protected]> * update REAMDE.md Signed-off-by: kta-intel <[email protected]> * update docstring Signed-off-by: kta-intel <[email protected]> * override self.port Signed-off-by: kta-intel <[email protected]> * remove tasks_connector.yaml Signed-off-by: kta-intel <[email protected]> * updates Signed-off-by: kta-intel <[email protected]> * pin flwr Signed-off-by: kta-intel <[email protected]> * remove time Signed-off-by: kta-intel <[email protected]> * formatting Signed-off-by: kta-intel <[email protected]> * formatting Signed-off-by: kta-intel <[email protected]> * formatting Signed-off-by: kta-intel <[email protected]> * copyright Signed-off-by: kta-intel <[email protected]> --------- Signed-off-by: kta-intel <[email protected]> Co-authored-by: teoparvanov <[email protected]>
1 parent cf0b4ff commit 3a72c98

File tree

28 files changed

+384
-224
lines changed

28 files changed

+384
-224
lines changed

openfl-workspace/flower-app-pytorch/README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Then create a certificate authority (CA)
2828
fx workspace certify
2929
```
3030

31-
This will create a workspace in your current working directory called `./my_workspace` as well as install the Flower app defined in `./app-pytorch.` This will be where the experiment takes place. The CA will be used to sign the certificates of the collaborators.
31+
This will create a workspace in your current working directory called `./my_workspace` as well as install the Flower app defined in `./src/app-pytorch.` This will be where the experiment takes place. The CA will be used to sign the certificates of the collaborators.
3232

3333
### Setup Data
3434
We will be using CIFAR10 dataset. You can install an automatically partition it into 2 using the `./src/setup_data.py` script provided.
@@ -63,44 +63,52 @@ data/
6363
Notice under `./plan`, you will find the familiar OpenFL YAML files to configure the experiment. `cols.yaml` and `data.yaml` will be populated by the collaborators that will run the Flower client app and the respective data shard or directory they will perform their training and testing on.
6464
`plan.yaml` configures the experiment itself. The Open-Flower integration makes a few key changes to the `plan.yaml`:
6565

66-
1. Introduction of a new top-level key (`connector`) to configure a newly introduced component called `ConnectorFlower`. This component is run by the aggregator and is responsible for initializing the Flower `SuperLink` and connecting to the OpenFL server. The `SuperLink` parameters can be configured using `connector.settings.superlink_params`. If nothing is supplied, it will simply run `flower-superlink --insecure` with the command's default settings as dictated by Flower. It also includes the option to run the flwr run command via `connector.settings.flwr_run_params`. If `flwr_run_params` are not provided, the user will be expected to run `flwr run <app>` from the aggregator machine to initiate the experiment. Additionally, the `ConnectorFlower` has an additional setting `connector.settings.automatic_shutdown` which is default set to `True`. When set to `True`, the task runner will shut the SuperNode at the completion of an experiment, otherwise, it will run continuously.
66+
1. Introduction of a new top-level key (`connector`) to configure a newly introduced component called `ConnectorFlower`. This component is run by the aggregator and is responsible for initializing the Flower `SuperLink` and connecting to the OpenFL server. Under `settings`, you will find the parameters for both the `flower-superlink` and `flower run` commands. All parameters are configuration by the user. By default, the `flower-superlink` will be run in `insecure` mode. The default `fleet_api_port` and `exec_api_port` will be automatically assigned, while the `exec_api_port` should be set to match the address configured in `./src/app-pytorch/pyproject.toml`. This is not set dynamically. In addition, since OpenFL handles cross network communication, `superlink_host` is set to a local host by default. For the `flwr run` command, the user should ensure that the `federation_name` and `flwr_app_name` is consistent with what is defined in `./src/<flwr_app_name>` (if different than `app-pytorch`) and `./src/<flwr_app_name>/pyproject.toml`. The Flower directory `flwr_dir` is set to save the FAB in `save/.flwr`. Should a user configure this, the save directory must be located inside the workspace. Additionally, the `ConnectorFlower` has a setting `automatic_shutdown` which is default set to `True`. When set to `True`, the task runner will shut the SuperNode at the completion of an experiment, otherwise, it will run continuously.
6767

6868
```yaml
6969
connector:
7070
defaults: plan/defaults/connector.yaml
7171
template: openfl.component.ConnectorFlower
7272
settings:
73-
automatic_shutdown: True
74-
superlink_params:
75-
insecure: True
76-
serverappio-api-address: 127.0.0.1:9091
77-
fleet-api-address: 127.0.0.1:9092
78-
exec-api-address: 127.0.0.1:9093
79-
flwr_run_params:
80-
flwr_app_name: "app-pytorch"
81-
federation_name: "local-poc"
73+
automatic_shutdown: true
74+
insecure: true
75+
exec_api_port: 9093
76+
fleet_api_port: 57085
77+
serverappio_api_port: 58873
78+
federation_name: local-poc
79+
flwr_app_name: app-pytorch
80+
flwr_dir: save/.flwr
81+
superlink_host: 127.0.0.1
8282
```
8383
84-
2. `FlowerTaskRunner` which will execute the `start_client_adapter` task. This task starts the Flower SuperNode and makes a connection to the OpenFL client.
84+
2. `FlowerTaskRunner` which will execute the `start_client_adapter` task. This task starts the Flower SuperNode and makes a connection to the OpenFL client. In addition, you will notice there are settings for the `flwr_app_name`, `flwr_dir`, and `sgx_enabled`. `flwr_app_name` and `flwr_dir` are for prebuilding and installing the Flower app and should follow the convention as the `Connector` settings. `sgx_enabled` enables secure execution of the Flower `ClientApp` within an Intel<sup>®</sup> SGX enclave. When set to `True`, the task runner will launch the client app in an isolated process suitable for enclave execution and handle additional setup required for SGX compatibility (see [Running in Intel<sup>®</sup> SGX Enclave](#running-in-intel®-sgx-enclave) for details).
8585

8686
```yaml
8787
task_runner:
8888
defaults: plan/defaults/task_runner.yaml
89-
template: openfl.federated.task.runner_flower.FlowerTaskRunner
89+
template: openfl.federated.task.FlowerTaskRunner
90+
settings :
91+
flwr_app_name : app-pytorch
92+
flwr_dir : save/.flwr
93+
sgx_enabled: False
9094
```
9195

9296
3. `FlowerDataLoader` with similar high-level functionality to other dataloaders.
9397

94-
4. `Task` - we introduce a `tasks_connector.yaml` that will allow the collaborator to connect to Flower framework via the interop server. It also handles the task runner's `start_client_adapter` method, which actually starts the Flower component and interop server. By setting `local_server_port` to 0, the port is dynamically allocated. This is mainly for local experiments to avoid overlapping the ports.
98+
4. `Task` - we introduce a `tasks_connector.yaml` that will allow the collaborator to connect to Flower framework via the interop server. It also handles the task runner's `start_client_adapter` method, which actually starts the Flower component and interop server. In the `settings`, the `interop_server` points to the `FlowerInteropServer` module that will establish connect between the OpenFL client and the Flower `SuperNode`. Like the `SuperLink` the host is set to the local host because OpenFL handles cross network communication. The `interop_server_port` and `clientappio_api_port` are automatically allocated by OpenFL. Setting `local_simulation` to `True` will further offest the ports based on the collaborator names in order to avoid overlapping ports. This is not an issue when collaborators are remote.
9599

96100
```yaml
97101
tasks:
98102
prepare_for_interop:
99103
function: start_client_adapter
100-
kwargs:
101-
interop_server_port: 0
104+
kwargs: {}
102105
settings:
103-
interop_server: src.grpc.connector.flower.interop_server
106+
clientappio_api_port: 59731
107+
interop_server: openfl.transport.grpc.interop.FlowerInteropServer
108+
interop_server_host: 127.0.0.1
109+
interop_server_port: 51807
110+
local_simulation: true
111+
104112
```
105113

106114
5.`Collaborator` has an additional setting `interop_mode` which will invoke a callback to prepare the interop server that'll eventually be started by the Task Runner

openfl-workspace/flower-app-pytorch/plan/plan.yaml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ aggregator :
1010
write_logs : false
1111

1212
connector :
13-
defaults : plan/defaults/connector.yaml
14-
template : src.connector_flower.ConnectorFlower
13+
defaults : plan/defaults/connector_flower.yaml
14+
template : openfl.component.ConnectorFlower
1515
settings :
16-
automatic_shutdown : True
17-
superlink_params :
18-
insecure : True
19-
serverappio-api-address : 127.0.0.1:9091
20-
fleet-api-address : 127.0.0.1:9092
21-
exec-api-address : 127.0.0.1:9093
22-
flwr_run_params :
23-
flwr_app_name : "app-pytorch"
24-
federation_name : "local-poc"
16+
exec_api_port : 9093
17+
flwr_app_name : app-pytorch
18+
federation_name : local-poc
19+
flwr_dir : save/.flwr
2520

2621
collaborator :
2722
defaults : plan/defaults/collaborator.yaml
@@ -31,15 +26,14 @@ collaborator :
3126

3227
data_loader :
3328
defaults : plan/defaults/data_loader.yaml
34-
template : src.loader.FlowerDataLoader
35-
settings :
36-
collaborator_count : 2
29+
template : openfl.federated.data.FlowerDataLoader
3730

3831
task_runner :
3932
defaults : plan/defaults/task_runner.yaml
40-
template : src.runner.FlowerTaskRunner
33+
template : openfl.federated.task.FlowerTaskRunner
4134
settings :
42-
flwr_app_name: app-pytorch
35+
flwr_app_name : app-pytorch
36+
flwr_dir : save/.flwr
4337
sgx_enabled: False
4438

4539
network :
@@ -56,9 +50,7 @@ assigner :
5650
- prepare_for_interop
5751

5852
tasks :
59-
defaults : plan/defaults/tasks_connector.yaml
60-
settings :
61-
interop_server: src.grpc.connector.flower.interop_server
53+
defaults : plan/defaults/tasks_flower.yaml
6254

6355
compression_pipeline :
6456
defaults : plan/defaults/compression_pipeline.yaml

openfl-workspace/flower-app-pytorch/src/app-pytorch/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version = "1.0.0"
88
description = ""
99
license = "Apache-2.0"
1010
dependencies = [
11-
"flwr-nightly",
11+
"flwr-nightly==1.19.0.dev20250513",
1212
"flwr-datasets[vision]>=0.5.0",
1313
"torch==2.5.1",
1414
"torchvision==0.20.1",

openfl-workspace/flower-app-pytorch/src/grpc/__init__.py

Whitespace-only changes.

openfl-workspace/flower-app-pytorch/src/grpc/connector/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

openfl-workspace/flower-app-pytorch/src/grpc/connector/flower/__init__.py

Whitespace-only changes.

openfl-workspace/flower-app-pytorch/src/grpc/connector/utils.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

openfl-workspace/flower-app-pytorch/src/util.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

openfl-workspace/workspace/plan/defaults/connector.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
template : openfl.component.ConnectorFlower
2+
settings :
3+
automatic_shutdown : True
4+
insecure : True
5+
superlink_host : 127.0.0.1
6+
serverappio_api_port : auto
7+
fleet_api_port : auto
8+
exec_api_port : auto

0 commit comments

Comments
 (0)