Learning over a network under attack
A network of devices can learn one model without a server: every device averages its model with those of its neighbors and takes gradient steps on its own data. This page shows what happens when some of the messages are altered on the way, and how RESIST, the algorithm of Fang, Dixit, Bajwa and Gürbüzbalaban (Transactions on Machine Learning Research, 2026), keeps the network learning. Its rule is short: before a node averages, it drops the largest and the smallest values it received.
A network learns to read digits, under attack
Twenty devices each hold 150 handwritten digits and train one classifier together: ten images of weights, one per digit. In every round of talk an attacker alters one of the messages that each device receives. On the left the devices average what they receive; on the right they run RESIST, under the same attack: the same hijacked links, in the same rounds. The run starts when the two networks come on screen.
Loading 3,400 handwritten digits…
What to try. Switch the altered message to a wrong model: a classifier built to read each digit as the next one. Plain averaging adopts it, so the image under 1 becomes a 0, the image under 2 becomes a 1, and nearly every digit is read one too high. Then test the first condition of the theorem: with 2 hijacked links per device and b = 1, the filter can no longer drop every altered value, and in this run RESIST fails too; with b = 2 it recovers. Click a device, or choose it in the list, to inspect its model.
In this experiment one altered message per device is enough to keep plain averaging from learning, while RESIST, which drops the extremes of what it hears, ends within a point or two of the test accuracy of the same network with no attack.
What is being computed
The problem. There are nodes (the devices above). Node holds data points and a loss that measures how badly a model fits them. The network wants the model that fits all the data, the empirical risk minimizer:
The digits task. A data point is an image of pixels with its label, taken from the MNIST database of handwritten digits (LeCun, Cortes and Burges). The model is a linear classifier, , that is, ten weight images , and is the softmax (cross-entropy) loss with a small ridge term:
Here , , , the stepsize is and a cycle has slots. The test accuracy of a device is the share of 200 further digits, which no device trained on, that its model reads correctly; a model that guesses reads about 10% of them on average. Every curve on the chart is the mean of this accuracy over all twenty devices of its run. An altered message is either the sender’s model plus Gaussian noise of standard deviation 10 in every weight, or one fixed wrong model: a classifier trained on all the digits of the network, whose ten images were then moved by one place and multiplied by 3, so that it tends to read a 3 as a 4 (it reads 188 of the 200 test digits as the next digit). A run lasts 300 slots, that is, 50 gradient steps.
The problem with two weights. The second playground, further down, replaces the digits by a problem small enough to draw: , a model is a point of the plane, and the loss is the least-squares fit
The data are generated as . With same source, every node uses the same , so the local losses differ only through sampling, and less so as grows. With different sources, every node has a of its own, and the local losses disagree however many samples there are.
The network. The nodes are scattered in the plane and every node is linked to its nearest ones. Links work in both directions; denotes the neighbors of node . No node sees the whole network, and there is no server.
The schedule. All runs on this page follow Algorithm 1 of the paper. Time is divided into slots , grouped into cycles of length : rounds of communication, then one local gradient step with stepsize .
RESIST screens the messages with a coordinate-wise trimmed mean. For each coordinate separately, node sorts the values it received, sets aside the largest and the smallest, and averages what remains together with its own value:
where is without those neighbors. The node does not try to find out which messages were altered: it drops the extremes whoever sent them, so honest messages are dropped too, and an altered value that is not extreme stays in. Plain averaging is the same rule with .
The attack on links. This is the model of the paper, a man-in-the-middle attack: every node is honest, but in each round of communication the messages on some links are replaced before they arrive. In the digits task the attacker moves to new links in every round. In the second playground the chips set how many incoming links of every node are hijacked in a round, whether the attacker keeps to the same links or moves to new ones in every round, and what an altered message carries: one fixed wrong model; the true message plus noise; the true message multiplied by ; or, coordinate by coordinate, the largest value that an honest neighbor sent, which never leaves the range of the honest values. On this page plain averaging and RESIST always face the same attack: the same links in the same rounds, the same rule and the same random draws. The altered messages themselves coincide in the two runs only when they do not depend on the models, as with the fixed wrong model; noise, for instance, is added to whatever the sender holds in that run.
The attack by agents. In the second view of that playground a fixed set of nodes is misaligned: every message they send is altered, in every round. Section 7 of the paper shows that such node-level (Byzantine) attacks, with at most faulty nodes in the whole network, are a static special case of the link model, with the compromised links being the outgoing links of the faulty nodes. The solution is then the minimizer of the losses of the honest nodes only, and on this page a misaligned agent has no loss of its own. The playground also lets you place more than of them. What the filter sees is how many of them an honest node has among its neighbors, but such a run is outside the statement of Section 7.
Let be the largest number of compromised incoming links at any node at any time. Suppose the losses are smooth, the iterates stay in a bounded set, and the network stays sufficiently connected when incoming links are removed at every node, in whichever way. Then, for a cycle length above a bound that depends on the network, and a suitable stepsize, RESIST converges at a geometric rate, up to a neighborhood, for strongly convex losses (in the distance to the minimizer) and when the average loss satisfies the Polyak–Łojasiewicz condition (in the value of the loss). For smooth nonconvex losses, with the stepsizes prescribed in the paper, the gradient of the average loss becomes small at a sublinear rate, again up to a term of the same kind. The size of the neighborhood reflects how much the local losses differ and the stepsize; when the local losses are identical and strongly convex, the convergence is exact. With independent samples from one distribution at every node, the paper also gives statistical learning rates, and the error due to the difference between the local losses vanishes as the number of samples grows.
The bound on is a sufficient condition and a conservative one: every cycle length offered on this page is far below it. The playgrounds show how the algorithm behaves in such settings; they are illustrations, not instances that the theorem covers.
What is plotted in the second playground. The distance to the solution is the mean of over the honest nodes. The stepsize is , with the largest curvature among the local losses, and every run lasts 396 slots. As in the digits task, plain averaging and RESIST face the same attack, on the same links in the same rounds.
The same algorithm on two weights, with the filter open
A model with 7,840 weights cannot be drawn, and neither can what the filter does to it. Here a model is a point of the plane, so the whole network fits in one picture and panel C shows, for one node, every value it received and which ones were dropped. The playground opens with one hijacked incoming link at every node, a different one in every round, each carrying the same wrong model. Press Play. Under plain averaging every round of talk drags the whole network toward the wrong model and every gradient step pulls it part of the way back, so it never settles. Under RESIST the same messages arrive and the filter removes almost all of their effect. The wrong model is usually an extreme value and is dropped; now and then one of its coordinates is not extreme and stays in, and honest values that happen to be extreme are dropped as well. The network settles close to the solution: in this opening instance its curve in panel B ends at about twice the distance of the dotted run without an attack, where plain averaging ends more than a hundred times further away.
Then test the first condition of the theorem. Set the hijacked links to 2 per node while RESIST still drops b = 1: the filter can no longer drop every altered value, and in this instance RESIST is dragged away as well. Raise b to 2 and it recovers. Switch the altered message to the largest honest value: such a value is not an outlier, and the filter may drop it or keep it. Either way the node is safe: as long as it hears no more altered values than it drops at each end, every coordinate of its new model lies between the smallest and the largest of its own value and the honest values it received.
Let the attack start at slot 132, after the network has learned, and watch the plain network unlearn. Choose different sources to see the neighborhood of the theorem: the nodes now hover around the solution at a distance set by how much their data disagree, with or without an attack. And switch the attack to agents: in the opening instance two misaligned agents stand apart, every honest node has at most one of them among its neighbors, and b = 1 copes; two of them next to the same honest node are too many for b = 1. Where they stand matters, and Section 7 of the paper covers only the case of at most b misaligned agents in the whole network.
20 nodes joined by 72 links (6 to 10 neighbors each). Every node holds 100 data points and fits a model with two weights to them; together they want the model that fits all 2,000 points.
Altered incoming messages per node, per round: at most 1. RESIST drops 1 at each end. That is within the first condition of the theorem (at most b). This line checks the attack budget only. The cycle lengths offered here are far below the paper’s sufficient bound on J, so a run illustrates the theorem; it does not verify its hypotheses.
A node’s shade is the distance of its model from the solution: pale at the solution, deep scarlet three units away or more (logarithmic). A scarlet arrow is a message altered in this round, pointing at the node that receives it. The number above each network is the mean distance at the slot shown. The ring marks the node inspected in panel C; click any node, or choose it in the list, to move it.
The plane of the two weights: every node has one point for each run, a filled steel dot under RESIST and a hollow ochre ring under plain averaging. The black cross is the solution, the model that fits all the data; the thin ellipses are level sets of the total loss, and the thin lines trace the average model of the network in each run. The scarlet cross is the wrong model that every altered message carries. The chart: the whole run, as the mean distance of the nodes’ models from the solution, averaged over each cycle of J slots, on a logarithmic scale; the dashed vertical line is the slot shown above. Within a cycle the models swing: talk pulls them together, or toward the attacker, and the gradient step pulls each node toward its own data.
9 messages, 1 altered. In each coordinate RESIST keeps 7 of them.
- −1.30 dropped
- −0.76
- −0.69
- 0.38
- 1.93
- 2.47
- 2.71
- 3.43
- 4.10 altered dropped
own value 1.29RESIST moves to 1.34plain averaging would move to 1.35
- −3.02 dropped
- −2.80
- −2.57
- −1.91
- −1.68
- 0.01
- 0.20
- 1.70 altered
- 1.77 dropped
own value −3.15RESIST moves to −1.28plain averaging would move to −1.15
One row per weight: the values node 1 received from its neighbors in that round of the RESIST run, sorted from smallest to largest. A graphite dot arrived as sent; a scarlet square was altered on the way. RESIST strikes out the 1 smallest and the 1 largest, whoever sent them, and moves to the mean of the rest and its own value; plain averaging would have used all of them. The filter does not classify messages: it drops honest values that are extreme, and it keeps an altered value that is not.
| Run | distance to the solution | disagreement | gradient steps |
|---|---|---|---|
| No attack, plain averaging | 0.012 | 0.089 | 66 |
| Under attack, plain averaging | 1.42 | 0.50 | 66 |
| Under attack, RESIST with b = 1 | 0.026 | 0.091 | 66 |
All three runs follow the same schedule for 396 slots from the same starting points, with the stepsize h = 1/L = 0.78 (L is the largest curvature among the local losses). Under attack, the two rules face the same attack: the same links in the same rounds, the same rule and the same random draws. The altered messages themselves are identical in the two runs only for the wrong model; the other three are built from the models of that run. The distance is the mean over the nodes of ‖wⱼ − ŵ‖, averaged over the last cycle; ŵ is the minimizer of the total loss, at distance 0.051 from the model that generated the data. The disagreement is the largest distance of a node from the network average at the last slot.
A node cannot tell which message was altered, and it does not have to: if it drops as many extremes as there can be altered messages, every coordinate of its new model stays between the smallest and the largest of its own value and the honest values it received.
The theory behind this page is in RESIST: resilient decentralized learning using consensus gradient descent by Cheng Fang, Rishabh Dixit, Waheed U. Bajwa and Mert Gürbüzbalaban (arXiv:2502.07977; Transactions on Machine Learning Research, 2026, Featured Certification): the link-level attack model in which the compromised links may change over time, the algorithm with several filtered rounds of communication for each gradient step, its convergence guarantees for strongly convex, Polyak–Łojasiewicz and smooth nonconvex losses, the statistical learning rates, and experiments on image classification (on MNIST and CIFAR-10, at a larger scale than here) with other screening rules. The page simulates the algorithm on 3,000 of the MNIST digits and on a problem small enough to draw; it is an illustration, not a proof. The wider thread is on the research page.
To reference this page:
@misc{gurbuzbalaban2026resistplayground,
title = {Learning over a network under attack, interactively},
author = {G{\"u}rb{\"u}zbalaban, Mert},
year = {2026},
howpublished = {\url{https://mert-g.org/playground/resist/}}
}