Sparsity
Sparsity is the share of values in a model's weights, activations or data that are zero, and the set of techniques that exploit those zeros to save memory and computation.
Google's machine learning glossary defines sparsity as the number of elements set to zero in a vector or matrix divided by the total number of entries. A matrix of 100 numbers with 80 zeros has a sparsity of 0.8. Zeros matter because multiplying by zero is wasted work and zeros need not be stored: a sparse representation keeps only the positions and values of the non-zero entries.
Sparsity turns up in three places. In data, many features are mostly zero; a vector marking which of 50,000 words appear in a short message is almost all zeros. In weights, pruning sets parameters that contribute little to zero. In activations, only part of the network does work for a given input. Mixture-of-experts models are the best-known case of the last kind: a router sends each token to a few experts, so most of the model's parameters sit idle for that token.
Pruned networks can be surprisingly good. A 2021 survey by Torsten Hoefler and colleagues, drawing on more than 300 papers, argued that sparse networks can perform as well as dense ones and sometimes better, and that sparsity can shrink memory needs enough for mobile devices and shorten training for large models. The survey also stresses that getting real speed from sparsity depends on the hardware.
That hardware point is the catch. Chips are fastest on dense blocks of numbers, and zeros scattered at random, known as unstructured sparsity, are hard to exploit. Structured sparsity imposes a pattern the chip can use. NVIDIA's Ampere architecture, introduced with the A100 GPU, supports a 2:4 pattern in which at least two of every four values are zero; its Sparse Tensor Cores skip the zeros and double throughput for that operand. In NVIDIA's own tests on matrix multiplications from BERT-Large layers, the measured speedup was 1.3 to 1.6 times, which shows the gap between theoretical and actual savings.
When a company calls a model sparse, it is worth asking which kind it means: a mixture-of-experts model with far fewer active parameters than total parameters, pruned weights, or sparse attention. Each saves something different, and none saves anything unless the software and chips are built to skip the zeros.
Sparsity means that most of the values in a vector, matrix or model are zero. It is measured as the fraction of zero entries. Sparse data, sparse weights and sparse activations can all be stored and processed more cheaply than their dense equivalents if the software and hardware take advantage of the zeros. In a dense model every parameter takes part in processing every input. In a sparse model many weights are zero or only part of the network is used for each input, as in mixture-of-experts models. Sparse models can be larger in total size while doing less work per token. It is a pattern supported by NVIDIA GPUs since the Ampere generation in which at least two of every four consecutive values are zero. Because the pattern is regular, the hardware can skip the zeros and double throughput for that part of the calculation. Models usually need some retraining to adopt the pattern without losing accuracy. Removing weights can lower accuracy, but much research shows networks can be heavily pruned and then retrained to recover most or all of their performance. How far a model can be pruned depends on the task and on how the pruning is done.Common questions
What does sparsity mean in machine learning?
What is the difference between a sparse model and a dense model?
What is 2:4 structured sparsity?
Does pruning hurt accuracy?
Search for "neural network pruning", "structured sparsity", "2:4 sparsity" or "sparsity in deep learning survey" to see the main methods and their trade-offs. Reliable sources include survey papers on arXiv, chip makers' developer documentation for what their hardware actually supports, and framework documentation for sparse tensor support. Treat speedup figures from vendors as measured on favourable workloads.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.