(Almost) Smooth Sailing: Towards Numerical Stability of Neural Networks Through Differentiable Regularization of the Condition Number

Rossen Nenov, Daniel Haider, Peter Balazs

TL;DR

Optimizing the condition number of weight matrices directly is notoriously difficult because condition numbers are discontinuous and non-differentiable whenever singular values vanish. This paper proposes a differentiable surrogate regularizer that penalizes the gap between the largest singular value and the average singular value, guaranteeing full-rank, well-conditioned weights while plugging cleanly into standard gradient descent.

What Problem Does This Paper Address?

In deep learning, numerical instability often traces back to ill-conditioned weight matrices. A matrix’s condition number—the ratio between its largest and smallest non-zero singular values, $\kappa(S) = \sigma_{\max}(S) / \sigma_{\min>0}(S)$—measures how dramatically small input perturbations (such as noise or numerical quantization) are amplified during forward passes.

While practitioners want well-conditioned matrices ($\kappa \approx 1$), directly minimizing $\kappa(S)$ via gradient descent is fundamentally ill-posed: $\kappa$ jumps discontinuously to infinity whenever a singular value drops to zero. Standard regularizers like Tikhonov regularization ($L_2$ weight decay) control weight magnitudes, but they do not control singular value ratios and can inadvertently drive condition numbers into the thousands.

Methods

The authors introduce an alternative regularizer defined as the difference between the squared spectral norm and the normalized squared Frobenius norm:

$$r(S) := \frac{1}{2}\|S\|_2^2 - \frac{1}{2\nu}\|S\|_F^2$$

where $\nu = \min(n, m)$ for a matrix $S \in \mathbb{R}^{n \times m}$.

  • Optimality & Full Rank: Because $\|S\|_F^2 = \sum \sigma_i^2$, $r(S) \ge 0$ is proportional to the difference between $\sigma_{\max}^2$ and the mean of all squared singular values. The minimum $r(S) = 0$ is attained if and only if all $\nu$ singular values are identical and non-zero (for $S \neq 0$), simultaneously ensuring full rank and an optimal condition number $\kappa(S) = 1$.
  • Differentiability Almost Everywhere: Using nonsmooth variational analysis (specifically the Mordukhovich subdifferential and Lewis’s theory of unitarily invariant matrix functions), the authors prove that $r(S)$ is differentiable whenever the largest singular value is unique. When this holds, the gradient is given in closed form: $$\nabla r(S) = \sigma_{\max}(S) u_1 v_1^T - \frac{1}{\nu} S$$ where $u_1, v_1$ are the leading left and right singular vectors.

  • Condition Number Decrease: The paper formally proves (Theorem 3.2) that a gradient descent step along $-\nabla r(S)$ strictly decreases the matrix condition number for sufficiently small step sizes.

Datasets

The authors evaluate their approach on:

  • Synthetic Random Matrix Least-Squares: Synthetic Gaussian matrices ($X \in \mathbb{R}^{50 \times 100}, Y \in \mathbb{R}^{20 \times 100}$).
  • MNIST: The standard MNIST benchmark evaluated under zero noise ($\text{SNR} = \infty$) as well as additive Gaussian noise at $\text{SNR} = 1.0$ and $\text{SNR} = 0.5$.

No new datasets were introduced.

Key Insights and Ideas

  • Variance Minimization over Ratios: Instead of minimizing the fragile ratio $\sigma_{\max} / \sigma_{\min}$, the regularizer acts as a variance penalty across squared singular values, anchoring them to their maximum.
  • Smoothness by Nature: Since matrices with repeated leading singular values form a set of codimension 2 in matrix space, random weight initialization and continuous gradient trajectories ensure $r(S)$ is differentiable almost surely.
  • Tikhonov’s Blind Spot: Traditional weight decay shrinks all singular values uniformly, often shrinking small singular values faster toward zero and wildly inflating $\kappa$.

Key Results

  • Synthetic Least-Squares: Regularization drastically reduced $\kappa(W)$ toward optimal values ($\approx 1$) while incurring less than a $6\%$ increase in approximation error.
  • Noisy MNIST Classification:
  • With strong noise ($\text{SNR} = 0.5$), the regularized network ($\lambda = 1$) maintained $\kappa(W_1) = 1.53$ and reached 84.25% test accuracy.
  • The unregularized baseline had $\kappa(W_1) = 43.12$ and collapsed to 71.91% accuracy.
  • By contrast, Tikhonov regularization inflated $\kappa(W_1)$ beyond $4000$ and peaked at $82.79\%$.
  • MNIST Denoising Autoencoder:
  • An unregularized autoencoder suffered massive instability, with encoder layer 1 reaching $\kappa(E_1) \approx 604$, causing reconstructed digits to disintegrate into noise.
  • The proposed regularizer kept condition numbers low across all layers ($E_1$: $23.39$, $E_2$: $1.08$, $D_2$: $1.07$), yielding sharp, legible digit reconstructions.

Limitations and Future Work

  • Performance Trade-Off: In clean, noise-free settings ($\text{SNR} = \infty$), the regularization slightly penalizes classification accuracy (dropping from $98.42\%$ to $96.50\%$).
  • Computational Overhead: Evaluating $\nabla r(S)$ requires computing the leading singular value and corresponding singular vectors ($u_1, v_1$) at each update step (e.g., via power iterations or partial SVD).
  • Scale: Experiments were limited to shallow feedforward networks and basic dense autoencoders; validating the technique on large convolutional networks, Transformers, or deep residual architectures remains open for future study.

Summary updated

BibTeX
@inproceedings{nenov2024almost,
  author = {Rossen Nenov and Daniel Haider and Peter Balazs},
  title = {{(Almost) Smooth Sailing: Towards Numerical Stability of Neural Networks Through Differentiable Regularization of the Condition Number}},
  booktitle = {Differentiable Almost Everything @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=OJkyvJXk2B},
}
Figure