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, , and two clients that hold equal amounts of data. Client A wants near , and client B wants near . Client B is also steeper, so its loss rises faster when moves away from .
- client A
- client B
- global objective
The shared best answer is the point where the average of the two clients' losses is lowest, which is . 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 before the average.
- The server starts at the best shared answer. It sends to both clients. Check: the two clients' gradients at are for A and for B. Their average is zero, so a server that took a single averaged gradient step would not move.
- Client A takes two local steps. Its gradient is , so the first step gives , and the second gives . Check: client A is pulled toward , its own best answer.
- Client B takes two local steps. Its gradient is , so the first step, at , gives . The second, at , gives . Check: client B is pulled toward , its own best answer.
- The server averages. The average is . Check: the server has moved from to even though the averaged gradient at was zero.
- Compare with the global loss. The global loss at is , against 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 , 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
Let clients hold examples each, with and weights . Client has local objective , and the global objective is the weighted average , which is the empirical risk over all the data. Client drift is the difference between the average of the clients' local models after local steps and the model that the global gradient would have produced, caused by the local gradients differing from the global gradient .
The idea is most visible in the case where each local objective is a quadratic. Client has curvature and best answer , so . The toy in the walkthrough is this case with , , and .
Step 2 in symbols: local steps
Each client runs steps of gradient descent on its own objective, starting from the server's model :
Here is the learning rate. Each client returns . 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:
In the walkthrough, client A has and , so . Client B has , so . The factor is the key: it depends on and on the client's own curvature, so each client's path is different.
Step 4 in symbols: the average and its bias
With one step, , this is exactly the FedSGD update, because the factor is linear in the gradient. With the power is no longer linear in , 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 and the FedSGD answer is the drift. In the toy, , while the FedSGD answer is .
Corrections in symbols
There are two standard corrections.
FedProx adds a penalty that keeps each local model near the server's model . Client minimises
so its gradient step is . The parameter controls how far a client may move. Setting gives FedAvg again.
SCAFFOLD keeps a control variate for each client, which estimates that client's gradient, and a server control . Each local step uses the corrected direction
When the controls are exact, the average over clients is
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
- Start the server at with learning rate . Client A has , so its gradient at is . Client B has , so its gradient at is .
- Each client takes one step. Client A gives . Client B gives .
- The average is .
- For comparison, the averaged gradient is , so one FedSGD step gives .
- 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.
- Start at the best shared answer, , with and local steps.
- Client A: .
- Client B: .
- The average is , and the distance from the optimum is .
- The global loss is at and at .
- 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.
Here the server starts at , away from the optimum, and both clients use two local steps with . Suppose the controls are set to each client's gradient at the optimum: and , so the server control is . In a real system these controls are estimated and updated each round, so this is a simplified case.
- Plain FedAvg from . Client A: . Client B: . The average is , which is from the optimum.
- SCAFFOLD, client A. The first corrected direction is , so . The second is , so .
- SCAFFOLD, client B. The first corrected direction is , so . The second is , so .
- The average is , which is from the optimum.
- Interpretation: the first corrected step equals the averaged global gradient, , 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 from , SCAFFOLD is from , so SCAFFOLD is 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 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 toward while client B moved only toward . The moves were unequal, so they did not cancel and the average landed away from the optimum.
| Approach | What it changes | Extra cost | When it helps |
|---|---|---|---|
| FedAvg | nothing; plain local steps and averaging | none | data are close to IID, or is small |
| One local step (FedSGD) | , so no drift | many more communication rounds | very heterogeneous data, cheap communication |
| FedProx | a penalty keeps clients near the server | a tuning parameter , slower local progress | moderate heterogeneity |
| SCAFFOLD | control variates correct each local step | one extra vector per client per round | strong 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 with . Client A's gradient at is and client B's is . What is the average after the step, and why does it match a FedSGD step?Show answer
Client A moves to and client B to . The average is . A FedSGD step uses the averaged gradient , which gives 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 , why does client B end at rather than at , its best answer?Show answer
Each step closes only part of the gap to . The factor is . After two steps the gap from is , so client B is at . 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
- Federated learning (Wikipedia)
- McMahan et al., Communication-Efficient Learning of Deep Networks from Decentralized Data (arXiv:1602.05629)
- Li et al., Federated Optimization in Heterogeneous Networks (arXiv:1812.06127)
- Karimireddy et al., SCAFFOLD: Stochastic Controlled Averaging for Federated Learning (arXiv:1910.06378)