Mahir Shahriar Tamim

AI Researcher · Explainable & Responsible AI · Vision, Language & Agentic Systems

Part 2 of Pruning and the Lottery Ticket

Why 90% sparse is not 10× faster

Module 2 · 5 min read

Why 90% sparse is not 10× faster

TL;DR

  • In dense storage a zero costs as much as any number, so unstructured sparsity alone saves nothing.
  • Removing whole channels or heads gives a smaller dense model that runs fast anywhere, at some accuracy cost.
  • NVIDIA’s 2:4 pattern (Ampere and later) sits in between, 50% sparse for up to 2× matmul throughput.

A matrix full of zeros is still a matrix

This surprised me the most. Prune 90% of a layer to zero and it runs exactly as fast, in as much memory, because the grid is stored as before and the GPU multiplies all of it. Multiplying by zero costs the same as by 0.73, and checking for zeros would cost more. To save anything you have to change how the matrix is stored and computed, and how easy that is depends on where the zeros are.

Three ways to place the same 50% of zeros

Pattern

Same layer, same number of zeros, toy weights. In 2:4, faint lines mark groups of four and each keeps exactly its two largest weights. In rows, whole output channels are removed.

Unstructured: most accurate, hardest to speed up

Removing the smallest weights wherever they are keeps the most accuracy but scatters the zeros. Skipping them needs a sparse format like CSR (compressed sparse row), which stores the non-zero values plus their positions. A 32-bit column index next to a 16-bit weight triples its size, so sparse storage only wins when very sparse.

One 4096×4096 layer in 16-bit numbers. CSR uses 2 bytes per non-zero value, a 4-byte column index for each, and one 4-byte pointer per row. A bitmask format uses 1 bit per position. Real arithmetic, simplified formats.

Speed is worse. GPUs like reading big, tidy blocks of memory and doing one operation on all of it, and index lists make them jump around while units sit idle. So on GPUs sparse kernels often win only at very high sparsity, and at the 50–80% pruning usually reaches, dense is often faster. CPUs with good sparse libraries, chips built for sparsity, and inference engines on memory-bound workloads (where reading fewer bytes is what matters) can gain, but never automatically.

Structured: remove whole pieces

Remove whole rows, columns, channels or heads instead and you get a smaller dense matrix that every GPU and library runs fast, half the channels for roughly half the work. Pruning picks which smaller model, starting from trained weights, often better than training that shape from scratch (debated, see part 3). Pruning Filters for Efficient ConvNets (Li et al., 2017) drops the convolution filters with the smallest total weight. Network Slimming (Liu et al., 2017) adds a training penalty that pushes unimportant channels towards zero, then cuts them.

The cost is that a removed channel may hold a few important weights, so for the same number removed, structured pruning usually hurts accuracy more.

The middle way: N:M sparsity

In 2020 NVIDIA’s Ampere GPUs (the A100 and later) added 2:4 structured sparsity, at most two non-zeros in every four consecutive weights. The hardware stores the two kept values with a 2-bit index each, and sparse tensor cores skip the zeros for up to 2× the math throughput of dense tensor cores. End-to-end gains are smaller, since these matrix multiplications are only part of a model’s time. Accelerating Sparse Deep Neural Networks (Mishra et al., 2021) reports that pruning then retraining keeps accuracy close to dense across many vision and language networks.

Basically, sparsity only pays when the hardware is built for that exact pattern.

PatternAccuracy for a given sparsityReal speedup on GPUsNeeds
Unstructuredbestlittle, unless very sparsesparse kernels, special formats
2:4 (N:M)good, after retrainingup to 2× on matmulsAmpere-or-newer GPU, supported libraries
Channels / headsloweryes, it’s just a smaller modelnothing special

Quick check

You prune 60% of a model’s weights (unstructured) and keep dense storage. How much faster does it run on a GPU?

Q&A

Can I use 2:4 sparsity on any GPU?

Support came with NVIDIA’s Ampere generation (A100, RTX 30 series) and continues in later ones. Older GPUs run the model but treat the zeros as normal numbers.

What about pruning attention heads?

That’s structured pruning too. Michel et al. (2019), “Are Sixteen Heads Really Better than One?”, found many heads in a trained Transformer can be removed at test time with little loss, though some layers depend on more heads than others.

Papers