Wasserstein Distances, Neuronal Entanglement, and Sparsity

## Abstract

Abstract We show how to improve the inference efficiency of an LLM by expanding it into a mixture of sparse experts, where each expert is a copy of the original weights, one-shot pruned for a specific cluster of input values. We call this approach Sparse Expansion . We show that, for models such as Llama 2 70B, as we increase the number of sparse experts, Sparse Expansion outperforms all other one-shot sparsification approaches for the same inference FLOP budget per token, and that this gap grows as sparsity increases, leading to inference speedups. But why? To answer this, we provide strong evidence that the mixture of sparse experts is effectively disentangling the input-output relationship of every individual neuron across clusters of inputs. Specifically, sparse experts approximate the dense neuron’s output distribution with fewer weights by decomposing the distribution into a collection of simpler ones, each with a separate sparse dot product covering it. Interestingly, we show that the Wasserstein distance between a neuron’s output distribution and a Gaussian distribution is an indicator of its entanglement level and contribution to the accuracy of the model. Every layer of an LLM has a fraction of highly entangled “Wasserstein” neurons, and model performance suffers more when these are sparsified as opposed to others. The code for Sparse Expansion is available
at: https://github.com/Shavit-Lab/Sparse-Expansion .

## 1 Introduction

The past few years have seen an explosion in machine learning model capabilities, specifically those of transformers and large language models (LLMs). However, such an increase in capability has demanded an exponential increase in model size, incurring drastic monetary and energy costs.

The performance of LLMs is dominated by the number of parameters executed per input token during computation, both due to the number of multiply-add (FMA) operations required per parameter, and data movement to set up these operations. Neural network sparsity [] attempts to reduce the executed number of parameters and thus improve performance. The most common form of sparsity is static sparsification, wherein unnecessary model parameters are pruned away, and the model performs the same computation for every input. Many methods, such as gradual magnitude pruning [], Wanda [], and SparseGPT [], utilize this approach. SparseGPT, in particular, is the state-of-the-art one-shot pruning technique, allowing models to be cheaply compressed without expensive retraining.

In contrast, input-dynamic sparsity involves performing different computations on different inputs and is generally achieved through converting a dense model into a mixture of experts (MoE) like framework. Existing techniques, including DejaVu [], MoEification [], and Scaling Transformers [], route inputs only to computations predicted to be necessary. These methods are based on the sparsity induced by the ReLU activation function and cannot be easily extended to other popular activation functions such as GeLU (as in GPT models []) and SwiGLU (as in Llama []).

In this paper, we improve the one-shot sparsification of a model by expanding it into a mixture of experts, where each expert is a copy of the original, statically pruned to perform well on a subset of the inputs. Our technique, which we dub Sparse Expansion,
begins by clustering input embeddings layer-wise; based on this clustering, Sparse Expansion leverages the input-aware nature of the SparseGPT pruner to specialize different sparse experts to different sets of inputs, starting from the same base weights. At run time Sparse Expansion routes the inputs to the sparse experts at each layer based on the clustering (one could of course use more a sophisticated MoE router [] in place of clustering). Our approach increases the overall size of the model, but greatly reduces the number of executed run time parameters. Through Sparse Expansion, we achieve state-of-the-art one-shot sparsification performance in terms of parameters activated per token, across LLMs from the Llama and Pythia families, at low accuracy loss. Moreover, we show that our approach can be coupled with efficient execution kernels, leading to non-trivial speedups for generative inference; for the largest linear layers in Llama 2 7B and 70B, a variant of our approach provides speedups of 3x and 4.8x, respectively, even taking the expert routing overhead into account.

Our main technical contribution is a detailed study of how this expansion method obtains performance. Every neuron in a network has a certain level of “entanglement,” which we view as the degree to which it must deal with different combinations of features in its inputs. We observe for the first time the existence of “highly entangled” neurons in the dense model. These neurons, which appear in all model layers, have striking, irregular output distributions (Figure 1d), and as we show later, seem to be responsible for the difficult task of differentiating similar input vectors through their dot product computation. Furthermore, these neurons have an outsize effect on model performance: removing them increases error much more than a similar collection of random neurons (Figure 4). We found that one can quantify the degree to which a neuron is entangled via the Wasserstein distance [] between its output distribution and a properly-normalized Gaussian.

Sparsity tends to push the outputs of a dot-product of a neuron towards the Gaussian distribution as it loses edges (see Figure 5), even with an adjustment of edge weights. It thus reduces the expressive power of each neuron, and leads to increased error. In accordance, high Wasserstein distance neurons are particularly difficult to sparsify, especially at higher sparsities.

Figure: Figure 1: The output distributions of neurons in Llama 2 7B. One can see that the red Sparse Expansion output distribution covers a random neuron slightly better than than the green SparseGPT distribution, and this improvement becomes much more pronounced for an entangled neuron. The reason is the ability of the separate dot product operations of the multiple experts, depicted each in a separate color (in c and f), to better cover the dense distribution. Sparsity is set to 90% per expert and the neurons are from the gate projection of the second FFN block. WD is the Wasserstein distance between the Sparse Expansion sparse output distribution and the dense distribution. RI is the relative improvement of Sparse Expansion over SparseGPT, defined later.
Refer to caption: extracted/5627619/sections/figures/clustering_saves_llama.png

We provide evidence that the key to the performance of Sparse Expansion is that it effectively “disentangles” the neuronal output distributions, in particular those with high Wasserstein distances, into much simpler ones. For example, SparseGPT mostly succeeds in capturing the dense output distribution of a non-entangled neuron with a sparse one (Figure 1a). However, it fails to capture the full dense output distribution of a highly entangled neuron (Figure 1d). Sparse Expansion overcomes this by disentangling the neuron. Each sparse expert is responsible only for a clustered subset of the inputs (i.e. can be viewed as capturing a subset of the input features) allowing it to model these with the more Gaussian shaped distribution imposed by sparsity. Each neuron’s output is then modeled by the collection of outputs of all the experts together. While sparse disentanglement helps cover the normal neuron’s distribution slightly better than SparseGPT, it greatly helps it in covering the output distribution of the entangled neuron where SparseGPT fails (Figure 1f). The Sparse Expansion technique allows one to readily see this because, unlike in traditional MoEs, each neuron retains the exact same position and role in each of the experts.

Because Sparse Expansion effectively disentangles neurons throughout the model, it improves its overall sparse performance, and not surprisingly, as the number of experts applied to a model grows, and with it its ability to disentangle, the overall accuracy of Sparse Expansion improves (Figure A.1).

Finally, we note that in the literature, disentanglement is generally used in the context of mechanistic interpretability to generate human-understandable features [, ]. Here, we use disentanglement as a performance enhancing tool, and link it to improved performance via induced sparsity. We believe this phenomena is at the base of general MoE performance, but is harder to analyze because of the retraining of the experts.

In the next section we explain the implementation of Sparse Expansion in detail. We then study how it supports disentanglement in LLMs, and finally present results showing its performance relative to other state of the art one-shot compression techniques.

## 2 Sparse Expansion

Figure: Figure 2: The Sparse Expansion process. One-shot expert creation process of Sparse Expansion (left). Inference process in an FFN block of Sparse Expansion (right).
Refer to caption: extracted/5627619/sections/figures/Sparse_Expansion.png

At a high level, Sparse Expansion clusters the incoming inputs to each layer into separate groups. Then, each expert is sparsified via the SparseGPT pruning algorithm []. Briefly, SparseGPT approximates the optimal sparse version w.r.t. L2 distance relative to the dense outputs of a given layer by leveraging the Hessian matrix of the second order derivatives of the error relative to the parameters within each linear layer $\mathbf{y=WX+b}$. Here, $\mathbf{y}$ is the set of outputs of the layer, $\mathbf{W}$ is the weight matrix for the layer, $\mathbf{b}$ is the bias for the layer, and $\mathbf{X}$ is a set of inputs arranged as a matrix, where each column is a separate input vector. Doing so yields $\mathbf{H=XX^{T}}$, where $\mathbf{H}$ is the Hessian matrix. Furthermore, SparseGPT is natively capable of performing one-shot quantization as well, due to the sharing of the error updates between sparsification and quantization. In our experiments, we thus test Sparse Expansion in both sparse and joint sparse-quantized settings.

In Sparse Expansion, we leverage the observation that SparseGPT is input-aware, and cluster the inputs to each layer via K-means and designating a separate, initially identical, expert for every cluster of inputs. (In order to facilitate better and faster clustering, we first utilize principal component analysis (PCA) to reduce the dimensionality of the inputs.) Following the clustering of the inputs, each sparse expert can now be tailored to a subset of inputs rather than trying to adapt to all of them. To allow the experts to specialize, a separate Hessian matrix is calculated for every input cluster, which is then used to prune the expert weight matrix through the SparseGPT pruning algorithm. Specialized experts have now been generated that are adapted to the subset of inputs routed to the corresponding cluster (Figure 2, Algorithm 1). Our Sparse Expansion approach therefore yields a mixture of sparse experts through one-shot sparsification, removing the need for expensive retraining.

During inference, each input will first have its dimensionality reduced by the PCA model, then separately evaluated via the K-means model to decide its expert, and finally be routed to the corresponding expert for the matrix multiply (Algorithm 2). As the routing is done via K-means on a lower dimension, and the PCA is a very low dimension matrix multiply, both are inexpensive to add on to normal LLM inference. Furthermore, routing in this manner prevents the need to train and run a more expensive router.

Our design departs from traditional MoEs in terms of their routing for the benefit of sparsity. In traditional MoEs, inputs are generally routed at the start of each FFN block once, such that the same up, gate, and down projection experts are associated with a particular routing. Furthermore, inputs are generally routed to multiple experts per inference pass, thus increasing the effective number of experts through the combination of different ones. However, routing to multiple experts in our case would incur a penalty in the sparsity of the model. Thus, we instead chose to do routing for the up and gate projection experts, and then again for the down projection expert (2). In this way, we square the effective number of experts combinations per input to a FFN block without decreasing sparsity.

## 3 Neuronal disentanglement

### 3.1 Characterizing non-Gaussian neuronal output distributions

We investigate the output distributions of individual neurons as the model processes its inputs during inference across all linear layers in each transformer block feed forward network (FFN). We focus our analysis in Pythia 1.4B [] and Llama 2 7B []. Most neurons exhibit a reasonably Gaussian output distribution after their dot product operation on the input vector (Figure 3a, 1a). However, we find the existence of a small group neurons with highly non-Gaussian outputs (Figure 3c, 1c). We observe the existence of such neurons in all FFN blocks of transformers.

To characterize the degree of difference between the non-Gaussian output distributions of these neurons from the Gaussian-like output distribution of an average neuron, we considered several metrics. However, we ultimately chose the Wasserstein distance (WD) [, ] as a means of quantifying the degree of difference. In optimal transport theory, the WD measures the minimal transportation cost between two distributions, taking their geometry in real space into account.

To find the WD of every neuron to the Gaussian $\mathcal{N}$, we first normalize the output distributions of each neuron $n$ to have zero mean and unit variance, and compare this normalized distribution $n^{\prime}$ to $\mathcal{N}(0,1)$. This is because the range of neurons is quite variable, and we wanted to prioritize finding the differences in the shape of the output distribution, not other properties of the distribution. We use the $1$-Wasserstein distance in one dimension, as shown in Equation 1:

$$ $W_{1}(n^{\prime},\mathcal{N})=\int_{0}^{1}|F^{-1}(z)-G^{-1}(z)|dz.$ (1) $$

$F^{-1}$ and $G^{-1}$ represent the inverse cumulative distribution function of $n^{\prime}$ and $\mathcal{N}(0,1)$, respectively, which can be approximated with our empirical data. To compute the WD of every neuron efficiently, we use the implementation provided by SciPy [].
When computing the difference metric in this way, we find that our originally observed neurons have been designated correctly with high WD to $\mathcal{N}$.

### 3.2 Wasserstein distances and entanglement

All neurons in the models we examined show some non-zero WD, and yet we find neurons with a high WD in all up and gate projection layers, some down projection layers (Figure A.4) in Llama 2 7B. Henceforth we focus on the high WD neurons because they offer a clearer example of the correlation of the WD with the computational roles of neurons. The high WD neurons have the odd shapes that we have been observing (Figures A.10 and A.9). We consider the difficulty of the dot product computation neurons perform in terms of the input-output relationships they are expected to handle in four broad groups. Namely, the dot product may map similar inputs to similar outputs, dissimilar inputs to dissimilar outputs, dissimilar inputs to similar outputs, and similar inputs to dissimilar outputs. Of the four relationships, the last seems most difficult to model, as small changes in the inputs must be mapped far away in output space. This relationship would be even more difficult to maintain under sparsity. This is because, as the number of nonzero entries in the weight vector decrease, the means and variance both tend toward zero (Figure A.6). Such a setting makes it all the more difficult to keep similar inputs far apart in the output space.

We use cosine similarity to measure the similarity between inputs and L1 distance to measure the similarity between outputs following computation by a particular neuron’s dot product. Larger cosine similarities indicate more similar inputs, and smaller L1 distances indicate more similar outputs. In Pythia 1.4B, for a neuron with a normal output distribution, the relationship between its input-output pairs is fairly reasonable. Very similar inputs with a cosine similarity of close to one have very similar outputs with L1 distance close to zero. Unrelated inputs with cosine similarity of close to zero have very far outputs with a large L1 distance between them. As input similarity decreases, output distance increases. Finally, there are pairs of dissimilar inputs that are mapped to close values. However, there are no input pairs that are similar with highly dissimilar outputs (Figure 3b).

However, for a high WD neuron, *this is not the case*—in addition to the previously mentioned relationships, it now has to contend with discerning between two similar inputs and map them far away in output space (Figure 3d). Note that even for two inputs that share a cosine similarity of 0.9, this neuron sometimes has to map them across a majority of its entire effective range.

Figure: Figure 3: Neuronal entanglement. The high WD neuron must map fairly similar inputs to outputs that are very far apart (as indicated by the dense upper right hand corner of (d) vs the empty one in (b)) through its dot product operation. The neurons are from the up projection of the second FFN block in Pythia 1.4B.
Refer to caption: extracted/5627619/sections/figures/neuron_output_IO.png

Because inputs that must be mapped far away in output space are close by and entangled in input space, we therefore term these high WD neurons as “entangled.”

### 3.3 Effect of high Wasserstein neurons on sparsification

We show that entangled neurons have a substantially outsized effect on model performance through the lens of sparsity. In Llama 2 7B, if just the 3% of the highest WD neurons are sparsified in every FFN block, model performance significantly degrades, far more than if random neurons were sparsified. The same is true if the neurons are sparsified 2:4 and then quantized to fewer bits, with high WD neurons drastically inhibiting model performance under compression. As compression increases, this effect becomes more obvious (Figure 4). Therefore, entangled neurons are crucial for maintaining model accuracy and are severely limited in their ability to be compressed.

Figure: Figure 4: Entangled neurons are sensitive to compression. In Llama 2 7B, 3% of neurons from every layer were sparsified in an unstructured manner (left) or sparsified to 2:4 and quantized (right). Compressing high WD neurons impairs the model significantly more than compressing random ones.
Refer to caption: extracted/5627619/sections/figures/highWDsensitivity.png

Additionally, as a neuron is increasingly sparsified, the output distribution becomes more Gaussian (See Figure 5). This in turn places even more stress upon the neuron - not only is it contending with the decreasing mean and variance, but also with the less expressive distribution shape. Thus, it seems that, especially at the higher sparsities that we are investigating, the irregular shape of the entangled neurons is much more challenging to model with fewer weights than a Gaussian-like distribution. To address the difficulty of sparsifying entangled neurons, we introduce Sparse Expansion.

Figure: Figure 5: Increasing sparsity induces normality. A highly entangled neuron’s dense distribution (blue) and sparse distributiuon (red). As sparsity increases, the output distribution of sparse neurons becomes progressively more Gaussian. WD represents the Wasserstein distance. This is the same neuron from Figure 3c.
Refer to caption: extracted/5627619/sections/figures/Distribution_of_neurons_with_sparsity.png

## 4 Sparse Expansion disentangles neurons

We revisit the output distributions of neurons to determine the effect that clustering has in a sparse setting. We measure the relative improvement (RI) that Sparse Expansion provides, where relative improvement is defined as the ratio of the L2 error between the dense output and the SparseGPT sparse output to the L2 error between the dense output and the Sparse Expansion sparse output.

For Llama 2 7B (Figure 1) and Pythia 1.4B (Figure A.3), both models and both neuron types—random and entangled—improve through Sparse Expansion, with the entangled neuron showing greater improvement. Furthermore, for the random neuron and especially for the entangled neuron, the geometry of the sparse output distribution much more closely matches that of the dense distribution in Sparse Expansion.

We also provide a visualization for the specialization of each cluster. Figure 1 and Figure A.3 each show the sparse output distributions of each individual cluster, with a different color per expert. For the randomly selected neurons, there is an improvement though each expert by and large is still responsible for approximately the same range and shape. For the entangled neurons, there is significant specialization for different parts of the distribution further away from the mean.

However, Sparse Expansion is not limited to improving just neurons with a high WD to normal. Across different sparsities and across different models, all but a tiny fraction of neurons improve through Sparse Expansion (Figure A.7). Thus, we believe that, in fact, every neuron is to some extent entangled. However, neurons with a high WD are the most obviously entangled neurons, and they benefit more from sparse disentanglement, especially at higher sparsities.

Finally, we note that other metrics of the dense neuronal output distribution, such as their means and variances, fail to act as a predictor of neuronal improvement to the degree that the Wasserstein distance to a Gaussian does (Figure A.8). Thus, we believe the Wasserstein distance to be the most suitable metric of entanglement within a neuron.

### 4.1 More sparse experts better fit the output distribution

The complex dense output distribution of highly entangled neurons is difficult to model with a single sparse expert, as in the case of SparseGPT. In figure 6, we show the output distribution of a high WD neuron in both dense and sparse computation. As the number of sparse experts increases, the output distribution of the sparse computation more closely matches that of the dense computation, as measured in both WD between the two distributions and relative improvement.

Figure: Figure 6: Modeling recovery with more experts. The sparse computation output distribution (red) matches the dense one (blue) better with more clusters. Sparsity is set to 90% for each expert. WD represents the Wasserstein distance between the Sparse Expansion sparse output distribution and the dense distribution. RI represents relative improvement of Sparse Expansion ($n\geq 1$ clusters) over SparseGPT ($n=1$ cluster). This is the same neuron from Figure 3c.
Refer to caption: extracted/5627619/sections/figures/dense_h_to_4h_cluster_sparse_distribution_neuron_2402_layer_1.png

## 5 Sparse Expansion performance

### 5.1 Models, datasets, and setup

We use the Pythia [] series of pre-trained LLMs to evaluate how Sparse Expansion performs across model sizes, from Pythia 70M to Pythia 12B. We further evaluate Sparse Expansion across the entire Llama 2 family []. We use the Wikitext-2 dataset [] as calibration data for input-aware pruning and evaluation. For our performance benchmarks, we use 16 clusters at each level of routing in Sparse Expansion. For all experiments, we use two NVIDIA A100 Tensor Core GPUs, except for Llama 2-70B where we use three NVIDIA A100s. We rely upon the RAPIDS library [] to accelerate the fitting and running of the PCA and K-means models by orders of magnitude. To run all models densely and through the MP, Wanda, and SparseGPT pruning approaches, we use a single AMD Instinct MI100 Accelerator GPU. Finally, we utilize and build upon the SparseGPT repositories.

### 5.2 Compression across scales

We evaluate the performance of Sparse Expansion against other one-shot pruning techniques across a range of model sizes in Pythia (Figure 7). To test both sparsification as well as compression, we compare the pruning techniques when sparsifying each model to 50% unstructured sparsity, as well as to 2:4 structured sparsity and 3 and 4 bit quantization. Across all model sizes, Sparse Expansion outperforms all other pruning techniques, approaching dense performance as model size increases. In fact, for compression, Sparse Expansion performs better at 3 bits than SparseGPT does at 4 bits across all model sizes but one.

Figure: Figure 7: Sparse Expansion across model sizes. Comparisons were made between Magnitude Pruning (MP), Wanda, SparseGPT, and Sparse Expansion on the Pythia series of models from sizes of 70M parameters to 12B parameters. Every MLP in each model was sparsified to 50% sparsity (left) or sparsified 2:4 and quantized to 3 or 4 bits (right). Performance was measured in cross-entropy loss to better show scaling laws.
Refer to caption: extracted/5627619/sections/figures/scaling_size.png

### 5.3 Performance across sparsification and quantization

To assess the performance of Sparse Expansion at different levels of sparsity or compression for the same model, we compared it to SparseGPT in Llama 2 7B (Figure 8). Every linear layer in each FFN block was sparsified in an unstructured manner across different degrees of sparsity, or sparsified in a structural manner to 2:4 sparsity and then quantized to a different number of bits. Across all levels of sparsity and compression, Sparse Expansion performs better than SparseGPT. Furthermore, at higher levels of sparsity and compression, the gap in performance between the two techniques grows. Here as well, Sparse Expansion performs better at 3 bits than SparseGPT does at 4 bits.

Figure: Figure 8: Sparse Expansion across levels of compression. Comparisons were made between SparseGPT and Sparse Expansion on Llama 2 7B. Every layer in each transformer block was sparsified in an unstructured manner (left) or sparsified 2:4 sparsity and quantized to the number of bits (right). Sparse Expansion performs the best across all settings as compared to SparseGPT.
Refer to caption: extracted/5627619/sections/figures/scaling_compression.png

### 5.4 Performance across the Llama family

Finally, we analyze the performance of Sparse Expansion against other sparsification algorithms across all members of the Llama 2 family - Llama 2 7B, Llama 2 13B, and Llama 2 70B - both under sparsity and joint sparsity-quantization compression.

**Table 1: Sparse Expansion across the Llama family. Sparse Expansion outperforms all other sparsification techniques for every member of the Llama family.**
|  | Sparsity | Bits | Llama 2 7B | Llama 2 13B | Llama 2 70B |
| --- | --- | --- | --- | --- | --- |
| Dense | 0% | 16-bit | 5.1168 | 4.5736 | 3.3192 |
| MP | 50% | 16-bit | 16.029 | 6.8270 | 4.9846 |
| Wanda | 50% | 16-bit | 6.7757 | 5.8527 | 4.0219 |
| SparseGPT | 50% | 16-bit | 5.7082 | 5.0521 | 3.9013 |
| Sparse Expansion | 50% | 16-bit | 5.5839 | 4.9728 | 3.8791 |
| SparseGPT | 2:4 | 16-bit | 6.9767 | 5.9934 | 4.8002 |
| Sparse Expansion | 2:4 | 16-bit | 6.4456 | 5.6255 | 4.6671 |
| SparseGPT | 2:4 | 4-bit | 7.2759 | 6.1101 | 4.9036 |
| Sparse Expansion | 2:4 | 4-bit | 6.5745 | 5.7151 | 4.7586 |
| SparseGPT | 2:4 | 3-bit | 13.076 | 6.5055 | 5.2552 |
| Sparse Expansion | 2:4 | 3-bit | 7.0757 | 5.9872 | 5.0588 |

Sparse Expansion outperforms all other pruning techniques for both 50% unstructured sparsity as well 2:4 sparsity in all Llama models (Figure 1). In addition to non-quantized sparsity, we consider how Sparse Expansion performs in the context of compression with 2:4 structured sparsity and quantization. We first sparsify each linear layer in each FFN block to 2:4 sparsity, then quantized to 3 and 4 bits. Our method outperforms SparseGPT across all models and across both conditions and in all models (Figure 1).

Across multiple model sizes, sparsity and compression levels, and advanced models, Sparse Expansion attains state-of-the-art performance for post-training one-shot sparsification when compared to other highly competitive pruning techniques. We do so by leveraging the powerful pruning algorithm of SparseGPT and combining it with input specialization to utilize the insights we gain from how entangled neurons behave under sparsity.

### 5.5 Inference speed

To evaluate the inference latency of Sparse Expansion we implemented a Sparse Expansion layer based on PyTorch and optimized sparse-quantized GPU kernels called Sparse Marlin [, ], which supports the INT4 + 2:4 sparse format. We use a linear layer of appropriate size as an upper bound approximation for our router cost, which is followed by 4 bits 2:4 sparse matrix multiplication. We have run the layer-wise benchmarks for the typical layers sizes from Llama models on a single RTX3090 GPU.
We can see in Table 2 that Sparse Expansion allows us to get up to 4.8$\times$ speedup over the dense baseline. The speedup comes from the highly-compressed linear layer representation, while the overhead over the original kernels can be explained by the effect of interleaved calls of dense router and sparse experts during Sparse Expansion inference.

**Table 2: Sparse Expansion inference speedup. Layer-wise single batch inference latency (in $\mu$s). The layer sizes are chosen specifically to match the layers of Llama 2 7b and Llama 2 70B.**
| Layer Size | 4k $\times$ 12k | 4k $\times$ 22k | 11k $\times$ 4k | 8k $\times$ 10k | 8k $\times$ 57k | 28k $\times$ 8k |
| --- | --- | --- | --- | --- | --- | --- |
| Dense | 132 | 227 | 114 | 220 | 1168 | 556 |
| Sparse Expansion | 76 | 76 | 75 | 76 | 241 | 138 |
| Speedup | 1.7$\times$ | 3.0$\times$ | 1.5$\times$ | 2.9$\times$ | 4.8$\times$ | 4.0$\times$ |
| Sparse | 26.8 | 44.7 | 24.4 | 42.3 | 216 | 109 |
| Expansion Overhead | 2.9$\times$ | 1.7$\times$ | 3.1$\times$ | 1.8$\times$ | 1.1$\times$ | 1.3$\times$ |

## 6 Additional related work

We cover additional related work not cited above.

#### Sparsification

Recently, several papers have attempted to impart activation sparsity to non-ReLU models by converting their activation functions to ReLU, as is the case with Relufication [], or to directly threshold post-activation function values based on magnitude, as is the case with CATS []. However, the former approach requires expensive retraining, and the latter requires one linear layer in each feedforward network (FFN) block to be run densely.

#### Mixture of experts

MoE models involve specializing components of a neural network to different sets of inputs during training and and inference []. MoEs have been developed for LLMs [], and recent MoE models have achieved state of the art performance over standard LLM architectures []. An arising area of MoE research is converting a model with standard architecture into an MoE, either for performance or for sparsity. One approach is to do so through first fully duplicating the weight matrix of linear layers in FFN blocks as separate experts, then fully training a router for and fine-tuning the experts []. Other approaches center around models that utilize the ReLU activation function [, , ], and very recently non-ReLU activation functions []. As different inputs sparsely activate different sets of neurons, neurons that activate together can be grouped together into a single expert. Different sets of experts can then be run for different inputs in a dynamic fashion, essentially creating an MoE like architecture.

## 7 Discussion and conclusion

In this work, we have shown for the first time the role of entanglement, and in particular of highly entangled neurons, in the accuracy of computing the FFN blocks of LLMs.
We have shown that the Wasserstein distance between the output distributions of neurons and the Gaussian distribution is a very suitable metric to identify the degree of entanglement in different neurons. Furthermore, we demonstrated the relevance of highly entangled neurons in the performance of models, both in terms of differentiating between similar inputs and in their significant sensitivity to sparsification and compression. As the focus of our study is analytical, we have only shown per-layer inference speeds.
In future work, we plan to integrate with an inference framework such as HuggingFace Transformers to show end-to-end inference numbers. We also plan to integrate with MoE-specific inference optimizations such as [], which should be compatible with our approach as well.

Looking forward, perhaps, just as outlier features and weights are well understood to be one of the most significant challenges when quantizing to fewer bits [, , , , , ], neuronal entanglement can provide a path to understanding the challenge of pruning to higher sparsities.

## 8 Acknowledgements

The authors would like to extend their gratitude to Lori Leu for her insightful comments on the application of the Wasserstein distance metric. We also wish to thank Elias Frantner for his help in working with the SparseGPT implementation and his advice for the project. Additionally, we would like to thank Tony Tong Wang for his valuable feedback and constructive discussions.

This work was supported by an NIH Brains CONNECTS U01 grant and AMD’s AI & HPC Fund.

## Appendix A Appendix

### A.1 Pseudo-code for Sparse Expansion

Algorithm 1 describes the sparsification process of Sparse Expansion. The sparse experts are created in a layer-wise sequential fashion for each linear layer of every FFN transformer block to create the sparse model. Algorithm 2 refers to the inference procedure of Sparse Expansion once the model is pruned following the methods described in Algorithm 1 and Section 2.

Figure: Algorithm 1 Sparse Expansion model generation. The following layerwise procedure can be repeated for each MLP layer in the transformer.

Figure: Algorithm 2 Sparse Expansion inference. The following layerwise procedure is repeated at inference time for each clustered layer.

### A.2 Additional clusters impart more performance

To understand how Sparse Expansion scales with the number of experts per linear layer, we test its performance from 2 to 32 experts. Interestingly, with 2 experts, very little performance benefits are realized. However, with each doubling of experts following 2 experts, we realize a nearly constant linear improvement in perplexity.

Figure: Figure A.1: Increasing the number of clusters improves Sparse Expansion performance in Llama 2 7B.
Refer to caption: extracted/5627619/sections/figures/more_clusters.png

### A.3 Further examples of disentanglement

We present additional evidence of neuronal disentanglement in Pythia 1.4B and Llama 2 7B. Figure A.2 shows the recovery of the dense output distribution with increasing experts in Llama 2 7B. This is analogous to Figure 5, where we see a similar trend in Pythia models. Clustering gradually decreases the WD of the sparse output to that of the dense, thus improving upon SparseGPT, equivalent to the single cluster case. Moreover, this results in direct improvement of model performance as depicted in figure A.1.

Figure: Figure A.2: Modeling recovery with more experts in Llama 2 7B. Use of more experts can recover the dense output distribution even at very high sparsity, which is set to 90% for each expert. This is the same neuron from Figure 1d.
Refer to caption: extracted/5627619/sections/figures/gate_proj_neuron_3390_layer_1.png

Analogous to Figure 1, we observe the effect of clustering inputs on a random neuron and an entangled neuron in the gate projection of the second FFN of Pythia 1.4B. SparseGPT fails to capture the output distribution of the high WD neuron as it does for a random neuron. With clustering via Sparse Expansion, both neurons improve, but the entangled neuron improves more. The granular analysis of the component clusters within both neurons reveals the specialization to vastly different parts of the output distribution in the entangled neuron as compared to the normal neuron (Figure A.3).

Figure: Figure A.3: Sparse Expansion disentangles neurons in Pythia 1.4B. The dense output distribution of a random neuron, along with its sparse via SparseGPT (a) and via Sparse Expansion (b) sparse output distributions. The dense output distribution of a random neuron, along with its sparse via SparseGPT (d) and via Sparse Expansion (e) sparse output distributions. For both the random and entangled neuron, component clusters are shown in a distinct color to visualize their range (c, e). WD represents the Wasserstein distance between the Sparse Expansion sparse output distribution and the dense distribution. RI represents relative improvement. These are the same neurons from Figure 3.
Refer to caption: extracted/5627619/sections/figures/clustering_saves.png

### A.4 Distribution of Wasserstein distances across all Llama 2 7B FFN layers

After collecting the Wasserstein distance to the normal distribution for every neuron, we find that all up and gate projection matrices in each Llama 2 7B FFN block have high WD neurons. We also find that certain down projection matrices also have high WD neurons, though most do not.

Figure: Figure A.4: High Wasserstein distance neurons in each layer. Many neurons with a high WD to the Gaussian distribution exist in every FFN block, and in every up (a) and gate projection (b) specifically. Certain down projection layers also have high WD neurons (c). The box plots show the range of non-outliers, as well as the first quartile, the median, and the third quartile of neuronal WD. The outliers are defined as 1.5 times the interquartile range less than the first or more than the third quartile and are represented by the points.
Refer to caption: extracted/5627619/sections/figures/highWDphenomenonUP.png

### A.5 Effect of sparsity on neuronal output distributions

With increasing sparsity, the sparse output distributions of the high WD neurons and random neurons converge toward the normal distribution. A specific example of a neuron is shown in Figure 5.

Figure: Figure A.5: Output distributions become normal under sparsity. The Wasserstein distance between a neuron’s normalized sparse output distribution and the Gaussian distribution is shown as sparsity increases for the top $3\%$ of entangled neurons as well as $3\%$ random neurons. For highly entangled neurons, the WD decreases significantly at higher sparsities whereas it remains more or less constant for random neurons.
Refer to caption: extracted/5627619/sections/figures/wasserstein_distance_progression_top_random_neurons.png

Furthermore, with increasing sparsity, the magnitudes of the means and variances of each neurons’ sparse output distribution both shift toward zero. This is reasonable, as with fewer nonzero weights to combine together features, both the mean and variance should decrease in magnitude.

Figure: Figure A.6: Mean and variance shift toward zero under sparsity. Across all neurons, With increasing sparsity, the magnitude of the mean of output distribution (left) and the variance of the output distribution (right) both tend toward zero. Both mean and variance have been normalized to their dense values. Data collected from of the second up projection layer in Pythia 1.4B. Error bars represent one standard error.
Refer to caption: extracted/5627619/sections/figures/normalized_mean_variance_output_distribution.png

### A.6 All neurons improve, but entangled neurons improve more at higher sparsities

Measuring the relative improvement of each neuron through Sparse Expansion, defined previously as the ratio between the L2 norm of the dense output distribution and the SparseGPT sparse output distribution to L2 norm of the dense output distribution and the Sparse Expansion sparse output distribution, we find that all neurons improve as a result of Sparse Expansion across both Pythia 1.4B and Llama 2 7B. Thus, we believe that every neuron has some level of innate entanglement, and thus all neuron performances can be and are improved. Interestingly, we note that, with increasing sparsity, highly entangled neurons tend to improve more.

Figure: Figure A.7: Entangled neurons improve more at higher sparsities. Relative improvement of each neuron in the second up projection matrix in Pythia 1.4B (top row) and in the second gate projection matrix in Llama 2 7B (bottom row) with respect to their WD from the Gaussian. Two sparsity levels, 80% and 90%, are shown. Sparse Expansion improves the expressibility of every neuron, thus improving performance. However, the entangled neurons improve more with higher sparsities, as visible in right columns.
Refer to caption: extracted/5627619/sections/figures/improvement.png

### A.7 The Wasserstein distance best captures which neurons improve

We also consider whether the magnitude of the mean of the output distribution or the variance of the distribution would be good predictors of the degree of neuronal improvement through Sparse Expansion. However, across both Pythia 1.4B and Llama 2 7B, the Wasserstein distance from the normal a better predictor of relative improvement, as defined previously (Figure A.7). Though there is some correlation of the magnitude of the mean and variance of the output distribution with the relative improvement in Pythia 1.4B, that is not the case in Llama 2 7B. Furthermore, using the WD to preduct neuronal improvement yields the highest coefficient of determination, R^2, across both models. Thus, we believe that the Wasserstein Distance to the normal distribution is the most accurate metric of the three to characterize entanglement.

Figure: Figure A.8: Wasserstein distance best captures improvement. Relative improvement of each neuron in the second up projection matrix in Pythia 1.4B (top row) and in the second gate projection matrix in Llama 2 7B (bottom row) with respect to the magnitude of the mean, variance, and Wasserstein distance from normal of the dense output distribution. Neurons pruned to 90% sparsity.
Refer to caption: extracted/5627619/sections/figures/meanvar.png

### A.8 Output distributions of entangled neurons in Pythia and Llama

Figures A.9 and A.10 show the non-trivial, non-Gaussian output distribution of a subset of neurons from the Pythia 1.4B and Llama 2 7B models, illustrating examples of entangled neurons. We observe such neurons in every FFN block of the LLMs we investigated and believe that the existence of these neurons is a global phenomenon in transformers.

Figure: Figure A.9: Dense output distributions of top 30 high WD neurons in Pythia 1.4B. The distributions are shown for the neurons of the up projection matrix in the second FFN block.
Refer to caption: extracted/5627619/sections/figures/Pythia_neuron_distribution.png

Figure: Figure A.10: Dense output distributions of top 30 high WD neurons in Llama 2 7B. The distributions are shown for the neurons of the up projection matrix in the sixteenth FFN block.
Refer to caption: extracted/5627619/sections/figures/gate_proj_layer_15_Llama2_7B.png

## Peer Reviews

confidence: 2
contribution: 3
initial_rating: 8
presentation: 3
questions: 1. Directly normalizing the distribution to calculate the Wasserstein distance seems like a strong simplification. Is there a better approach that accounts for mean and variance?
2. In Equation (2), why is the mean used for mapping difficulty, the maximum for $N_x$ , and the median for $N_y$?
3. In Figure 4b, what does the "normalized input/output L2" represent?
4. On line 282, there is a missing word after “the.”
5. How is the weighted cluster distance calculated in Figure 6b?
6. Are the K-NN and evaluation conducted on the same training set of wikitext-2?
7. Could the authors explain why there is no correlation between the optimal number of Gaussians and relative improvement? Is this due to sparse expansion being applied directly to the weight matrix while the GMM is estimated for individual neurons? Is the relative improvement possibly influenced by the neurons with the largest GMM value? Could differences in measurement — one on the entire weight matrix, the other on individual neurons — lead to inconsistencies?
8. How do outlier weights (or neurons) overlap with neurons that have large Wasserstein distances?
9. How do neurons in the MoE model perform in terms of Wasserstein distance?
soundness: 3
strengths: - Understanding the relationship between sparsity and entanglement is an important research area.
- The paper conducts extensive experiments to explore the connection between Wasserstein distance, entanglement, and their impact on sparsification.
summary: The paper proposes using the Wasserstein distance to select entangled neurons. The authors use the mapping difficulty to measure the entanglement and argue that the Wasserstein distance is strongly correlated with it. They further introduce a sparse expansion method that disentangle the Wasserstein neurons better.
weaknesses: - The concept of using the Wasserstein distance has been addressed in prior work [1]. The authors could benefit from a broader literature review. It would be helpful to discuss how other works evaluate entanglement.
- The sparse expansion approach relies on prior knowledge of the distribution to support K-means clustering. How robust is this method for out-of-distribution data?
- Practical aspects of the sparse expansion, such as runtime and inference speed (e.g., with 16 experts), should be discussed more thoroughly.
- The writing could be improved; The reviewer finds that many phrases and sentences are difficult to parse.

[1] You, Lei, and Hei Victor Cheng. "Swap: Sparse Entropic Wasserstein Regression for Robust Network Pruning." The Twelfth International Conference on Learning Representations. 2024.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: 1.  On the Sparse Expansion (SE) algorithm:
    - How is the number of clusters $k$ chosen? From Figure A2, it seems that increasing $k$ consistently improves performance (in terms of perplexity). Besides increased memory usage, are there other performance trade-offs when increasing $k$?
    - If the clustering approach mainly addresses the issue with the entangled neurons, do all neurons need the same number of clusters? 
    - How much optimization/run-time overhead does the PCA+$k$-means step add to the sparseGPT algorithm when sparsifying the weights? 
2.  Since the link between entanglement and Wasserstein neurons is made through the MD metric, I am wondering if we see MD also decreases by the Sparse Expansion algorithm.
3. Shouldn't the clusters learned through the SE algorithm depend on the structure of the data/task used for this purpose? For example, in Figure 10, is SE both performed and validated on Wikitext2? If so, would the sparse model still have improved performance on other downstream tasks/datasets (like the ones evaluated in Figure 2)?
soundness: 3
strengths: I am not fully familiar with the literature on neural disentanglement and the interpretability results. However, I find the paper’s approach to improving the performance of sparsified models by analyzing neuron interpretations interesting.

The authors take a step-by-step approach to justify their claims/arguments and to make connections between the different concepts discussed in the paper.
summary: This paper examines the performance of models under weight sparsity by considering the entanglement of the neurons in the dense model. The authors first empirically show that neurons with high Wasserstein distance (WD) to a Gaussian distribution will more negatively impact the model's performance when sparsified. They then demonstrate that the WD metric has positive correlation with the Mapping Difficulty (MD) of each neuron, which serves as a heuristic for measuring neuron entanglement.

Motivated by this observation, the authors propose an algorithm (Sparse Expansion - SE) that adjusts the SparseGPT (Frantar & Alistarh, 2023) algorithm for making the model sparse: For each layer, they learn $k$ sparse weights (experts), corresponding to $k$ clusters of input data, by the SparseGPT algorithm. The clusters at each layer are identified by $k$-means clustering on the low-dimensional representations derived from PCA on the original inputs. Then, during inference, each input is routed through the closest clusters. The paper claims that each cluster will help disentangle the neurons, leading to a decrease in WD in the sparse model. Finally, they show that the sparse models learned by SE have improved performance, as measured by perplexity.
weaknesses: I find that many of the arguments in the paper are either based on intuition or established by showing correlations between metrics. In some cases, it is not very clear to me whether there is some sort of causation also involved. For example,  I don't understand why a neuron with a smaller WD to Gaussian should be less entangled (and thus more interpretable?). In the paper, this conclusion relies on the correlation between WD and MD, which is itself an intuitive metric for measuring entanglement. Nevertheless, the arguments are still motivating for further research in this direction.

I think the flow of the paper can be slightly improved: For example, in section 2, Wasserstein neurons and entangled neurons are used interchangeably before properly establishing their connection in section 2.3. This was a bit confusing on the first read, requiring some back and forth through the sections to clarify their connections.

(Minor) The paper's generally well-written, but it would benefit from a revision as there are several typos throughout the paper.

---

confidence: 3
contribution: 2
initial_rating: 6
presentation: 1
questions: See weaknesses
soundness: 2
strengths: The proposed sparse expansion seems to outperform SparseGPT and all other baselines, though I’m not in this subfield and I don’t know what are the strong and weak baselines here.
summary: The authors propose to compute the distance between the output distribution of a neuron in a neural network and a gaussian using Wasserstein distance as a measure of entanglement, i.e. a neuron could be highly polysemantic and thus entangled. It’s shown that some of the neurons in LLMs are highly entangled under the Wasserstein distance metric and sparsifying them leads to significant performance degradation compared to sparsifying random neurons. The authors propose sparse expansion by separating the input vectors and creating a mixture of neurons with low Wasserstein distance. The proposed sparse expansion methods outperform all other baselines under sparsity / pruning.
weaknesses: - It’s very unclear what do you mean by the gaussian output distribution of a single neuron. For example, the introduction section says that a column of a weight matrix is a neuron. Here it’s unclear what’s the matmul operation between input and weights. Is it right or left multiply? Are you saying that the output scalar $y=\mathbf{w}^\top \mathbf{x}$ is a sample from the gaussian distribution? As a reader I have to read between the lines to figure out what’s the proper definition. Please write down the precise mathematical quantity.
- There is a confounding factor here regarding the idea of highly entangled neurons. If I understand properly, the output distribution of a neuron at initialization is basically a gaussian. This is because the weights are gaussian initialized unless otherwise specified. Then perhaps highly entangled neurons are basically neurons with proper feature learning, i.e. enough gradient updates, and neurons with low wasserstein distance to a gaussian could just be a neuron that didn’t receive enough gradient update. This is especially true when you consider LLMs under width scaling, as some of the parameters might not be learned properly. See https://arxiv.org/abs/2203.03466. Then it might not make sense to prune out or sparse highly entangled neurons since they could actually be the useful neurons or neurons with proper feature learning. Would like to hear what the authors think about this.

---

confidence: 4
contribution: 3
initial_rating: 8
presentation: 2
questions: 1) The way I understand your sparsification algorithm in Figure 2 is this: For 3% of the neurons, you set 95% of the weights going into them to zero. Is this correct? And if so, how do you choose these weights? 

2) Figure 10: Which model is used? The caption speaks of many, but the figure shows only one, as far as I understand it. 

Line 422 typo: "the the"
Line 428 typo: "as" -> has
soundness: 4
strengths: 1) The relevance of individual neurons is studied in detail, which is interesting from a technical point of view when reducing the model size, but also points to areas that explainable AI researchers should look for.

2) A potential application in terms of model reduction is provided.
summary: In this work, the relevance of individual neurons in LLMs is estimated by comparing their normalized output distribution before the activation function to a Gaussian using the Wasserstein distance measure. 
They find that the output of a small group of neurons deviates significantly from the gaussian distribution, and that these neurons contribute significantly to the model's performance. They define that a neuron is particularly entangled when it has to produce different outputs for similar inputs. They find that neurons that deviate from a gaussian distribution are particularly entangled.
They provide a framework that disentangles the neurons to some extent, that is, they reduce the Wasserstein distance measure. Using this framework, they obtain a lower loss on Wikitext-2 compared to other techniques when creating a sparsified model.
weaknesses: 1) The exact sparsification algorithm used to generate Figure 2 is not given in the manuscript.

2) There are some problems with the Figures: Figures 1, 3, and 7 lack x and y labels.
In Figure 10, the caption does not match what is shown in the figure.

Meta-review: The paper explores neuron entanglement in sparse neural networks, proposing that a high Wasserstein distance (WD) to a Gaussian indicates entangled, polysemantic neurons whose removal harms performance. A sparse expansion method is introduced to improve performance by clustering inputs and training sparse "experts" for each cluster, theoretically disentangling neurons. 

The reviewers noted a lack of novelty of using Wasserstein distance, and raised concerns about some assumptions and computational costs. Nevertheless, the strong experimental analysis and promising results will be of interest to the community and I recommend acceptance.

Decision: Accept (Spotlight)