Search

Search papers and lessons

Client Drift

Level 4 · 14 min read

Client drift is the pull of each device's local training toward its own data, so after several local steps the averaged federated model can land away from the best shared model.

On this page

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

TL;DR

Client drift is what happens when each device in a federated system takes several training steps on its own data before the server averages the results. Each device's model slides toward the answer that fits its own data, which is not the answer that fits everyone's. The average of those slid models can end up away from the best shared model, and more local steps make the gap larger. Methods that fix drift either limit how far a device may move or add a correction to each device's update.

Builds on: Federated Learning, Stochastic Gradient Descent, Statistical Independence · Leads to: FedProx, SCAFFOLD

Where it's used

Phone keyboards. Each phone's typing history reflects its owner. One user writes in short messages with emoji, another writes long emails, and a third mostly types in a second language. A next-word model trained on each phone for several steps learns those habits strongly. Averaging the results gives a model that fits none of the phones well, which is the drift problem in its everyday form.

Hospitals sharing a model. A federated model across hospitals would see different patient mixes, different scanners and different referral patterns at each site. Each site's local training pulls the shared model toward its own population. This is an illustration of the idea, not a claim about any real deployment.

Shops in one chain. A demand model shared by the stores of a chain sees a city-centre shop that sells mostly lunch food and a suburban shop that sells mostly groceries. Each shop's local updates move the model toward its own sales pattern. The averaged model can then forecast badly for both.

How it works

Take a tiny instance with one parameter, ww, and two clients that hold equal amounts of data. Client A wants ww near 00, and client B wants ww near 44. Client B is also steeper, so its loss rises faster when ww moves away from 44.

01234502468model parameter wloss
  • client A
  • client B
  • global objective
The global objective is lowest at w = 3. After the two local steps in the walkthrough, the server holds w = 2.25, where the global loss is 3.56 rather than 3.0.

The shared best answer is the point where the average of the two clients' losses is lowest, which is w∗=3w^{\ast} = 3. From there, each client's own loss wants the model to move somewhere else, in opposite directions. The walkthrough shows what the server gets when each client takes two local steps with learning rate η=0.5\eta = 0.5 before the average.

  1. The server starts at the best shared answer. It sends w=3w = 3 to both clients. Check: the two clients' gradients at w=3w = 3 are +3+3 for A and −3-3 for B. Their average is zero, so a server that took a single averaged gradient step would not move.
  2. Client A takes two local steps. Its gradient is ww, so the first step gives w=3−0.5×3=1.5w = 3 - 0.5 \times 3 = 1.5, and the second gives w=1.5−0.5×1.5=0.75w = 1.5 - 0.5 \times 1.5 = 0.75. Check: client A is pulled toward 00, its own best answer.
  3. Client B takes two local steps. Its gradient is 3(w−4)3(w - 4), so the first step, at w=3w = 3, gives w=3+1.5=4.5w = 3 + 1.5 = 4.5. The second, at w=4.5w = 4.5, gives w=4.5−0.75=3.75w = 4.5 - 0.75 = 3.75. Check: client B is pulled toward 44, its own best answer.
  4. The server averages. The average is (0.75+3.75)/2=2.25(0.75 + 3.75) / 2 = 2.25. Check: the server has moved from 33 to 2.252.25 even though the averaged gradient at 33 was zero.
  5. Compare with the global loss. The global loss at 2.252.25 is 3.56253.5625, against 3.03.0 at the optimum. Check: the round made the shared model worse.

If the clients had taken one local step each, the average would have been 33, because a single step is the same as a single averaged gradient step. Drift starts only when a client takes a second step on its own data.

The math

Definition: Client drift

Let KK clients hold nkn_k examples each, with n=∑knkn = \sum_k n_k and weights pk=nk/np_k = n_k / n. Client kk has local objective Fk(w)F_k(w), and the global objective is the weighted average f(w)=∑kpk Fk(w)f(w) = \sum_k p_k\, F_k(w), which is the empirical risk over all the data. Client drift is the difference between the average of the clients' local models after τ\tau local steps and the model that the global gradient would have produced, caused by the local gradients ∇Fk\nabla F_k differing from the global gradient ∇f\nabla f.

The idea is most visible in the case where each local objective is a quadratic. Client kk has curvature ak>0a_k > 0 and best answer ckc_k, so Fk(w)=ak2(w−ck)2F_k(w) = \frac{a_k}{2}(w - c_k)^2. The toy in the walkthrough is this case with aA=1a_A = 1, cA=0c_A = 0, aB=3a_B = 3 and cB=4c_B = 4.

Step 2 in symbols: local steps

Each client runs τ\tau steps of gradient descent on its own objective, starting from the server's model w0w_0:

wt+1k=wtk−η ∇Fk(wtk),w0k=w0w_{t+1}^{k} = w_{t}^{k} - \eta\, \nabla F_k(w_{t}^{k}), \qquad w_0^{k} = w_0

Here η\eta is the learning rate. Each client returns wτkw_\tau^{k}. With a stochastic minibatch gradient in place of the full one, the same structure holds with extra noise.

Step 3 in symbols: the closed form for quadratics

For a quadratic, the gap to the client's own best answer shrinks by the same factor at every step:

wτk−ck=(1−ηak)τ (w0−ck)w_\tau^{k} - c_k = (1 - \eta a_k)^{\tau}\,(w_0 - c_k)

In the walkthrough, client A has 1−0.5⋅1=0.51 - 0.5 \cdot 1 = 0.5 and τ=2\tau = 2, so w2A=0+0.52⋅3=0.75w_2^A = 0 + 0.5^2 \cdot 3 = 0.75. Client B has 1−0.5⋅3=−0.51 - 0.5 \cdot 3 = -0.5, so w2B=4+(−0.5)2⋅(3−4)=3.75w_2^B = 4 + (-0.5)^2 \cdot (3 - 4) = 3.75. The factor (1−ηak)τ(1 - \eta a_k)^\tau is the key: it depends on τ\tau and on the client's own curvature, so each client's path is different.

Step 4 in symbols: the average and its bias

wˉτ=∑kpk wτk=∑kpk[ck+(1−ηak)τ(w0−ck)]\bar{w}_\tau = \sum_{k} p_k\, w_\tau^{k} = \sum_{k} p_k \bigl[c_k + (1 - \eta a_k)^{\tau}(w_0 - c_k)\bigr]

With one step, τ=1\tau = 1, this is exactly the FedSGD update, because the factor is linear in the gradient. With τ>1\tau \gt 1 the power (1−ηak)τ(1 - \eta a_k)^{\tau} is no longer linear in ηak\eta a_k, so the average depends on each client's curvature and best answer in a way that the global gradient does not capture. The difference between wˉτ\bar{w}_\tau and the FedSGD answer is the drift. In the toy, wˉ2=12(0.75+3.75)=2.25\bar{w}_2 = \tfrac{1}{2}(0.75 + 3.75) = 2.25, while the FedSGD answer is 33.

Corrections in symbols

There are two standard corrections.

FedProx adds a penalty that keeps each local model near the server's model wtw_t. Client kk minimises

Fk(w)+μ2∥w−wt∥2F_k(w) + \frac{\mu}{2}\lVert w - w_t \rVert^2

so its gradient step is ∇Fk(w)+μ(w−wt)\nabla F_k(w) + \mu (w - w_t). The parameter μ≥0\mu \ge 0 controls how far a client may move. Setting μ=0\mu = 0 gives FedAvg again.

SCAFFOLD keeps a control variate ckc_k for each client, which estimates that client's gradient, and a server control c=∑kpkckc = \sum_k p_k c_k. Each local step uses the corrected direction

∇Fk(w)−ck+c\nabla F_k(w) - c_k + c

When the controls are exact, the average over clients is

∑kpk(∇Fk(w)−ck+c)=∇f(w)−c+c=∇f(w)\sum_k p_k\bigl(\nabla F_k(w) - c_k + c\bigr) = \nabla f(w) - c + c = \nabla f(w)

so the average of the corrected steps is the global gradient step. The correction removes the systematic part of the drift. The control variates are updated after each round, and they add communication, since each client sends one more vector.

Worked examples

Example
1. One local step: no drift
  1. Start the server at w0=2w_0 = 2 with learning rate η=0.5\eta = 0.5. Client A has FA(w)=12w2F_A(w) = \tfrac{1}{2}w^2, so its gradient at 22 is 22. Client B has FB(w)=32(w−4)2F_B(w) = \tfrac{3}{2}(w - 4)^2, so its gradient at 22 is 3(2−4)=−63(2 - 4) = -6.
  2. Each client takes one step. Client A gives 2−0.5×2=12 - 0.5 \times 2 = 1. Client B gives 2−0.5×(−6)=52 - 0.5 \times (-6) = 5.
  3. The average is (1+5)/2=3(1 + 5) / 2 = 3.
  4. For comparison, the averaged gradient is 12(2)+12(−6)=−2\tfrac{1}{2}(2) + \tfrac{1}{2}(-6) = -2, so one FedSGD step gives 2−0.5×(−2)=32 - 0.5 \times (-2) = 3.
  5. Interpretation: the two answers match. With one local step, averaging the local models is the same as taking one averaged gradient step, so no drift happens.
Example
2. Two local steps: the standard drift case
  1. Start at the best shared answer, w0=3w_0 = 3, with η=0.5\eta = 0.5 and τ=2\tau = 2 local steps.
  2. Client A: 3→3−0.5×3=1.5→1.5−0.5×1.5=0.753 \to 3 - 0.5 \times 3 = 1.5 \to 1.5 - 0.5 \times 1.5 = 0.75.
  3. Client B: 3→3−0.5×(−3)=4.5→4.5−0.5×1.5=3.753 \to 3 - 0.5 \times (-3) = 4.5 \to 4.5 - 0.5 \times 1.5 = 3.75.
  4. The average is (0.75+3.75)/2=2.25(0.75 + 3.75) / 2 = 2.25, and the distance from the optimum is 0.750.75.
  5. The global loss f(w)=14w2+34(w−4)2f(w) = \tfrac{1}{4}w^2 + \tfrac{3}{4}(w - 4)^2 is 3.03.0 at w=3w = 3 and 3.56253.5625 at w=2.25w = 2.25.
  6. Interpretation: the server did nothing useful in the round. Each client moved a long way toward its own answer, and the moves partly cancelled, but the cancellation left the average off the optimum.
Example
3. A control-variate correction on a realistic schedule

Here the server starts at w0=2w_0 = 2, away from the optimum, and both clients use two local steps with η=0.5\eta = 0.5. Suppose the controls are set to each client's gradient at the optimum: cA=3c_A = 3 and cB=−3c_B = -3, so the server control is c=12(3)+12(−3)=0c = \tfrac{1}{2}(3) + \tfrac{1}{2}(-3) = 0. In a real system these controls are estimated and updated each round, so this is a simplified case.

  1. Plain FedAvg from w0=2w_0 = 2. Client A: 2→1→0.52 \to 1 \to 0.5. Client B: 2→5→3.52 \to 5 \to 3.5. The average is (0.5+3.5)/2=2.0(0.5 + 3.5) / 2 = 2.0, which is 1.01.0 from the optimum.
  2. SCAFFOLD, client A. The first corrected direction is ∇FA(2)−cA+c=2−3+0=−1\nabla F_A(2) - c_A + c = 2 - 3 + 0 = -1, so w=2+0.5=2.5w = 2 + 0.5 = 2.5. The second is ∇FA(2.5)−3=−0.5\nabla F_A(2.5) - 3 = -0.5, so w=2.5+0.25=2.75w = 2.5 + 0.25 = 2.75.
  3. SCAFFOLD, client B. The first corrected direction is −6−(−3)=−3-6 - (-3) = -3, so w=2+1.5=3.5w = 2 + 1.5 = 3.5. The second is 3(3.5−4)+3=1.53(3.5 - 4) + 3 = 1.5, so w=3.5−0.75=2.75w = 3.5 - 0.75 = 2.75.
  4. The average is (2.75+2.75)/2=2.75(2.75 + 2.75) / 2 = 2.75, which is 0.250.25 from the optimum.
  5. Interpretation: the first corrected step equals the averaged global gradient, −2-2, so the correction removes the systematic part of drift. The remaining gap comes from the controls being stale after the first step.

Try it: in Example 3, how much closer to the optimum is the SCAFFOLD average than the FedAvg average? Answer: FedAvg is 1.01.0 from 33, SCAFFOLD is 0.250.25 from 33, so SCAFFOLD is 0.750.75 closer.

Common mistakes and tradeoffs

It is tempting to think that more local steps always help. In fact local steps save communication, but each extra step lets a client move further toward its own answer. Drift grows with the number of local steps and with how different the clients are, so the best τ\tau depends on the data.

It is tempting to think that drift only happens with non-IID data. In fact drift needs clients whose best answers differ. If the data are independent and identically distributed, the clients' best answers are close and the drift is small. Real phone or hospital data are rarely that close, which is why the problem shows up in practice.

It is tempting to think that averaging removes drift. In fact averaging cancels random noise, but it does not cancel a systematic pull. In the walkthrough the two clients pulled in opposite directions, but client A moved 2.252.25 toward 00 while client B moved only 0.750.75 toward 44. The moves were unequal, so they did not cancel and the average landed away from the optimum.

ApproachWhat it changesExtra costWhen it helps
FedAvgnothing; plain local steps and averagingnonedata are close to IID, or τ\tau is small
One local step (FedSGD)τ=1\tau = 1, so no driftmany more communication roundsvery heterogeneous data, cheap communication
FedProxa penalty μ2∥w−wt∥2\tfrac{\mu}{2}\lVert w - w_t \rVert^2 keeps clients near the servera tuning parameter μ\mu, slower local progressmoderate heterogeneity
SCAFFOLDcontrol variates correct each local stepone extra vector per client per roundstrong heterogeneity, when extra traffic is acceptable

When to use a correction. Use one when clients have different best answers, when they take several local steps, and when the server can afford the extra traffic.

When not to use one. If the clients are close to IID or take only a few steps, plain FedAvg is simpler and usually good enough. A correction adds a parameter to tune or a state to store on every device.

History

FedAvg, introduced in 2016, showed that averaging locally trained models works well in practice, and its experiments included non-IID splits of the data, where each client's data is not a fair sample of the whole. Later work named the cause. In 2018, Li and colleagues introduced FedProx, which adds the proximal penalty to keep local models near the server's model. In 2019, Karimireddy and colleagues introduced SCAFFOLD, which uses control variates, and the SCAFFOLD paper uses the term client drift for the effect. Both papers are now standard references for heterogeneous federated learning.

Recap

  • Each client takes several local steps toward its own best answer, which is cheap and saves communication.
  • With several local steps, the averaged model is pulled away from the global optimum, and the pull depends on how different the clients are. This is client drift.
  • With one local step, averaging is the same as a global gradient step, so drift needs at least two local steps and different client optima.
  • FedProx limits how far each client moves, and SCAFFOLD corrects each local step with control variates so the average follows the global gradient.
  • Read next: the FedProx paper for the proximal penalty, the SCAFFOLD paper for control variates, and the FedAvg paper for the baseline.

Check yourself

QuestionTwo clients take one local step each from w0=3w_0 = 3 with η=0.5\eta = 0.5. Client A's gradient at 33 is 33 and client B's is −3-3. What is the average after the step, and why does it match a FedSGD step?Show answer

Client A moves to 3−0.5×3=1.53 - 0.5 \times 3 = 1.5 and client B to 3+1.5=4.53 + 1.5 = 4.5. The average is (1.5+4.5)/2=3(1.5 + 4.5) / 2 = 3. A FedSGD step uses the averaged gradient 12(3)+12(−3)=0\tfrac{1}{2}(3) + \tfrac{1}{2}(-3) = 0, which gives 33 as well. With one local step the average of the local models is always the same as one averaged gradient step, so there is no drift.

QuestionIn the walkthrough with τ=2\tau = 2, why does client B end at 3.753.75 rather than at 44, its best answer?Show answer

Each step closes only part of the gap to 44. The factor is (1−ηaB)=1−0.5×3=−0.5(1 - \eta a_B) = 1 - 0.5 \times 3 = -0.5. After two steps the gap from 44 is (−0.5)2×(3−4)=−0.25(-0.5)^2 \times (3 - 4) = -0.25, so client B is at 3.753.75. Two steps are not enough for client B to reach its best answer, but they are enough to pull the average away from the global optimum.

QuestionA team sees that its federated model improves when it cuts the number of local steps from 20 to 2, even though the clients are unchanged. What does this suggest, and what is the cost?Show answer

It suggests that client drift is significant: with 20 local steps, each device drifts far toward its own data, and the average is pulled away from the shared optimum. The cost is communication: with 2 local steps, each round does less work per device, so more rounds are needed for the same progress.

QuestionA server wants to use SCAFFOLD on a network of devices with very different data. Give one reason it is a good fit and one reason it might be too expensive.Show answer

It is a good fit because the control variates correct the systematic pull of each device's local gradient, so the average follows the global gradient even when devices differ strongly. It might be too expensive because each device stores a control variate and sends an extra vector every round, which adds traffic on links that may already be slow.

Sources