# Noisy Quadratic Model, Momentum & Weight Decay | Stanford CS312 Lecture 3 with Tatsunori Hashimoto

## Executive summary

This lecture explores the complex dynamics of deep learning optimization, moving beyond classical convex optimization theory. It introduces the Noisy Quadratic Model (NQM) to provide intuitive insights into the trade-offs between batch size, learning rate, and steady-state loss. A major focus is placed on the phenomenon of parameter norm growth in scale-invariant architectures (like Transformers), which forces effective step sizes to shrink. The session concludes by detailing Hyperball, an algorithmic approach that projects weights onto a fixed-radius sphere to stabilize training and improve hyperparameter transfer.

## Key takeaways

- Critical Batch Size and Diminishing Returns: The NQM predicts that increasing batch size improves training efficiency only up to a critical point. Beyond this point, the learning rate hits a stability limit (2/h, where h is the narrowest curvature), and additional batches yield strongly diminishing returns.
- Norm Growth and Effective Step Size: In scale-invariant systems (e.g., those using Layer Norm), the loss is independent of the parameter norm. This causes gradients to lie tangent to the sphere, leading to norm growth. This growth, in turn, reduces the effective step size, limiting the control over the learning rate.
- Weight Decay Controls Effective Learning Rate: In the one-pass setting, weight decay does not primarily control model complexity; instead, it controls the effective learning rate of the optimization process. This allows weight decay to be used as a mechanism to maintain tight control over the system's scale.
- Hyperball for Stability: Hyperball is an optimization trick that projects both the gradients and the parameters back onto a fixed-radius sphere (defined by the initialization norm). This hard constraint stabilizes training and improves hyperparameter transfer across different model sizes.

## Technical details

- Noisy Quadratic Model (NQM): The NQM is a simplified toy model where the quadratic loss is diagonalized, and the noise covariance is assumed to be axis-aligned with the quadratic. This allows for coordinate-by-coordinate analysis of SGD and momentum dynamics, revealing trade-offs between convergence rate and steady-state loss.
- Momentum Regimes: Momentum SGD operates in two regimes: overdamped (smooth, similar to gradient descent) and underdamped (oscillatory). The NQM suggests that the rate-limiting step is often the overdamped regime, and gains from momentum are most pronounced when the SGD learning rate is constrained by a stability limit.
- AdamW Mechanics: AdamW incorporates a momentum term (M_T, tracking exponentially decaying averages of gradients) and a preconditioning term (V_T, tracking squared gradients). The 'W' (weight decay) is implemented as decoupled weight decay, meaning it is added directly to the update rather than being filtered through the momentum machinery.
- Preconditioning and Tradeoffs: Preconditioning (using a matrix P, ideally the inverse Hessian) strictly improves the convergence rate. However, in the noisy case, stronger preconditioning (larger P) tends to worsen the steady-state error, illustrating a fundamental trade-off between convergence speed and final loss.

## Practical implications

- Understanding the limits of batch size and learning rate is crucial for efficient resource allocation and scaling large models.
- The concept of norm control (via Hyperball) provides a robust method for improving hyperparameter transferability across different model sizes.
- The observation that weight decay controls the effective learning rate suggests a new way to think about regularization, moving beyond simple complexity control.

## Topics

Deep Learning, Optimization Algorithms, Hyperparameter Tuning, AI Architecture, Gradient Descent, Stanford CS312: Deep Learning Alchemy

Source: https://www.youtube.com/watch?v=wdjnAOrS7f8
