Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 60 additions & 27 deletions docs/researchers/tutorial-federated-learning.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ This tutorial is for researchers who want to try federated learning on
ELIXIR On-Cloud. You start a federated learning job with [NVIDIA
FLARE](https://github.com/NVIDIA/NVFlare) (NVFlare) from your terminal,
follow it to the end and read its result. The job trains a small model
(a logistic regression) at two sites, one at the FI Node, at CSC, and one
at the CZ Node, at CERIT-SC. Each site trains on its own data, and only
the model updates leave the sites. A run takes about two minutes.
(a logistic regression) at four sites: two TES implementations, TESK and
Poiesis, at each of two Nodes, the FI Node, at CSC, and the CZ Node, at
CERIT-SC. Each site trains on its own data, and only the model updates
leave the sites. A run takes about two minutes.

The job runs on the NVFlare hub of the [NVFlare Testbed][testbed]: a
[GA4GH WES][ga4gh-wes] service that runs the FL server itself and starts
Expand Down Expand Up @@ -84,11 +85,21 @@ curl -fsS --max-time 30 https://flare-wes.2.rahtiapp.fi/ga4gh/wes/v1/service-inf
]
}
},
"sites": "site-1,site-2"
"sites": "tesk-fi,tesk-cz,poiesis-fi,poiesis-cz"
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
}
```

`site-1` is the FI Node and `site-2` the CZ Node. `FEDAVG` is a simpler
Each site is a TES deployment of a Node, named after its implementation
and Node:

| Site | TES | Node |
|---|---|---|
| `tesk-fi` | TESK | FI Node, CSC |
| `tesk-cz` | TESK | CZ Node, CERIT-SC |
| `poiesis-fi` | Poiesis | FI Node, CSC |
| `poiesis-cz` | Poiesis | CZ Node, CERIT-SC |

`FEDAVG` is a simpler
federated averaging of the testbed without NVFlare, which this tutorial
doesn't use.

Expand Down Expand Up @@ -133,27 +144,32 @@ isn't in the testbed's [release 0.1.0][testbed-release] yet.
```bash
python3 scripts/sdk_run.py \
--wes https://flare-wes.2.rahtiapp.fi/ga4gh/wes/v1 \
--sites site-1,site-2 \
--nodes "FI (site 1) and CZ (site 2)"
--sites tesk-fi,tesk-cz,poiesis-fi,poiesis-cz \
--nodes "FI and CZ, TESK and Poiesis" \
--expect 1.000
```

The script asks for your token without showing it: paste it, then press
Enter. It then checks the hub's service info, submits the job
`logreg-fedavg` for both sites, and asks for the state of the run every 10
seconds, for at most 20 minutes (`--timeout` changes that).
`logreg-fedavg-4` for the four sites, and asks for the state of the run
every 10 seconds, for at most 20 minutes (`--timeout` changes that).
`--expect 1.000` is the holdout accuracy that the four-site job reaches
on the test data; the script's default, 0.975, is that of two sites.

**Check:** the script prints the run ID, the state of the run, the state
of NVFlare's job and the task of each site:

```text
run ID: <RUN ID>
state: COMPLETE (NVFlare job: FINISHED:COMPLETED)
site-1: task <TASK ID> COMPLETE at the WES
site-2: task <TASK ID> COMPLETE at the WES
tesk-fi: task <TASK ID> COMPLETE at the WES
tesk-cz: task <TASK ID> COMPLETE at the WES
poiesis-fi: task <TASK ID> COMPLETE at the WES
poiesis-cz: task <TASK ID> COMPLETE at the WES
```

`COMPLETE` with `FINISHED:COMPLETED` means that both sites took part and
the federated model was trained.
`COMPLETE` with `FINISHED:COMPLETED` means that all four sites took part
and the federated model was trained.

Then the script tries to download the model, to compute its accuracy on
held-out data. The hub doesn't serve the model publicly (see
Expand Down Expand Up @@ -225,13 +241,15 @@ ga4gh-cli --profile flare service-info --service WES | jq .workflow_type_version

An NVFlare run is a WES run with the workflow type `NVFLARE`, version
`2.9`. The workflow URL is the name of a job that the hub has; here,
`logreg-fedavg`, for two sites. The parameter `sites` says which sites take
`logreg-fedavg-4`, for four sites (`logreg-fedavg` takes two sites and
`logreg-fedavg-3` three; the hub refuses a run whose number of sites
doesn't match its job). The parameter `sites` says which sites take
part (see [Start a run](cli.md#start-a-run)):

```bash
RUN_ID=$(ga4gh-cli --profile flare wes run logreg-fedavg \
RUN_ID=$(ga4gh-cli --profile flare wes run logreg-fedavg-4 \
--type NVFLARE --type_version 2.9 \
--params '{"sites": ["site-1", "site-2"]}' \
--params '{"sites": ["tesk-fi", "tesk-cz", "poiesis-fi", "poiesis-cz"]}' \
--format json | jq -r .run_id)
echo "${RUN_ID:?no run ID, see the error above}"
```
Expand Down Expand Up @@ -265,7 +283,8 @@ ga4gh-cli --profile flare wes get "$RUN_ID" \
```

**Result:** the run is `COMPLETE`, NVFlare's job `FINISHED:COMPLETED`, and
the tasks `fl-client site-1` and `fl-client site-2` are `COMPLETE`. If the
the tasks `fl-client tesk-fi`, `fl-client tesk-cz`, `fl-client
poiesis-fi` and `fl-client poiesis-cz` are `COMPLETE`. If the
run failed, `jq .run_log` shows the hub's error.

The run's `outputs` also list `global_model`, the trained model. Its link
Expand All @@ -291,8 +310,10 @@ you (ga4gh-cli, your token)
├─> starts the FL server of the job
└─> one TES task per site, with your token
└─> proTES, the TES gateway
├─> TESK of the FI Node (site-1) CSC, Rahti
└─> TESK of the CZ Node (site-2) CERIT-SC
├─> TESK of the FI Node (tesk-fi) CSC, Rahti
├─> TESK of the CZ Node (tesk-cz) CERIT-SC
├─> Poiesis of the FI Node (poiesis-fi) CSC, Rahti
└─> Poiesis of the CZ Node (poiesis-cz) CERIT-SC
each task: an NVFlare client, which
downloads its site's data, dials out to
the FL server, and trains in rounds
Expand All @@ -304,9 +325,9 @@ you (ga4gh-cli, your token)
2. **The hub starts the FL server,** next to its WES, and one NVFlare
client per site as a TES task.
3. **proTES sends each task to its site,** and only there: the hub pins
each task to the TESK of its site (see
[proTES](../operators/services/protes.md)). Each TESK checks the token
that proTES sends, with proTES's own token. The hub sends the tasks to
each task to the TES of its site (see
[proTES](../operators/services/protes.md)). Each TES checks proTES's
own credentials: TESK its token, Poiesis its API key. The hub sends the tasks to
proTES with your token, so at proTES you own them.
4. **The clients dial out to the hub.** Nothing at the sites has to accept
connections. Each client trains on its site's data and sends only model
Expand All @@ -317,9 +338,12 @@ you (ga4gh-cli, your token)
in the run's log and, for a failed task, in the task's `system_logs`.

On real data, the federated model would be one that no site could train
alone. In the testbed's runs, it reached a holdout accuracy of 0.975,
against 0.825 and 0.875 for models trained at either site alone (see the
testbed's [Results][testbed-results]).
alone. Each site trains on its own share of the synthetic data, and each
share covers another part of it. With all four shares, the federated
model reaches a holdout accuracy of 1.000, against 0.825, 0.875, 0.925
and 0.900 for models trained on one share alone; the testbed's two-site
runs reached 0.975 (see the testbed's [Test set][testbed-testset] and
[Results][testbed-results]).

## Limits

Expand Down Expand Up @@ -352,8 +376,11 @@ hacks][testbed-shortcuts]). As of 29 November 2026:
## How this tutorial was tested

- **Step 2** ran as written against the deployed hub on 29 November 2026;
the output is from that run. The registry entry and the `401` for
requests without a token were checked on the same day.
the output is from that run, except for the sites: the four site names
shown are those of the switch on 2 December 2026 (see **Four sites**
below) and haven't been checked against the deployed hub yet. The
registry entry and the `401` for requests without a token were checked
on 29 November 2026.
- **Part 1:** the script, with the real `ga4gh-cli` 0.1.0, ran in the
testbed's CI against a local copy of the hub, with a test identity
provider: a member's run ended `COMPLETE`, and a caller without the
Expand All @@ -370,6 +397,11 @@ hacks][testbed-shortcuts]). As of 29 November 2026:
hub,
[nvflare-wes-testbed#73](https://github.com/elixir-cloud-aai/nvflare-wes-testbed/issues/73),
is still to be recorded in the testbed's [Results][testbed-results].
- **Four sites:** on 2 December 2026, the hub's sites were renamed after
their TES and Node (they were `site-1` and `site-2` for the TESKs
before), and each of the four got its own share of the data. The runs
above used two sites; the four-site job with these names hasn't been
recorded against the deployed hub yet.
- **Part 2** uses the same requests and options that the script sends to
the CLI (without the script's tag `submitted_with=ga4gh-cli`), but nobody has typed them by hand against the deployed hub
yet. The `jq` filters in steps 7 and 9 follow the hub's answers in
Expand Down Expand Up @@ -397,5 +429,6 @@ repository](https://github.com/elixir-cloud-aai/docs/issues).
[testbed-report]: <https://nvflare-wes-testbed.readthedocs.io/en/latest/outcomes/report/>
[testbed-results]: <https://nvflare-wes-testbed.readthedocs.io/en/latest/outcomes/results/>
[testbed-sdk-run]: <https://nvflare-wes-testbed.readthedocs.io/en/latest/setup/real-sites/#running-a-job-from-the-ga4gh-sdk-cli>
[testbed-testset]: <https://github.com/elixir-cloud-aai/nvflare-wes-testbed/blob/dev/testset/README.md>
[testbed-shortcuts]: <https://nvflare-wes-testbed.readthedocs.io/en/latest/testbed/shortcuts/>
[testbed-tests]: <https://nvflare-wes-testbed.readthedocs.io/en/latest/tests/>