Structured Pruning › Width Pruning

Michael BrenndoerferFebruary 27, 20265 min read
Language AI HandbookAll chapters
Part 41 of 67Model Compression
Chapter 310Structured Pruning › Width Pruning
Reading section 5 of 13 · Width Pruning · 5 minSection 5 of 13 · 5 min

Book contents

Section 5 of 13 · 5 min read

Structured Pruning › Width PruningOne section · Sections in this chapter5 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Width pruning targets the internal dimensions of individual layers rather than removing entire heads or layers. In transformer feedforward sublayers, the input dimension dmodeld_{\text{model}} is projected up to an intermediate dimension dffnd_{\text{ffn}} (often 4 times larger), passed through a nonlinearity, then projected back down. Width pruning removes neurons from this intermediate dimension, making the feedforward sublayer smaller while keeping the layer itself in the architecture.

Width pruning is more fine-grained than layer or head pruning, which allows you to tune the compression ratio with greater precision. Instead of choosing between keeping or removing an entire layer (which jumps the parameter count by a large discrete amount), you can remove neurons one at a time, finding the exact tradeoff between size and quality that meets your deployment constraints.

Feedforward Neuron Importance

For the feedforward sublayer, each intermediate neuron receives input from the first linear layer and sends output through the second. Neuron nn in the feedforward sublayer of layer ll has activation an(l)(x)a_n^{(l)}(x) for input xx. A natural importance score is the mean absolute activation:

In(l)=Ex∼D[∣an(l)(x)∣]I_n^{(l)} = \mathbb{E}_{x \sim \mathcal{D}} \left[ \left| a_n^{(l)}(x) \right| \right]

where:

  • In(l)I_n^{(l)} is the importance score for neuron nn in feedforward sublayer ll
  • an(l)(x)a_n^{(l)}(x) is the activation value of neuron nn for input xx after the first linear projection and nonlinearity
  • Ex∼D\mathbb{E}_{x \sim \mathcal{D}} is the expectation over the calibration dataset D\mathcal{D}

Neurons that are consistently near zero contribute little to the computation. A threshold τ\tau determines which neurons to remove: all neurons with In(l)<τI_n^{(l)} < \tau are eliminated.

The choice of nonlinearity affects how well this criterion works. With ReLU activations, neurons that are dead (always outputting zero) have zero importance by definition. With GELU or SiLU activations, which are smooth and only approach zero asymptotically, you need the mean absolute activation criterion to identify low-importance neurons because no neuron is ever exactly zero. In modern language models that use GELU or SiLU, mean absolute activation is the standard criterion for feedforward width pruning.

The mechanics of width pruning are similar to head pruning. The first feedforward projection W1∈Rdmodel×dffn\mathbf{W}_1 \in \mathbb{R}^{d_{\text{model}} \times d_{\text{ffn}}} has its columns pruned, and the second projection W2∈Rdffn×dmodel\mathbf{W}_2 \in \mathbb{R}^{d_{\text{ffn}} \times d_{\text{model}}} has its rows pruned correspondingly. Removing kk neurons shrinks both matrices and reduces FLOPs proportionally. The bias terms (if present) must also be updated consistently: the bias of the first layer loses kk entries, and if the second layer has a bias, it remains unchanged in dimension because it is added to the dmodeld_{\text{model}}-dimensional output rather than the intermediate dimension.

For models using gated linear units (such as the SwiGLU variant used in Llama), the feedforward sublayer has two parallel projections instead of one. Both projections must be pruned consistently: removing neuron nn requires removing column nn from both the gate projection and the value projection, and row nn from the output projection. The paired nature of gated feedforward layers means you need to be careful to prune both projections together.

Attention Head Width Pruning

Width pruning can also target the head dimension dkd_k within attention heads. Rather than removing entire heads, you reduce the dimensionality of each head by eliminating less-important dimensions of the query, key, and value projections. This is a finer-grained form of pruning that allows more gradual size reduction.

For attention head hh, the query projection WQ(h)∈Rdmodel×dk\mathbf{W}_Q^{(h)} \in \mathbb{R}^{d_{\text{model}} \times d_k} can be pruned by removing columns whose corresponding activations have low importance. The same columns must be removed from WK(h)\mathbf{W}_K^{(h)} and WV(h)\mathbf{W}_V^{(h)} to maintain dimensional consistency, and the corresponding rows from the output projection must also be removed. Note that the attention score computation divides by dk\sqrt{d_k}, so after reducing dkd_k, you must update this scaling factor accordingly.

Head dimension pruning is less commonly applied in practice than feedforward width pruning because the attention head dimensions are already relatively small (often 64 or 128), and reducing them further tends to hurt quality more than removing entire low-importance heads. Feedforward neurons are more numerous and more unevenly used, making them better targets for width pruning.

Hidden Dimension Pruning

The most aggressive form of width pruning targets the model dimension dmodeld_{\text{model}} itself, reducing the embedding size used throughout the entire model. This affects every weight matrix in the architecture simultaneously and requires careful identification of which dimensions to prune.

Principal component analysis on the activations at each layer can identify dimensions with low variance across inputs. These low-variance dimensions carry little information and are candidates for removal. You compute the covariance matrix of the activations across your calibration dataset, find the eigenvectors with the smallest eigenvalues, and remove the corresponding dimensions from all weight matrices simultaneously. This is related to the idea of intrinsic dimensionality: large language models often operate in a much lower-dimensional subspace than their nominal parameter count suggests.

Hidden dimension pruning is substantially harder to implement correctly than feedforward or head pruning because it requires coordinated changes to all weight matrices in the model. Every embedding matrix, every query, key, value, and output projection, every feedforward projection, and every layer normalization parameter must be updated. Small misalignments (for example, pruning the wrong corresponding rows and columns in two matrices) produce incorrect results without necessarily raising an obvious error. In practice, most practitioners use feedforward and head pruning rather than hidden dimension pruning because the former are safer to implement and still achieve substantial compression ratios.