← Explainer Library

Interactive Explainer

Federated Learning, Round by Round

Six clients with private data train a shared classifier without ever sending the data to a server. Watch FedAvg succeed on IID clients and collapse on non-IID ones; flip to FedProx and watch it recover. Then the privacy + security stack (secure aggregation, differential privacy).

Step 1

The federated setting

Data lives on $K$ clients (phones, hospitals, edge devices, sensor networks). Each client has a private dataset $\mathcal{D}_k$ it will not share. A central server coordinates training of a shared model $\theta$. Each round:

  1. Server sends $\theta$ to a random sample of clients.
  2. Each client runs $E$ local epochs of SGD on its data.
  3. Clients send back updated $\theta_k$.
  4. Server averages: $\theta \leftarrow \sum_k \frac{n_k}{n}\,\theta_k$ (FedAvg, McMahan et al., 2017).

FedAvg is one of the most cited DL papers of the decade and one of the brittlest. It works beautifully when client datasets are IID (random partition of a global dataset); it collapses when they aren't (which is most of the time in production).

Step 2

FedAvg vs FedProx — see them break and heal

Six clients, three-class 2-D classification. The non-IID slider controls how skewed each client's label distribution is. At 0, every client sees roughly uniform classes; at 1, each client sees only one or two classes. FedProx (Li et al., 2020) adds a proximal term $\frac{\mu}{2}\|\theta_k - \theta\|^2$ to each client's local objective, gently pulling local updates back toward the global model.

round 0 global acc
Global classifier on test data
Per-client class distribution
Accuracy vs rounds
What to watch. With non-IID α near 0, FedAvg converges within ~10 rounds. Push α to 1 and FedAvg oscillates or diverges — each client's local SGD overfits to its own classes and the average ends up worse than any client's local model. Switch to FedProx; the proximal term clips drift and accuracy climbs again.
Step 3

The privacy + security stack

FedAvg by itself isn't private. Sharing gradients leaks information; reconstruction attacks (Zhu et al., 2019) can recover original images from a single client update. Three layers fix this:

Practical setups in 2026: FedML, Flower, NVFlare, OpenFL all ship FedAvg/FedProx/SCAFFOLD, secure aggregation, and DP-SGD as drop-in components.

Step 4

Algorithm zoo — what to use when

AlgorithmKey ideaBest when
FedAvgPlain weight averageIID-ish clients, baseline
FedProx+ proximal term on client objectiveNon-IID, system heterogeneity
SCAFFOLDControl variates to cancel client driftStrongly non-IID, large E
FedAvgM / FedAdamServer-side momentum / AdamSlow / unstable convergence
FedDFDistillation on a server-side public setHeterogeneous client architectures
FedBNKeep BatchNorm stats local, average everything elseImage clients with different statistics
Personalised FL (pFedMe, Ditto)Per-client head, global trunkPer-client distribution drift; medical, mobile keyboards
Federated MoEMixture-of-experts where each expert is localStrongly heterogeneous clients; 2024+
Step 5

Practical pitfalls

The slogan. Federated learning works when clients differ a little; collapses when they differ a lot; needs FedProx / SCAFFOLD / personalised variants in the middle; and always needs privacy primitives if the data is private. The algorithmic part is small; the systems and threat-model parts dominate.