# #30 Pruning vs Quantization. Final showdown!

# Table of contents

**Introduction.****Pruning vs quantization. Which one is better?****Closing thoughts.**

# Introduction

I know what you might be thinking. I have already discussed about quantization and pruning in two past articles:

However, the paper [1] published recently on arxiv really caught my eyes, as It is the first paper I have read that directly compares the two techniques to be able to decide which one is best in different settings.

I found the results pretty interesting and I really wanted to share them with you!

Let's get started!

# Pruning vs quantization. Which one is better?

The following methods have been compared:

Magnitude pruning.

Symmetric uniform quantization.

The methods have been evaluated on the common signal-to-noise ratio (SNR) measure.

Many weights in neural networks are roughly Gaussian-shaped, so the first distribution that was evaluated was the Gaussian distribution.

As we can see from the figure, the errors for both methods have very different behavior. The quantization error oscillates between the quantization nodes and has a moderate range. The pruning error effectively corresponds to rounding many weights to zero and thus has a higher error. As we can see in figure 1 (right), this results in a higher SNR for quantization.

The second distribution being evaluated is one with heavy tails: a student-t distribution is chosen.

Despite the significant outliers and high kurtosis, quantization still has higher SNR in most of the cases for moderate compression. Pruning is better however in the region of high clipping range and very high compression rate, e.g. 2-3 bits per value.

Still, the previous results were mostly theoretical in nature. The paper goes on to compare all pre-trained model from the PyTorch model zoo:

Results from the previous theoretical section hold. The kurtosis is indeed a good metric for predicting if a tensor should be quantized or pruned for optimal accuracy.

The paper goes on to discuss the Per-layer comparison between Post-training quantization and Post-training pruning.

The rectangles indicate the full range of the pruning and quantization methods between the heuristic solution and the error lower bound or the global solution. Whenever a rectangle for each chunk intersects the diagonal line, the ranking of the two methods could depend on the optimization method, while in cases below or above the diagonal, the ranking is guaranteed regardless of the optimizer.

Quantization mostly outperforms pruning for moderate compression, while methods become more comparable for higher compression ratios.

# Closing thoughts

The conclusion is clear: under the paper's assumption, Quantization generally outperforms pruning for neural networks.

Next time you need to shrink a model size, forget about pruning! ;)