Skip to content

Federated averaging: training where the data lives

Clients train on their own data and a server averages their weights. See how the average is weighted, why different clients drift apart, and why keeping data on the client is not the same as privacy.

Advanced ~11 min8 steps

What runs in CodeSplash

You will be able to

  • Describe one round of federated averaging and how client updates are weighted
  • Explain client drift and what more local steps do to it
  • Say what federated training protects and what it doesn't
  • Evaluate a federated model per client, not only on average

Read first

01

One round

Read

In federated averagingFederated averaging (FedAvg)Clients train locally on their own data; a server averages their weights, weighted by data size, and sends the average back., the data stays on many clients (phones, hospitals, branches). Each round:

  1. The server sends the current weights to some clients.
  2. Each client trains locally for a few epochs on its own rows.
  3. The server averages the returned weights, each client weighted by its number of rows:
w←∑knkn wk.w \leftarrow \sum_k \frac{n_k}{n}\, w_k .

In the reference's example, two clients with 30 and 70 rows return different weights, and the average lands at 1.28 and 1.86, closer to the larger client.

02

Client drift

Read

If every client's data looked alike, local training would move all of them the same way and the average would be what one big training run gives. Real clients differ: different customers, different scanners, different class balances. With many local steps, each client heads toward its own optimum, and the average of those can sit somewhere none of them would choose: client driftClient driftWhen clients' data differ, many local steps pull each client toward its own optimum and the average lands somewhere worse..

Fewer local steps reduce drift but need more communication rounds. Variants add a pull toward the global weights during local training.

03

What stays private

Read

Raw rows never leave the client, which matters for law and logistics. But the weight updates are computed from those rows, and updates can leak them: an attacker who sees one client's update can sometimes reconstruct examples or test membership. Real privacy needs more: secure aggregation, so the server only sees the sum, and differential privacy on the updates, with the same clipping and noise as DP-SGD.

04

Evaluate per client

Read

An average accuracy across clients can hide a client the global model serves badly, often the small or unusual one whose updates carried little weight. Report the score per client (or per group), and the worst one, next to the average.

Federated averaging is explained here: CodeSplash trains on one computer, where the data already sits in one place. The idea still helps when you read about models trained across organizations.

05

Predict: more local epochs

Predict

Predict first

Clients' data differ a lot. You raise the local epochs per round from 1 to 20. What changes?

Fewer rounds and no downsideFewer rounds, but more drift when clients differNo effect
Reveal

Fewer rounds, more drift. Each client moves further toward its own optimum before averaging, so the average can get worse even as communication falls.

06

What runs here

Read
07

Check: federated averaging

Checkpoint

Check yourself

Client A (25 rows) returns a weight of 4; client B (75 rows) returns 2. What weight does federated averaging produce?

Show the answer

Answer: 2.5

(25 × 4 + 75 × 2) / 100 = (100 + 150) / 100 = 2.5.

Check yourself

A vendor says federated training makes the model private because raw data never leaves the client. What's missing?

Show the answer

Answer: a

Local data is a logistics and legal benefit, not a formal privacy guarantee.

Check yourself

How should a federated model's accuracy be reported?

Show the answer

Answer: a

Small or unusual clients carry little weight in the average and can be served badly without the average showing it.

08

Recap

Recap
  • FedAvg: local training on each client, then a row-weighted average of the weights.
  • Different clients drift toward different optima; more local steps make drift worse.
  • Data staying local isn't privacy; add secure aggregation and differential privacy.
  • Report per-client scores and the worst client.

Concepts in this lesson