Tutorial: Federated Learning with NVFlare¶
Synopsis¶
This tutorial is for researchers who want to try federated learning on ELIXIR On-Cloud. You start a federated learning job with NVIDIA FLARE (NVFlare) from your terminal, follow it to the end and read its result. The job trains a small model (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: a
GA4GH WES service that runs the FL server itself and starts
one learning client per site as a GA4GH TES task. You talk
only to the WES, with ga4gh-cli, the command line tool of the GA4GH
SDK, and your own LS Login access
token.
You can start the run in two ways: with the testbed's script, which does
every step in one command (part 1), or step by step with ga4gh-cli
(part 2). How this tutorial was tested
says which steps have run against the deployed hub. The commands are for
Bash or Zsh on Linux or macOS.
A sandbox, with synthetic data only
The hub is a test service of the testbed, not a production service. The data of the sites is synthetic, and the hub chooses it; you can't bring your own data or model. Don't use the service with personal or other sensitive data. See Limits.
1. Before you start¶
You need:
- An LS Login account, and membership of the LS Login group
ECP_CLN:EOC-Compute. Only members can start runs on the hub. See Apply for compute access. - Krini, the web portal, to get your token. The hub accepts only LS Login access tokens that were issued to Krini (see step 3).
curlandjq, to check the hub (step 2).- For part 1: Git, and Python 3.12 or later. To compute the accuracy
of the model, the script also needs NumPy or
uv; it can do without them. - For part 2:
ga4gh-cli0.1.0. See Install, or step 2 of Tutorial: Your First Run from the Command Line.
The hub runs one run at a time, for all users. If someone else's run is
active, yours is refused with 409 (see Limits).
2. Check the hub¶
The hub's WES is in the Cloud Registry as nvflare-wes, of CSC - IT Center
for Science, with the ID QR0WZ7, and is verified there (see Verified
services). Its API
root is https://flare-wes.2.rahtiapp.fi/ga4gh/wes/v1. Its service info
needs no token:
curl -fsS --max-time 30 https://flare-wes.2.rahtiapp.fi/ga4gh/wes/v1/service-info \
| jq '{name, workflow_type_versions, sites: .tags.sites}'
Check: the hub answers with the workflow type NVFLARE, version
2.9, and its sites:
{
"name": "nvflare-wes",
"workflow_type_versions": {
"NVFLARE": {
"workflow_type_version": [
"2.9"
]
},
"FEDAVG": {
"workflow_type_version": [
"1.0"
]
}
},
"sites": "tesk-fi,tesk-cz,poiesis-fi,poiesis-cz"
}
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.
3. Get your token¶
Log in to Krini and copy your access token, as Copy your access
token describes. Tokens of other LS
Login clients get 401 from the hub. If you became a member of
ECP_CLN:EOC-Compute after you logged in to Krini, log out and in again
first: older tokens don't carry the group, and the hub refuses them with
403.
The token expires after a while (with LS Login, about an hour after it was issued, when you logged in to Krini; copying it doesn't extend it), and the script refuses a token with less than 5 minutes left. Your run needs the token until it ends (see Limits): copy it right before you start the run.
Part 1: Run the job with the testbed's script¶
The testbed's script scripts/sdk_run.py does what part 2 does by hand:
it downloads ga4gh-cli 0.1.0, checks its checksum, submits the job,
follows the run and prints the result. It keeps your token out of the
command line, files and output, and doesn't touch your own CLI
configuration in ~/.ga4gh-cli.
4. Get the script¶
Clone the testbed's repository, at the commit that this tutorial was written for:
git clone https://github.com/elixir-cloud-aai/nvflare-wes-testbed.git
cd nvflare-wes-testbed
git checkout c4b869b8a906b525182c1751bcff7fbb542b1460
The script needs nothing beyond Python's standard library. The script isn't in the testbed's release 0.1.0 yet.
5. Start the run¶
python3 scripts/sdk_run.py \
--wes https://flare-wes.2.rahtiapp.fi/ga4gh/wes/v1 \
--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-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:
run ID: <RUN ID>
state: COMPLETE (NVFlare job: FINISHED:COMPLETED)
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 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
Limits), so this step fails with [FAIL] the global model
couldn't be fetched, a hint for the hub's operators, and the exit status
1. That failure is expected; the run itself is done. The script also
writes a summary of the run, without your token, to
sdk-run-<RUN ID>.md in the current folder, for the testbed's results.
You can delete it.
If the script stops before the run ends, it prints STOP: and the reason:
| Status | What it means | What to do |
|---|---|---|
401 |
The hub didn't take your token: it expired, or it isn't from Krini. | Copy a new token from Krini (step 3). |
403 |
Your token is fine, but you aren't a member of ECP_CLN:EOC-Compute, or your token is older than your membership. |
Apply for compute access, or log out of Krini and in again. |
409 |
Another run is active at the hub. | Wait a few minutes and try again. |
If the run doesn't end in time, follow it again without submitting a new
one: python3 scripts/sdk_run.py --wes <WES API ROOT> --run-id <RUN ID>,
with the hub's API root from step 2. python3 scripts/sdk_run.py --help
lists all options; the testbed's Running a job from the GA4GH SDK
CLI describes them.
Part 2: Run the job step by step¶
These are the requests that the script of part 1 sends, one by one, with
your own ga4gh-cli. See Use the Command Line for the commands.
6. Configure the hub¶
Add a profile for the hub to ~/.ga4gh-cli/config.json in a text
editor, so that your other services stay as they are (see Use several
deployments with
profiles). If your file
has sections at the top level, as in Configure, move
them into a profile default next to flare, so that your other commands
keep using them. With only the hub in it, the file looks like this:
{
"profiles": {
"flare": {
"WES": {
"base_path": "https://flare-wes.2.rahtiapp.fi/ga4gh/wes/v1",
"oauth_access_token_env": "LS_LOGIN_TOKEN"
}
}
}
}
Put your token from step 3 into the variable (see Log in with LS
Login). The commands below choose the
profile with --profile flare, so your other commands keep their profile:
Check: the CLI shows the hub's service info, as in step 2:
7. Submit the job¶
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-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):
RUN_ID=$(ga4gh-cli --profile flare wes run logreg-fedavg-4 \
--type NVFLARE --type_version 2.9 \
--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}"
Check: the CLI prints the ID of the new run. For 401, 403 and
409, see the table in step 5. If the command ends with another error,
the hub may have started the run anyway: list your runs with
ga4gh-cli --profile flare wes list, and if the run isn't there, list
them again after a minute. Submit again only if it still isn't there;
otherwise, use its ID.
8. Follow the run¶
Ask for its state until it is COMPLETE (see Follow a
run). The run is QUEUED while the hub prepares
it, and RUNNING once it has sent the sites' tasks, while the sites
train:
9. Read the result¶
Get the run, and pick NVFlare's job status and the task of each site:
ga4gh-cli --profile flare wes get "$RUN_ID" \
| jq '{state, job: .outputs.flare_job_status,
tasks: [.task_logs[] | {name, state: .system_logs[-1]}]}'
Result: the run is COMPLETE, NVFlare's job FINISHED:COMPLETED, and
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
works only inside the hub's cluster (see Limits).
10. Clean up¶
Remove the token from the terminal:
The configuration file holds no token, so you can keep it for next time.
What happens under the hood¶
you (ga4gh-cli, your token)
└─> hub: GA4GH WES, with the FL server beside it CSC, Rahti
├─> checks your token with LS Login: issued to Krini,
│ and you are a member of ECP_CLN:EOC-Compute
├─> starts the FL server of the job
└─> one TES task per site, with your token
└─> proTES, the TES gateway
├─> 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
- The hub checks you. It accepts LS Login access tokens issued to
Krini, and starts runs only for members of
ECP_CLN:EOC-Compute. It asks LS Login for your groups with your token. - The hub starts the FL server, next to its WES, and one NVFlare client per site as a TES task.
- proTES sends each task to its site, and only there: the hub pins each task to the TES of its site (see proTES). 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.
- 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 updates to the server, which averages them into the federated model.
- The run ends when NVFlare's job ends; the hub then waits up to 300
seconds for the final state of each task, records it and keeps the
federated model. A run that failed says why: the hub states the reason
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. 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 and Results).
Limits¶
The hub is a testbed, and takes shortcuts (see its Shortcuts and hacks). As of 29 November 2026:
- Your tasks run as you, for as long as your token lasts. The hub sends your run's tasks to proTES with the same access token you started the run with, so at proTES they belong to you: you can see and cancel them there too. The hub keeps your token in memory for the run only. If your token expires before the run ends (with LS Login, about an hour after it was issued, when you logged in to Krini; copying it doesn't extend it), the run fails with a message that your token expired: log in to Krini again if needed, and copy a fresh token right before you start a run.
- One run at a time, for all users, and runs only in memory: a restart of the hub forgets them.
- No model download. Only the WES API is public; the federated model stays at the hub, and only its operators can fetch it.
- Fixed jobs, sites and data. The jobs come with the hub's image, the sites are the hub's, and the synthetic data comes from public addresses that the hub chooses. Sites run any job the hub sends them; there's no approval by the sites.
- Short runs only. A run must end before your token expires; the hub can't renew it. The verified runs took about two minutes.
- Not in Krini yet. Krini lists WES services from the Cloud Registry, but starting NVFlare runs from Krini hasn't been tested: see krini#133.
How this tutorial was tested¶
- Step 2 ran as written against the deployed hub on 2 December 2026,
after the switch to the four sites (see Four sites below); the
output is from that run. The registry entry and the
401for requests without a token were checked on 29 November 2026. - Part 1: the script, with the real
ga4gh-cli0.1.0, ran in the testbed's CI against a local copy of the hub, with a test identity provider: a member's run endedCOMPLETE, and a caller without the group got403(see the testbed's Tests). The same job ran on the deployed hub through proTES at both Nodes on 27 November 2026, started by the hub's operators with the hub's own token (run607ecdff). On 29 November 2026, with the hub imagesha-ab8882e, which forwards the submitter's token, a run with a member's own token (SDK CLI 0.1.0) endedCOMPLETEafter about 122 seconds (run2968ba34): site 1 ran at the TESK of the FI Node, site 2 at that of the CZ Node, and proTES made the submitter the owner of both tasks. Only the download of the global model failed (HTTP 503), as described in Limits. A run of the script by a member against the deployed hub, nvflare-wes-testbed#73, is still to be recorded in the testbed's Results. - Four sites: on 2 December 2026, the hub's sites were renamed after
their TES and Node (they were
site-1andsite-2for 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. Thejqfilters in steps 7 and 9 follow the hub's answers in the testbed's tests; they weren't run against the deployed hub.
If you follow this tutorial, please tell us what didn't work: in the Discussions or in an issue in the docs repository.
Where to go next¶
- What the testbed is, and how to run it on your own computer: NVFlare Testbed.
- How the testbed works, what it showed, and what's missing for federated learning on GA4GH services: the testbed's Report.
- To bring a Node's TES service into the federation: Tutorial: Onboard a Node.
- Other runs from the terminal: Tutorial: Your First Run from the Command Line.
- Questions: the Discussions or cloud-service@elixir-europe.org.