Mert Gürbüzbalaban

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 MM nodes (the devices above). Node jj holds NN data points and a loss fjf_j that measures how badly a model ww fits them. The network wants the model that fits all the data, the empirical risk minimizer:

w^=arg⁡min⁡w  1M∑j=1Mfj(w).\hat w = \arg\min_{w} \; \frac{1}{M} \sum_{j=1}^{M} f_j(w).

The digits task. A data point is an image of 28×2828 \times 28 pixels with its label, taken from the MNIST database of handwritten digits (LeCun, Cortes and Burges). The model is a linear classifier, w∈R7840w \in \mathbb{R}^{7840}, that is, ten weight images w0,…,w9w_0, \dots, w_9, and fjf_j is the softmax (cross-entropy) loss with a small ridge term:

fj(w)=−1N∑n=1Nlog⁡exp⁡(wyjn⊤xjn)∑c=09exp⁡(wc⊤xjn)+λ2∥w∥2.f_j(w) = -\frac{1}{N} \sum_{n=1}^{N} \log \frac{\exp\big(w_{y_{jn}}^\top x_{jn}\big)}{\sum_{c=0}^{9} \exp\big(w_c^\top x_{jn}\big)} + \frac{\lambda}{2} \|w\|^2 .

Here M=20M = 20, N=150N = 150, λ=10−4\lambda = 10^{-4}, the stepsize is h=0.3h = 0.3 and a cycle has J=6J = 6 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: xjn∈R2x_{jn} \in \mathbb{R}^2, a model is a point w∈R2w \in \mathbb{R}^2 of the plane, and the loss is the least-squares fit

fj(w)=12N∑n=1N(xjn⊤w−yjn)2.f_j(w) = \frac{1}{2N} \sum_{n=1}^{N} \big(x_{jn}^\top w - y_{jn}\big)^2 .

The data are generated as y=x⊤wj+noisey = x^\top w_j + \text{noise}. With same source, every node uses the same wjw_j, so the local losses differ only through sampling, and less so as NN grows. With different sources, every node has a wjw_j 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; Nj\mathcal{N}_j denotes the neighbors of node jj. 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 t=0,1,2,…t = 0, 1, 2, \dots, grouped into cycles of length JJ: J−1J - 1 rounds of communication, then one local gradient step with stepsize hh.

wj(t+1)={filterb({wi(t)}i∈Nj, wj(t))if (t+1) mod J≠0,wj(t)−h ∇fj(wj(t))otherwise.w_j(t+1) = \begin{cases} \mathsf{filter}_b\big(\{w_i(t)\}_{i \in \mathcal{N}_j},\, w_j(t)\big) & \text{if } (t+1) \bmod J \neq 0, \\[2pt] w_j(t) - h\,\nabla f_j\big(w_j(t)\big) & \text{otherwise.} \end{cases}
Definition: the filter of RESIST

RESIST screens the messages with a coordinate-wise trimmed mean. For each coordinate kk separately, node jj sorts the values it received, sets aside the bb largest and the bb smallest, and averages what remains together with its own value:

[wj(t+1)]k=1∣Nj∣−2b+1∑i ∈ Cjk(t)∪{j}[wi(t)]k,\big[w_j(t+1)\big]_k = \frac{1}{|\mathcal{N}_j| - 2b + 1} \sum_{i \,\in\, \mathcal{C}_j^k(t) \cup \{j\}} \big[w_i(t)\big]_k ,

where Cjk(t)\mathcal{C}_j^k(t) is Nj\mathcal{N}_j without those 2b2b 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 b=0b = 0.

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 −2-2; 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 bb 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 w^\hat w 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 bb 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.

What the paper proves

Let bb 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 2b2b incoming links are removed at every node, in whichever way. Then, for a cycle length JJ 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 JJ 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 ∥wj(t)−w^∥\|w_j(t) - \hat w\| over the honest nodes. The stepsize is h=1/Lh = 1/L, with LL 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

What to try

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.

the attack is oninstance 3
hijacked links
an altered message is
the attack starts
RESIST drops b =largest and smallest, per coordinate
cycle length JJ − 1 rounds of talk, then one gradient step
data per node
network

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 The same attack on the same network, under two rules
Plain averagingslot 0: mean distance 2.331234567891011121314151617181920RESIST, b = 1slot 0: mean distance 2.331234567891011121314151617181920
slot 0 of 396: round 1 of 5 of talk

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.

B The models of the nodes, and their distance to the solution
solutionthe wrong modelRESIST, b = 1plain averagingweight 1weight 2 ↑1010.10.010100200300396RESIST, b = 1, under attackplain averaging, under attackplain averaging, no attackdistance to the solution, mean over each cycle (log)time slots

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.

C The filter at node 1, in the round of slot 0

9 messages, 1 altered. In each coordinate RESIST keeps 7 of them.

weight 1
  1. −1.30 dropped
  2. −0.76
  3. −0.69
  4. 0.38
  5. 1.93
  6. 2.47
  7. 2.71
  8. 3.43
  9. 4.10 altered dropped

own value 1.29RESIST moves to 1.34plain averaging would move to 1.35

weight 2
  1. −3.02 dropped
  2. −2.80
  3. −2.57
  4. −1.91
  5. −1.68
  6. 0.01
  7. 0.20
  8. 1.70 altered
  9. 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.

At the end of the run: the distance is averaged over the last cycle, the disagreement is taken at the last slot.
Rundistance to the solutiondisagreementgradient steps
No attack, plain averaging0.0120.08966
Under attack, plain averaging1.420.5066
Under attack, RESIST with b = 10.0260.09166

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/}}
}