When Will Gradient Regularization Be Harmful?

Yang Zhao, Hao Zhang, Xiuyuan Hu

TL;DR

Gradient Regularization (GR) is a powerful tool for improving model generalization, but this paper reveals a hidden catch: it can severely degrade performance when paired with adaptive optimizers like Adam. By identifying that GR destabilizes gradient statistics early in training, the authors propose "GR Warmup" strategies—most notably "Zero-warmup"—which can boost Vision Transformer accuracy by up to 3%.

What Problem Does This Paper Address?

In the era of over-parameterized models like Vision Transformers (ViTs), regularization is essential to prevent overfitting. Gradient Regularization (GR), which penalizes the norm of the loss gradient, has become a go-to technique because it encourages the optimizer to find "flat minima," which generally generalize better to unseen data.

However, the authors noticed a paradox: while GR is theoretically sound, it often causes performance to degrade when used alongside adaptive optimizers (like Adam or RMSProp) and learning rate warmup. The paper investigates this incompatibility, asking: Why does a technique meant to help generalization sometimes make models perform worse than vanilla training?

Methods & Theoretical Insights

The authors combine empirical observation with mathematical analysis to solve the puzzle.

  • The "Bias" Trap: Early in training, adaptive optimizers attempt to estimate the first and second moments of gradients. GR introduces a biased estimation of these gradients, leading to "misleading" statistics that steer the optimization toward suboptimal local minima.
  • Variance is the Villain: The paper’s core theoretical contribution links the decline in gradient norm to an explosion in the variance of the adaptive learning rate. Essentially, GR makes the "steps" the optimizer takes much more erratic at the beginning of the run.

To fix this, they propose three ways to "warm up" the regularization, similar to how we warm up learning rates:

  1. $r$-warmup: Gradually increasing the perturbation radius used to calculate the gradient penalty.
  2. $\lambda$-warmup: Gradually ramping up the regularization coefficient ($\lambda$).
  3. Zero-warmup: Completely disabling GR during the initial learning rate warmup phase and switching it on only after the optimizer's gradient statistics have stabilized.
Gradient Norm of ViT-B with GR Warmup Strategies

As shown above, these warmup strategies prevent the premature and sharp drop in the gradient norm during the critical early epochs (shaded region), allowing the optimizer to stabilize.

Key Results

The researchers evaluated their methods across several standard benchmarks (CIFAR-10, CIFAR-100, TinyImageNet, ImageNet-1K) and modern architectures (ViT family, Swin Transformers, CaiT). The results show that "fixing" GR with warmup leads to substantial gains, especially for larger models.

Testing Error Rate Comparison
  • ViT-B on CIFAR-10: Using standard GR resulted in a 12.36% error rate. Applying Zero-warmup slashed that to 9.42%—a nearly 3% absolute improvement.
  • Simplicity Wins: Surprisingly, the simplest strategy—Zero-warmup—consistently performed the best. Letting the optimizer "see" the raw landscape for a few dozen epochs before applying the gradient penalty is more effective than trying to gradually introduce the penalty.
  • Scalability Matters: The "harmful" effects of standard GR are more pronounced in larger, more complex models. As models scale up (e.g., from ViT-Ti to ViT-B), the need for proper GR warmup becomes critical.
  • Consistency across Architectures: On Swin-Base (CIFAR-10), Zero-warmup reduced error from 11.88% (vanilla GR) to 10.90%. For Swin-Tiny on ImageNet, Zero-warmup achieved a 21.58% error rate, outperforming both vanilla training (23.43%) and standard GR (22.34%).

Limitations and Future Work

While the paper provides a robust solution for Transformer-based models, there are a few areas for further exploration:

  • Architecture Scope: The study focuses heavily on Transformers. While the authors note that CNNs are often trained with SGD (which doesn't suffer from this specific adaptive variance issue), more testing on diverse architectures like GNNs or State Space Models (Mamba) would be valuable.
  • Hyperparameter Sensitivity: The "Zero-warmup" strategy currently ties the GR warmup duration directly to the learning rate warmup duration. Future work could investigate if decoupling these two schedules provides even better results.
  • Theoretical Assumptions: The proof assumes a Gaussian distribution for gradients; exploring how non-Gaussian, heavy-tailed gradient distributions affect this variance would deepen the theoretical foundation.

Summary updated

BibTeX
@inproceedings{zhao2024when,
  author = {Yang Zhao and Hao Zhang and Xiuyuan Hu},
  title = {{When Will Gradient Regularization Be Harmful?}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=60vC1FY0dZ},
}
Figure