Search

Search papers and lessons

SCAFFOLD: Stochastic Controlled Averaging for Federated Learning

Sai Praneeth Karimireddy, Satyen Kale, Mehryar Mohri et al. · 2019

Karimireddy and colleagues show that federated averaging slows down when devices hold different data, and fix it with SCAFFOLD, which corrects each device's steps with control variates.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Linear algebra
  • Neural network basics
  • Optimizers
  • ReadReady to readNot yet

TL;DR

Federated learning trains one model across many devices or hospitals while the data stays where it was collected. The standard method, FedAvg, lets each participating device take several local gradient steps before the server averages the results. When the devices hold very different data, their local steps pull in different directions, an effect the paper calls client drift, and convergence becomes slow and unstable. SCAFFOLD adds a control variate to every local step, so each device corrects its direction toward the global gradient. It needs fewer communication rounds on heterogeneous data and is relatively unaffected by which clients are sampled.

Builds on: Communication-Efficient Learning of Deep Networks from Decentralized Data, Federated Learning, Stochastic Gradient Descent, Control Variate, Client Drift · Leads to: Adaptive Federated Optimization, Advances and Open Problems in Federated Learning

Why it mattered

The paper gives a rigorous account of when federated averaging is slow and a method that avoids the slowdown without sending more data. Its analysis allows clients whose data are arbitrarily different, with no assumption on how similar they are. The authors also show that for quadratic losses, taking several local steps can help rather than hurt when the clients are similar. The abstract calls this the first result to quantify the usefulness of local steps in distributed optimization.

The paper is also a clear example of a general idea: if you know a per-client bias, you can estimate it and subtract it. The same move appears in variance reduction for single-machine stochastic optimization, and SCAFFOLD makes that link explicit by describing its correction as client-variance reduction.

Federated averaging, described in Communication-Efficient Learning of Deep Networks from Decentralized Data, is in the paper's words the algorithm of choice for federated learning. Zhao and colleagues (2018) first observed that performance drops on non-identical client data. Earlier analyses bounded the resulting drift with strong assumptions about gradients or client optima. This paper proves rates for FedAvg without such assumptions and then removes the drift with control variates.

The problem

Federated learning has three hard constraints. Communication between server and clients is slow and unreliable. Only a small subset of clients is available in a given round. And the data on different clients is heterogeneous, so each client's loss has its own minimum. The most popular method, FedAvg, reduces communication by running several local steps per round. The heterogeneity is where it breaks.

Each client moves toward its own minimum during its local steps. The server then averages those moves, and the average points toward the mean of the client minima, which is not the minimum of the global loss. The gap between the two is the drift. To stop the drift from overwhelming the progress, FedAvg must use smaller step sizes, and smaller steps mean more rounds.

The paper makes this precise. Its Theorem I gives FedAvg convergence rates that depend on a gradient-dissimilarity constant GG. Its Theorem II gives a lower bound: for some strongly convex problems, FedAvg's error after RR rounds is at least of order G2/(μR2)G^2/(\mu R^2), even with no noise and no client sampling. The paper also notes that plain SGD can be faster than FedAvg on such problems. The question is whether the drift can be removed without losing the savings from local steps.

How it works

SCAFFOLD keeps one extra vector per client and one for the server, and uses their difference to correct every local step. Here is one tiny instance, with two clients and one number as the model.

Client 1 has loss f1(x)=12x2f_1(x) = \tfrac{1}{2}x^2, so its minimum is at 0. Client 2 has loss f2(x)=12(x−4)2f_2(x) = \tfrac{1}{2}(x-4)^2, with its minimum at 4. The global loss is the average f(x)=14x2+14(x−4)2f(x) = \tfrac{1}{4}x^2 + \tfrac{1}{4}(x-4)^2, whose minimum is at 2. The plot shows the three curves.

−101234502468model xloss
  • client 1 loss f_1
  • client 2 loss f_2
  • global loss f
Each client's minimum is far from the global minimum. The corrected steps aim at the global gradient, which is zero at x = 2.
  1. Start. The server model is x=0x = 0. Suppose the control variates already hold the clients' gradients at the global optimum: client 1 holds c1=2c_1 = 2 (its gradient f1′(2)=2f_1'(2) = 2), client 2 holds c2=−2c_2 = -2 (its gradient f2′(2)=−2f_2'(2) = -2), and the server holds c=0c = 0, their average. Check: cc is the average of the cic_i.
  2. Compute the corrected direction. Each local step uses the raw gradient minus the client's control variate plus the server's: gi(y)−ci+cg_i(y) - c_i + c. At the first local point y=0y = 0, client 1's raw gradient is 00, and its corrected direction is 0−2+0=−20 - 2 + 0 = -2. Client 2's raw gradient is 0−4=−40 - 4 = -4, and its corrected direction is −4−(−2)+0=−2-4 - (-2) + 0 = -2. Check: both corrected directions equal −2-2, the average raw gradient (0−4)/2=−2(0 - 4)/2 = -2.
  3. Take the local step. With local step size ηl=0.5\eta_l = 0.5, each client moves by −ηl-\eta_l times its corrected direction. Both move from 0 to 0−0.5⋅(−2)=10 - 0.5 \cdot (-2) = 1. Check: both clients are now at the same point, 1.
  4. Repeat for the second local step. At y=1y = 1, client 1's corrected direction is 1−2=−11 - 2 = -1, and client 2's is (1−4)−(−2)=−1(1 - 4) - (-2) = -1. Both step to 1−0.5⋅(−1)=1.51 - 0.5 \cdot (-1) = 1.5. Check: both clients agree again.
  5. Update the control variate. Each client refreshes cic_i from the steps it just took (the paper's option II), so the next round starts from a better estimate of its own gradient. The server then averages the changes.
  6. Aggregate. The server model moves by the average client change, x←x+ηg⋅12((1.5−0)+(1.5−0))=0+1.5=1.5x \leftarrow x + \eta_g \cdot \tfrac{1}{2}\big((1.5 - 0) + (1.5 - 0)\big) = 0 + 1.5 = 1.5, with global step size ηg=1\eta_g = 1. Check: the server moved toward the global minimum at 2.

The pattern is what matters. Without the correction, the two clients would walk toward their own minima and end at different points, one at 0 and one at 3 in this run. The correction makes the two local paths identical, so every local step follows the average gradient. In this run the FedAvg average also lands at 1.5, but only because the two drifts are symmetric and cancel. The paper's point is that FedAvg's average is biased in general, while the corrected steps are not.

flowchart LR
  S["Server sends model x and control variate c"] --> C["Sampled clients take K corrected local steps"]
  C --> U["Each client refreshes its own c_i"]
  U --> A["Server averages the changes in x and c"]
  A --> S

Second round

Start round 2 from the server model x=1.5x = 1.5 reached at the end of round 1. Option II has refreshed the variates: client 1 holds c1=0.5c_1 = 0.5, client 2 holds c2=−3.5c_2 = -3.5, and the server holds c=−1.5c = -1.5, which is their average. Each variate was computed as ci−c+(x−yi)/(Kηl)c_i - c + (x - y_i)/(K\eta_l) from round 1, for example 2−0+(0−1.5)/1=0.52 - 0 + (0 - 1.5)/1 = 0.5 for client 1.

Example
The standard case, a second round
  1. At y=1.5y = 1.5, client 1's raw gradient is 1.51.5. Its corrected direction is 1.5−0.5+(−1.5)=−0.51.5 - 0.5 + (-1.5) = -0.5.
  2. Client 2's raw gradient is 1.5−4=−2.51.5 - 4 = -2.5. Its corrected direction is −2.5−(−3.5)+(−1.5)=−0.5-2.5 - (-3.5) + (-1.5) = -0.5.
  3. Both match the global gradient f′(1.5)=1.5−2=−0.5f'(1.5) = 1.5 - 2 = -0.5, and both move by −0.5⋅(−0.5)=0.25-0.5 \cdot (-0.5) = 0.25 to 1.751.75.
  4. At y=1.75y = 1.75, the two corrected directions are −0.25-0.25 each. Both move to 1.75+0.125=1.8751.75 + 0.125 = 1.875.
  5. The server moves by the average client change, 1.5+(1.875−1.5)=1.8751.5 + (1.875 - 1.5) = 1.875.

Interpretation: the error to the optimum at 2 went from 0.5 after round 1 to 0.125 after round 2, shrinking by a factor of 4 per round. The clients stayed in lockstep, and the corrected direction matched the global gradient at every step.

The math

Definition: the SCAFFOLD round. There are NN clients, SS of them are sampled each round, and each sampled client takes KK local steps with step size ηl\eta_l. The server has model x\mathbf{x} and control variate c\mathbf{c}. Each client ii has its own control variate ci\mathbf{c}_i, and gig_i is its stochastic gradient. The global loss is f(x)=1N∑ifi(x)f(\mathbf{x}) = \tfrac{1}{N}\sum_i f_i(\mathbf{x}).

Step 1 in symbols: the corrected local step

For a sampled client ii starting from yi←x\mathbf{y}_i \leftarrow \mathbf{x}, each of the KK steps is

yi←yi−ηl(gi(yi)−ci+c).\mathbf{y}_i \leftarrow \mathbf{y}_i - \eta_l \big( g_i(\mathbf{y}_i) - \mathbf{c}_i + \mathbf{c} \big).

The term c−ci\mathbf{c} - \mathbf{c}_i is the correction. In the worked example it was 0−2=−20 - 2 = -2 for client 1 and 0−(−2)=20 - (-2) = 2 for client 2, which turned both raw gradients into the same direction.

Step 2 in symbols: updating the client control variate

After its local steps, client ii computes a new control variate ci+\mathbf{c}_i^{+}. The paper gives two options:

ci+={gi(x)(option I)ci−c+1Kηl(x−yi)(option II)\mathbf{c}_i^{+} = \begin{cases} g_i(\mathbf{x}) & \text{(option I)} \\ \mathbf{c}_i - \mathbf{c} + \tfrac{1}{K\eta_l}(\mathbf{x} - \mathbf{y}_i) & \text{(option II)} \end{cases}

Option I takes one extra pass over the local data to compute the gradient at the server model. Option II reuses the gradients from the local steps: since x−yi\mathbf{x} - \mathbf{y}_i is the sum of the local steps, option II works out to the average of the gradients computed along the local path. The paper says option II is cheaper and usually enough, and all its experiments use it.

Step 3 in symbols: aggregation

The server averages the client changes over the sampled set S\mathcal{S} and updates both variates:

x←x+ηg∣S∣∑i∈S(yi−x),c←c+1N∑i∈S(ci+−ci).\mathbf{x} \leftarrow \mathbf{x} + \frac{\eta_g}{|\mathcal{S}|} \sum_{i \in \mathcal{S}} (\mathbf{y}_i - \mathbf{x}), \qquad \mathbf{c} \leftarrow \mathbf{c} + \frac{1}{N} \sum_{i \in \mathcal{S}} (\mathbf{c}_i^{+} - \mathbf{c}_i).

The server control variate moves by the average change of the client variates, scaled by 1/N1/N rather than 1/∣S∣1/|\mathcal{S}|, so it stays the average of all clients even when only some are sampled. Setting every ci\mathbf{c}_i to zero turns the algorithm back into FedAvg.

The convergence rate in symbols

For β\beta-smooth functions with no assumption on how different the clients are, the paper's Theorem III gives, for strongly convex ff with no sampling (S=NS = N), a number of rounds of order

R=O~(σ2μNKϵ+1μ),R = \tilde{\mathcal{O}}\Big(\frac{\sigma^2}{\mu N K \epsilon} + \frac{1}{\mu}\Big),

where σ2\sigma^2 bounds the gradient noise, μ\mu is the strong-convexity constant, and ϵ\epsilon is the target error. The heterogeneity constant GG is absent. Compare this with FedAvg's rate in Theorem I, which has the extra term (1−S/N)G2/(μSϵ)(1 - S/N) G^2/(\mu S \epsilon) and a G/(μϵ)G/(\mu\sqrt{\epsilon}) term that grows with the heterogeneity.

Results

Simulated quadratics. The paper uses two clients with full-batch gradients and no noise. FedAvg slows as the number of local steps grows and as the gradient dissimilarity GG grows. SCAFFOLD is unaffected by GG, and with K=10K = 10 it is about 5 times faster than SGD, while K=2K = 2 is twice as fast. The gain from more local steps is sublinear because the clients differ in their Hessians, which Theorem IV says limits the benefit.

EMNIST logistic regression. The paper splits EMNIST across 100 clients. Each client gets s%s\% of i.i.d. data and the rest sorted by label, so 0% similarity means fully sorted data. Table 4 gives communication rounds to reach 0.45 test accuracy with 5 epochs per round.

MethodSampled clients0% similarity10% similarity
SCAFFOLD20%1439
SCAFFOLD5%29013
SCAFFOLD1%79028
FedAvg20%17912
FedAvg5%33417
FedAvg1%1k+35

The paper's reading is that SCAFFOLD is consistently faster than FedAvg, and that its slowdown under sampling is sublinear, better still for more similar clients.

EMNIST two-layer network. Table 5 gives the best test accuracy after 1,000 rounds, with 20% of clients sampled and 5 epochs per round.

Method0% similarity10% similarity
SGD0.7660.764
FedAvg0.7870.828
SCAFFOLD0.8010.842

The paper's reading is that SCAFFOLD gives the best accuracy in both settings, and that SGD does not improve with similarity while the local methods do.

Example
A realistic case: the sampling sweep
  1. Compare FedAvg and SCAFFOLD at 20% sampling with 0% similarity: 179/143≈1.25179 / 143 \approx 1.25, so FedAvg needs about a quarter more rounds on this run.
  2. Drop to 1% sampling, so one round touches one client in a hundred. SCAFFOLD now needs 790 rounds, while FedAvg does not reach 0.45 within 1,000 rounds.
  3. Repeat with 10% similarity, where clients hold more mixed data. SCAFFOLD needs 9 rounds at 20% sampling and 28 at 1%. FedAvg needs 12 and 35.
  4. Interpretation: sampling fewer clients slows both methods by a similar factor, and SCAFFOLD needs fewer rounds at every sampling level. The control variates are meant to let the sampled clients stand in for the whole population. Try it: from the 20% and 1% rows with 0% similarity, how many times more rounds does SCAFFOLD need at 1% than at 20%? Answer: 790/143≈5.5790 / 143 \approx 5.5, which matches the 5.5 times in the table.

Common mistakes and tradeoffs

It is tempting to think SCAFFOLD removes heterogeneity from the problem. In fact it removes the effect of heterogeneity on the local steps, but each client still has its own minimum. The control variates let the local steps follow the global gradient. They do not make the data more similar.

It is tempting to think SCAFFOLD is free because it uses the same number of rounds. In fact each client sends both its model change and its control variate change in every round, so each message carries two vectors instead of one. The paper compares methods by rounds, not bytes. The saving is real only if fewer rounds outweigh the larger messages.

It is tempting to think more local steps always help. In fact on heterogeneous data FedAvg gets worse as KK grows, while SCAFFOLD benefits. For identical clients, the paper's Theorem IV gives a complexity whose second term falls as 1/(μK)1/(\mu K), so local steps help in proportion to KK. For clients that are similar but not identical, the bound's second term is β/(μK)+δ/μ\beta/(\mu K) + \delta/\mu, so extra local steps help less and less once the δ/μ\delta/\mu floor dominates. This is why the experiments show sublinear gains from KK.

It is tempting to think the server must hold every client's state. In fact the server holds one vector c\mathbf{c}, but each client must store its own ci\mathbf{c}_i across rounds, because the paper's clients are stateful.

When to use SCAFFOLD. Use it when the clients' data differ a lot, when only a fraction of clients are sampled per round, and when a client can keep a vector of state between rounds. When not to. If the clients are nearly identical, FedAvg is simpler and nearly as good. If clients cannot store state, or if message size rather than round count is the bottleneck, the tradeoff changes. An alternative is FedProx, which adds a penalty that keeps each client near the global model, described in Federated Optimization in Heterogeneous Networks.

Limits

The experiments are small: a logistic regression model, a two-layer network, and one dataset. The authors say larger experiments are beyond the scope of the paper. The analysis assumes smooth losses and bounded noise, and the local-steps result covers only quadratic functions, which the paper names as an open problem for general functions. The rounds comparison also hides the doubled message size noted above.

Reading guide

The chain of ideas the paper builds, in order: FedAvg's rates under heterogeneity, then the lower bound that shows the drift is real, then the control-variate correction, then its rates without the heterogeneity term, then the advantage from local steps on similar quadratics, then experiments.

  1. Abstract and Section 1 (Introduction). Needs Federated Learning and Communication-Efficient Learning of Deep Networks from Decentralized Data. The three challenges are slow links, partial participation and heterogeneous data.
  2. Section 2 (Setup). Needs Stochastic Gradient Descent and Smooth Function. The sum over clients and the bounded-variance noise assumption come from there. The dissimilarity assumptions (A1) and (A2) are defined here and are the paper's vocabulary for heterogeneity.
  3. Section 3 (Convergence of FedAvg). Needs Convex Function and Strong Convexity for the rate statements, and Gradient Descent for the local step. Read Theorem I as a benchmark, not as the paper's method.
  4. Section 3.2 (Lower bound). Needs Client Drift. Theorem II explains the drift as a gap between the average of client minima and the global minimum.
  5. Section 4 (Algorithm). Needs Control Variate. Algorithm 1 and Figure 2 are the core. Re-derive the corrected step from the ideal update in equation (6), as in How it works.
  6. Section 5 (Convergence of SCAFFOLD). Theorem III is the main result. Its rate has no heterogeneity term.
  7. Section 6 (Local steps). Needs only the second derivative (the Hessian) and Smooth Function. Theorem IV and the Hessian argument are the paper's novel contribution for quadratics.
  8. Section 7 (Experiments). Tables 4 and 5 are the main evidence for the claims above.
  9. Appendices. Appendix E holds the full convergence proofs; Appendix F covers the quadratic case.

Read next: Communication-Efficient Learning of Deep Networks from Decentralized Data for the baseline the paper improves on, and Federated Optimization in Heterogeneous Networks for another answer to the same heterogeneity problem. Adaptive Federated Optimization takes the server side of federated learning further.

Check yourself

QuestionIn one sentence, what is client drift, and why does it force FedAvg to use smaller step sizes?Show answer

Client drift is the movement of each client's local model toward its own minimum during local steps, so the average of the client updates points toward the mean of the client minima instead of the global minimum. To keep the drift from overwhelming progress, FedAvg must shrink the step size, and smaller steps need more rounds.

QuestionIn the tiny example, client 1 has control variate 2 and client 2 has control variate -2, and both raw gradients at 0 are 0 and -4. What is client 2's corrected direction at 0, and why does it match client 1's?Show answer

The corrected direction is −4−(−2)+0=−2-4 - (-2) + 0 = -2. Client 1's corrected direction is 0−2+0=−20 - 2 + 0 = -2. They match because the correction turns each raw gradient into its deviation from its own control variate plus the server value, and here both come out to the average raw gradient (0−4)/2=−2(0 - 4)/2 = -2.

QuestionWhy does the server update the control variate c with a factor of 1/N rather than 1/|S|?Show answer

The control variate c is supposed to equal the average of all NN client variates. A client that is not sampled keeps its old ci\mathbf{c}_i, so the sum over sampled clients must be divided by NN to keep c\mathbf{c} as the average over all clients, even when only some of them changed.

QuestionIn the EMNIST 0% similarity runs, SCAFFOLD needs 143 rounds with 20% of clients sampled and 790 rounds with 1%. What is the ratio, and what does it say about sampling?Show answer

The ratio is 790/143≈5.5790 / 143 \approx 5.5. Sampling 1% of clients rather than 20% makes SCAFFOLD about 5.5 times slower in rounds. Participation fell by a factor of 20, but rounds rose only about 5.5 times, so the slowdown is sublinear.

QuestionSuppose you run SCAFFOLD on clients whose data are all identical. Would you expect the control variates to matter much? Explain using the paper's Theorem IV reasoning.Show answer

Probably not much. If the clients are identical, the gradients are the same, so the control variates are nearly equal and the correction c−ci\mathbf{c} - \mathbf{c}_i is close to zero. The paper's Theorem IV says that for identical functions the complexity's second term falls as 1/(μK)1/(\mu K), so local steps help SCAFFOLD on identical clients. The control variates contribute little there, because the correction they supply is already near zero.

Sources

Read the full paper

Sai Praneeth Karimireddy, Satyen Kale, Mehryar Mohri et al., 2019. arXiv:1910.06378