Automatically generated from handwritten notes — prune_a_linear_model.pdf

Efficient AI · Lecture notes · Jul 18, 2026

Pruning a neuron

Preserve the function a neuron computes under a sparsity budget, then greedily choose which weight to remove.

Setup

A linear neuron computes an inner product of weights and inputs:

\[ y = \langle w, x \rangle = w \cdot x, \qquad w, x \in \mathbb{R}^d. \]
w x y
Inputs $x$ weighted by $w$ produce
$y = \vec{w}\cdot\vec{x}$.
Q. What should we try to preserve when pruning?
Remark — inference vs training When pruning at inference time, the goal is to preserve the function the model already computes. During training, one might instead care about expressive power (capacity to learn), which leads to different considerations.

Preserving behavior under compression

We want a sparse (or budget-constrained) weight vector $\hat{w}$ that matches the original neuron on all inputs:

\[ \hat{w} \in \mathbb{R}^d \quad\text{s.t.}\quad \|\hat{w}\|_0 \le k, \qquad \hat{w}\cdot x \;\simeq\; w\cdot x \quad \forall\, x. \]

Let $X$ be representative data. Then choose $\hat{w}$ by least-squares reconstruction of the neuron’s outputs:

\[ \hat{w} = \underset{\|\hat{w}\|_0 \le k}{\arg\min} \; \bigl\| \hat{w}\cdot X - w\cdot X \bigr\|_2^2 . \]

Equivalently, introduce a binary mask $M$ and write

\[ \hat{w},\, M = \underset{ \substack{ \hat{w}\in\mathbb{R}^d \\[2pt] M\in\{0,1\}^d \\[2pt] \|M\|_0 \le k } }{\arg\min} \; \bigl\| (\hat{w} \odot M)\cdot X - w\cdot X \bigr\|_2^2 , \]

where $\odot$ is the elementwise (Hadamard) product.

Jointly optimizing $M$ and $\hat{w}$ is NP-hard (Blumensath & Davies, 2008) $\;\rightarrow\;$ use a greedy algorithm.

Which element to prune first?

Simple heuristics are incomplete:

True model
\[ y = w \cdot X \]
Approximated model
\[ \hat{y} = \hat{w} \cdot X \]

To remove one weight, solve the constrained reconstruction problem (at most $d-1$ nonzeros — some $\hat{w}_i = 0$):

\[ \min_{\|\hat{w}\|_0 \le d-1} \; \bigl\| \hat{w}\cdot X - w\cdot X \bigr\|_2^2 . \]

Greedy step: try zeroing each coordinate in turn and keep the best:

\[ \min_{\hat{w}_1=0} \|\hat{w}\cdot X - w\cdot X\|_2^2, \quad \min_{\hat{w}_2=0} \|\hat{w}\cdot X - w\cdot X\|_2^2, \quad \ldots, \quad \min_{\hat{w}_d=0} \|\hat{w}\cdot X - w\cdot X\|_2^2. \]

Whichever index $i$ gives the best (smallest) loss is the one we prune.

Subproblem for a fixed index $i$

Drop column $i$ of $X$ (write $X_{-i}$) and refit the remaining weights by linear regression against the original outputs $y = X\cdot w$:

\[ \hat{\omega}^{(i)} = \arg\min \; \bigl\| X_{-i}\,\hat{\omega}^{(i)} - X\cdot\omega \bigr\|_2^2 = \arg\min \; \bigl\| X_{-i}\,\hat{\omega}^{(i)} - y \bigr\|_2^2 . \]

Normal equations for $X_{-i}\,\hat{\omega} = y$:

\[ \hat{\omega} = \bigl(X_{-i}^\top X_{-i}\bigr)^{-1} X_{-i}^\top y . \]

Loss (saliency) of pruning coordinate $i$:

\[ \hat{y} = X_{-i}\,\hat{\omega}, \qquad \ell_i = \|\hat{y} - y\|_2^2 . \]

Choose the index with the least loss.

Greedy prune-one step
  1. For each $i$, compute saliency $\ell_i$ by refitting on $X_{-i}$.
  2. Prune $i^\star = \arg\min_i \ell_i$.
  3. Update remaining weights: $\omega_{-i^\star} \leftarrow \hat{\omega}^{(i^\star)}$.

Related: Pruning a model