TL;DR
A dense network can be made sparse after training by Pruning, but then the full dense model had to be trained first. Dynamic sparse training starts with a sparse network and keeps it sparse for the whole run. Every so often it drops some of the weights that are active, grows the same number of new weights elsewhere, and keeps training. The goal is a sparse model whose training is cheap in memory and compute from the first step.
Builds on: Pruning, Stochastic Gradient Descent · Leads to: RigL
Where it's used
Training image classifiers under a compute budget. Research on sparse training has trained image models such as ResNet-50 on ImageNet with most of their weights held at zero for the whole run. The RigL paper is the best-known example, and it compares its sparse training against dense training of the same network.
Training on memory-limited devices. A phone or small board may have room for the active weights of a model but not for the full dense weights plus the optimiser state that training needs. A method that never allocates the dense model is attractive here. The saving is real only if the framework stores the sparse weights in a sparse format.
Searching for a good sparse structure. Pruning a finished dense model (see Pruning) needs the dense training first. Dynamic sparse training searches over sparse structures while it trains, so the search and the training are one job. This is the sparse-to-sparse route, in contrast to dense-to-sparse pruning.
How it works
Start with a small question. Pruning begins with a dense network and removes weights at the end. What if the network never became dense? Suppose a layer has six weights and a budget of three active weights at any moment. The three inactive weights are exactly zero, and the forward pass uses only the active ones. Training updates only the active weights. The method must decide which three positions are active, and it revises that choice as training goes on.
The walkthrough below uses that tiny layer, with a mask update after a few training steps.
- Start with a sparse mask. Choose three positions as active. Say positions 1, 3 and 5 are active, so the weights are . Check: three weights are active and three are exactly zero.
- Train the active weights. Ordinary gradient steps move only the active weights. Suppose one step changes the first weight from to and the fifth from to . Check: the inactive positions 2, 4 and 6 are still zero.
- Measure every position, active or not. Compute the gradient of the loss with respect to all six weights. For an inactive weight this gradient says how the loss would change if that weight were switched on. Suppose the gradients are . Check: the largest magnitude, , belongs to position 2, which is inactive.
- Drop the weakest active weight. The active weights are now , and in magnitude. The smallest is , at position 3. Switch it off. Check: positions 1 and 5 remain active.
- Grow the strongest inactive position. Among the inactive positions, the gradient magnitudes are at position 2, at position 4, at position 3 and at position 6. The largest is position 2, so switch it on with value zero. Check: the active set is now , which is still three.
- Keep training. Continue with the new active set. Check: the budget is unchanged, and position 2 starts at zero, so it changes only as training moves it.
flowchart LR
A["Sparse mask with fixed budget"] --> B["Train the active weights"]
B --> C{"Update step reached?"}
C -- "no" --> B
C -- "yes" --> D["Drop the weakest active weights"]
D --> E["Grow the same number of inactive weights by gradient"]
E --> B
The drop step uses the same rule as magnitude pruning. The growth step is where methods differ. Inactive weights are zero, so their size tells us nothing, and the method needs another signal. The most common choice is the gradient.
The math
Setup (step 1)
Let be the weights of a layer, and let be a mask, with meaning position is active. The mask has a fixed budget: at every moment, where counts the nonzero entries of the mask, as in Pruning. The sparsity is . The network computes with the effective weights , where is the entrywise product, so the loss is .
Training changes only the active entries. The chain rule gives the update direction as , so an inactive entry receives no step. This is step 2 in symbols.
Gradient for every position (step 3)
Let , evaluated at the current weights where inactive entries are exactly zero. Since those entries are zero, the forward pass with is the same as the forward pass with . So is a real sensitivity for every position: for an inactive , it is the rate at which the loss changes as moves away from zero. This is the dense gradient, and computing it needs one backward pass that keeps the inactive positions in the calculation. Step 3 of the walkthrough used .
Drop and grow (steps 4 and 5)
Let be the set of active indices and let be the number of swaps, where is a fraction such as . The drop set takes the active indices with the smallest magnitude, and the grow set takes the inactive indices with the largest gradient magnitude:
The new mask is , and the new weights are for . Because , the budget is preserved: .
In words, is the set of active positions with the smallest total weight magnitude, and is the set of inactive positions with the largest total gradient magnitude. In the walkthrough, since is the smallest active magnitude, and since is the largest inactive gradient magnitude.
Training between updates (step 6)
Between mask updates the weights follow an ordinary step. With learning rate (see Learning Rate), and the gradient step of Stochastic Gradient Descent,
and the inactive entries stay at zero. Some implementations decay over the course of training, so that late in the run the mask changes less.
Worked examples
A layer has four weights, budget , and active set . The weights are
Suppose the gradients are , and we swap one weight.
- The active magnitudes are and . The smallest is , at position 3, so .
- The inactive positions are 2 and 4, with gradient magnitudes and . The largest is , at position 4, so .
- The new active set is , and the new weights are .
Interpretation: the layer still has two active weights. Position 4 was chosen because the loss is most sensitive to it, even though its current value is zero.
A layer has weights and budget , so sparsity is 90%. Each update swaps a fraction of the budget.
- Each update swaps weights: 30 are dropped and 30 are grown.
- After each update the active count is , so the budget holds.
- After 10 updates, at most positions can have been newly activated, on top of the 100 active at the start.
- The most positions that can ever have been active is therefore , which is 40% of the layer.
Interpretation: a sparse run with a fixed budget still explores a growing share of the layer, because each swap moves the mask. If is too large, the mask churns and the network never settles on a structure it can train well.
Assume a sparse training step costs of a dense step, since 90% of the weights are inactive, and ignore all overheads. Every 100 steps, an update step computes the dense gradient, which costs a full instead of .
- A sparse step costs on average.
- Each update step costs instead of , an extra .
- Over 100 steps, there is one update, so the extra cost is spread over 100 steps.
- The average cost per step is .
- That is about 11% of a dense step.
Interpretation: under these assumptions the periodic dense gradient is cheap on average. The result depends on the assumption that a sparse step really costs a tenth of a dense step, which holds only with sparse kernels. With dense kernels, each step costs the same as dense training.
Try it: a layer has 500 weights and a budget of 50 active weights. Each update swaps 20% of the budget. How many weights are swapped in one update, and at most how many distinct positions can have been active after three updates?
Answer: weights are swapped per update. After three updates at most distinct positions have been active.
Common mistakes and tradeoffs
"The mask is chosen once at the start and then fixed." This is static sparsity, and it is one method, not the dynamic one. In dynamic sparse training the mask is revised during training, and the revision is what makes it dynamic.
"Growing the inactive weights with the largest magnitude is the natural rule." It is tempting to reuse the Pruning rule in reverse. In fact every inactive weight is zero, so magnitude cannot rank them. Growth needs a signal from the loss, such as the gradient. The original sparse evolutionary method grew connections at random, which avoids the ranking problem but ignores what the loss needs.
"A sparse mask means training is automatically cheaper." It is tempting to expect savings from the count of zeros. In fact scattered zeros still take part in dense multiplications unless the library has a sparse kernel. Many research codes store dense tensors and multiply by a mask, so they reduce the number of active parameters but not the time or memory cost. The saving must be measured on the actual hardware and framework.
When to use it: a large model where memory or compute is the limit during training, and a stack that can store and multiply sparse tensors. When not to use it: a small model, which has little redundancy to exploit, or a setting where you have the compute to train dense and only need the final model to be small. In that case, dense training followed by Pruning is simpler.
| Situation | What goes wrong | Better choice |
|---|---|---|
| No sparse kernels available | Dense multiplies cost the same, so there is no speedup | Structured sparsity, or dense training followed by pruning |
| Swap fraction too large | The mask churns and training never settles | A smaller swap fraction, decayed later in training |
| Growth by magnitude | Every inactive weight is zero, so the rule cannot rank them | Grow by gradient magnitude |
| Small model | Little redundancy to exploit | Dense training |
Dynamic sparsity also adds hyperparameters that pruning does not have: the swap fraction, the interval between updates, and when to stop updating. Each needs tuning.
History
Before 2018, the main route to a sparse network was dense-to-sparse: train, then prune. Han, Pool, Tran and Dally (2015) showed that magnitude pruning followed by retraining could remove most connections in large image networks (Han et al.). Frankle and Carbin's Lottery Ticket Hypothesis (2018) went further and showed that a pruned subnetwork could be retrained from its original initialisation, which made researchers ask whether the good sparse structure could be found and trained directly (the lottery ticket paper).
In 2018 Mocanu and colleagues introduced sparse evolutionary training, which keeps a fixed number of connections during training, drops the weakest ones and grows new ones at random. Evci and colleagues' RigL, published in 2019 and presented at a 2020 conference, kept the same drop-and-grow loop but grew by gradient magnitude, and it compared favourably with the random rule in its experiments. The method caught on because it showed that a sparse network can be trained from scratch without a dense model ever being built.
Recap
- Dynamic sparse training keeps the number of active weights fixed while the set of active positions changes during training.
- Each mask update drops the weakest active weights by magnitude and grows the same number of inactive ones.
- Growth needs a signal from the loss, such as the gradient, because inactive weights are zero.
- Savings in memory and time are real only with sparse storage and kernels. A dense simulation of a sparse mask saves nothing.
- Next: RigL is the gradient-growth method built on this loop. The lottery ticket paper explains why a good sparse structure is worth searching for.
Check yourself
QuestionName the two decisions made at each mask update, and say which signal each one uses.Show answer
The method decides which active weights to drop and which inactive weights to grow. Dropping uses the weight magnitude, because a small active weight contributes little to the output. Growing uses a signal from the loss, usually the gradient magnitude at the zero-valued positions, because the inactive weights are zero and their size cannot rank them.
QuestionA layer has 8 weights and a budget of 4 active. The active set is with values , , and . The inactive gradient magnitudes are , , and . Swap one weight. Which is dropped, which is grown, and what is the new active set?Show answer
The smallest active magnitude is , at position 3, so position 3 is dropped. The largest inactive gradient magnitude is , at position 4, so position 4 is grown. The new active set is , which still has four positions, so the budget holds.
QuestionWhy can't a growth rule simply pick the inactive weights with the largest magnitude?Show answer
Every inactive weight is exactly zero, so all of their magnitudes are equal and the ranking is empty. The rule needs a signal that is not the current weight, such as the gradient, which tells how the loss would change if the weight were switched on.
QuestionA team trains with dynamic sparse training on a GPU that has only dense kernels, and they find the wall-clock time is the same as dense training. Explain why, and say what would change it.Show answer
The mask has zeros in scattered positions, and a dense kernel multiplies by those zeros, so it does the same work as the dense model. The speedup needs either a sparse kernel that skips the zeros, which adds indexing overhead, or structured sparsity that removes whole rows or channels so the remaining matrices are smaller and dense. Memory savings would need sparse storage as well.
Sources
- Evci, Gale, Menick, Castro, Elsen, Rigging the Lottery: Making All Tickets Winners (2019): https://arxiv.org/abs/1911.11134
- Frankle and Carbin, The Lottery Ticket Hypothesis (2018): https://arxiv.org/abs/1803.03635
- Han, Pool, Tran, Dally, Learning both Weights and Connections for Efficient Neural Networks (2015): https://arxiv.org/abs/1506.02626