Simple Algorithm
Deep Learning · Emergence · 28 min

Mode Connectivity & Permutation Symmetry

Low-loss paths between solutions, weight matching and linear interpolation.

Train the same network twice from different random seeds, and the straight line between the two solutions climbs over a ridge of high loss. Yet the two are joined by simple curves of low loss, copies that share a short stretch of training are joined by straight lines, and much of the ridge between independent runs disappears once their hidden units are put in the same order. This lesson develops these findings, the algorithms behind them and the conjecture they support.

What you’ll learn

  • Define loss barriers and (linear) mode connectivity, construct low-loss curves between two solutions, and state when dropout stability guarantees such paths.
  • Describe instability analysis and the finding that linear connectivity sets in early in training, and connect it to lottery tickets, federated averaging and weight averaging.
  • State the permutation conjecture, count the symmetries behind it, and derive weight matching as a sequence of linear assignment problems.
  • Derive variance collapse in averaged networks and its REPAIR correction, and weigh the evidence on width, depth, training time and the conjecture's limits.

Curves of low loss

Let θA\boldsymbol\theta_A and θB\boldsymbol\theta_B be two trained networks with the same architecture, for instance from two random seeds. How the loss behaves on paths between them shows how the low-loss regions of the loss landscape fit together.

Garipov, Izmailov, Podoprikhin, Vetrov & Wilson (2018) searched for low-loss curves directly. They fix the two endpoints and train the free parameters of a simple curve, a polygonal chain with one bend or a quadratic Bézier curve with one control point ω\boldsymbol\omega:

ϕω(t)=(1−t)2 θA+2t(1−t) ω+t2 θB,min⁡ω Et∼U[0,1][L(ϕω(t))]\boldsymbol\phi_{\boldsymbol\omega}(t)=(1-t)^2\,\boldsymbol\theta_A+2t(1-t)\,\boldsymbol\omega+t^2\,\boldsymbol\theta_B,\qquad\min_{\boldsymbol\omega}\ \E_{t\sim U[0,1]}\Big[\loss\big(\boldsymbol\phi_{\boldsymbol\omega}(t)\big)\Big]
Each training step samples a point tt on the curve and takes an SGD step on L(ϕω(t))\loss(\boldsymbol\phi_{\boldsymbol\omega}(t)) with respect to ω\boldsymbol\omega, an unbiased stochastic gradient of the loss averaged along the curve.

Between independently trained ResNets, VGG networks and wide ResNets on CIFAR-10 and CIFAR-100, they found curves along which the training loss and the test accuracy stay nearly constant. Draxler, Veschgini, Salmhofer & Hamprecht (2018) reached the same conclusion with the nudged elastic band method from chemistry and called the paths "essentially flat": minima look less like the bottoms of separate valleys than like points on one connected low-loss manifold. Yet networks along a curve make different predictions, enough that ensembling them helps. Garipov et al. turned this into fast geometric ensembling: after about 80% of a normal training run, a cyclical learning rate with cycles of 2 to 4 epochs keeps the weights moving through the low-loss region, and the checkpoints taken where the rate is lowest form an ensemble for about the price of one run. Averaging such checkpoints instead of their predictions is the subject of Weight Averaging: SWA, EMA & Model Soups.

Check your understanding

In Kuditipudi et al.'s construction, what does permuting the hidden units of one network achieve?

  1. It makes the two networks compute the same function, so the path becomes trivial
  2. It puts one network's surviving units into the slots the other leaves empty, so one half can be faded out while the other is faded in
  3. It lowers the loss of the permuted network
  4. It aligns the two networks so that the straight line between them has no barrier
Show the answer

B. It puts one network's surviving units into the slots the other leaves empty, so one half can be faded out while the other is faded in

After the dropout moves, each network uses at most half the units of every layer. A permutation, which leaves the function unchanged, moves one network's survivors into the other's empty slots. With disjoint units, a few segments can switch one network off while switching the other on without the two interfering.

Linear connectivity sets in early

Curves must be trained; straight lines are free. Frankle, Dziugaite, Roy & Carbin (2020) asked when two runs end in the same linearly connected region, using instability analysis: train a network to step kk, make two copies, finish training each with different SGD noise (data order and augmentation), and measure the error barrier on the straight line between the two results. At k=0k=0, two runs from one shared initialization, every network they studied except a small LeNet on MNIST ended in regions separated by a barrier. After a short stretch of shared training the barrier was gone:

NetworkDataStable to SGD noise from
LeNetMNISTinitialization
ResNet-20CIFAR-10iteration 2,000 (3% of training)
VGG-16CIFAR-10iteration 1,000 (1.5%)
ResNet-50ImageNetepoch 18 (20%)
Inception-v3ImageNetepoch 28 (16%)
Measured with the test error by Frankle et al. (2020). From that point on, the outcome of training is confined to one linearly connected region, whatever the later SGD noise.

Three practices rest on this observation.

  • Lottery tickets. Sparse subnetworks found by iterative magnitude pruning reach full accuracy only from a point at which they are stable in this sense: at initialization for small MNIST networks, early in training for ResNet-50 and Inception-v3 on ImageNet. That is why large-scale tickets are rewound to an early iterate rather than to initialization (Pruning, Sparsity & Lottery Tickets).
  • Federated averaging. McMahan et al. (2017) trained pairs of MNIST networks, each on its own 600 examples, and averaged their weights: from different initializations the average was a poor model, while from a shared initialization it had lower loss on the full training set than either parent. Federated averaging, which repeatedly averages client models that each start from the current shared model, relies on this.
  • Weight averaging. Checkpoints of one run, and fine-tuned copies of one pretrained model (which stay in one basin: Neyshabur, Sedghi & Zhang, 2020), can be averaged into a single better model for the same reason (Weight Averaging: SWA, EMA & Model Soups; Model Merging & Task Arithmetic).
Think first Averaging the weights of two ResNet-20s trained on CIFAR-10 from different seeds gives a network far worse than either. Two copies spawned from a checkpoint at 5% of training and then finished separately average with almost no increase in error. Why the difference?

The independent runs end in regions separated by a barrier, partly because their hidden units sit in unrelated orders, so the average mixes units that do different jobs. Copies spawned after the stability point, about 3% of training for ResNet-20, end in one linearly connected region, and their average lies on a low-loss segment. Putting the independent runs' units in the same order first, the subject of the next step, recovers much of what averaging lost.

Permutations: the conjecture and the matching algorithms

Why do independent runs end in different regions at all? One reason is guaranteed by permutation symmetry. Reordering the nn units of a hidden layer, together with the rows of its incoming weights and the columns of its outgoing weights, leaves the function unchanged, so a network with hidden widths n1,…,nL−1n_1,\dots,n_{L-1} has ∏ℓnℓ!\prod_\ell n_\ell! copies of every solution, and 2nℓ2^{n_\ell} times more per layer when the activation is odd, like tanh, because all of a unit's weights can flip sign (Symmetries & Conservation Laws). Two runs that learned exactly the same features would still differ by a permutation, and averaging them would mix units that play different roles.

Predict before you look

A hidden layer has 512512 units. About how many orderings of its units compute the same function? Give log⁡10(512!)\log_{10}(512!).

Show the answer

1167 log₁₀

By Stirling's formula, log⁡10n!≈nlog⁡10(n/e)+12log⁡10(2πn)=512×2.275+1.75≈1166.5\log_{10}n!\approx n\log_{10}(n/e)+\frac12\log_{10}(2\pi n)=512\times2.275+1.75\approx1166.5, so 512!512! has 1,167 digits. Even the widget's network below, with two tanh layers of 32 units, has (232⋅32!)2≈1090(2^{32}\cdot32!)^2\approx10^{90} equivalent copies of each solution. No search can try them all: the alignment has to be computed.

DerivationWeight matching (Ainsworth, Hayase & Srinivasa, 2023)
  1. min⁡π∥θA−π(θB)∥2  ⟺  max⁡P1,…,PL−1 ∑ℓ=1L⟨WℓA,  PℓWℓBPℓ−1⊤⟩F\min_\pi\norm{\boldsymbol\theta_A-\pi(\boldsymbol\theta_B)}^2\iff\max_{P_1,\dots,P_{L-1}}\ \sum_{\ell=1}^{L}\big\langle W^A_\ell,\;P_\ell W^B_\ell P_{\ell-1}^\top\big\rangle_F

    A permutation π\pi acts on network B layer by layer, Wℓ↦PℓWℓPℓ−1⊤W_\ell\mapsto P_\ell W_\ell P_{\ell-1}^\top with permutation matrices PℓP_\ell (P0=PL=IP_0=P_L=I: inputs and outputs stay fixed; biases are permuted with their units). Choose π\pi to bring B closest to A. Permutations preserve norms, so this maximizes an inner product:

  2. max⁡Pℓ ⟨Pℓ,  WℓAPℓ−1(WℓB)⊤+(Wℓ+1A)⊤Pℓ+1Wℓ+1B⟩F\max_{P_\ell}\ \Big\langle P_\ell,\;W^A_\ell P_{\ell-1}(W^B_\ell)^\top+(W^A_{\ell+1})^\top P_{\ell+1}W^B_{\ell+1}\Big\rangle_F

    Each term is bilinear in two neighboring permutations, and the joint problem, a sum of bilinear assignment problems, is NP-hard for L>2L>2. With every other layer fixed, though, the objective is linear in PℓP_\ell:

  3. max⁡P∈Sn⟨P,C⟩F=max⁡σ∈Sn ∑i=1nCiσ(i)\max_{P\in S_n}\langle P,C\rangle_F=\max_{\sigma\in S_n}\ \sum_{i=1}^nC_{i\sigma(i)}

    Maximizing ⟨P,C⟩F\langle P,C\rangle_F over permutation matrices is the linear assignment problem, which the Hungarian method solves exactly in O(n3)\order{n^3} time. Weight matching sweeps over the layers, solving one assignment problem at a time, until no permutation changes: coordinate ascent that runs in seconds and needs no data. Activation matching instead pairs units whose activations agree on the training data, solving max⁡P⟨P,ZA(ZB)⊤⟩F\max_P\langle P,Z^A(Z^B)^\top\rangle_F for each layer separately, with ZZ the units' activations over the dataset.

python
import torch
from scipy.optimize import linear_sum_assignment

def align_hidden(A, B):
    """Permute the hidden units of B (Linear, ReLU, Linear) to best match A's weights."""
    W1a, b1a, W2a = A[0].weight, A[0].bias, A[2].weight
    W1b, b1b, W2b = B[0].weight, B[0].bias, B[2].weight
    # similarity of A's unit i and B's unit j: incoming weights, bias and outgoing weights
    S = W1a @ W1b.T + torch.outer(b1a, b1b) + W2a.T @ W2b
    _, perm = linear_sum_assignment(S.detach().numpy(), maximize=True)  # exact LAP, O(n³)
    with torch.no_grad():
        B[0].weight.copy_(W1b[perm]); B[0].bias.copy_(b1b[perm])
        B[2].weight.copy_(W2b[:, perm])
    return B                       # the same function, at a different point in weight space

With one hidden layer, weight matching is a single assignment problem, solved exactly by scipy.optimize.linear_sum_assignment. The aligned B computes exactly what B did, up to rounding; only its position in weight space, and so the straight path from A, has changed.

Variance collapse and the limits of alignment

DerivationWhy averaged networks lose their signal (Jordan et al., 2023)
  1. Var⁡(XA+XB2)=σ2+σ2+2ρσ24=1+ρ2 σ2\Var\Big(\frac{X_A+X_B}{2}\Big)=\frac{\sigma^2+\sigma^2+2\rho\sigma^2}{4}=\frac{1+\rho}{2}\,\sigma^2

    Take an aligned pair of first-layer units, with pre-activations XAX_A and XBX_B (random over the data), equal variances σ2\sigma^2 and correlation ρ\rho. The averaged network's unit computes their average:

  2. ρ=0.4⟹Var⁡(XA+XB2)=0.7 σ2\rho=0.4\quad\Longrightarrow\quad\Var\Big(\frac{X_A+X_B}{2}\Big)=0.7\,\sigma^2

    Aligned units are similar but not identical: Jordan et al. report correlations around 0.40.4 as typical, so the averaged unit keeps about 70% of the variance. The shrinkage compounds through the layers, and deep layers of an averaged network become nearly constant across inputs: a variance collapse that alignment alone cannot undo.

  3. E[Xα]=(1−α) E[XA]+α E[XB],std⁡(Xα)=(1−α)std⁡(XA)+αstd⁡(XB)\E[X_\alpha]=(1-\alpha)\,\E[X_A]+\alpha\,\E[X_B],\qquad\operatorname{std}(X_\alpha)=(1-\alpha)\operatorname{std}(X_A)+\alpha\operatorname{std}(X_B)

    REPAIR rescales and shifts each unit (or channel) of the interpolated network θα\boldsymbol\theta_\alpha so that its mean and standard deviation over the data equal the interpolations of the endpoints' statistics, which costs a few passes over training data:

On top of neuron alignment, REPAIR reduced barriers by 60% to 100% across architecture families and datasets: by 90% for ResNet-18 on CIFAR-10 and by 74% for ResNet-50 on ImageNet. What else the evidence says:

  • Width. Ainsworth et al. found no linear connectivity after alignment for ResNet-20 and VGG-16 of standard width on CIFAR-10, but the barrier fell with width and reached zero for a ResNet-20 32 times wider than standard, the first zero-barrier connection between independently trained ResNets on CIFAR-10. On ImageNet, alignment cut the ResNet-50 barrier by 67% without removing it.
  • Training time. Alignment found no linear connectivity early in training: it emerges as training proceeds.
  • Depth. Without alignment, barriers grow quickly with depth (Entezari et al., 2022).
  • The optimizer. Ainsworth et al. built solutions that no permutation linearly connects. They are not SGD solutions, so the conjecture survives, but connectivity must then come partly from SGD's implicit bias rather than from the landscape alone. Other symmetries, such as rescalings and features that move between layers, exist as well.
  • Theory. Ferbach, Goujaud, Gidel & Dieuleveut (2024) proved, from convergence rates of empirical measures in Wasserstein distance, that two wide enough two-layer networks trained by SGD are linearly connected after permutation with high probability, and bounded the widths at which deep networks with independent neuron weights become connected. The required width grows with the dimension of the support of the neurons' weight distribution, which also tracked connectivity in their experiments.

Key takeaways

  • The barrier B(θA,θB)B(\boldsymbol\theta_A,\boldsymbol\theta_B) is the largest rise of the loss above the chord on the straight path. Independent solutions have high barriers on straight lines but are joined by simple low-loss curves (Garipov et al., 2018), and dropout-stable solutions provably by piecewise-linear paths (Kuditipudi et al., 2019).
  • Copies that share a short stretch of training end linearly connected: after about 3% of training for ResNet-20 on CIFAR-10 and 20% for ResNet-50 on ImageNet (Frankle et al., 2020). Lottery-ticket rewinding, federated averaging and weight averaging rely on this.
  • Permutation symmetry gives every solution ∏ℓnℓ!\prod_\ell n_\ell! copies. The conjecture says SGD's solutions are linearly connected modulo permutations; weight matching aligns networks by coordinate ascent over layer-wise linear assignment problems, activation matching by correlating units.
  • Averaging aligned units with correlation ρ\rho keeps only 1+ρ2\frac{1+\rho}2 of their variance, compounding with depth; REPAIR restores the statistics and cuts barriers by 60–100%. Zero barriers have been reached only for wide networks on small datasets, connectivity emerges during training, and non-SGD counterexamples show it depends on SGD's implicit bias.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

In instability analysis, two copies of a network are trained from its state at step kk with different data orders and augmentations. What did Frankle et al. (2020) find for ResNet-20 on CIFAR-10?

  1. The final networks were separated by a barrier for every kk
  2. They were linearly connected for every kk, including k=0k=0
  3. They were separated by a barrier for k=0k=0, but linearly connected once kk reached about 3% of training
  4. They were linearly connected only for k=0k=0
Show the answer

C. They were separated by a barrier for k=0k=0, but linearly connected once kk reached about 3% of training

From a shared initialization the two runs still end in different regions, but after about 2,000 iterations of shared training, 3% of the run, SGD noise no longer changes which linearly connected region training ends in.

Question 2

How does weight matching (Ainsworth, Hayase & Srinivasa, 2023) find the permutations that align network B with network A?

  1. By gradient descent on the entries of the permutation matrices
  2. By trying all n!n! orderings of each layer
  3. It needs the training data to compare the units' activations
  4. With the other layers fixed, choosing one layer's permutation is a linear assignment problem, solved exactly in O(n3)\order{n^3} time; it sweeps over the layers until nothing changes, since the joint problem is NP-hard
Show the answer

D. With the other layers fixed, choosing one layer's permutation is a linear assignment problem, solved exactly in O(n3)\order{n^3} time; it sweeps over the layers until nothing changes, since the joint problem is NP-hard

The objective ∑ℓ⟨WℓA,PℓWℓBPℓ−1⊤⟩F\sum_\ell\langle W^A_\ell,P_\ell W^B_\ell P^\top_{\ell-1}\rangle_F is linear in each PℓP_\ell when its neighbors are fixed, so each sub-step is an assignment problem for the Hungarian method. The joint problem, a sum of bilinear assignment problems, is NP-hard, hence the coordinate ascent.

Question 3

Two aligned hidden units have equal variance and correlation ρ=0.6\rho=0.6 over the data. What fraction of that variance does the corresponding unit of the averaged network keep?

  1. 0.80.8
  2. 0.60.6
  3. 1.01.0
  4. 0.50.5
Show the answer

A. 0.80.8

Var⁡(XA+XB2)=1+ρ2σ2=0.8 σ2\Var\big(\frac{X_A+X_B}2\big)=\frac{1+\rho}{2}\sigma^2=0.8\,\sigma^2. The shrinkage compounds layer by layer, which is the variance collapse that REPAIR corrects by restoring each unit's mean and standard deviation.

Question 4

Ainsworth et al. constructed solutions, not found by SGD, that no permutation can linearly connect. What does this imply for the permutation conjecture?

  1. It refutes the conjecture
  2. It shows that permutations play no role in barriers
  3. It does not contradict it, because the conjecture is about SGD's solutions; connectivity must then come partly from SGD's implicit bias, not from the landscape alone
  4. It shows that wider networks are always linearly connected
Show the answer

C. It does not contradict it, because the conjecture is about SGD's solutions; connectivity must then come partly from SGD's implicit bias, not from the landscape alone

The conjecture claims that SGD's solutions, with high probability, form a set that is linearly connected modulo permutations. Adversarially built minima outside that set do not contradict it, but they show the landscape alone does not guarantee connectivity.

Further reading

  • T. Garipov, P. Izmailov, D. Podoprikhin, D. Vetrov & A. G. Wilson, "Loss surfaces, mode connectivity, and fast ensembling of DNNs," NeurIPS (2018).
  • J. Frankle, G. K. Dziugaite, D. M. Roy & M. Carbin, "Linear mode connectivity and the lottery ticket hypothesis," ICML (2020).
  • R. Entezari, H. Sedghi, O. Saukh & B. Neyshabur, "The role of permutation invariance in linear mode connectivity of neural networks," ICLR (2022).
  • S. K. Ainsworth, J. Hayase & S. Srinivasa, "Git Re-Basin: Merging models modulo permutation symmetries," ICLR (2023).
  • K. Jordan, H. Sedghi, O. Saukh, R. Entezari & B. Neyshabur, "REPAIR: REnormalizing permuted activations for interpolation repair," ICLR (2023).