<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kavith Rashintha on Medium]]></title>
        <description><![CDATA[Stories by Kavith Rashintha on Medium]]></description>
        <link>https://medium.com/@wgkrashintha?source=rss-32289814b433------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*a35bWrw3rO-20mRcfDmyug.jpeg</url>
            <title>Stories by Kavith Rashintha on Medium</title>
            <link>https://medium.com/@wgkrashintha?source=rss-32289814b433------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:35:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wgkrashintha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[When FedAvg Falls Short: Understanding FedProx for Real-World Federated Learning]]></title>
            <link>https://medium.com/@wgkrashintha/when-fedavg-falls-short-understanding-fedprox-for-real-world-federated-learning-4c4dfc80e6b6?source=rss-32289814b433------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c4dfc80e6b6</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[federated-learning]]></category>
            <category><![CDATA[fedprox]]></category>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Kavith Rashintha]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 18:19:30 GMT</pubDate>
            <atom:updated>2026-11-08T18:19:30.205Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is about the algorithm that was built to handle the exact problems of FedAvg. It is called FedProx, and its main idea fits in one sentence as let clients learn from their own data, but don’t let them wander too far from the shared model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwJgFq_0yq5UNCYlo9HtSA.png" /></figure><p><strong>Let’s define our terms</strong></p><p><strong>Heterogeneity -</strong> In federated learning, it means the clients are not all the same. They differ in the data they hold, and in the devices they run on.</p><p><strong>Statistical heterogeneity -</strong> The data differs from client to client. One hospital mostly sees elderly patients, another mostly sees young ones. Researchers also call this <strong>non-IID data</strong>, short for “not independent and identically distributed,” which simply means the data on each client doesn’t look like a fair sample of the whole population.</p><p><strong>Systems heterogeneity -</strong> The devices differ. One client is a powerful hospital server, another is an old server with weak memory and a slow connection.</p><p><strong>Client drift -</strong> When a client trains on its own unusual data for several epochs, the model slowly moves away from the global model it started with. That movement away is called drift.</p><p><strong>Straggler -</strong> A client that is too slow to finish its local training before the server’s deadline for the round.</p><p><strong>Loss function -</strong> A number that measures how wrong the model currently is. Training is the process of adjusting the weights to make this number smaller.</p><p><strong>Regularization -</strong> A technique that adds an extra penalty to the loss function to stop the model from doing something undesirable, such as fitting too wildly. Think of it as a gentle rule added to the training process.</p><p><strong>Proximal term -</strong> The specific penalty that FedProx adds. “Proximal” means “near.” It rewards the local model for staying near the global model.</p><p><strong>Hyperparameter -</strong> A setting that is chosen before training starts, rather than something the model learns by itself. Learning rate and number of epochs are common examples. FedProx adds exactly one new one.</p><p><strong>The two kinds of “different” that became a problem in FedAvg</strong></p><p>Let’s take the previous hospital example. Three hospitals want to train one shared diagnostic model without sharing patient records. In the neat version of the process, every hospital has a similar mix of patients, similar computers, and plenty of time. FedAvg handles that world beautifully.</p><p>In the real-world implementation of the process, two things go wrong.</p><p>First, the patients are different. Hospital A is a children’s hospital, Hospital B serves a retirement community, and Hospital C is a general city hospital. Each one’s data tells a different part of the process. A model trained only on children’s scans will learn patterns that don’t fully apply to older adults, and vice versa.</p><p>Second, the hospitals are different. Hospital A has a rack of powerful GPUs. Hospital B has one modest machine that is also used for other work. Hospital C’s connection drops out now and then. If the server insists that everyone completes the same amount of training in the same time window, the slower hospitals either rush and do poor work or get dropped from the round entirely. Both problems matter, and FedProx was designed to address both at once.</p><p><strong>Client drift - the reason why averaging can go wrong</strong></p><p>At the start of a round, the server sends the same global model to every client. Everyone starts from exactly the same place. Then each client trains for several epochs on its own data. With each step, the model moves a little in whatever direction its data suggests. After many steps, the models have drifted apart. The longer each client trains locally, and the more different their data, the further they wander in different directions. When the server averages those far-flung models, the result can be a poor compromise, and the global model can bounce around instead of steadily improving. There is a real tension here. You want clients to train for several epochs locally, because that saves communication. But the more local training they do, the more they drift. FedAvg gives no built-in way to manage this trade-off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yu2DBqyJxLaPeHGm0mJHDg.png" /></figure><p><strong>The FedProx idea</strong></p><p>If the problem is that local models wander too far, then make wandering costly. So FedProx changes one thing: what each client is trying to minimize during local training. In FedAvg, a client simply tries to reduce its own loss on its own data. In FedProx, the client tries to do two things at once:</p><ol><li>Reduce its loss on its own data, as before.</li><li>Stay close to the global model it received at the start of the round.</li></ol><p>If the client moves far away from the global model, it pays a penalty. The farther it goes, the bigger the penalty. That penalty is the proximal term, and it works exactly like a leash. The client is free to explore and free to learn from its own data, but the leash stops it from running off to the other side of the park.</p><p><strong>The formula, explained without the hard math</strong></p><p>Here is what each client tries to minimize in FedProx:</p><p><strong>h(w) = F(w) + (μ / 2) × ‖w − w_global‖²</strong></p><p>Let’s explain this piece by piece.</p><ul><li><strong>w - </strong>client’s current local weights, the ones being adjusted during training.</li><li><strong>F(w) -</strong> the client’s normal loss on its own data. This is exactly what FedAvg uses. It measures how wrong the model is, and it pulls the model toward fitting local data.</li><li><strong>w_global -</strong> global model the client received at the start of the round. Think of it as the anchor point.</li><li><strong>w − w_global -</strong> the difference between where the client’s model is now and where it started.</li><li><strong>‖ … ‖² - </strong>this means “measure the size of that difference and square it.” Squaring means small differences cost very little, while large differences cost a lot. A small step away is almost free, but a big leap is expensive.</li><li><strong>μ - the </strong>number you choose that controls how strong the leash is.</li><li>The <strong>/ 2 -</strong> a mathematical convenience that makes the calculus tidier. You can safely ignore it.</li></ul><p>Simply, the client minimizes its normal loss, plus a penalty for how far it has moved from the global model. That’s the whole difference between FedAvg and FedProx. The pull from this penalty also has a simple form. At every training step, it gently nudges each weight back toward its starting value, with a strength proportional to how far it has already strayed.</p><p>μ - the one you get to turn</p><p>FedProx adds exactly one new hyperparameter, and it is μ. It decides how long the leash is.</p><ul><li><strong>μ = 0 (no penalty at all) -</strong> Behaves exactly like FedAvg.</li><li><strong>Small μ (a long, loose leash) - </strong>Clients have freedom, and drift is mildly reduced.</li><li><strong>Moderate μ (a balanced leash) - </strong>Clients learn from local data but stay near the global model.</li><li><strong>Very large μ (a very short leash) -</strong> Clients barely move, so learning becomes slow.</li></ul><p>Two things are worth noticing here.</p><p>First, FedAvg is just a special case of FedProx where μ equals zero. That is a comforting fact. If you add FedProx to a system, you aren’t throwing away anything you had before. You are only adding a dial. Second, the right μ depends on how different your clients are. If the clients are very different, a stronger leash helps. If they are very similar, a strong leash just slows learning for no benefit. In practice, μ is tuned by trying a handful of values, and the original paper explored small values, such as 0.001, 0.01, 0.1, and 1, across different datasets. There is no single magic number that works everywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oe2yT_O3LWNCBSsrtZV4pg.png" /></figure><p><strong>The second problem - stragglers and partial work</strong></p><p>Now let’s return to the second kind of difference, the one about slow or unreliable devices. In a typical FedAvg setup, the server asks every selected client to run the same number of local epochs. A client that can’t finish in time is often simply dropped from that round. It’s as if that hospital never showed up. That has two costs. You waste the work the slow client did manage to do, and you quietly bias your model toward the faster, better-resourced clients. If the slow clients tend to be the ones with unusual data, you are systematically leaving their data out of the picture. FedProx handles this more gracefully. It allows each client to do a variable amount of local work, depending on what it can actually manage, and the server still accepts and uses whatever partial result comes back.</p><p>But wouldn’t a half-trained model throw off the average? This is where the leash helps again. Because the proximal term keeps every local model close to the global model, a client that only did a little work, or a lot of work, produces an update that stays within a reasonable distance. The authors showed that this makes it safe to combine updates from clients that did different amounts of work, so nobody has to be thrown away. In short, the same leash that tames drift also makes partial work usable.</p><p><strong>Walking through one full FedProx round</strong></p><p>Let’s explain one round using our three hospitals. You’ll notice it looks almost identical to FedAvg, with one difference in the middle.</p><p><strong>Step 1 - Broadcast.</strong> The server sends the current global model to Hospital A, Hospital B, and Hospital C. Each hospital also remembers this as its anchor point.</p><p><strong>Step 2 - Local training, with a leash.</strong> Each hospital trains on its own data. At every step, it tries to reduce its normal loss and the proximal penalty for drifting from the anchor. A fast hospital may complete all of its planned epochs. A slow hospital may complete fewer, and that’s allowed.</p><p><strong>Step 3 - Upload.</strong> Each hospital sends its new weights back to the server. Only the weights travel, never the patient records.</p><p><strong>Step 4 - Averaging.</strong> The server combines the returned weights in the same weighted-average way that FedAvg does, with each client’s share based on its dataset size. The leash did its work during local training, so the aggregation step itself doesn’t change.</p><p><strong>Step 5 - Repeat.</strong> The improved global model goes out again, and the cycle restarts.</p><p>The key point is that FedProx changes what happens inside the client, not what happens at the server. That makes it very easy to adopt.</p><p><strong>What FedProx looks like in code</strong></p><pre>import copy<br>import torch<br><br>def local_train_fedprox(global_model, data_loader, epochs=3, lr=0.01, mu=0.01):<br>    # Each client starts from a copy of the global model<br>    local_model = copy.deepcopy(global_model)<br><br>    # Remember where we started: this is the anchor for the leash<br>    global_params = [p.detach().clone() for p in global_model.parameters()]<br><br>    optimizer = torch.optim.SGD(local_model.parameters(), lr=lr)<br>    loss_fn = torch.nn.CrossEntropyLoss()<br><br>    for _ in range(epochs):<br>        for x, y in data_loader:<br>            optimizer.zero_grad()<br><br>            # The normal loss, exactly as in FedAvg<br>            loss = loss_fn(local_model(x), y)<br><br>            # The only new part: the proximal term<br>            prox = 0.0<br>            for w, w_global in zip(local_model.parameters(), global_params):<br>                prox += ((w - w_global) ** 2).sum()<br>            loss = loss + (mu / 2) * prox<br><br>            loss.backward()<br>            optimizer.step()<br><br>    return local_model.state_dict()</pre><p>After each client returns its weights, the server uses the very same fedavg_aggregate function from the last article. Nothing changes on the server side.</p><p>A few things worth noticing -</p><ul><li>The anchor (global_params) is saved <strong>before</strong> training begins and never changes during the round. That is what keeps the leash attached to a fixed point.</li><li>The proximal term is added to the loss in just three lines. If you set mu=0, those lines add nothing, and you are back to plain FedAvg.</li><li>To support stragglers, you would let each client pick its own number of epochs, depending on its device, instead of forcing everyone to use the same epochs value.</li></ul><p><strong>The strengths of FedProx</strong></p><p><strong>More stable on uneven data -</strong> By limiting drift, FedProx keeps the global model from bouncing around when clients disagree. The authors reported that in highly heterogeneous settings, FedProx converged more reliably and reached noticeably better accuracy than FedAvg.</p><p><strong>Tolerates slow and unreliable devices -</strong> Clients that can only do partial work still contribute, instead of being dropped. That means more of your data is used, and the model is less biased toward fast clients.</p><p><strong>A tiny change -</strong> You add one term to the local loss and one hyperparameter. The server code stays the same. If your system already runs FedAvg, upgrading to FedProx takes minutes.</p><p><strong>Contains FedAvg as a special case -</strong> Setting μ to zero recovers FedAvg exactly, so you never lose the option of going back.</p><p><strong>The limitations of FedProx</strong></p><p><strong>Need to tune μ -</strong> There is no universal best value. Too small and nothing improves, too large and learning crawls. Finding a good value usually means running several experiments, and every experiment costs training time.</p><p><strong>The benefit shrinks when data is already similar -</strong> If your clients look alike, FedAvg already works well, and FedProx’s leash adds little. You may even slow things down slightly.</p><p><strong>It limits drift but doesn’t remove it -</strong> The leash reduces how far clients wander, but it doesn’t fix the root cause, which is that each client’s data is different. Other approaches attack that problem more directly, and we’ll look at some of them later in the series.</p><p><strong>The extra penalty costs a little computation -</strong> Each training step has to compute the distance from the anchor, which adds a small overhead on the client’s device. For big models on weak devices, that can matter.</p><p><strong>It still trusts every client -</strong> FedProx has no way to tell a genuinely different client from an unreliable or malicious one. A client that sends back a bad update is still averaged in. The leash limits how far a bad update can wander in one round, but it isn’t a defense.</p><p><strong>It adds no formal privacy -</strong> Just like FedAvg, the raw data stays on the client, which is a big win. But the weights themselves can still leak some information, and FedProx offers nothing extra to prevent that.</p><p><strong>What do we have to learn from this ?</strong></p><p>FedProx is a good example of how research often progresses. It doesn’t throw away FedAvg. It keeps what works, adds one small, well-reasoned fix, and makes the whole system more forgiving of the messy reality of real clients. But notice how much FedProx didn’t address. It helps when clients are different. It doesn’t help when clients are unreliable. It doesn’t protect against bad updates, and it doesn’t add privacy guarantees. Those are separate problems, and each one has its own family of solutions, many of which build on ideas like FedAvg and FedProx rather than replacing them. And the first problem, data that differs from client to client, deserves a much closer look than we’ve given it here. It is one of the biggest open challenges in the whole field, and it is where we are going next.</p><p>Next in this series, we’ll take a closer look at the problem FedProx only touches, non-IID data. Why does different data on different clients make federated learning so hard, what does it actually look like, and what can we do about it ?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c4dfc80e6b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Federated Learning Actually Works: A Complete Guide to FedAvg]]></title>
            <link>https://medium.com/@wgkrashintha/how-federated-learning-actually-works-a-complete-guide-to-fedavg-c8373c8b50ef?source=rss-32289814b433------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8373c8b50ef</guid>
            <category><![CDATA[privacy-protection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[federated-averaging]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[federated-learning]]></category>
            <dc:creator><![CDATA[Kavith Rashintha]]></dc:creator>
            <pubDate>Thu, 15 Oct 2026 03:50:39 GMT</pubDate>
            <atom:updated>2026-10-15T03:50:39.530Z</atom:updated>
            <content:encoded><![CDATA[<p>The algorithm that lets a central server combine everyone’s learning into one model without ever seeing their data.</p><p><strong>A quick recap from the last article</strong></p><p>In the last article, we covered the big idea behind Federated Learning, which is that instead of moving private data to a central model, you move the model out to where the data lives, let it learn there, and only bring back what it learned. The loop looked like this, that the server sends the model out, each client trains it locally, the clients send back their updates, and the server combines those updates into a new, improved global model.</p><p>That last step, <em>“the server combines everyone’s updates,”</em> is the part we glossed over. It’s also the part that makes the whole system work. This article is dedicated entirely to it.</p><p>The algorithm behind that step is called <strong>FedAvg</strong>, short for <strong>Federated Averaging</strong>. It was introduced by Google researchers in 2017, in a paper by H. Brendan McMahan and colleagues, and it’s still the default starting point for almost every federated learning system built today. If you understand FedAvg, you understand the engine room of federated learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UauFDcdJjAOKllrPP_xikA.png" /></figure><p><strong>Define the terms</strong></p><p><strong>Weights (or parameters) - </strong>A trained model is really just a big collection of numbers that determine how it makes decisions. These numbers are called weights. Training means adjusting these weights, bit by bit, until the model gets good at its task and provides the most accurate results.</p><p><strong>Gradient -</strong> When a model is training, it calculates how much each weight should change to reduce its mistakes. This “how much to change” signal is called the gradient. You can think of it as a small nudge telling each weight which direction to move in.</p><p><strong>Local update -</strong> After a client trains the model on its own data for a while, its weights will have shifted from where they started. The local update is simply the client’s new set of weights (or, in some versions, the difference between the new weights and the old ones).</p><p><strong>Epoch -</strong> One full pass through a dataset during training. When a client “trains locally,” it usually does a handful of epochs on its own data before sending an update back.</p><p><strong>Global model -</strong> The single shared model, sitting on the server, that represents the combined knowledge from every client so far.</p><p><strong>Round -</strong> One complete cycle of send-train-return-combine. Federated learning doesn’t happen in one shot; it happens over many rounds, with the global model getting a little better each time.</p><p><strong>The problem FedAvg actually solves</strong></p><p>Let’s take the same example of the hospital example from the last article. Say three hospitals are training a shared diagnostic model:</p><ul><li><strong><em>Hospital A</em></strong><em> has 100 patient records.</em></li><li><strong><em>Hospital B</em></strong><em> has 50 patient records.</em></li><li><strong><em>Hospital C</em></strong><em> has 200 patient records.</em></li></ul><p>Each hospital trains the model locally and ends up with its own slightly different set of weights, shaped by its own patients. Now the server has three different sets of weights in front of it. What should the new global model be? The naive answer is to average the three sets of weights together, each counted equally. Take weight number one from all three models, average those three numbers, and that becomes weight number one in the new global model. Repeat for every single weight in the network.</p><p>That naive answer has a problem, though. It treats Hospital B, with only 50 patients, as equally important as Hospital C, with 200 patients. That doesn’t feel like the correct way to average it. Hospital C’s model probably learned more and is probably more trustworthy, simply because it saw four times as much data. A plain, unweighted average would let a small, thin dataset drag the global model around just as much as a large, well-trained one. This is exactly the gap FedAvg fills. It doesn’t just average and it averages <strong>weighted by how much data each client had.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EqvqHxGHyCjh-zEp6CcEDQ.png" /></figure><p><strong>The FedAvg formula: simple explanation</strong></p><p>Here’s the actual formula</p><p>w(global) = Σ ( n_k / n ) × w_k</p><ul><li><strong>w_k</strong> is the local weights that came back from client <em>k</em> (for example, Hospital A’s updated model).</li><li><strong>n_k</strong> is how many data samples client <em>k</em> trained on (Hospital A’s 100 patients).</li><li><strong>n</strong> is the <em>total</em> number of data samples across all participating clients (100 + 50 + 200 = 350 in our example).</li><li><strong>n_k / n</strong> is that client’s <strong>share</strong> of the total data — its weight in the average. Hospital A contributes 100/350 ≈ 0.29, Hospital B contributes 50/350 ≈ 0.14, and Hospital C contributes 200/350 ≈ 0.57.</li><li><strong>Σ</strong> just means “sum up.” You multiply each client’s weights by their share, then add all those results together.</li></ul><p>Simply, <strong>the new global model is a weighted average of everyone’s local models, where clients with more data get more say.</strong> That’s it. That’s the entire idea behind FedAvg. It’s a beautifully simple formula for something that sounds like it should be complicated.</p><p><strong>Walking through one full round</strong></p><p><strong>Step 1 - Broadcast.</strong> The server has a global model, currently at some starting point (maybe randomly initialized, maybe from a previous round). It sends an identical copy of this model to Hospital A, Hospital B, and Hospital C.</p><p><strong>Step 2 - Local training.</strong> Each hospital now trains its copy for a few epochs, using nothing but its own patient data. Hospital A trains on its 100 records, Hospital B on its 50, Hospital C on its 200. After this, each hospital has weights that have shifted slightly away from the original starting point, shaped by what that hospital’s data taught it.</p><p><strong>Step 3 - Upload.</strong> Each hospital sends its new weights back to the server. Only the weights travel that never the underlying patient records.</p><p><strong>Step 4 - Weighted averaging.</strong> The server applies the FedAvg formula. It multiplies Hospital A’s weights by 0.29, Hospital B’s weights by 0.14, and Hospital C’s weights by 0.57, then adds the three results together, weight by weight, layer by layer. The output is a brand-new global model that blends all three hospitals’ learning, proportionally to how much data each one had.</p><p><strong>Step 5 - Repeat.</strong> This new, slightly-improved global model is broadcast out again, and the whole cycle restarts. Over dozens or hundreds of rounds, the model keeps absorbing a little more from everyone, round after round, gradually converging into a strong, well-rounded model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7xWGJeojJo0lwvqWTydoQ.png" /></figure><p><strong>What FedAvg looks like in code</strong></p><p>Here’s a simplified, framework-agnostic sketch of FedAvg. This isn’t about to dropped into production and it’s meant to make the formula from before feel concrete.</p><pre>def fedavg_aggregate(client_weights, client_sizes):<br>    &quot;&quot;&quot;<br>    client_weights: a list of state_dicts (one per client)<br>    client_sizes:   a list of ints, number of samples each client trained on<br>    &quot;&quot;&quot;<br>    total_samples = sum(client_sizes)<br>    new_global_weights = {}<br><br>    for layer_name in client_weights[0].keys():<br>        weighted_sum = 0<br>        for weights, n_k in zip(client_weights, client_sizes):<br>            share = n_k / total_samples<br>            weighted_sum += share * weights[layer_name]<br>        new_global_weights[layer_name] = weighted_sum<br><br>    return new_global_weights<br><br><br>def run_one_fedavg_round(global_model, clients, local_epochs=3):<br>    client_weights = []<br>    client_sizes = []<br><br>    for client in clients:<br>        local_model = copy.deepcopy(global_model)      # Step 1: broadcast<br>        train(local_model, client.data, epochs=local_epochs)  # Step 2: local training<br>        client_weights.append(local_model.state_dict())       # Step 3: collect update<br>        client_sizes.append(len(client.data))<br><br>    new_weights = fedavg_aggregate(client_weights, client_sizes)  # Step 4: aggregate<br>    global_model.load_state_dict(new_weights)<br>    return global_model  # Step 5: ready for the next round</pre><p>A few things worth noticing in this sketch:</p><ul><li>Every client starts each round from the exact same global model that’s what makes the averaging fair and meaningful.</li><li>The aggregation happens layer by layer. A neural network has many layers, each with its own set of weights, and FedAvg averages each one separately using the same weighting scheme.</li><li>Nowhere in this code does any client’s raw data get passed around. Only state_dict() which is the model&#39;s learned numbers that ever leaves a client.</li></ul><p><strong>The strengths of FedAvg</strong></p><p><strong>Simplicity -</strong> There’s no complicated negotiation, no fancy math beyond a weighted average. This simplicity makes it easy to implement, easy to debug, and easy to reason about.</p><p><strong>Communication efficiency -</strong> Instead of sending data back and forth on every single training step, clients do several epochs of local training before sending anything. This cuts down dramatically on network traffic compared to naive approaches, which matters a lot when your “clients” might be millions of phones on patchy mobile data.</p><p><strong>Respects to the data volume fairly -</strong> By weighting contributions by dataset size, FedAvg avoids letting a client with a tiny, possibly noisy dataset have the same influence as one with a large, well-trained model.</p><p><strong>Proven default -</strong> Because FedAvg is well studied, well understood, and widely implemented, it’s the safe first choice for almost any new federated learning project. You don’t need to justify picking it that you need to justify picking something else.</p><p><strong>The limitations of FedAvg</strong></p><p><strong>Assumptions on local training finishes “on schedule” -</strong> FedAvg expects every client to complete the same amount of local training and report back around the same time. In the real world, some clients are fast, some are slow, and some might not respond at all before the deadline for a round.</p><p><strong>Struggles when data looks very different across clients -</strong> If Hospital A mostly treats older patients and Hospital C mostly treats younger ones, their local models can drift in different directions. Simply averaging their weights afterward doesn’t always produce as strong a result as if all the data had been pooled together. Researchers call this the <strong>non-IID problem</strong> (data that isn’t identically and independently distributed across clients), and it’s one of the most active research areas in federated learning today.</p><p><strong>Dataset size isn’t the same as data quality -</strong> FedAvg weights clients by how much data they have, not by how good or reliable that data is. A client with a large amount of noisy or mislabeled data still gets a big vote in the final model.</p><p><strong>No built-in defense against bad actors -</strong> FedAvg has no way of knowing whether a client’s update is legitimate learning or something malicious. It simply trusts every update it receives and folds it in.</p><p><strong>Privacy still needs extra work -</strong> The raw data never leaves the client, which is a huge privacy win. But the weights themselves can, in some cases, leak partial information about the data that produced them. FedAvg by itself doesn’t add any formal privacy protection, that’s a separate layer that gets added on top, often using techniques like differential privacy.</p><p><strong>Where this leaves us</strong></p><p>FedAvg is the foundation, not the finish line. It answers the core question of <em>“</em>how do we combine everyone’s learning into one model,<em>”</em> and it does so elegantly. But its limitations that struggling with uneven data, having no defense against unreliable participants, and needing extra work for strong privacy are exactly why researchers have spent the years since 2017 building on top of it.</p><p>Some of these extensions adjust how much local training each client is allowed to do before checking back in, to handle stragglers gracefully. Others change how much say each client gets in the final average, based on how trustworthy their updates seem, rather than just how much data they had. Others focus purely on making sure the updates themselves can’t leak anything sensitive, even to the server doing the averaging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y51gSbF6wSk6lP9geJ7EuQ.png" /></figure><p>Next in this series, we’ll open up the family tree from the diagram above and look at the other aggregation algorithms that came after FedAvg.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8373c8b50ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Federated Learning Explained: How AI Learns Without Seeing Your Data]]></title>
            <link>https://medium.com/@wgkrashintha/federated-learning-explained-how-ai-learns-without-seeing-your-data-a53764af0c16?source=rss-32289814b433------2</link>
            <guid isPermaLink="false">https://medium.com/p/a53764af0c16</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[federated-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-privacy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Kavith Rashintha]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 15:11:25 GMT</pubDate>
            <atom:updated>2026-09-28T15:11:25.257Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Is Federated Learning? Training Models Without Centralizing Data</h3><p>Imagine you want to build a smart keyboard. You want it to predict the next word a person is about to type, the way your phone already does. To train a model that good, you need data from different users to use as a rich dataset that represents different user behaviors. Specifically, you need examples of how real people actually type.</p><p>When users&#39; data needs to be collected for model training, there is a problem that needs to be addressed before model training. That is, the things that users type on their keyboards, because it contains their sensitive data such as passwords, private messages, etc. Therefore, Users do not want all of that uploaded to a company’s servers so an algorithm can study it. And in many cases, the law won’t allow it either.</p><p>So, there is a puzzle that needs to be solved. You need everyone’s data to train a great model, but you’re not allowed to collect everyone’s data in one place. For a long time, that puzzle didn’t have a clean answer, and then we can say that Federated Learning is the clean answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DlJeWsq2ESbHLXhBr_jvoQ.png" /><figcaption>Centralized Learning (Old Way) vs Federated Learning (New Way) of training models</figcaption></figure><p><strong>The Old Way: Bring the Data to the Model</strong></p><p>For most of the time in machine learning, training worked in one obvious way. Gather all the data into one pile, and you train your model on top of that pile. While explaining the old way, let’s define a couple of terms while we’re here, because we’ll use them a lot.</p><p>A <strong>model</strong> is just a mathematical system that learns patterns from a given data set. Think of it as a student that learns and gets better at a task the more examples it studies.</p><p><strong>Training</strong> is the process of providing data to learn patterns; more simply, showing the model lots of examples so it can adjust itself and improve. Every time it sees an example and learns from it, it nudges its internal settings a tiny bit in the right direction.</p><p>In the centralized training approach, training needs the data and the model to sit together in the same place. So step one is always to collect all the data<em>.</em> Pull every user’s photos, messages, or medical records into one central database, then let the model feast on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*70zIyN2AlK97Ft4rbflFFw.png" /><figcaption>How centralized training approach works</figcaption></figure><p><strong>Why Collecting Data into a Centralized Server Became a Problem</strong></p><p>We can identify 3 main problems that come with the centralized training approach that requires bringing data to the model.</p><p><strong>Privacy - </strong>People have become far more aware that their data is valuable and personal. Sending users’ private information to a server to train the model may violate their privacy rights, make them feel uncomfortable, and often be unsafe.</p><p><strong>Regulation - </strong>Laws caught up. Rules like GDPR in Europe and HIPAA for health data in the United States put real limits on moving personal data around. A hospital, for example, often legally cannot ship its patient records to an outside data repository, no matter how helpful the resulting model would be.</p><p><strong>Inability to move data - </strong>Sometimes the data is just too sensitive or too big to relocate. A network of hospitals might each hold thousands of medical scans. No single hospital is allowed to see another’s patients, and no one wants to build one giant shared database that becomes a hacker’s target.</p><p>So, there is valuable data trapped in separate silos, unable to leave the data repository. A <strong>silo</strong>, in this context, just means an isolated store of data that stays where it is, such as one hospital’s private records, walled off from the rest.</p><p>The question becomes: can the model learn from all these silos without the data ever leaving any of them?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Voj8BhAaa8D8NqsEUSphQ.png" /></figure><p><strong>The New Way: Bring the Model to the Data</strong></p><p>Federated Learning is the new way, and it flips the old approach completely. Instead of moving the data to the model, it moves the model to the data. Let’s clarify this with the previous example of the keyboard. Rather than uploading your typing history to a server, your phone keeps that history right where it is. The model comes to your phone, learns a little from your data on the device, and then leaves. Your raw data never goes anywhere. Only what the model learned (a set of small mathematical adjustments) gets sent back. This is the heart of Federated Learning, and it’s worth stating the formal definition of that as below.</p><p><em>Federated Learning is a way of training a shared model across many devices or organizations, where each one keeps its own data private and only shares model updates, never the raw data itself.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoZjiyaVTA9pJUi16zlJUQ.png" /></figure><p><strong>How It Works, Step by Step</strong></p><p><strong>Step 1 - The server shares the model.</strong> It all starts with a central coordinator, usually called the <strong>server</strong>. The server holds the current version of the shared model that is identified as the <strong>global model</strong>, because it’s the one everybody contributes to. At the start of a round, the server sends a copy of this global model out to a selection of participating devices. These devices are usually called <strong>clients, </strong>a client is simply one participant, like a single phone or a single hospital.</p><p><strong>Step 2 - Each client learns locally.</strong> Now each client trains that copy of the model using only its own local data. Your phone improves the model based on your typing. A hospital improves it based on its own scans. This training happens entirely on the device. Crucially, no raw data leaves at any point. This local training is usually light weight process in this context.</p><p><strong>Step 3 - Clients send back only what they learned.</strong> After a bit of local training, each client’s copy of the model has changed slightly. The client sends only these changes which we call as the <strong>model update</strong> back to the server. An update is essentially a bundle of small numerical adjustments describing how the model shifted. It contains no photos, no messages, no records.</p><p><strong>Step 4 - The server combines everything.</strong> The server now has updates coming in from many clients. It merges them together into one improved global model. The most common way to do this is to average all the updates, giving more weight to clients that trained on more data. This merging step is called <strong>aggregation, </strong>combining many separate updates into one.</p><p><strong>Step 5 - Repeat.</strong> The server now has a slightly smarter global model. It sends this improved version back out to clients, and the whole cycle begins again. Round after round, the shared model keeps getting better even though the server never once saw anyone’s actual data.</p><p>Do this hundreds or thousands of times, and you end up with a genuinely strong model built from everyone’s data, without that data ever being pooled together.</p><p><strong>Where Federated Learning Is Already Being Used</strong></p><p><strong>Your phone’s keyboard -</strong> Predictive text and autocorrect on smartphones are a classic real-world use. The keyboard learns from how you type without shipping your keystrokes off your device.</p><p><strong>Healthcare -</strong> Multiple hospitals can jointly train a model to help detect disease in medical images, each keeping its own patients’ data private and in-house. This lets institutions collaborate on better diagnostic tools without ever sharing confidential records.</p><p><strong>Banking and finance -</strong> Banks can work together to build stronger fraud-detection models by sharing what the model learns about fraud patterns, without exposing any individual customer’s transactions.</p><p><strong>Smart devices and cars -</strong> Devices spread across the world can collectively improve shared features such as voice recognition, image features, and driving-assistance systems while each device keeps its own recordings local.</p><p>The common thread is always the same, the data is valuable, the data is sensitive, and the data can’t be pooled, but everyone still benefits from a model trained across all of it.</p><p><strong>What Federated Learning Is Not</strong></p><p>This is to clear up a common misunderstanding, because it’s easy to over-promise here. Federated Learning keeps raw data on the device, that’s its whole point. But sending model updates instead of data isn’t automatically, perfectly private on its own. Clever attackers can sometimes try to infer things from the updates. Because of that, real systems usually combine Federated Learning with extra privacy techniques that add mathematical protection on top. Federated Learning is a powerful foundation for privacy-friendly machine learning, not a method that solves privacy entirely by itself. We’ll dig into those extra protections in a later article. In the next article, let’s discuss another interesting part of Federated Learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a53764af0c16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to gRPC]]></title>
            <link>https://medium.com/@wgkrashintha/an-introduction-to-grpc-0fe79829df4d?source=rss-32289814b433------2</link>
            <guid isPermaLink="false">https://medium.com/p/0fe79829df4d</guid>
            <dc:creator><![CDATA[Kavith Rashintha]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 08:48:13 GMT</pubDate>
            <atom:updated>2025-03-31T08:48:13.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0TkcwPCV6YeRq5qae0a4w.png" /></figure><p>When it comes to the gRPC, we need to know about the client-server model before going to gRPC. Therefore, let’s see what is client-server model.</p><p><strong>What is Client-Server Model ?</strong></p><p>When it comes to the client-server model, it is a distributed application structure that partitioned the tasks of an application to service providers and the service requesters. Service provider are called as server and the requesters are called as clients. If simply explain how this model works is, when a client send a request to the server through the internet. Server process the request and send the response back to the client through the internet. Because of the separation, there should be a communication method between client and server in an application which has client-server model such as HTTP (such as REST APIs), WebSockets, gRPC, etc… This is how our topic became about the gRPC and let’s see what is gRPC.</p><p><strong>What is gRPC ?</strong></p><p>gRPC is an open-source Remote Procedure Call (RPC) framework used for communication in a client-server model. Before moving forward with gRPC, let’s see what is remote procedure call. <strong>Remote procedure call</strong> is a protocol that calls a procedure (such as a function) in a remote server as if it were a local procedure call. You may curious about the statement which is “as if it were a local procedure call”. That means when you are calling a procedure in a remote server, you don’t have to worry about the network details such as how the calling request delivered to the remote server. It is like you are calling a function which exists on your local computer’s code. This is the simple explanation about RPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*F9_8kSMB-WoNLHtvVSVTZQ.png" /></figure><p><strong>Client</strong> is the component which makes the RPC request to call a procedure on a remote server. <strong>Stub</strong> is a component which acts as a proxy for the client or the server. <strong>Client stub</strong> is the one that provides a local interface to the client to call remote procedures on a remote server. <strong>Server</strong> is the component which receive and process the RPC requests which comes from the client. This is because the server hosts the procedures. <strong>Server stub</strong> is the one that truly invoke the procedures. Then it send the result to the client stub. This is how the RPC work which is presented in the above diagram.</p><p><strong>gRPC</strong> is a specific implementation of RPC. gRPC became very useful for distributed application and gRPC provides a fast and high performance framework to connect those distributed applications. gRPC uses HTTP/2 which supports multiplexing (Send multiple requests over a single connection) and data serialization to accomplish these requirements. Data serialization is a way to structure data in to a format that can be transfer over a network when we are communicating between two end points which use two different data formats. What happen in data serialization is a process converting complex data into small, encoded package which is a compact binary format. gRPC uses protocol buffer (Protobuf) to perform data serialization. To implement protobuf, first we have to create <strong>.proto</strong> file and define the data structure that needs to transfer over the network. Then use the protobuf compiler and generate the code with a chosen language. Then the code will convert the data in to the defined structure and transfer over the network. Protobuf is the gRPC’s interface definition language (IDL) and this helps the real-time data sharing and processing.</p><p><strong>How gRPC Works ?</strong></p><p>To explain the how gRPC is working, let’s use below diagram of a simple application which uses gRPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_MmfRFj06JNxlSbKYhuJw.png" /></figure><p>When an application uses gRPC for the communication between the client and the server, we can represent the application as above diagram. <strong>gRPC server</strong> is the component which host the procedures that need to be executed through remote procedure calls. <strong>gRPC client</strong> call the procedures which has hosted in the gRPC and for that a client has a gRPC stub. gRPC stub serialize the request <strong>(Proto request)</strong> and send to the gRPC server using HTTP/2. When the server receives the request it deserialize the request and perform the procedure according to the request from the client. Then the server send the response and server also serialize the response <strong>(Proto response)</strong> and sent it the respective client. You might wonder why I did not mentioned about a gRPC stub on the server component. Because there is no need of a gRPC stub for the server as stub Pact as a proxy for calling remote procedures and server directly implement the procedures. At the end, client receives the respond and the request will be deserialized. This how a simple client-server application which uses gRPC works. Along with all of these, gRPC possesses several significant features which make it special among other communication methods. Let’s see what are they.</p><p><strong>Features of gRPC</strong></p><p><strong>HTTP/2</strong> — HTTP is a transfer protocol that uses to exchange information. gRPC uses HTTP/2 as its transfer protocol for the communication. HTTP/2 provides multiplexing which enables to have multiple requests in a single connection. gRPC uses channels to send multiple requests over multiple connections</p><p><strong>Bidirectional Streaming</strong> — Streaming is continuous data exchange between the client and the server without closing the connection. Bidirectional streaming means both the client and the server can stream data independently in the same time. Bidirectional streaming enables greater flexibility in communication.</p><p><strong>Code Generation</strong> — gRPC uses a compiler to generate both the client side and the server side code according to the .proto file. The compiler supports various languages for the code generation.</p><p><strong>TLS Based Security </strong>— gRPC has built-in transport layer security which encrypt the data that will be exchanged over the connection.</p><p><strong>Various Methods For Data Transmission</strong> — gRPC has both the unary, bidirectional streaming, client-side streaming, server-side streaming. Unary method just sent a request from the client to the server and server process the request and send a respective response. Bidirectional streaming is another method and explain in an above feature. Client-side streaming is client send multiple requests at once and the server send response at a time. Server-side streaming is client send a one request and server responds with multiple responses.</p><p>So, this is the comprehensive introduction to gRPC as the first article of the gRPC article series. From this article you have got the knowledge of what is client-server model, what is RPC, what is gRPC, how gRPC works, and what are the features that make the gRPC special from other communication methods. Hope you guys got a good understanding about the gRPC and there will be more articles regarding gRPC in future. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0fe79829df4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>