Skip to main content
Distributed Machine Learning

Federated Averaging and SCAFFOLD

Published: 2026-09-11
Level: postgraduate
Audience: Postgraduate students in Distributed Machine Learning

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

  • Hospitals, Non-IID Data and When Vertical Partitioning Appears — covered in Lecture 1
  • Non-IID Data: Same Features Versus Mixed Features — covered in Lecture 3
  • Weighted Aggregation with Neighbor Importance — covered in Lecture 3
  • Distributed Machine Learning and Federated Learning Architectures — covered in Lecture 5
  • Federated Learning and Asynchronous Parameter Aggregation — covered in Lecture 5
  • Mathematical Formulation of Ensemble Averaging and Federated Averaging — covered in Lecture 5
  • Federated Learning: Train Locally, Share Updates — covered in Lecture 9
  • Traditional ML versus Federated Learning, Side by Side — covered in Lecture 9
  • Federated Averaging: Plain Mean versus Sample-Count Weights — covered in Lecture 9
  • Weighted Average by Local Sample Count — covered in Lecture 9

10.1 Local Data, Shared Models, and Vertical Feature Completion

Federated learning is a way to train one shared model across many devices or institutions without ever pooling their private records in one place. The picture that opens this unit is industrial, not abstract. Phones train a shared next-word predictor without uploading keystrokes. Hospitals train a shared diagnostic model without shipping patient files. Banks train a shared risk model without sending account ledgers.

The rule is simple and it does not change later in this material. Data stays on the device or in the local system. You never share the raw data. You always share the model, which means you share parameters, not examples.

How do you train one useful model when the records that would make it useful are legally stuck on many separate disks?

Each site already has data. Training still needs a useful model. So each site trains locally on what it already has. Then it sends an updated model, not the dataset, to a central server. The server combines those models and sends a new shared model back.

Think of a neighborhood cookbook. Every household keeps its own recipes in a locked kitchen. Nobody photocopies the family notebook. What travels is a short list of “tweaks to the shared batter recipe.” The village baker mixes those tweaks into one batter card and sends the card back. The mapping is: kitchen = local disk, recipe notebook = private dataset, batter-card tweaks = model parameters, village baker = server. The analogy breaks when two kitchens cook entirely different cuisines: averaging batter tweaks then yields a compromise that fits nobody, which is the non-IID problem taken up in Section 10.5.

10.1.1 The Core Rule: Keep Data Local, Share Only the Model

A client is one participating device or organization. A server is the coordinator that holds the current shared model and runs the merge step. The shared model is a vector of numbers called parameters. We write that vector as . Each client holds a private local dataset and never transmits .

Federated contract. The data is in the system, in the device. You never share the data. You always share the model. Later algorithms change how the model is updated and how the server merges updates. They do not change this contract.

  • Client keeps on site.
  • The object that moves is , a length- parameter vector.
  • The server stores the current shared and returns a merged after each round.

In a linear model, matches the feature length (plus a possible intercept stored as one extra weight). In a deep net, is the full count of weights and biases. The same contract covers both.

The first practical algorithm for that contract is Federated Averaging, often written FedAvg. It is the vanilla baseline: each chosen client runs local training, then the server takes a sample-size-weighted average of the returned parameter vectors. Later we study SCAFFOLD. The expansion used in this unit is Stochastic Control Averaging for Federated Learning. The standard paper title is Stochastic Controlled Averaging for Federated Learning. The extra “-ed” is a naming detail, not a new method. SCAFFOLD is a repair for a failure mode of FedAvg, not a replacement of the privacy rule.

Standard form of the same contract, written as a one-round loop:

FedAvg fills in a specific ClientUpdate (local mini-batch steps) and a specific Aggregate (weights ). SCAFFOLD fills in a corrected ClientUpdate and also ships a small extra vector called a control variate. Both still send models, never .

10.1.2 Vertical Feature Completion Across Sites

Before the FedAvg derivation, the discussion finished a related industrial pattern: vertical federated learning. In vertical federated learning, different sites hold different feature groups for overlapping people, not just different people with the same feature list.

A feature is one measured field, such as a lab value, a skin finding, or an eye-scan score. One hospital may see the eye fields. Another may see cardiology fields. A third may see skin fields. The same patient can appear in more than one site, but no site has the full row.

Horizontal federated learning, which occupies the rest of this material, is the other axis: many clients hold different rows (different people or devices) with a similar feature layout, and they share models rather than rows. Reference treatments call horizontal FL sample-based and vertical FL feature-based. A bank and an e-commerce firm may both know the same city residents, but the bank holds credit fields and the shop holds purchase fields. They can train together without sending the joined table.

The practical job in the vertical picture taught here is often to fill missing features. If site A lacks fields that site B has, we look at people who appear in both views, measure how their overlapping fields line up, and then infer the missing fields for people who appear in only one view. More advanced completion methods exist, including encrypted matching of shared identifiers. The classroom picture is the simple neighbor-style comparison: who is close to whom on the shared fields, then copy or blend the missing fields from the close neighbor.

Picture three spreadsheets for the same people, each missing a different block of columns. The overlapping columns are the bridge. Distance on the bridge tells you whose missing block is a reasonable fill-in. The analogy breaks if the overlapping columns are weak: two patients can look alike on skin scores and still differ on eye fields.

Axis What differs across sites What is shared Typical product
Horizontal (sample-based) Different people or devices, similar columns Model parameters One shared predictor
Vertical (feature-based) Different columns, overlapping people Derived features or partial models, not the joined table Completed rows and a joint model

When to pick which: use horizontal FedAvg when each phone, hospital, or bank holds its own pile of similar-shaped rows. Use vertical completion when one person is split across departments or companies and the missing fields are the bottleneck.

10.1.3 Hospital Walkthrough: Patients P1 and P2

Setup. Take two patients, and . An eye hospital does not have a complete feature row for . Cardiology and skin departments do have overlapping fields for both and .

Label the views:

  • Eye hospital: complete eye fields for ; missing eye fields for .
  • Cardiology: overlapping cardiology fields for and .
  • Skin: overlapping skin fields for and .

Walkthrough.

  1. Look at the overlapping cardiology features of and .
  2. Look at the overlapping skin features of and .
  3. Compare those shared fields to see whether is close to (or to some other complete patient).
  4. Use that closeness to fill the missing eye-hospital fields for .

No numeric table was filled in this segment. The pattern is the point: overlapping features are the bridge; missing features are the target; the completed row can then enter training. That is vertical feature completion.

Sense-check. If cardiology and skin already say “ looks like ,” copying ’s eye fields onto is a neighbor guess, not a proof that the eyes match. The completed row is a training input, not a clinical claim.

A tiny numeric sketch of the same neighbor idea, using made-up overlapping scores so the comparison is visible:

  • Shared cardiology score: , .
  • Shared skin score: , .
  • Distance on the shared plane: .

If another complete patient sits at cardiology and skin , the same distance from is much larger. The fill for ’s missing eye fields should come from , not from .

Scope. This neighbor fill assumes a useful overlap: some people appear in more than one view, and the shared fields actually move with the missing fields. It breaks when identifiers cannot be matched, when overlap is tiny, or when the missing view is only weakly related to the shared view. Horizontal FedAvg in the rest of this unit assumes the other split: different rows, similar columns. Do not mix the two pictures in one answer.

Visual intuition: draw a table with people as rows and departments as column-blocks. Shade the eye block empty for . Draw arrows from the cardiology and skin blocks of and into a “closeness” check, then an arrow into the empty eye block. The takeaway is that the empty block is filled from a neighbor on the shared blocks, while raw rows still never leave their site.

10.1.4 Industry Applications

Vertical completion is used when a patient, customer, or user is split across departments or companies. Horizontal FedAvg is used when each phone, hospital, or bank is a client with its own local sample pile. Both keep raw records local. Both send models or derived parameters, not the private table.

A bank and a retailer that share customers but not columns are the classic vertical pair: they can join feature types without shipping the joined ledger. Cross-silo hospital networks are the classic horizontal pair: each hospital is a client with its own patients and a similar chart layout.

Pitfalls.

  • Treating “federated” as “send a sample of the data.” The contract is: send the model, never the table.
  • Collapsing vertical and horizontal into one story. Vertical joins columns for overlapping people. Horizontal averages models across different people.
  • Expecting the later SCAFFOLD correction to change the privacy rule. It changes the update, not the contract.
  • Filling missing features from a neighbor and then treating the fill as ground truth. It is an inferred column, useful for training, not a measured lab value.

In the broader field, this is how on-device keyboard models, multi-hospital diagnostics, and multi-bank fraud models get trained under privacy law: knowledge moves as parameters, not as records.

Data stays local; only the model moves. FedAvg is the vanilla merge for that contract. Vertical feature-joining is the column-split cousin: overlapping fields fill missing fields, as in the / hospital walkthrough. Next we write the horizontal goal as math: clients, local counts , and one that should do well on the combined data.

Exam note: Be ready to state the federated contract in one sentence: data stays local; only the model moves. Be ready to contrast vertical feature-joining with horizontal model-averaging.

10.2 Clients, Local Datasets, and the Federated Optimization Goal

FedAvg starts from a concrete inventory. There are clients. Client has a local dataset with points. Clients need not have the same number of points. may be small. may be huge. That size gap will matter as soon as we average.

If we cannot legally pile every local set into one table, what single model should we still try to learn?

If we could pile every local set into one table, the combined dataset would be the union of the client sets. The total sample count would be the sum of the client counts. Federated learning tries to reach a model that is good on that combined table without building the table.

Think of locked filing cabinets. Each cabinet holds its own folder count . The goal is not “make cabinet 1 happy.” The goal is a filing rule that would work if you could read every folder. You never dump the folders onto one desk. You only pass around the current rule card .

10.2.1 Setup: Clients and Uneven Local Data

Let be the number of clients. For each client index :

  • is the local dataset of client .
  • is the number of local points on client . is a positive integer. It can differ across .

The spoken inventory was: there are clients; each client has a local dataset; may have points; may have points; each may have different data points.

A data point here is a pair . The vector is the feature vector of example . The value is its label. Every client stores its own pairs. No client sends those pairs to the server.

Local inventory. Client stores only . The server never receives a pair from . Uneven is normal: a large hospital and a small clinic can both be clients.

10.2.2 The Combined Dataset and Total Sample Count

The combined dataset is the union of the local sets. If you combine all these data, the overall dataset equals adding all the datasets. If you perform the union operation, you get the overall dataset.

The total number of entities, written with a sum, is

Here is the total sample count across clients. is the count on client only. Bounds run over clients to .

If some people appear in more than one client, a strict set-union could count them once while a sum of sizes would count them twice. The rest of the derivation treats as the sum of local sizes. That is the usual FedAvg accounting when clients hold disjoint rows (a partition of the combined table). Standard write-ups define the same way, with for local size.

Spot-check. Two clients, , , disjoint rows. Then and . If the same three people also sat in client 2, a set-union would have , but FedAvg still uses as the weight denominator. This unit follows the disjoint-row convention.

Scope. is a conceptual combined set. It is not a table the server builds. is the weight total. The formulas assume non-negative integer counts and, for the union-equals-sum story, disjoint local rows. If rows overlap, say so, and do not pretend .

10.2.3 What We Actually Optimize

The goal is not “move weights with the least network lag.” The goal is a single parameter vector that makes loss small on the combined data. People think about eliminating loss across the complete dataset, not only on , , or . We take the union of the datasets and try to minimize loss with respect to that union. The dataset contains the features, and the objective of the global loss is to minimize with respect to the global dataset.

Let be the global model parameters. The picture treated as a vector in , with a tiny running sketch of a three-dimensional vector when . So is a length- parameter vector. is the number of weights (and, in a linear model, it matches the feature length).

Each client can train its own copy:

  • Client 1 trains on and ends with parameters .
  • Client 2 trains on and ends with .
  • Client trains on and ends with .

The server then aggregates those copies into one . Aggregation here means a weighted mix of the parameter vectors, not a mix of the datasets. After aggregation, if we could test on every point from every client, the total loss should be small. That is the optimality target: find that minimizes total loss across the clients.

Statistical goal. Find that makes loss small on the union of all client datasets. Data stays split. The model is single. From we form one . When that is tested on , loss should be minimal.

A three-coordinate sketch: when . Each local copy has the same three slots. Averaging happens slot by slot, never by concatenating datasets.

Visual intuition: on a number line of “how wrong the model is on all folders,” we want near the bottom. Each client only sees its own dip. The server never sees the full curve. It only mixes the that each client found on its own dip.

10.2.4 Student Questions: Is the Goal Network Lag and Quantization?

A natural systems reading is: the hard part is shipping big weight vectors, so maybe the thing we optimize is network lag, and that is why we compress, or quantize, the weights. Those systems issues are real later. They are not the objective of this unit.

Q: Is the optimization problem transferring the weights from the clients to the master server who will calculate the gradient? Individual agents have to transfer all the weights, so we have to take into account network lagging, and that is why we do quantization. Is that what we optimize?

A: That goes beyond the object of this unit. Those systems issues are real later. The line that defines the problem here is statistical: we want to minimize loss on the union of all client datasets, not on one client alone. is the union. It contains the features. The global objective is to minimize loss with respect to that complete set.

A second restatement from the room landed on the right target: we minimize loss with respect to the complete dataset, not only on individual clients. The trigger “transferring weights and network lagging with quantization” is a plausible systems story. It is still the wrong exam answer for “what FedAvg optimizes.”

Pitfalls.

  • Naming quantization or lag as the FedAvg objective. They can appear as communication tricks. They are not the loss being minimized.
  • Optimizing only and hoping the other clients will be fine. The target is the combined set.
  • Thinking the server computes the full-data gradient. The server never sees the pairs. It mixes parameters.

In production, phones still care about bandwidth, and hospitals still care about round time. Those constraints shape how often you communicate. They do not replace the loss on .

clients hold disjoint-style local sets of size . Conceptually and . We want one with small loss on that combined data, without building the table. Next we write that global loss as a weighted mix of local losses.

Exam note: If a short question asks “what is optimized in FedAvg,” answer with the global loss on the combined data, not with quantization or lag. Quantization can appear as a communication trick. It is not the FedAvg objective taught here.

10.3 Global Loss as a Weighted Average of Local Losses

Because data is split, the global loss cannot be computed as one sum over a central table. The classroom replacement is a weighted average of local losses. The weight of client is its share of the total sample count, . A client with more points pulls the global loss more. A client with one lonely point does not get a full vote.

If every hospital got one vote, why would a clinic with a single odd record shove the shared model as hard as a hospital with a thousand records?

Take the same global parameters . Send that to client . Client evaluates loss on only. That number is the local loss of client . Repeat for every client. Mix those local losses with weights . The mix is the global loss.

10.3.1 Why a Weighted Average

Since data is distributed across multiple clients, the global loss function is computed as a weighted average of each client's local loss. Same , which is the global model parameters. Client uses . Average using , the total number of samples, and , the number of samples from that client.

If we skipped the weights and treated every client as equal, a tiny client with a wild loss would shove the average as hard as a huge hospital. The factor is the fix.

Think of a class average. One quiz taken by 5 students should not count as much as a quiz taken by 45 students. The weight is headcount, not “one vote per room.” The analogy breaks if the 5-student quiz is a different subject: then you are mixing unlike tasks, which is the non-IID issue, not the size issue.

10.3.2 Mathematical Formulation of the Global Objective

Let be the global loss — the scalar we want to drive down. Let be client 's local loss on . The spoken construction is a weighted average. You take only the sample fraction, the number of samples, divided by :

Here is the shared parameter vector, is the global loss, is the local loss of client , is the local count, and is the total count. Each weight lies in and the weights sum to :

The optimization problem is then

We need a common . If we combine the parameters sent by all the models, make a global model, and give it the global dataset, the loss must be minimized. Because the data is distributed, that global loss is the size-weighted mix of local losses, not an unweighted mean of hospitals.

Standard form in the same notation: texts often write with for local size. This unit uses and .

Limiting case. If , then and : ordinary centralized training. If every is equal to , then : equal client votes, which is fair only when sizes match.

Domain check. Weights are in and sum to 1, so is a convex combination of the local losses. If each , then .

10.3.3 Local Loss on One Client

How is itself built? Walk through every sample inside . For each sample , evaluate a pointwise loss with the same . Add those pointwise values. The local objective is that average (or that sum; the weight already carries the size).

Take all the samples. Within the client dataset you will go through all the samples by name and the same . You will try to compute the loss. Then you will add it.

A standard write-up of that average is

where is the loss on one example . The classroom emphasis was summing pointwise losses with shared . The average is the usual match to a later mix.

If is already an average, then the global mix equals the average of over all points:

That last line is the mean of over every local pair. If were a raw sum instead of an average, the same mix would be the wrong scale: large clients would be double-counted. The teaching intent is: global loss equals size-weighted mix of local losses, and each local loss uses only local pairs.

Each client computes its own loss using only its local dataset. Then that local loss is reduced by local training. All clients do this. The server never sees .

10.3.4 Square Loss and Cross-Entropy

The pointwise loss can be whatever the task needs. Two forms were named.

For a regression-style picture, the square loss was: the label minus theta into , quantity square. With the label of example and the feature vector of example ,

Here is a scalar label, is the feature vector, and is a scalar score. The phrase “theta into ” is the inner product . If you store a bias by appending a onto , the same product still holds. In words: is the label, is the data point, every client has pairs , and you multiply with the same .

Spot-check. Let , , . Then and . If , then . Shapes: , , product is a scalar, square is a scalar.

For classification, cross-entropy loss is also allowed. We can use any loss. This is not a problem. We are using some loss function. The FedAvg and SCAFFOLD merge rules do not lock you to squares. They lock you to “each client evaluates some on local pairs, then we mix parameters.”

A common classification form (not required to derive here) is . One-hot cross-entropy matches that when is a one-hot label. The merge rule does not care which of those you pick.

The problem type can be regression or classification. The shared object is still one . You loop through each client's points. You need that common to do well on all of them.

10.3.5 Worked Fraction Example: Five Local Samples in Fifty

Setup. One client has samples. All clients together have samples.

Weight. The client's share is

What the weight does. If that client's local loss is , it enters the global mix as , not as a full . A five-point client cannot outvote a much larger client.

Numeric mix. Suppose this client’s local loss is and the other forty-five points live on a second client with . Then

An unweighted mean of the two clients would be , which treats the tiny client as half the world. The size-weighted mix is the one that matches “loss on all fifty points” when each local is already an average.

Sense-check. Five out of fifty is ten percent, so a tenth of the vote. The line that said “five samples are there; overall samples of all the clients 50; so 1 by 5” does not match . Treat as the rule, and treat “1 by 5” as a slip.

10.3.6 Student Questions and Answers

Q: So the global loss is the weighted average of the individual losses, and the weight is the number of samples that were used to train those units?

A: Yes. Ultimately the aim is: if we combine the parameters sent by all the models into a global model and then give it the global dataset, the loss must be minimized. Because the data is distributed, that global loss is the weighted average of each client's local loss. For client , the weight is . is that client's sample count. is the total count. We walk every local set with the same , add the losses, and want that total small.

The next doubt is different: if we add loss across data points, how does that even help with training steps?

Q: You are taking the loss across all the data points and then adding it up. How does that even help to find the gradients? That will then be a totally different figure. Conceptually, how is that going to work?

A: The object we want is . The sum of losses is the score of a candidate , not yet the training loop. The training loop is FedAvg: clients reduce local loss, send parameters, and the server mixes them. After that mix, we return to the same claim: the mixed should make the total loss small. The gradient question is answered by the local updates inside FedAvg, not by summing losses on a server that cannot see the data.

Adding loss across data points to find the gradients is a reasonable mix-up: in ordinary centralized training, the sum (or mean) of is exactly the thing you differentiate. Here the server cannot form that sum. Local FedAvg updates supply the steps. The mixed should make total loss small. That is the re-explanation: summed loss is a score for ; local updates supply the training direction.

Pitfalls.

  • Giving every client equal weight when differ. A lonely point must not get a full vote.
  • Writing as a raw sum and still mixing with . Use the average form, or change the weights.
  • Thinking the server adds every itself. It never sees .
  • Treating the global mix as the training loop. is the score. FedAvg is the loop.

Visual intuition: a bar chart of client sizes. The height of client ’s bar is . The global loss is a blend of local losses with those heights as weights. A one-sample spike is a short bar. The takeaway: headcount, not hospital count, sets the vote.

10.3.7 Exam Notes

Global loss is , and each is the mean of a pointwise on . Square loss and cross-entropy are both allowed. Next we turn this score into the FedAvg loop: local mini-batch steps, then a weighted mix of .

Exam note: Expect a conceptual question on why global loss is a weighted mix. The weight is sample count, not “one vote per hospital.” Expect to name at least one allowed pointwise loss (square loss or cross-entropy) and to say that the merge rule does not care which of those you pick.

10.4 The FedAvg Algorithm: Local Steps and Weighted Aggregation

FedAvg is the first minimal algorithm for the split-data goal. Multiple clients train. Each has its own parameters . The server combines them. The combination taught here is a sample-size-weighted average of the parameter vectors.

A client-sampling rate exists in the full method. It was set aside as “nothing different; leave it,” except for the practical picture: each round, pick a subset of clients , such as ten clients, rather than waking every device.

If data cannot move, what is the shortest loop that still drives the global loss down?

This section is a procedure, not a new definition of . The purpose is to train one shared when each stays put. Inputs include the current , a batch size , a local step count , and a learning rate . Outputs are a new global after each round.

10.4.1 Round Structure and Client Sampling

Inputs named here. Model parameters . Batch size . Number of local steps . Learning rate (heard as “eta,” “meta,” “meter,” and “neta”). Loss on a single sample . The gradient of that loss.

Server loop, in order:

  1. Initialize the global model .
  2. For each round :
  3. Choose a set of clients . Example: ten clients.
  4. For each client , send the current parameters (and the client id). Also send batch size , local step count , and learning rate .
  5. Each chosen client runs a client update on its own and returns a new local .
  6. The server aggregates the received into a new global .
  7. Repeat.

If there are three clients in , the same initial goes to client 1, then client 2, then client 3. They train in parallel on private data. They send models back, not mini-batches and not raw rows.

Purpose. Run many communication rounds so that a mix of locally trained copies of tracks a small .

Inputs and outputs. In: current , , , , and the chosen set . Out: updated . Each client also keeps , which never leaves.

Reference treatments sample clients per round, with the participation rate. Full participation is . The classroom example of “ten clients” is that subset .

10.4.2 Client Update: Mini-Batches, Gradients, and Learning Rate

The fundamental principle: train the local model with local data. Client owns . A mini-batch is a small handful of examples drawn from , not a packet from the server.

Client update, as a numbered local procedure:

  1. Receive the current global , plus , , and .
  2. For local step to :
  3. Sample a mini-batch of examples from . Sample your mini-batch from the client's local dataset .
  4. For each sample in that mini-batch, evaluate the loss and its gradient with respect to .
  5. Add those gradients.
  6. Update by stepping against that gradient, scaled by the learning rate.

The spoken update mixed two ideas at once. Idea A: the number of mini-steps is the total local count divided by batch size, so if you make one pass. Idea B: a written-looking step “theta minus divided by batch size times eta times the (summed) gradient.”

The per-mini-batch step that matches ordinary local SGD is

where is the batch size (the same capital in “batch size ”), is the learning rate, and is the gradient of the pointwise loss. Repeat this about times to walk the local set.

The literal extra factor that was spoken, “theta minus number of samples divided by capital into eta into the sum of gradients,” would look like

That extra is the count of local mini-steps, not a multiplier that should sit inside one SGD step. Read it as “do gradient steps,” not as “multiply one step by .”

Steps (local). Copy . Repeat times: draw a mini-batch from , average the per-example gradients, step with size . If you want one pass over local data, set . Then send the updated .

Loss on a batch can be square loss or a classification loss. Feed the batch to the model . Compute this function. Maybe a regression function. Maybe a classification function. The dataset belongs to the mini-batch. Loop. Add gradients. Multiply by eta. Take the average.

Spot-check. Let , , , batch gradients . Mean gradient . New . If you wrongly multiplied by , you would subtract , landing at , which is a different algorithm.

After the local steps, the client sends its updated to the server.

10.4.3 Server Aggregation with Sample-Size Weights

The server receives from the chosen clients. It does not treat them as equal votes. It weights each local model by how many samples that client used.

Whenever I receive , I multiply by how many samples that client has. Divide by the total number of samples . That is the average. Client 1 used samples. Client 2 used . Add those contributions divided by .

This mix is the vanilla FedAvg merge. The global model is formed by taking a weighted average. Aggregating is nothing but taking the thetas and normalizing. Standard form uses the same weighted mean with .

If the sampled set is not the full population, a strict implementation renormalizes by the sum of over only:

The classroom formula used as the global total. Keep both: the exam story in this unit is “weight by .” Production code usually renormalizes over the clients who actually answered this round, so the weights still sum to 1.

Boundary check. If every chosen client has the same and is the full set, both formulas reduce to the ordinary mean .

10.4.4 Worked Example: Local Values 0.8 and 0.5 Mix to 0.59

Setup. Three clients. Total sample count . Treat each as a single scalar so the arithmetic is visible. Client 1 sends and has samples. Client 2 sends and has samples. A third client is present (“plus this”) so that the counts can sum to .

Step 1. Client 1's weighted piece:

Step 2. Client 2's weighted piece, following the same “count over total times value” pattern:

The phrase was “200 by 1000 into 0.8 plus 500 by 1000 plus 0.5 plus this, so 0.59 is the global model.” The “into” on the first term is the multiply. The second multiply was looser in speech. The formula still multiplies, not adds: , not .

Step 3. The reported global value is . Remaining count if is . The remaining weighted mass is , which would mean a third local value of . That third value was not spoken; only the final was. It is inferred from the reported mix so the weights still sum to one:

Step 4. Compare with a naive equal average of the two named values: , which is not . Sample-size weights move the answer. In words: 0.8 is client 1; then client 2 and client 3; if you take the (weighted) average, 0.59.

Sense-check. Client 2 has the most data, so the mix should sit nearer than . The value is between them and closer to , which matches.

10.4.5 Why Equal Weighting Hurts

Without the weights, every client gets equal importance. Suppose five clients, and one of them trained on only one sample. That one-sample model can have a very high loss. If you add it in as a full vote, it shoves the global . If instead you scale by sample count, a spike on one point is diluted across the thousand-point pile.

If a model is trained with only one sample, the loss may be very high. Without averaging, if you add it, that will impact the total loss. If all the samples are, say, a thousand samples, and one sample loss is high, because we are averaging over the number of samples, the impact will be reduced. That is why you use times .

The same warning was given twice with the same one-sample-out-of-five picture. Keep both angles: (1) equal votes over-credit tiny clients; (2) size-weighted mix shrinks a one-point spike.

Tiny numeric echo: five clients, four of them send from each, one sends from (total ). Equal mean . Weighted mix . The spike is almost gone.

The hoped-for end state: the mixed , substituted into the entire dataset, yields a small loss. Each local should already be a low-loss fit on its own . The mix should stay good on the union.

Scope. Weighted FedAvg assumes that a larger is a more reliable local . That fails if the large client's data is corrupted, or if local steps are so many that a large client has already drifted (Section 10.5). Size weights fix count imbalance. They do not fix distribution imbalance.

Visual intuition: plot client index on the horizontal axis and on the vertical axis, with bubble size . The FedAvg mix is the size-weighted center of those bubbles. Equal weighting is the center of the bubbles if you ignore size. The takeaway: a tiny bubble should not yank the center.

10.4.6 Student Questions and Answers

Q: Suppose there are 10 clients. Out of 10, five have already reached minimization and the other five have not. Because of that, the global model is not at minimization. How do we make sure the already-minimized clients will not do extra computation, and force the other clients to keep computing until they reach minimization?

A: That is a real gap, and it is why later methods exist. Under FedAvg itself, if five clients have already reduced loss and five are far away, averaging still blends all of them. The mix may not converge. FedAvg just takes the maximum possible parameters from each client and normalizes. If we want loss near zero but some clients still sit at 17, 20, 30, we cannot repair that inside plain averaging. We keep iterating. The already-good clients still run extra local computation. If they still do not converge, we cannot do anything more inside FedAvg except send the current and normalize. Then we debug: data problem, layer problem, network problem, or architecture problem.

The next confusion is about where the mini-batch lives.

Q: The mini-batch is actually sent by the server to the clients, right? Is the mini-batch coming from the server, or is it the client's own mini-batch?

A: Clients send , not the mini-batch. The server sends the model. Batch size , number of local steps, and learning rate are configuration. The mini-batch is examples from . is that client's local dataset. The rule is: train the local model with local data. The samples live on the client machine.

The trigger “mini-batch sent by the server to the clients” is plausible if you picture the server as the data owner. In this design the server owns , not the rows. Mini-batches are local draws from , not server packets.

Pitfalls.

  • Putting inside a single SGD step. That factor is the number of local steps , not a learning-rate multiplier.
  • Equal votes when sizes differ. A one-sample client shoves global unless you weight by .
  • Believing FedAvg will pause healthy clients while others catch up. It will not.
  • Believing the server ships examples. It ships , , , and .

10.4.7 Industry Applications and Exam Notes

FedAvg is described here as the most popular way to train one shared model across many devices such as phones, hospitals, and banks without collecting private data in one place. Each client trains locally for several steps. Only the updated model is sent. The server averages. Communication cost stays low because data never moves. That is the Gboard-style loop: on-device training, then a weighted mean of weights.

Time cost: each round waits on the slowest chosen client. Space cost: each client stores and . The method gets slow when is huge and every device uploads a full every round, or when a few devices never finish local steps.

When to use it: start here when clients are roughly similar and you need a simple merge. Alternatives appear when data are unlike (SCAFFOLD) or when you must hide even the updates (differential privacy, later).

Walk the loop: init ; sample clients; send ; local mini-batch SGD; send ; mix with . The mix is weighted. The mini-batch is local. FedAvg will not pause healthy clients while stragglers catch up.

Exam note: Be able to walk that loop. Be able to say why the mix is weighted. Be able to say the mini-batch is local. FedAvg will not pause healthy clients while stragglers catch up.

10.5 Non-IID Data and the Limits of FedAvg

FedAvg is a first attempt. It can work when clients look alike. It strains when they do not. The name used in the room for “clients look different” was non-IAD data, meaning non-IID data: not independent and identically distributed. IID would mean each client's examples look like draws from the same process. Non-IID means hospital A’s rows do not look like hospital B’s rows.

If two hospitals start from the same and then train hard on unlike patients, why should the average of their models still be a good shared model?

In an ideal federated setting, local datasets are IID, devices have similar compute, and nobody sabotages the merge. Real hospitals and phones often miss the first of those three. This section is about that miss.

10.5.1 Heterogeneous Clients and Client Drift

In the real world, every client has different-looking data. That is heterogeneous data, also called non-IID data. A hospital in Bangalore does not see the same patients as a hospital in Delhi. Cardiac feature ranges and characteristics can differ by site.

When a client trains locally for many steps, its model slowly gets pulled toward the best answer for its own local data. Client A’s model hugs client A’s records. Client B’s model hugs client B’s records. That pull away from the shared starting point is client drift.

Start from one global model. After local training, client A’s parameters sit over here. Client B’s parameters sit over there. The server average lands in the middle, which may be a poor compromise. Each client drifts toward its own local best. Even though both started from the same , local data gives each copy the properties of that client. The average of drifted copies is unstable and slow to settle.

Client drift. Let be a minimizer of client 's local . After many local steps, walks toward , not toward a minimizer of the global . FedAvg has no extra brake. Whatever the client sends, the server averages. There is no restriction that says “do not walk too far toward your private minimum.”

A parameter-space cartoon: two clients start at the same point. Under IID data they walk toward nearby stars, so the average stays near both stars. Under non-IID data the stars sit far apart. The average of the two walked points can miss both stars.

Reference MNIST sketches make the same point with labels: one client holds digits 0–4, the other holds 5–9. Local tasks are no longer the same 10-class problem. Repeated averaging then pulls each model toward the wrong star.

10.5.2 Hospital Bias Walkthrough

Imagine federated training across hospitals for a condition that is not purely an eye disease. One round of sites is dominated by patients who mostly have eye problems and few other conditions. The local datasets are then biased. Aggregating those local models can bake in the bias.

That is non-IID structure, not a coding bug. One site’s cardiac features live in one numeric range. Another site’s live in another. We should not expect a 100% accurate global model. Random guessing in a balanced two-class sketch sits near 50%. The working aim named here is in the 70% to 80% band, not perfection.

We may not expect it to be a hundred percent accurate. We are aiming at some 80%, not a random 50%. We aim till 70%, 70%, and so on. FedAvg is not very accurate in these terms, but it can still lead to something usable. It is the first attempt. Later work improves it. SCAFFOLD is one of those improvements. Many other aggregation proposals exist, including a later family named FedBSS, which was only previewed.

Scope. The 70%–80% band is a teaching target for this non-IID hospital sketch, not a universal accuracy law. Mild skew can still let FedAvg look decent. Extreme skew, such as disjoint label sets, can make the average of local models poor on every client. Size weights do not remove this. They only reweight by count.

Visual intuition: two arrows in the plane of model parameters. One arrow points at “Bangalore cardiac range.” The other points at “Delhi cardiac range.” FedAvg draws the midpoint. If the arrows are almost opposite, the midpoint is not a hospital that exists. The takeaway: unlike data yields unlike local optima; the mean need not be a good model.

10.5.3 What FedAvg Cannot Guarantee

Three failure pictures now sit on the table:

  1. Size imbalance. A one-point client can wreck an unweighted mix. FedAvg’s weights reduce that.
  2. Progress imbalance. Some clients have already minimized; others have not. FedAvg still averages all of them and still asks the healthy clients to compute again.
  3. Distribution imbalance. Non-IID drift. FedAvg averages drifted models and can fail to converge, especially if local optima point in very different directions, even roughly orthogonal directions.

SCAFFOLD attacks picture 3 by measuring drift and subtracting it.

On a sketch where two local gradients are orthogonal, the average step can cancel useful progress on both axes. That is why “just average whatever arrived” is not enough when clients are unlike.

still appears in the merge. It is the size fix from Section 10.4. It is not a drift fix. A huge Delhi hospital still pulls toward Delhi patients.

10.5.4 Student Questions and Answers

Q: Let’s say we only have patients with eye problems across different hospitals, and a bias is introduced because people with mostly eye problems may not have other conditions. We may be training on a totally biased dataset across hospitals and then aggregating. That might not be the best thing to aggregate.

A: Yes. This is non-IID data. Cardiac features can have different ranges and different characteristics across sites. We should not expect 100% accuracy. We aim for something like 70% to 80%, not a coin-flip 50%. FedAvg is a first attempt. Later algorithms improve on it.

The student reading is right: aggregating biased eye-problem hospital datasets can be a bad idea. It is a data-distribution problem, not only a merge-formula problem. Treat it as limited-accuracy FedAvg, not as a coin-flip success and not as a coding bug.

Pitfalls.

  • Calling any federated run a failure because it is not 100% accurate. Under unlike sites, 70%–80% can be the working band.
  • Expecting to cure unlike distributions. That weight cures size, not drift.
  • Running many local steps on unlike data and then blaming the server average. Long local walks create drift.
  • Treating “non-IAD” as a different method. It is the same non-IID idea with a slurred acronym.

10.5.5 Industry Applications

A hospital in Bangalore versus a hospital in Delhi is the running geographic picture for heterogeneous patients. Cross-hospital training without shipping records is the reason to federate at all. The cost of that choice is drift. Phones and banks have the same pattern: each device or branch is its own distribution. Keyboard logs differ by language and slang. Branch ledgers differ by city.

Non-IID means clients are not identically distributed. Local models drift toward local optima. Averaging drifted models can be slow or unstable, especially when directions are far apart. SCAFFOLD exists to measure that drift and subtract it.

Exam note: Non-IID is the reason FedAvg can be slow or fail to settle. If asked why a later control-variate method exists, answer: local models drift toward local optima; averaging drifted models is unstable.

10.6 SCAFFOLD: Measure Drift, Then Subtract It

SCAFFOLD’s teaching slogan is short: measure the drift, then subtract it. Along with the model, the server and each client keep a small extra vector called a control variate. Think of that extra vector as a note. The note says: your local data tends to pull you in this direction, while the whole group actually needs to move in that direction.

FedAvg is simple and cheap to communicate. SCAFFOLD spends a bit more state — one control vector on the server and one on each client — to cancel the systematic local pull.

If each hospital’s extra local steps yank toward that hospital’s patients, can we measure the yank and take it back out before we average?

This is a procedure that sits on top of the same federated contract. Data still never moves. What changes is the local step and the extra note that travels with the model.

10.6.1 Client Drift After Local Training

Picture the global model as a point. Client 1 trains and walks toward its local best. Client 2 trains and walks toward a different local best. The average of those two walked points is not the true joint step. If you skip the scaffold-style correction, the path zigzags. The server model sits in one place. Client models sit elsewhere. Averaging them writes a new server model that still is not the joint optimum.

The job is to reduce that drift. When local training would shove too far, we subtract a correction so is not allowed to run beyond a band. You are not allowing the theta values to move beyond a certain value. If you allow it, it may deviate too much. If you go beyond, subtract the value. You should not deviate much. The drift should not happen.

A demo contrast was shown. FedAvg’s clients send raw updates; convergence takes time and may never arrive. SCAFFOLD’s clients send values after a drift correction; the path settles because you are subtracting the drift, so there is not much deviation.

Purpose. Cancel the systematic local pull so local steps track the group trend, not only the private minimizer.

Inputs and outputs. In: global model , global control , client control , local data , step size , local step count. Out: a parameter change and a control change, which the server uses to refresh and .

10.6.2 Control Variates as Direction Notes

Let be the global model on the server (the same object we called before; SCAFFOLD’s algebra used and ). Let be the global control variate — the group direction. Let be client ’s control variate — that client’s stored local direction or bias. Let be the local working copy of the model on client .

Shapes match the model. If , then , , and . A model with about one lakh (100,000) parameters has a control vector of the same length. Weight number 5377 of the model has its own personal correction entry: component 5377 of . Each parameter has two parts to watch — how this parameter is deviating for this client, and how it is deviating from the global point of view.

Notation: texts keep for the server model and for FedAvg. This section follows the SCAFFOLD letters. They name the same kind of object: a length- weight vector.

What is stored in ? The gradient of client ’s local loss, averaged over client ’s whole dataset, at the current global model. So tracks, per parameter, how much local data wants to adjust that weight.

Here is client ’s local loss, is its full local set, is its local count, and is the current global model. Take the current global model . Go through the samples from the dataset. Compute the local loss. Take the average. Store that in .

The global is the matching group object: an average of those local directions, so it points where the whole set of clients is moving.

when every client participates and each is already a mean gradient. In the running algorithm, is maintained by mixing uploaded control changes, not by a fresh full-data pass on the server.

Domain check. has the same shape as . A probability loss can make some coordinates of large; nothing forces . It is a direction and a magnitude, not a forced length-one vector.

10.6.3 The Corrected Local Update

Each round, the server samples some clients and sends them both and . On a client:

  1. Initialize the local model: . Whatever it receives, it copies into .
  2. Repeat local steps times (the local loop count; this is local steps, not the number of clients used earlier for FedAvg).
  3. Each local step: draw a mini-batch, compute a mini-batch gradient of the local loss at , then update with a correction.

The heart of SCAFFOLD is this line. Read the bracket as: raw local direction, minus the client bias, plus the group direction.

Here is the local step size (the “constant”), is the mini-batch gradient at the current local model, is the client control, and is the global control.

equals minus a constant times (gradient of that model minus plus ). Raw local direction is how my gradients are moving. I subtract the bias. I add the overall group direction — how all the other clients are moving. I subtract my own drift so I stay in line with the global moving trend. Model parameters are updated by considering the overall global trend and subtracting the current model bias.

Why this cancels drift at the source: cancels the systematic pull of my data. Adding removes what my data always says and inserts what the group says. If the local gradient is the usual SGD direction, then

The term is the correction term. The local dashed gradient may point at that client’s private minimizer . The correction shoves the step back toward the global (blue) trend.

Directional sketch. For one parameter, all clients move by , but you move by .

Group trend (the leftover after mixing): about from the others, versus your .

Net leftover after canceling your bias sits in the neighborhood, not the raw :

You do not apply your full private pull . You apply the group pull after removing your own bias. A one-line picture of that leftover is

if you only subtract bias from a group note, or a softer classroom net “about ” when the story is “others , you , keep a small positive leftover.” The exam skill is the comparison: do not keep raw ; keep a step that has had the local bias removed and the group direction added.

Sense-check. If your pull is opposite the group, the corrected step should not look like a full opposite yank.

Steps (local, SCAFFOLD). Copy . For local mini-steps, replace ordinary with . Then refresh (next subsection) and send changes, not full portraits.

10.6.4 Refreshing Client Controls and Sending Differences

After the local loop, the client refreshes . Two options were named.

Option A. Set the new client control from a gradient of the global model, spoken as “ of ”:

That matches the paper’s Option I: evaluate the local mean gradient at the received server model . It needs an extra pass over (or a large batch) at .

Option B. A control-state update spoken as: minus global plus one over eta times minus :

Here is the local-step count, not the FedAvg client count. This is the paper’s Option II. It reuses the displacement already caused by the corrected steps, so you do not form a fresh full-batch gradient.

Why Option B is algebra, not magic. If every local step used the same corrected direction and we pretend is constant for a sketch, then

so

and

which is a stand-in for a new local control. Real mini-batch changes each step; Option B is still the cheap estimator used in practice.

Then the client does not upload the full and full as absolute portraits. It uploads differences:

  • Parameter change:
  • Control change:

The client uploads differences, not absolute values; minus , and the difference in the parameters. Those values are used to compute the new and . Every client sends the corrections only. Once the server receives the corrections, it updates and . is the model. is the global correction state.

The server also has a global step size among the named inputs. Let be the clients who answered this round, and let be the total client population. A standard mixing rule is

The classroom did not dictate those two lines in full. The teaching content is that the uploaded and are the only ingredients for the server’s update of and . Keep the professor’s story (send differences; server refreshes and ) and treat the display above as the usual completion of the missing algebra.

10.6.5 Per-Parameter Corrections in a Large Model

Do not picture one scalar “drift number” for the whole network. Picture a parallel correction for every weight.

Suppose the current combined view of one weight’s trend across clients looks like on different coordinates of the story. Client 1’s own trend on a coordinate might be different from the average of all clients. SCAFFOLD keeps, inside , how much to correct each coordinate.

If weight 5377 on the client wants to move by relative to the group, that lives in component 5377 of . The ordinary gradient step on that weight would be the usual

SCAFFOLD still uses a gradient, then adds the stored correction so that the step follows the group, not the private yank.

Complexity. Extra memory is one vector of length on the server and one on each client. Extra communication is one more length- difference beside . Local time grows with mini-steps, same as FedAvg, plus a control refresh.

10.6.6 Student Questions: What Is the Global Direction?

Q: Instead of sending the global gradients as they are, you reduce client drift by finding a unit vector of that direction, subtracting it, and adding the global direction. How do you find the global direction?

A: The global direction is the average of the same control value across clients. For the th client we compute that client’s gradient. If we did this for all , the average of those gradients is the global object. For this parameter, all clients may be moving by while you move by . We take the net, about , not your raw . Every client cancels its own bias and adds the global one. That is why the copies converge toward the global one. That is the main reason for SCAFFOLD.

The trigger used a unit vector picture. That is a fair geometric instinct (keep only direction). The stored is not forced to length one. It is the (mean) local gradient, so it keeps magnitude. The global direction is still “average of those controls,” not a separate oracle.

A second pass in the same exchange: five clients including you, your deviation , others . The spoken average was “seven nine by five,” about , rounded in speech to “one point something” and then “1.5.” Your trend is . You subtract your effect. You add the leftover global trend, not the drift that happened in your case.

Scope. SCAFFOLD assumes the extra control state can be stored and sent. It helps when local gradients are biased relative to the group, which is the non-IID case. If already, the correction is zero and you are back to ordinary local SGD (Section 10.8). It does not by itself hide from a curious server; that is a privacy topic for later.

10.6.7 Exam Notes

Pitfalls.

  • Replacing FedAvg’s privacy contract. SCAFFOLD still sends models (and control notes), never .
  • Using as “number of clients” inside . In this update, is local steps.
  • Sending full and full as the required payload. This telling sends differences.
  • Treating as one number for the whole net. It is per-parameter, length .

The line to remember is , in words: raw local direction minus my bias plus group direction. Clients send deltas, not full models, in this telling. is per-parameter and about the same size as the model. Do not memorize a long derivation. Do know the role of , , , , and the two uploaded differences.

Exam note: Remember . Know that clients send differences, not full models. Know that is per-parameter. Next we run the same correction on three numbers so the naive landing and the corrected landing can be compared.

10.7 Numerical Walkthrough of the SCAFFOLD Correction

The correction is easier with three numbers than with a full network. The room worked the same idea more than once with slightly shifting figures. Both passes are kept. They teach the same rule: do not take the old value minus the raw local gradient; take a step that uses global trend minus local trend so the new value stays nearer the group.

If a local trend would jump a weight from 5 to 7, what smaller step keeps you nearer the shared 5?

These figures are teaching sketches. They are not a polished least-squares fit of a real network, and they are not a promise that one exam paper will ask you to grind many decimals.

10.7.1 Setup With Three Parameters

Let the current global model have three coordinates

So , , . These are the current global parameters.

Client 1’s local trend on those three coordinates was first spoken as . Other clients were moving positive, with a second client spoken as . A third client was added as also moving positive. The average of the first coordinate’s story was spoken as “7 minus 2 is 5; 5 by 3, say 1.5.” That 1.5 is the global trend on the first coordinate in this sketch. A strict mean of is about ; speech rounded to . The mix of client gradients was informal.

A later pass used client values on the three coordinates, and again a global first-coordinate average of from “C1, C2, C3.”

Keep as the classroom global trend on the first weight, and keep as this client’s local trend on that weight.

Matching informal group trends for the other coordinates in the first pass: “6 plus 6 is 12, 12 by 3 is 4” and “4 plus 6 is 10 by 3, something like 3.3.” Those were not fully turned into side-by-side landings.

10.7.2 Naive Local Step Versus Corrected Step (First Pass)

Naive FedAvg-style local step on the first weight. Old value . Local trend . If we do old value minus the current client value in the usual “subtract the local gradient” way with a negative local trend, the naive landing is

If this correction is not there, I am going to do minus 2; it becomes 7; deviation is more. We do not want much deviation. We want to stay closer to the global 5.

Correction used in the first pass. Global trend minus local trend, treating the local trend as a magnitude :

Then the corrected landing was spoken as instead of . In words: 1.5 minus 2 is minus 0.5, so it will become 5.5 only instead of 7; global is 5 and your value must be toward 5.5 rather than 7.

Sense-check. is one half-step from . is two full steps away. The first pass is a teaching sketch whose job is: cancel local drift and keep the global path.

That pass treated the local trend as a magnitude in the subtraction . It is not a unique algebra line. Subtracting local from global for each coordinate still matches the slogan, because each of holds that client’s gradient on that coordinate.

10.7.3 Second Classroom Pass With the Same Idea

The second pass used the same global first weight and the same local trend , and it named the naive landing again. This pass is a more literal “step size equals ” picture.

Naive, unchanged:

Global trend from averaging client controls: .

Correction with :

Corrected parameter:

I am not doing old value minus the current client value. If I do that, it becomes 7; it is far. Instead I do global minus local; 1.5 minus minus 2 becomes 3.5; 5 minus 3.5 is 1.5. If I do not consider the global trend, 5 minus minus 2 is 7.

Sense-check. The comparison that did not shift: naive is too far from global ; the corrected step is the one that uses .

The two landings disagree because the spoken algebra shifted: first pass , second pass . Keep both as they were taught. Do not pick a silent winner.

A third, standard SCAFFOLD line on the same numbers, for reconciliation only. If the mini-batch gradient equals the stored local control, , and , , then

That is another landing. It is the ordinary paper update when local gradient matches . The exam story in this unit is still the comparison against naive , not a demand that you reproduce unless the question writes explicitly.

10.7.4 Five-Client Net-Effect Example

Another net-effect sketch used five clients and one parameter.

  • Your deviation:
  • Other spoken values:
  • Sum of the five numbers
  • Average , spoken as “seven nine by five,” “one point something,” then “1.5”

The group trend is about to . Yours is . You do not add to . You subtract your effect and add the leftover group trend. You are adding the global trend to your parameter, not the drift that happened in your case.

If all five were treated as controls , the global is their average. Your update uses , which removes the pull and leaves the net group direction:

You do not need that as a memorized exam number. You need the direction of the story: drop your yank; keep the group mean near .

10.7.5 What the Demo Curves Show

A side-by-side path was described. At first both FedAvg and SCAFFOLD deviate. Then SCAFFOLD converges. FedAvg keeps wandering and is not able to converge in the demo.

Why does the FedAvg curve keep moving? Each dataset points in a different direction. The directions may even be orthogonal. The datasets themselves stay the same in both methods. The only difference is the parameter update.

  • FedAvg: no restriction; whatever the client sends, average it.
  • SCAFFOLD: before the client sends, it is given the global trend; it nullifies local trend against global trend; it adds only the remaining group piece.

Because almost all clients remove their own drift, the path can settle. The local dashed gradient still points at the private star. The correction term brings the step back toward the global trend, again and again.

Visual intuition: two traces versus round index (horizontal axis) and a one-number stand-in for “how far the server model still moves” (vertical axis). FedAvg’s trace keeps oscillating. SCAFFOLD’s trace rises at first, then flattens. Landmark: the flattening is the correction doing its job, not a change of dataset.

Scope. These classroom numbers (, , , , , ) are for intuition. They assume a one-coordinate cartoon and a step that looks like “subtract a trend.” Real SCAFFOLD uses in . If an exam ever uses numbers, they will look like this comparison, not like a hidden multi-page derivation.

10.7.6 Student Questions and Answers

Q: Why is the FedAvg curve not settling, while SCAFFOLD does?

A: In the FedAvg case you are not restricting the update. Each dataset can point in a different direction, maybe orthogonal. The data stays the same. The difference is the update. SCAFFOLD sends the global trend to the client, nullifies local versus global, and adds the leftover. Clients remove their drift, so the run can converge.

Pitfalls.

  • Treating naive as acceptable because “SGD subtracts a negative gradient.” The point of the sketch is that is too far from global .
  • Forcing the first-pass and the second-pass to be the same number. Speech shifted. The shared lesson is “use .”
  • Memorizing as if the lecture required that decimal. Speech then said .
  • Thinking the demo datasets changed between methods. Only the update changed.

Naive landing: , too far from global . Corrected pictures use global minus local, whether the landing was told as or as . FedAvg wanders when local directions disagree. SCAFFOLD can settle because clients drop their own drift.

Exam note: A numerical item, if it appears at all, would be in this spirit: given a global value, a local trend, and a group trend, compare the naive landing with the corrected landing. The classroom itself later said not to expect heavy numeric papers. Still, this walkthrough is how the correction was taught.

10.8 When FedAvg and SCAFFOLD Match, and When a Global Model Is Not the Goal

Two closing questions matter in practice. First: when is SCAFFOLD the same as FedAvg? Second: what if you never wanted a shared global model at all, because your phone should follow your vocabulary?

If every client already walks the same way, is the extra SCAFFOLD note doing any work?

The short answer is no: the extra note is for unlike pulls. The rest of this section makes that algebraic, then separates a shared from a personal on-device product.

10.8.1 Homogeneous Data

FedAvg and SCAFFOLD line up when the dataset is homogeneous — clients look like each other, IID rather than non-IID. If every local distribution matches, local drift is not a different direction from the group. The extra correction has nothing special to cancel.

When the dataset is homogeneous, FedAvg and SCAFFOLD will be the same.

That is the statistical test. Alike clients, alike local gradients, alike controls. Then measuring drift and subtracting it does not change the step.

10.8.2 Zero Correction When Local and Global Controls Match

A sharper algebraic condition was accepted in the room: the two methods match when client drift matches server drift, that is, when and are the same.

Look at the extra piece that SCAFFOLD adds, . If that resultant is zero, the same parameters are used as in an uncorrected step. If all clients move in the same direction, there is no global-versus-local split. Then

and the SCAFFOLD update collapses to ordinary local gradient descent plus ordinary averaging. If every three, or all, of the parameters travel toward the same direction, then there is no global drift and all the locals are the same.

Write the collapse in one line. Start from

If , then , so

which is the uncorrected local SGD step used inside FedAvg. The server mix can then be the same weighted average of the .

So two verbal tests:

  1. Homogeneous data (clients statistically alike).
  2. (local control equals global control), so the correction is nullified.

When the correction vanishes. The extra term is . It is the zero vector when every client control matches the server control, which is the algebraic twin of “everyone moves the same way.”

Scope. Homogeneous data is a reason may already equal . It is not the only reason. A run that has already aligned the controls can also show a zero correction even if the world started non-IID. Conversely, “the clients are hospitals” does not automatically mean SCAFFOLD differs from FedAvg; you still need unlike pulls.

10.8.3 Personal On-Device Models Versus a Shared Global Model

A systems question pushed against the whole global-model use case. On a mobile device, you may want next-word guesses from your vocabulary and your stock of words. You may not want a global model. You may not want to average at all. You want a model that is good on the edge case that is you.

The reply does not deny that personalization exists. It blocks a false split between “global model” and “local model.” There is no global model built by ignoring local models. The global model is built on top of local models. Local client models are client-specific in the sense that they learn the same on that client’s samples. The final still has to work with those local samples.

Look back at the loss. There is no separate global loss computed on secret central rows. Local loss is reduced on local rows. is best for client 1’s data. is best for client 2’s data. Those are sent and aggregated. The first condition is: there is nothing like a global model that performs worst on the client set. The mixed is scored by the same local losses.

You cannot come up with a global model by ignoring the local model. The global model is built on top of the local model. When we say the final model, that final model is , and that has to work with the local samples of the local client.

This does not claim that one mixed is always the product you want on a keyboard. It claims that the FedAvg/SCAFFOLD object, if you are training a shared , is already tied to local performance through local loss. A fully personal model that never averages is a different product. It was flagged as a good question to reopen with more time.

Reference treatments call that other product personalization: fine-tune the shared model on local logs, accepting a trade-off between “good on me” and “good on everyone.” That is not the same as refusing to average during the shared training loop.

Visual intuition: two stacked boxes. Bottom box: local losses on local rows. Top box: mixed . Arrows go up from every local box into the mix, then back down as the next starting . There is no side door labeled “global loss on hidden central data.”

10.8.4 Student Questions and Answers

Q: When are FedAvg and SCAFFOLD the same?

A: When the dataset is homogeneous. From the condition point of view, they are also equal when client drift is the same as server drift, that is, when and are the same. If the resultant that you add is zero, the same parameters are used. If all clients move in the same direction, there is no extra deviation to cancel.

The second question is the keyboard use case, not a repeat of the algebra.

Q: We are coming up with a global model, but in some scenarios we might need a model that does well on the edge cases. On my mobile device I want words predicted from my vocabulary. I do not want a global model. I just want my model trained on local data. I do not want to average.

A: You cannot build that shared global model by ignoring the local models. The global model is built on top of the local models. Local loss on local samples is what we reduce. Each is best for that client, then we aggregate. The final still has to work with local samples. There is not a separate global model that is allowed to be worst on the clients.

The trigger “words predicted from my vocabulary on a mobile device” is a real product wish. The resolution is not “you must average forever.” It is: you cannot build that shared global model by ignoring the local models. A shared is built on top of local models and local loss. A never-averaged on-device model is another product.

Pitfalls.

  • Saying SCAFFOLD is “always better,” even on IID data where .
  • Claiming there is a global loss table sitting on the server. There is not.
  • Treating “I want my keyboard” as a proof that FedAvg is pointless. It is a different product requirement.
  • Forgetting the two tests: homogeneous data, or .

10.8.5 What Comes Next

Advanced aggregation methods continue after SCAFFOLD. FedBSS was named as one of the next algorithms in the prepared sequence. Differential privacy — how to apply it in this setting — was named as a following topic. The same control-variate picture will be reused rather than replaced.

Mobile next-word prediction is the concrete personalization story. Hospitals and banks remain the concrete shared-model story. Both live under the same constraint: raw records stay on site.

FedAvg equals SCAFFOLD when data are homogeneous or when , so the correction is nullified. A shared is built from local and local loss. A purely personal non-averaged model is a different product. Next-unit names to recognize: differential privacy, FedBSS.

Exam note: Do not sink into heavy algebra. Know the algorithm, the role of each symbol, and when the SCAFFOLD correction becomes zero. Next-unit names to recognize: differential privacy, FedBSS. There will not be heavy mathematical problem-solving of the long numeric kind.

Exam Guidance Summary

There will not be mathematical problem-solving questions of the long numeric kind. The paper is set to test whether you understand the algorithms. How does FedAvg work? How does SCAFFOLD work? What is the role of each piece? When is the correction nullified? What are the uploaded differences, spoken as and — the change in the model and the change in the control?

Do not go too deep into mathematics. That depth is not required here. If a numeric-style problem were ever used, similar problems would be discussed first. The planned emphasis is conceptual: steps, roles, and the homogeneous / collapse.

Open-book materials will be watermarked copies of the course visuals. Several more sessions remain in the sequence (spoken as six more, then corrected to about five more). Use that time on algorithm flow, not on replica algebra.

Exam note: Fair-game topics, in the order they were taught:

  • Federated contract: share models, never raw data.
  • Global loss as .
  • FedAvg local mini-batch updates and weighted merge.
  • Mini-batches come from , not from the server.
  • Why exists (tiny clients, one-sample spikes).
  • Non-IID client drift; why vanilla averaging can fail.
  • SCAFFOLD line ; send differences; per-parameter .
  • When FedAvg equals SCAFFOLD.
  • Global is built from local , not by ignoring local loss.

Key Industry Applications

Phones, hospitals, banks. Federated averaging trains one shared model across many devices without collecting private data in one place. Only updated models move. Communication stays comparatively cheap. The same loop is the industrial story behind on-device keyboards and cross-silo medical or financial models.

Vertical hospital features. Eye, cardiology, and skin views of patients and show how overlapping fields can fill missing fields. Industry uses vertical federated learning to combine views, train, and complete missing features without sending a joined raw table.

Cross-city hospitals. Bangalore versus Delhi patients is the picture for non-IID medical data. Cardiac ranges differ. Expect roughly 70%–80% utility, not 100%, from vanilla FedAvg.

Biased specialty sites. A network of eye-heavy hospitals can poison a naive aggregate. That is a data-distribution problem, not just a merge-formula problem.

On-device keyboards. Next-word prediction from a personal vocabulary is the case where a user may not want a global average at all. The shared-model math still insists that any global be built from local losses; a purely personal non-averaged model is a different product.

Follow-on production tools. SCAFFOLD is one repair for drift. FedBSS was named as a later algorithm in the same industrial line. Differential privacy was named as the next protection to apply on top of these training loops.

DML Lecture 10 notes · Federated Averaging and SCAFFOLD

Distributed Machine Learning· postgraduate· 2026-09-11

Sections Breakdown

1Local Data, Shared Models, and Vertical Feature Completion

Keep private records on site and share only model parameters. Contrast horizontal FedAvg with vertical feature completion across overlapping people.

2Clients, Local Datasets, and the Federated Optimization Goal

K clients hold local sets D_k of size N_k. The goal is one theta with small loss on the combined data, not quantization or lag.

3Global Loss as a Weighted Average of Local Losses

Global loss F(theta) is a sample-count weighted mix of local losses. A five-in-fifty client gets weight 1/10.

4The FedAvg Algorithm: Local Steps and Weighted Aggregation

Each round samples clients, runs local mini-batch SGD on D_k, and mixes returned theta_k with weights N_k/N.

5Non-IID Data and the Limits of FedAvg

Unlike clients cause client drift. Size weights do not fix unlike distributions; vanilla averaging can fail to settle.

6SCAFFOLD: Measure Drift, Then Subtract It

Control variates store local and group directions. The local step uses g minus c_i plus c, and clients upload differences.

7Numerical Walkthrough of the SCAFFOLD Correction

From global 5 with local trend -2, a naive step lands at 7. Corrected classroom landings use global minus local.

8When FedAvg and SCAFFOLD Match, and When a Global Model Is Not the Goal

The SCAFFOLD correction is nullified when data are homogeneous or c_i equals c. A shared theta is built from local models.

9Exam Guidance Summary

The paper tests algorithm understanding: FedAvg, SCAFFOLD, uploaded differences, and when the correction is nullified.

10Key Industry Applications

Phones, hospitals, and banks train shared models without pooling records. Vertical completion fills missing hospital fields.

Postgraduate students in Distributed Machine Learning

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Local Data, Shared Models, and Vertical Feature Completion

Must-know: Data stays local; only the model moves. Contrast vertical feature-joining with horizontal model-averaging.

⚠️ Top pitfall: Treating federated learning as sending a sample of the data, or collapsing vertical and horizontal into one story.

Self-check: In one sentence, what is allowed to leave a hospital in this design?

Connects to: 10.2 Clients, Local Datasets, and the Federated Optimization Goal, 10.4 The FedAvg Algorithm: Local Steps and Weighted Aggregation

Clients, Local Datasets, and the Federated Optimization Goal

Must-know: FedAvg optimizes global loss on the union of client datasets, not network lag or quantization.

⚠️ Top pitfall: Naming quantization or lag as the objective, or thinking the server sees the pairs.

Self-check: What is optimized in FedAvg: communication cost or loss on the combined data?

Connects to: 10.3 Global Loss as a Weighted Average of Local Losses, 10.4 The FedAvg Algorithm: Local Steps and Weighted Aggregation

Global Loss as a Weighted Average of Local Losses

Must-know: Global loss is a weighted mix by N_k/N. A lonely point does not get a full vote. Square loss and cross-entropy are both allowed.

⚠️ Top pitfall: Equal client votes, or treating the summed loss as a server-side gradient loop.

Self-check: If N_k=5 and N=50, what is the client's weight in F(theta)?

Connects to: 10.2 Clients, Local Datasets, and the Federated Optimization Goal, 10.4 The FedAvg Algorithm: Local Steps and Weighted Aggregation

The FedAvg Algorithm: Local Steps and Weighted Aggregation

Must-know: Walk init, sample clients, local mini-batch SGD, weighted merge. Mini-batches come from D_k. N_k/B is the local step count, not a multiplier inside one step.

⚠️ Top pitfall: Server-sent mini-batches, equal votes, or pausing already-minimized clients.

Self-check: Does the server send the mini-batch, or does the client draw it from D_k?

Connects to: 10.3 Global Loss as a Weighted Average of Local Losses, 10.5 Non-IID Data and the Limits of FedAvg

Non-IID Data and the Limits of FedAvg

Must-know: Non-IID drift is why vanilla averaging can be slow or unstable. Size weights do not fix unlike distributions.

⚠️ Top pitfall: Expecting 100 percent accuracy, or thinking N_k/N cures drift.

Self-check: Why can FedAvg fail when two hospitals see unlike patients?

Connects to: 10.4 The FedAvg Algorithm: Local Steps and Weighted Aggregation, 10.6 SCAFFOLD: Measure Drift, Then Subtract It

SCAFFOLD: Measure Drift, Then Subtract It

Must-know: Remember g - c_i + c: raw local direction minus my bias plus group direction. Send differences, not full models. c_i is per-parameter.

⚠️ Top pitfall: Using K as client count inside the Option B refresh, or picturing one drift number for the whole net.

Self-check: What three terms sit inside the SCAFFOLD local step bracket?

Connects to: 10.5 Non-IID Data and the Limits of FedAvg, 10.7 Numerical Walkthrough of the SCAFFOLD Correction, 10.8 When FedAvg and SCAFFOLD Match, and When a Global Model Is Not the Goal

Numerical Walkthrough of the SCAFFOLD Correction

Must-know: Naive 7 is too far from global 5. The corrected step uses global minus local. FedAvg is not restricting the update.

⚠️ Top pitfall: Forcing the 5.5 and 1.5 landings to be the same number, or thinking the demo datasets changed.

Self-check: Given global 5 and local trend -2, what is the naive landing?

Connects to: 10.6 SCAFFOLD: Measure Drift, Then Subtract It, 10.8 When FedAvg and SCAFFOLD Match, and When a Global Model Is Not the Goal

When FedAvg and SCAFFOLD Match, and When a Global Model Is Not the Goal

Must-know: The SCAFFOLD correction is nullified when c_i = c or when clients move the same way. You cannot build a shared global model by ignoring local models.

⚠️ Top pitfall: Saying SCAFFOLD is always different from FedAvg, or claiming a server-side global loss table exists.

Self-check: When will the SCAFFOLD correction be nullified?

Connects to: 10.6 SCAFFOLD: Measure Drift, Then Subtract It, 10.7 Numerical Walkthrough of the SCAFFOLD Correction

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.