STEP: Learning N:M Structured Sparsity Masks from Scratch with Precondition

Yucheng Lu, Shivani Agrawal, Suvinay Subramanian, Oleg Rybakov, Christopher De Sa, Amir Yazdanbakhsh

Training sparse neural networks from scratch using adaptive optimizers like Adam often results in significant accuracy degradation. This is primarily due to weight masking, which introduces noise into Adam’s variance estimation. We present STEP (STE with Precondition), a two-phase training strategy that stabilizes variance estimates on a dense model before freezing them to serve as a "preconditioner" for learning N:M structured sparsity masks. Our approach enables models like BERT and GPT-2 to achieve near-dense performance under aggressive hardware-friendly sparsity constraints.

The Challenge: Adam's Failure in Sparse Training

Modern deep learning deployment benefits from N:M structured sparsity (e.g., 2:4 sparsity), which accelerates inference on specialized hardware like Nvidia's Tensor Cores. Ideally, these sparse masks should be learned from scratch to avoid expensive fine-tuning. However, while methods like the Sparse Refined Straight-Through Estimator (SR-STE) perform well with Stochastic Gradient Descent (SGD), they struggle with Adam—the standard optimizer for Large Language Models (LLMs).

Validation accuracy of SR-STE vs Dense models using SGD and Adam optimizers.

As shown in Figure 1, SR-STE maintains performance with SGD but suffers a notable accuracy gap when paired with Adam. The root cause is Adam's reliance on a "second moment" (variance) estimate to scale learning rates. Masking weights during training injects extreme noise into gradients, preventing this variance from converging and leading to incorrect learning rate scaling.

Methodology: STE with Precondition (STEP)

To resolve this, STEP decouples variance estimation from mask learning through a two-phase recipe:

  1. Precondition Phase: The model is trained as a dense network using Adam. This allows the optimizer to build a reliable, stable estimate of the gradient variance ($v_t$).
  2. Mask-Learning Phase: The variance estimate is frozen ($v^*$). The model then learns the N:M sparsity masks using the Straight-Through Estimator (STE). By using a stable, noise-free "preconditioner" ($v^*$), the optimizer can effectively update weights despite the sparsity-induced noise.

To automate the transition between phases, the authors introduce AutoSwitch. This subroutine monitors the "concentration" of variance updates, switching to Phase 2 once changes to the variance fall below Adam’s smoothing constant ($\epsilon$).

Key Insights: The Variance Gap

The failure of sparse Adam training is characterized by a "Variance Gap." In standard dense training, the norm of the gradient variance naturally decreases as the model converges. In contrast, sparse training with Adam results in a variance norm that remains high and erratic.

Comparison of the second moment norm ||v_t|| between Dense and SR-STE training.

Figure 3 illustrates this phenomenon across different architectures. Freezing the variance during the sparse phase—rather than continuing to update it with noisy masked gradients—is a key innovation that stabilizes the adaptive learning rate logic. Theoretical analysis confirms that the error introduced by this fixed preconditioning is bounded and decreases over time.

Experimental Results

STEP was evaluated across various tasks, including Computer Vision (ResNet18, DenseNet121), Natural Language Understanding (BERT), and Language Modeling (GPT-2, Transformer).

  • Large Language Models: On the GLUE benchmark, BERT-Base with STEP achieved an average score of 80.7, nearly matching the dense baseline of 81.0, whereas SR-STE dropped to 78.3.
  • Generative Models: For GPT-2 on WikiText-2, STEP reached a perplexity of 23.85, significantly outperforming SR-STE (28.54) and Nvidia’s ASP (37.09).
  • Vision Tasks: On CIFAR-100, STEP with 1:8 sparsity even slightly outperformed the dense model, suggesting the preconditioning phase may offer beneficial regularization.

Conclusion and Future Work

STEP provides a robust framework for training N:M sparse models from scratch with adaptive optimizers. While highly effective for structured sparsity, future research could explore its applicability to unstructured sparsity or its scalability to "extreme" LLMs with hundreds of billions of parameters. Additionally, investigating the compatibility of preconditioning with other optimizers like Adafactor or Lion remains an open area of interest.

Summary updated

BibTeX
@inproceedings{lu2023step,
  author = {Yucheng Lu and Shivani Agrawal and Suvinay Subramanian and Oleg Rybakov and Christopher De Sa and Amir Yazdanbakhsh},
  title = {{STEP: Learning N:M Structured Sparsity Masks from Scratch with Precondition}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=0O7b2Y198V},
}
Figure