Skip to content
mlmentorship

Pruning: structured vs unstructured sparsity

Set unimportant weights to zero, recover most of the accuracy. Unstructured pruning shrinks model size; structured pruning shrinks inference time. They solve different problems.

Published · 4 min read ·Role-specific ·Advanced

Visual quick review

Visual first · depth when needed

Distinguish pruning individual weights from removing whole output channels by seeing whether the matrix shape presented to dense hardware changes.

Preparing the visual…

Summary

Pruning removes weights from a trained network and fine-tunes to recover accuracy. Unstructured pruning zeros individual weights. Structured pruning removes entire neurons, channels, heads, or layers.

Modern networks are massively over-parameterized. The lottery ticket hypothesis (Frankle & Carbin, 2019) suggests that within a trained dense network, a small subnetwork (10 to 20 percent of weights) reaches the same accuracy when retrained. Pruning is the practical exploitation of that observation.

Two distinct goals:

  • Smaller model on disk and in memory: unstructured pruning + sparse storage. Useful for distribution and memory-bound deployment.
  • Faster inference on real hardware: structured pruning. Removes whole tensors so the remaining computation is dense and matches GEMM kernels.

Learning objective

Does pruning change only the values, or the matrix shape that hardware executes?

Unstructured: 8 weights, logical shape 4 x 4

Individual connections become zero, but every input-output position remains in the operator.

InputOut 1Out 2Out 3Out 4
In 1w0w0
In 20w0w
In 3ww00
In 400ww

Dense path still sees 4 x 4; sparse speed needs a compatible sparse kernel.

Structured: 8 weights, executed shape 4 x 2

Remove output channels 2 and 4, then pack the survivors into a smaller dense matrix.

InputOut 1Out 3
In 1ww
In 2ww
In 3ww
In 4ww

Standard dense path now executes 4 x 2 and produces two output channels.

Read it this way: both examples retain eight weights, but only structured pruning changes this dense operator from 4 x 4 to 4 x 2. A zero count saves compute only when storage and hardware kernels can exploit its pattern.

The two regimes

Unstructured pruning

Zero individual weights below some magnitude threshold. Common criterion: magnitude pruning (), often combined with weight decay during fine-tuning.

Sparsity achievable90 to 95 percent on overparameterized models
Storage benefitReal (CSR / CSC formats)
Speed benefitNone on standard GPUs
Why no speedupSparse matmul kernels are rarely faster than dense matmul until > 90 percent sparsity, and only on specialized hardware (NVIDIA 2:4 sparsity, custom accelerators)

Structured pruning

Remove entire structures: convolutional channels, transformer heads, FFN neurons, sometimes whole layers.

Sparsity achievable30 to 70 percent typical
Storage benefitReal
Speed benefitReal, proportional to sparsity
Why it works on hardwareOutput is a smaller dense tensor; runs through standard GEMM

The 2:4 semi-structured compromise

NVIDIA Ampere and later support 2:4 sparsity: in every group of 4 weights, at least 2 are zero. Sparse Tensor Cores can provide up to 2x the math throughput of the equivalent dense operation; end-to-end speedup is lower and workload-dependent. This is a compromise between unstructured pruning (more flexible, but requiring general sparse kernels) and coarse structured pruning (less flexible, but producing smaller dense tensors).

Pipeline

  1. Train the dense model normally.
  2. Score weights or structures by importance (magnitude, gradient-magnitude, Hessian-based, Fisher).
  3. Prune below a target sparsity.
  4. Fine-tune to recover accuracy. Often iterative: prune-finetune-prune-finetune.
  5. Optional: lottery-ticket rewind. Reset weights to an early-training checkpoint, train the sparse mask from there.

Tradeoffs vs other compression

  • Pruning vs quantization: orthogonal. Combine both. INT8 + 50 percent structured sparsity is common in production.
  • Pruning vs distillation: distillation trains a smaller model from scratch with a teacher’s soft targets. Pruning starts dense and shrinks. Distillation often produces better small models but needs the teacher’s training data.
  • Pruning at training time (e.g. RigL, Sparse Transfer): grow-and-prune during training. Avoids the prune-finetune cycle but harder to tune.

Common pitfalls

  • Reporting unstructured-sparsity speedups on standard GPUs. Almost always misleading. Sparse storage is not sparse compute.
  • Pruning before training is done. Pruning the trajectory of training, not the final model, often hurts.
  • Treating “90 percent sparse” as a quality measure. What matters is task performance at the achieved compute or memory cost.
  • Forgetting batchnorm / layernorm. Structured pruning needs to also adjust normalization statistics for the kept channels.