The problem

Neural networks are heavily over-parameterised. Removing most of their weights cuts memory and compute, but choosing which weights to keep is a subset-selection problem: picking the best k of d features is NP-hard even for linear regression.

Most practical methods are greedy. They rank weights by size or by an estimated importance and cut the lowest. We asked whether a principled optimisation of the selection, and a smarter way to merge neurons instead of deleting them, could do better, and in which situations.

Direction 1: block-annealed selection

Selection matrix. A layer's weights are written as \(w = Qx\). The vector \(x \in \mathbb{R}^k\) holds the \(k\) values that will survive, and column \(j\) of \(Q\) says where value \(x_j\) is placed:

$$ \begin{aligned} & w = Q\,x \\ & q_{rj} \ge 0, \quad \textstyle\sum_{r} q_{rj} = 1, \quad q_{rj} = 0 \;\text{ for } r \notin \mathcal{B}_j \end{aligned} $$
(1)
Each column is a probability distribution over the positions of its own block.
where
\(Q \in [0,1]^{d \times k}\)
soft selection matrix; a one-hot column puts \(x_j\) in exactly one position
\(\mathcal{B}_j\)
the block of candidate positions owned by column \(j\) (blocks are disjoint, so two columns never pick the same weight)
\(k\)
number of weights kept: one per block

Annealed objective. \(Q\), \(x\) and the biases \(b\) are trained together. At each stage of the anneal, the method minimises

$$ \begin{aligned} J_\beta(Q,x,b) = \; & \underbrace{\mathcal{L}(Qx,\,b)}_{\text{fit}} + \lambda_x \lVert x \rVert_2^2 \\ & - \frac{1}{\beta}\sum_{r,j} H_{\mathrm{bin}}(q_{rj}) \\ & + \lambda_v\,\underbrace{\tfrac12 \textstyle\sum_r S_r \sum_j x_j^2\, q_{rj}(1-q_{rj})}_{\text{variance term}} \end{aligned} $$
(2)
where
\(\mathcal{L}\)
training loss of the network with weights \(Qx\)
\(H_{\mathrm{bin}}(q) = -q\log q - (1-q)\log(1-q)\)
binary entropy; rewards soft, undecided columns
\(\beta\)
inverse temperature: small at first, raised between stages
\(S_r\)
curvature estimate for position \(r\) (Gauss–Newton diagonal)
\(\lambda_x,\ \lambda_v\)
weights of the \(\ell_2\) and variance penalties

With small \(\beta\) the entropy term dominates and every column stays spread over its block, so the network behaves like a smooth average of its candidates. As \(\beta\) grows, the variance term takes over. It is the expected extra loss of sampling a hard choice from \(Q\), and it is zero only when every column is one-hot, so it pushes the columns to commit.

Update for \(Q\). Within a stage, \(x\) and \(b\) take Adam steps, and each column of \(Q\) moves toward a closed-form Gibbs target:

$$ T_{rj} \;=\; \sigma\!\big(-\beta\,(\Xi_{rj} + \theta_j)\big), \qquad \sum_{r \in \mathcal{B}_j} T_{rj} = 1 $$
(3)
θj is found by bisection so that each column still sums to one.
where
\(\Xi_{rj}\)
gradient of the non-entropy part of \(J_\beta\) with respect to \(q_{rj}\)
\(\sigma\)
logistic sigmoid

Hardening. Once every live column has \(\max_r q_{rj} \gt 0.99\), columns with negligible \(|x_j|\) are dropped and the rest are rounded to their arg-max, giving a network with exactly one weight per block. The surviving values can optionally be retrained with the positions fixed ("refit").

Benchmarking protocol: how "a clear win" is defined

Every method is compared at the same number of non-zero weights, retrained with the same recipe, and run with 3 seeds. A difference \(\Delta\) between two methods is called clear only if it exceeds the seed noise:

$$ |\Delta| \;\gt\; 3 \cdot \max(\mathrm{sd}_A,\ \mathrm{sd}_B) $$
(4)

For example, with 1,000 MNIST images the gap is \(86.29 - 82.27 = 4.02\) points against a threshold of \(3 \times 0.87 = 2.61\), so it counts as clear. At 10,000 images the gap to sparse VD is 0.16 points, well inside the noise, so it is reported as a tie.

Accuracy with limited training data

Mean of 3 seeds. The block-annealed network is the most accurate at every size, by the widest margin with 1,000 images. A likely reason is that the block rule limits how many inputs each neuron can use, which acts as a regulariser when data is scarce.

ACAS Xu. ACAS Xu is a set of small collision-avoidance networks for unmanned aircraft, known to be hard to prune. On network 1_1, the block-annealed network agrees with the original on 73.8% of non-trivial advisories without any retraining, against 62.4% for the strongest data-driven baseline (greedy pruning).

ACAS Xu network 1_1, no retraining

Agreement (%) with the original network on non-COC advisories, mean of 3 seeds. After 5 or more epochs of retraining, greedy pruning overtakes (81.2% at 60 epochs), because it keeps the original trained weights.

Direction 2: clustering-based neuron merging

Structured pruning removes whole neurons or filters, and the work those neurons did is lost. Neuron merging compensates by folding each removed neuron into a similar kept one. It is exact only for ReLU-like activations.

I proposed a data-free alternative: group a layer's neurons by k-means on their incoming weights, bias and outgoing weights, then replace each cluster with a single neuron whose incoming weights are the cluster average and whose outgoing weights are the cluster sum. The merge is exact for identical neurons under any activation, and its error is bounded by the k-means objective. No data and no fine-tuning are needed.

VGG-16 on CIFAR-10: accuracy vs pruning ratio

Original accuracy 92.55% with 14.98M parameters, no fine-tuning. Clustering is ahead up to 60% pruning (+2.97 points at 60%). Beyond 70%, clusters contain dissimilar neurons whose average shrinks, and neuron merging wins.

Clustering-based merging: the maths

Step 1: one vector per neuron. For neuron \(j\) of a layer, stack its incoming weights, bias and outgoing weights:

$$ v_j \;=\; \big[\, w_j \,;\; b_j \,;\; a_j \,\big] $$
(5)
Two neurons are interchangeable only if they compute the same thing (w, b) and are used the same way by the next layer (a).

Step 2: cluster. k-means++ on \(v_1,\dots,v_N\) gives \(k = \lfloor (1-p)N \rfloor\) clusters \(C_1,\dots,C_k\) for pruning ratio \(p\).

Step 3: merge. Each cluster becomes one neuron. Its inputs are averaged, but its outputs are summed, because it must replace the outputs of all \(|C_i|\) members:

$$ \tilde w_i = \frac{1}{|C_i|}\sum_{j \in C_i} w_j, \qquad \tilde b_i = \frac{1}{|C_i|}\sum_{j \in C_i} b_j, \qquad \tilde a_i = \sum_{j \in C_i} a_j $$
(6)

Why it works. Let \(c_i\) be the centroid of cluster \(i\) (with the input \(x\) extended by a constant 1 so that the bias is part of the dot product). The error of the compressed layer is

$$ y - \hat y \;=\; \sum_{i=1}^{k} \sum_{j \in C_i} a_j \big[\, f(w_j \cdot x) - f(c_i \cdot x) \,\big] $$
(7)
Each bracket compares a neuron with its centroid.
Result 1: identical neurons are merged exactly, for any activation

If every member of a cluster equals its centroid, every bracket in (7) is zero, so \(\hat y = y\) whatever the activation \(f\) is. Without the sum in (6), that is, using the average outgoing weight \(\bar a_i\), the error would be \(\sum_i (|C_i|-1)\,\bar a_i\, f(c_i \cdot x) \ne 0\). Neuron merging, in contrast, is exact only for positive multiples of a neuron and only for ReLU.

Result 2: the error is bounded by the k-means objective

If \(f\) is \(L\)-Lipschitz (\(L = 1\) for ReLU and tanh, \(L = \tfrac14\) for sigmoid), and \(c\) denotes the centroid of neuron \(j\)'s cluster, then

$$ \begin{aligned} \lVert y - \hat y \rVert &\le \sum_j \lVert a_j \rVert \, \big| f(w_j \cdot x) - f(c \cdot x) \big| && \text{triangle inequality} \\ &\le L\,\lVert x \rVert \sum_j \lVert a_j \rVert\,\lVert w_j - c \rVert && \text{Lipschitz, Cauchy–Schwarz} \\ &\le L\,\lVert x \rVert \Big(\sum_j \lVert a_j \rVert^2\Big)^{1/2} \Big(\underbrace{\sum_j \lVert w_j - c \rVert^2}_{\text{k-means objective}}\Big)^{1/2} && \text{Cauchy–Schwarz for sums} \end{aligned} $$

So k-means directly minimises an upper bound on the output error. The centroid is the best merge point for this bound, because for any point \(c\), \(\sum_{j \in C_i} \lVert w_j - c \rVert^2 = \sum_{j \in C_i} \lVert w_j - c_i \rVert^2 + |C_i|\,\lVert c_i - c \rVert^2\).

Result 3: the centroid cancels the first-order error

For smooth \(f\), a Taylor expansion gives \(f(w_j \cdot x) - f(c_i \cdot x) = f'(c_i \cdot x)\,(w_j - c_i)\cdot x + r_j\), with \(r_j\) of second order in \(\lVert w_j - c_i \rVert\). Writing \(a_j = \bar a_i + \delta_j\):

$$ y - \hat y = \sum_i f'(c_i \cdot x) \Big[ \bar a_i \Big( \underbrace{\textstyle\sum_{j \in C_i} (w_j - c_i)}_{=\,0\ \text{for the centroid}} \Big) \cdot x + \sum_{j \in C_i} \delta_j\,(w_j - c_i)\cdot x \Big] + \sum_j a_j r_j $$

The leading term vanishes only at the centroid. What remains is small when members are close to the centroid and have similar outgoing weights (small \(\delta_j\)), which is why the outgoing weights are part of the clustered vector (5).

All three results say the same thing: the error grows with the spread of a cluster. That explains the VGG-16 curve above. At mild compression clusters are tight and clustering wins; at heavy compression they contain dissimilar neurons, whose average is much shorter than its members, and neuron merging's explicit scale factor wins.

What I took away

  1. Annealing helps most when data or retraining is scarce. With full MNIST data it matches progressive magnitude pruning and gets far smaller than BC-GNJ (about 5× fewer weights), but sparse variational dropout is still more accurate.
  2. Keeping trained weights matters once you can retrain. After retraining, methods that start from the original weights catch up and pass it, and the annealed choice of weights is on par with the heuristics rather than better.
  3. Averaging beats scaling for noisy near-copies. In a controlled test with noisy copies of a filter, clustering's output error was about 0.7× that of neuron merging. Merging is better when similar neurons differ mainly in size.
  4. Negative results are part of the result. The ACAS Xu study covers one network of 45, and clustering loses on ImageNet VGG-16 and at heavy compression. Both are stated plainly in the report.