Search

Search papers and lessons

Communication-Efficient Learning of Deep Networks from Decentralized Data

H. Brendan McMahan, Eider Moore, Daniel Ramage et al. · 2016

McMahan et al. (2016) introduce FederatedAveraging: devices train on their own data and a server averages the results, cutting communication rounds by 10 to 100 times versus synchronized SGD.

On this page

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

TL;DR

McMahan and colleagues at Google wanted to train a deep network on data that stays on users' phones, where the data is private and the connections are slow. Their method, FederatedAveraging (FedAvg), has each selected device run several passes of stochastic gradient descent on its own data, then sends its updated weights to a server, which averages them weighted by how much data each device holds. The paper reports that this needs 10 to 100 times fewer communication rounds than synchronized SGD.

Builds on: Federated Learning, Stochastic Gradient Descent, Feedforward Neural Network, Cross-Entropy Loss · Leads to: practical Federated Learning systems, and the communication-reduction and secure aggregation work the paper cites as follow-ups

Why it mattered

The paper gave the name federated learning to training that keeps data on the devices that produce it, and it showed a simple algorithm that works on deep networks. The authors argue that the privacy gain comes from sending only model updates, not raw data, and that the updates can be discarded once applied.

The paper's own list of follow-up work is a good map of what came after. It cites Bonawitz and colleagues for an efficient secure aggregation protocol, and Konečný and colleagues for algorithms that cut communication further. It also names stronger guarantees, such as differential privacy and secure multi-party computation, as future directions. Those are the places where the idea grew.

The problem

Training on data from phones breaks several assumptions of data-centre training. The data is non-IID, meaning one user's data is not a fair sample of the whole population, and unbalanced, meaning some users have far more data than others. Devices are often offline, and the upload bandwidth may be 1 MB/s or less. In a data centre, computation dominates the cost; on a phone network, communication dominates.

The paper's central question is how to reduce the number of communication rounds. The naive baseline, SGD with one gradient computed per round, needs very many rounds. Averaging models trained separately is a known idea, but earlier work on it considered only data-centre settings with fast networks and balanced, IID data. The paper adapts that style of averaging to the federated setting and tests it on the features that matter there.

How it works

Take a tiny example with two clients and one weight ww. Client 1 holds one example with target 0, and client 2 holds three examples with target 4. The loss for each example is (w−target)2(w - \text{target})^2. The global objective weights each client by its share of the data, so its minimum is the weighted mean (1×0+3×4)/4=3(1 \times 0 + 3 \times 4) / 4 = 3. We use learning rate 0.250.25 and one local gradient step per round.

  1. Server sends the model. The server sends w=0w = 0 to both clients.

  2. Each client takes one local step. A step on client kk with target aka_k is w←w−0.25×2(w−ak)=0.5w+0.5akw \leftarrow w - 0.25 \times 2(w - a_k) = 0.5w + 0.5a_k. Client 1 gets 00 and client 2 gets 0.5×0+0.5×4=20.5 \times 0 + 0.5 \times 4 = 2. Check: each device moved halfway to its own target.

  3. Server averages by data size. The new weight is 14×0+34×2=1.5\frac{1}{4} \times 0 + \frac{3}{4} \times 2 = 1.5. Check: client 2 counts three times as much because it holds three examples.

  4. Repeat the round. From w=1.5w = 1.5, client 1 gets 0.750.75 and client 2 gets 2.752.75. The average is 14×0.75+34×2.75=2.25\frac{1}{4} \times 0.75 + \frac{3}{4} \times 2.75 = 2.25. Check: the distance to 3 has halved, from 1.5 to 0.75.

  5. Keep going. Round three gives 2.6252.625, and each round halves the remaining distance to 3. Check: the server converges toward the global optimum 3 without ever seeing an example.

flowchart LR
  S[Server sends weights] --> C1[Client 1 trains on its data]
  S --> C2[Client 2 trains on its data]
  C1 --> A[Server averages by data size]
  C2 --> A
  A --> S

The full algorithm works the same way, but each client takes many steps. A client with nkn_k examples runs EE passes over its data in minibatches of size BB, so it takes about nkE/Bn_k E / B local steps per round. Each round the server picks a random fraction CC of the clients.

The math

Write the global objective as an average over all nn training examples, f(w)=1n∑i=1nfi(w)f(w) = \frac{1}{n} \sum_{i=1}^{n} f_i(w), where fi(w)f_i(w) is the loss on example ii. If client kk holds the examples in the set Pk\mathcal{P}_k, with nkn_k examples, the objective can be rewritten as

f(w)=∑k=1KnknFk(w),Fk(w)=1nk∑i∈Pkfi(w).f(w) = \sum_{k=1}^{K} \frac{n_k}{n} F_k(w), \qquad F_k(w) = \frac{1}{n_k} \sum_{i \in \mathcal{P}_k} f_i(w).

Each FkF_k is the average loss on client kk, and the weights nk/nn_k / n add up to 1.

Step 2 in symbols: one local step

The naive federated gradient step with one gradient per client per round is wt+1=wt−η∑knkngkw_{t+1} = w_t - \eta \sum_k \frac{n_k}{n} g_k, where gk=∇Fk(wt)g_k = \nabla F_k(w_t). The paper shows that this equals a two-stage process: each client computes wt+1k=wt−ηgkw^k_{t+1} = w_t - \eta g_k, and the server averages these with the same weights. This is the step in the toy example, where g1=2(0−0)=0g_1 = 2(0 - 0) = 0 and g2=2(0−4)=−8g_2 = 2(0 - 4) = -8 give w1=0w^1 = 0 and w2=0−0.25×(−8)w^2 = 0 - 0.25 \times (-8), which is 22. Note that 14×0+34×2=1.5\frac{1}{4} \times 0 + \frac{3}{4} \times 2 = 1.5 is the same as 0−0.25×(14×0+34×(−8))=1.50 - 0.25 \times (\frac{1}{4} \times 0 + \frac{3}{4} \times (-8)) = 1.5.

Step 3 in symbols: FedAvg

FedAvg replaces the single gradient with several local steps. In round tt the server selects a set StS_t of clients, and mt=∑k∈Stnkm_t = \sum_{k \in S_t} n_k is the total number of examples they hold. Each selected client runs EE epochs of minibatch SGD on its own data, giving wt+1kw^k_{t+1}, and the server computes

wt+1=∑k∈Stnkmtwt+1k.w_{t+1} = \sum_{k \in S_t} \frac{n_k}{m_t} w^k_{t+1}.

The average is taken over the selected clients only, which is the correction the paper notes in its algorithm box. The expected number of updates per client per round is u=nE/(KB)u = nE / (KB), which the paper uses to compare settings.

Results

Setup. The paper tests a two-layer MLP and a CNN on MNIST, a character LSTM on the complete works of Shakespeare, a CNN on CIFAR-10, and a word-level LSTM on a large social network dataset of 10 million posts from over 500,000 authors. The MNIST 2NN has 199,210 parameters, the CNN has 1,663,370, and the Shakespeare LSTM has 866,578. The Shakespeare clients are speaking roles in plays, 1146 in total, and the data is unbalanced.

Rounds to reach a target accuracy, MNIST CNN, 99 percent. With IID data, FedSGD needs 626 rounds. FedAvg with E=20E = 20 and B=10B = 10 needs 18 rounds, a speedup of 34.8 times. With non-IID data, FedSGD needs 483 rounds and the same FedAvg setting needs 173, a speedup of 2.8 times. The paper's abstract reports the 10 to 100 times reduction across its experiments.

MNIST 2NN, client fraction. With E=1E = 1, C=0.1C = 0.1 and B=10B = 10, the 2NN reaches 97 percent in 87 rounds with IID data, against 316 rounds at C=0C = 0, a speedup of 3.6 times. With non-IID data, the same setting takes 664 rounds against 3275, about 4.9 times.

CIFAR-10. Baseline SGD reaches 86 percent after 197,500 minibatch updates. FedAvg reaches 85 percent after 2,000 communication rounds. For the 85 percent target, SGD needs 99,000 and FedAvg needs 2,000, a speedup of 49.5 times.

Large-scale word LSTM. Here FedAvg reaches 10.5 percent accuracy in 35 communication rounds, while FedSGD needs 820, a speedup of 23 times. The paper states that these runs were not tuned as thoroughly as the others.

Limits. The experiments partition existing datasets over clients in a controlled environment, not real phones, and the paper sets aside the practical deployment issues of a full federated system. Results are shown mainly in figures and tables for chosen targets, so the reader should check which target and setting a speedup refers to. The paper also reports that very large numbers of local epochs can make FedAvg plateau or diverge on the Shakespeare LSTM (its Figure 3), so more local work is not always better.

Reading guide

Check yourself

QuestionIn the two-client toy example, the client updates are 0 and 2, with 1 example on client 1 and 3 on client 2. What does the server send next, and why is client 2 weighted more?Show answer

The server sends 14×0+34×2=1.5\frac{1}{4} \times 0 + \frac{3}{4} \times 2 = 1.5. Client 2 holds three of the four examples, so its update counts three times as much, which matches the global objective that weights each example equally.

QuestionOn the MNIST CNN with IID data, FedSGD needs 626 rounds to reach 99 percent and FedAvg with E=20E = 20, B=10B = 10 needs 18. How many times fewer rounds does FedAvg need?Show answer

626/18≈34.8626 / 18 \approx 34.8. FedAvg needs about 35 times fewer rounds, which matches the speedup the paper reports for that row.

QuestionFor the Shakespeare LSTM, the non-IID speedup is larger than the IID speedup. What reason does the paper give?Show answer

The paper conjectures that some roles have relatively large local datasets, so extra local training on those clients is especially valuable. It reports a 95 times speedup for the non-IID case against 13 times for the IID case, with E=5E = 5 and B=10B = 10.

QuestionA team sets the number of local epochs very high so that each device trains for a long time between rounds. What risk does the paper report, and what does it suggest?Show answer

For very large numbers of local epochs, FedAvg can plateau or diverge on the Shakespeare LSTM, so more local work does not always help. The paper suggests that in later stages of training it may help to reduce the local computation per round, with smaller EE or larger BB, in the same way that decaying the learning rate helps. The team must test this on its own model.

Sources

Read the full paper

H. Brendan McMahan, Eider Moore, Daniel Ramage et al., 2016. arXiv:1602.05629