Divit Rawal

A Theory of Saddle Escape in Deep Nonlinear Networks

When do neural networks first learn features? [arXiv]

[NOTE] Still a work in progress; some parts are rough.

Generally, when a network is trained from small initialization (i.e. all its weights are initially very small), we tend to see a pretty characteristic pattern: long plateaus where loss barely drops, with sharp drops as new features are acquired. This "saddle-to-saddle" structure is pretty well understood for deep linear networks (where the activation function is Id⁑:x↦x\operatorname{Id}: x \mapsto x). For nonlinear networks, why this happens remains mysterious; here we try to provide a result that shows that deep nonlinear networks are not that different than their linear counterparts.

Saddle-to-saddle training dynamics
Saddle-to-saddle training dynamics (image from learningmechanics.pub).

Background#

Deep Linear Networks#

Much of the existing theory for optimization dynamics is based in the deep linear network model: an LL-layer network without any activation function, just a long chain of matrix multiplications y^=WLβ‹―W1x\hat y = W_L \cdots W_1 x. Although the model is simple, deep linear networks exhibit surprisingly nontrivial dynamics during gradient flow (WΛ™=βˆ’βˆ‡WL\dot W = - \nabla_W \mathcal L) and many features of deep learning (e.g. saddle-to-saddle structure, low-rank bias, progressive feature learning) appear here in an analytically tractable form [SMG14].

A lot of the reason deep linear networks are so nice to analyze is due to the conservation law of the imbalance of the weight matrix norms between adjacent layers: Δℓ≐βˆ₯Wβ„“+1βˆ₯F2βˆ’βˆ₯Wβ„“βˆ₯F2. \Delta_\ell \doteq \|W_{\ell+1}\|_F^2 - \|W_\ell\|_F^2. For linear networks, one can show Ξ”Λ™β„“=0\dot \Delta_\ell = 0 for all β„“\ell [DHL18]. Intuitively, the network only ever sees the composition Wβ„“+1Οƒ(Wβ„“h)W_{\ell+1}\sigma(W_\ell h), so if Οƒ\sigma is linear we can shrink Wβ„“W_\ell by any factor cc and grow Wβ„“+1W_{\ell+1} by 1/c1/c without changing the output function. The loss then has a flat direction, and gradient flow cannot move along a direction in which the loss doesn't change, so whatever that rescaling moves is frozen.

In a broader sense, this follows for any activation function that satisfies Euler's homogeneity identity: zβ‹…Οƒβ€²(z)=Οƒ(z)z \cdot \sigma'(z) = \sigma(z), e.g. for Οƒ(z)=z\sigma(z) = z or ReLU.1 So, if we define the functional φσ(z)≐zΟƒβ€²(z)βˆ’Οƒ(z), \varphi_\sigma(z) \doteq z\sigma'(z) - \sigma(z), for a 1-homogeneous function, it vanishes exactly. This is actually a much bigger deal than it seems; this conserved quantity is what makes linear network analysis work!

Nonlinear Activations#

For a general nonlinear activation Οƒ\sigma, φσ≑̸0\varphi_\sigma \not\equiv 0 and our neat conservation law is not guaranteed.

To remedy this, let us study the Taylor expansion of φσ\varphi_\sigma near zero. Writing Οƒ(u)=Ξ±u+aquq+O(uq+1)\sigma(u) = \alpha u + a_q u^q + O(u^{q+1}) with Ξ±=Οƒβ€²(0)>0\alpha = \sigma'(0) > 0, the linear part cancels in φσ\varphi_\sigma (that is what Euler's identity says), and the first surviving term has order qq: φσ(z)=(qβˆ’1)aqzq+O(zq+1). \varphi_\sigma(z) = (q-1)a_q z^q + O(z^{q+1}). For tanh⁑\operatorname{tanh}, Οƒ(z)β‰ˆzβˆ’z3/3\sigma(z) \approx z - z^3/3, so Ο†tanh⁑(z)=zsech2(z)βˆ’tanh⁑(z)β‰ˆβˆ’23z3\varphi_{\tanh}(z) = z\mathrm{sech}^2(z) - \tanh(z) \approx -\tfrac{2}{3}z^3, giving q=3q = 3. For a quadratic activation Οƒ(z)=z+a2z2\sigma(z) = z + a_2 z^2 one gets φσ(z)=a2z2\varphi_\sigma(z) = a_2 z^2, so q=2q = 2.

That's kinda the main idea underlying the whole paper. Near the origin (where our network is initialized, since we take initialization tending to zero), the pre-activations (i.e. the values passed into the activation) are small, so φσ(z)β‰ˆcqzq\varphi_\sigma(z) \approx c_q z^q is high order small. Thus, the conservation law is only "slightly broken" and we can track exactly its drift to order qq, which gives us enough control to do what we want to with our analysis. A similar argument in principle is the physics small angle approximation; sin⁑θ≠θ\sin\theta \neq \theta, but the error is cubic, so for small swings we may use the linear theory and carry a correction to be bounded later.

Imbalance and Drift#

Consider an LL-layer network y^=WLΟƒ(WLβˆ’1β‹―Οƒ(W1x)⋯ )\hat y = W_L \sigma(W_{L-1} \cdots \sigma(W_1 x) \cdots) with pre-activations zℓ≐Wβ„“Οƒ(zβ„“βˆ’1)z_\ell \doteq W_\ell \sigma(z_{\ell-1}) and population loss L\mathcal{L}.

Theorem 1. For any smooth activation Οƒ\sigma and any differentiable loss L\mathcal{L}, dΞ”β„“dt=2E[⟨Wβ„“+1βŠ€βˆ‡zβ„“+1L,φσ(zβ„“)⟩]. \frac{d\Delta_\ell}{dt} = 2\mathbb{E}\left[\bigl\langle W_{\ell+1}^\top \nabla_{z_{\ell+1}} \mathcal{L}, \varphi_\sigma(z_\ell) \bigr\rangle\right].

The proof is quite natural; it follows by considering scaling before and after activation is applied; we outline it below.

Scaling layer β„“\ell and scaling layer β„“+1\ell+1 both act on the same object zβ„“+1=Wβ„“+1Οƒ(zβ„“)z_{\ell+1} = W_{\ell+1}\sigma(z_\ell), but they enter in different places; one multiplies the argument of Οƒ\sigma, the other multiplies its output. Differentiating each at s=0s=0, dds[Wβ„“+1Οƒ((1+s)zβ„“)]=Wβ„“+1(zβ„“βŠ™Οƒβ€²(zβ„“)),dds[(1+s)Wβ„“+1Οƒ(zβ„“)]=Wβ„“+1Οƒ(zβ„“). \frac{d}{ds}\Big[W_{\ell+1}\sigma\bigl((1+s)z_\ell\bigr)\Big] = W_{\ell+1}\bigl(z_\ell \odot \sigma'(z_\ell)\bigr), \qquad \frac{d}{ds}\Big[(1+s)W_{\ell+1}\sigma(z_\ell)\Big] = W_{\ell+1}\sigma(z_\ell). Subtracting gives that the difference is φσ\varphi_\sigma. The imbalance drifts at the rate by which Οƒ\sigma fails to commute with scaling.

Some important comments on the above: (1) the identity is exact and assumes basically nothing, and (2) the right-hand side is a correlation between the upstream gradient at layer β„“+1\ell+1 and φσ\varphi_\sigma applied to the pre-activations at layer β„“\ell. When φσ≑0\varphi_\sigma \equiv 0 we recover exact conservation; when it doesn't vanish, the drift is controlled by how large φσ(zβ„“)\varphi_\sigma(z_\ell) is, and near the saddle that is O(Ξ΅q)O(\varepsilon^q).2

Note that we are using an approximation that is valid near the origin in order to analyze the event which is fundamentally defined as taking the network away from the origin (learning features). So, "escape" is declared at a small fixed threshold rather than at the end of training. Then the time integral we take is dominated by the early part, where the network is deepest inside the regime the approximation covers.3 Most of the actual work in the paper is showing that this defect stays negligible along the entire trajectory, and not just at initialization.

Reducing the ODE#

Approximate conservation now gives us the same thing the linear theory has, plus an error we need to control. If the bottleneck layers (those initialized at scale Ξ΅\varepsilon) start at comparable scales, they will stay comparable for the whole escape, so instead of tracking rr matrices we can reduce the problem to only tracking their shared gain.

Note that these layer gains have no real reason to agree with each other, and once the escape is over they definitely don't, but through the transition itself they move in unison.

The other neat reduction we will want to make is that near the saddle every layer's gradient collapses to rank one, and every layer points along the same rank-one direction. So, we also want to track the network's overlap with the one direction it's being pushed in; call it Ξ³\gamma. Then, we have the following relation between the layer gain and the overlap: Y˙≍Γγ,γ˙≳ΓYrβˆ’1, \dot Y \asymp \Gamma\gamma, \qquad \dot\gamma \gtrsim \Gamma Y^{r-1}, where YY is the squared gain of the first bottleneck layer and Ξ“\Gamma is the strength of the signal the data presents (we'll pin it down in a moment). This is fundamentally a feedback loop! The network can only grow its channel as fast as it is correlated with the target, and it can only become correlated with the target as fast as the channel lets signal through.4 Near the origin both are tiny, which is what causes the plateau. Integrating this loop gives us the main escape time law.

Critical-Depth Law#

Suppose rr of the LL layers initialize at scale Ξ΅β†’0+\varepsilon \to 0^+ (call these the bottleneck layers) and the remaining Lβˆ’rL - r initialize at scale Θ(1)\Theta(1). By the reduction above, all rr bottleneck layers share a magnitude y(t)y(t), with Y=y2Y = y^2.

Now, note that the gradient driving any one bottleneck layer is the product of the signals passing through all of the other bottleneck layers, so it scales as yrβˆ’1y^{r-1} (a layer does not appear in its own gradient). The Lβˆ’rL-r full-size layers contribute O(1)O(1) factors and only really change the prefactor. So the scalar ODE for the shared bottleneck magnitude is y˙≍Γyrβˆ’1, \dot y \asymp \Gamma y^{r-1}, and the time to get from y(0)=Ξ΅y(0) = \varepsilon out to a small fixed threshold Ο‘\vartheta is given by τ≍1Ξ“βˆ«Ξ΅Ο‘yβˆ’(rβˆ’1)dy. \tau \asymp \frac{1}{\Gamma}\int_\varepsilon^\vartheta y^{-(r-1)}dy. Then, everything we need follows immediately from the behavior of that integral!

Theorem 2 (Critical-Depth Escape Law). As Ξ΅β†’0+\varepsilon \to 0^+, the escape time satisfies Ο„={Θ(Ξ“βˆ’1)r=1Θ(Ξ“βˆ’1log⁑(1/Ξ΅))r=2Θ(Ξ“βˆ’1Ξ΅βˆ’(rβˆ’2))rβ‰₯3. \tau = \begin{cases} \Theta\bigl(\Gamma^{-1}\bigr) & r = 1 \\[2pt] \Theta\bigl(\Gamma^{-1}\log(1/\varepsilon)\bigr) & r = 2 \\[2pt] \Theta\bigl(\Gamma^{-1}\varepsilon^{-(r-2)}\bigr) & r \geq 3. \end{cases}

The βˆ’(rβˆ’2)-(r-2) exponent has a pretty neat interpretation: one power of Ξ΅\varepsilon is consumed because each layer's gradient is yrβˆ’1y^{r-1} rather than yry^r, and a second is absorbed by the integral. The threshold at r=2r=2 is pretty interesting since it's the minimal bottleneck for which the escape time diverges at all as Ξ΅β†’0\varepsilon \to 0.

Escape time against bottleneck scale for critical depths one through six
Critical depth predicts escape time. Left: escape times under population flow (dots) against the prediction (lines) for r=1,…,6r = 1, \dots, 6. For each rr the prefactor is fixed at the smallest initialization scale (the open dot) and every other scale is held out. Right: predicted against observed on those held-out scales.

It is also worth remarking on the absence of width or total depth in the asymptotic theorem. In addition, the escape time law does not depend on the activation or number of features in the target. At first, this is somewhat surprising: width multiplies the number of directions the flow could move in, extra depth multiplies the number of compositions, and changing the activation changes the loss landscape. However, none of these matter because of the rank-one structure from the earlier section; since we can reduce the high-dimensional ODE to a 1D ODE, the only things that matter are the quantities given in the escape law.

Data Contribution#

Near the origin the activations are all evaluated close to zero, where Οƒ(u)β‰ˆΞ±u\sigma(u) \approx \alpha u, so the network is a linear map to leading order. A linear map can only correlate with the linear part of the target, so every nonlinearity in the target is invisible to the network until it has already moved. So the only property of the data that can possibly set the initial clock is the input-output correlation Ξ“=βˆ₯E[yx]βˆ₯. \Gamma = \bigl\|\mathbb{E}[yx]\bigr\|.

It is important to note that Ξ“\Gamma is the norm of a vector sum. If the target is built from several features vkv_k with amplitudes Ξ²k\beta_k, each one contributes a vector ∝βkuka^k\propto \beta_k u_k \hat a_k, where a^k\hat a_k is the direction of Ξ£vk\Sigma v_k, and these add with signs: Ξ“=hΟƒβˆ₯βˆ‘kΞ²kuka^kβˆ₯. \Gamma = h_\sigma\Bigl\|\textstyle\sum_k \beta_k u_k \hat a_k\Bigr\|. Here Ξ£=E[xx⊀]\Sigma = \mathbb{E}[xx^\top] is the input covariance, the target is y=βˆ‘kΞ²kΟƒ(vk⊀x/sk)y = \sum_k \beta_k \sigma(v_k^\top x/s_k) for unit vectors vkv_k with sk2=vk⊀Σvks_k^2 = v_k^\top \Sigma v_k, uk=βˆ₯Ξ£vkβˆ₯/sku_k = \|\Sigma v_k\|/s_k, and hΟƒ=E[gΟƒ(g)]h_\sigma = \mathbb{E}[g\sigma(g)] is the linear part of Οƒ\sigma for a standardized input gg. Thus, two features whose covariance images point in opposing directions partially cancel one another. If you rotate them in favor of them cancelling out, Ξ“\Gamma decreases, and the network sits on the plateau proportionally longer, even though neither feature has become any weaker on its own. This also has the interesting consequence that a teacher direction that is misaligned with Ξ£\Sigma gets presented to the network more strongly than its own variance would suggest.5

Escape slowdown as two teacher modes rotate toward cancellation
Ξ“\Gamma predicts escape time. Left: slowdown as two equally weighted features rotate toward cancellation, against the vector prediction (solid) and a baseline that ignores the angle between them (dashed). Right: predicted against observed under input anisotropy and mode interference, with the prefactor fixed once on a separate isotropic single-mode condition.

Because Ξ“\Gamma is just a correlation, you never really need to decompose the target into features to compute it, and nothing in the definition dictates whether expectation is over a population or a finite sample. So, on a real dataset it is Ξ“^=βˆ₯nβˆ’1βˆ‘iyixiβˆ₯\hat\Gamma = \bigl\|n^{-1}\sum_i y_i x_i\bigr\|, which is computable from real data without any knowledge of the true data-generating function.

Predicted against observed escape times on MNIST and CIFAR-10 covariates
The same predictions on real covariates. Left and center: predicted against observed escape times on MNIST and CIFAR-10, for targets built from the covariates and from the class labels respectively. Right: critical-depth predictions for r=2,…,5r = 2, \dots, 5. Open points are the calibration conditions; everything else is held out.

Feature Arrival Timing#

Looking at the first figure (the loss staircase), the obvious interpretation is that a single step corresponds to a single feature being learned. Our theory says when the network leaves the first saddle, but the picture above makes it tempting to assume that departure is really several departures, one per feature, that are averaged together. This isn't necessarily the case, however!

This part is a bit difficult to explain why without getting quite technical, but if you're interested, this is covered in Section 5 of the paper.

  1. This should be quite easy to verify yourself. ↩
  2. The scalar relation controls the relative size of adjacent layers, which isn't enough on its own; we can in fact lift the theorem to a matrix version, which is what we actually use. ↩
  3. It also means "escape time" is defined up to the choice of threshold. Changing the threshold only affects the constant, not the exponent. ↩
  4. The control-theoretic reading of this (a loop gain, and the question of determining when it exceeds one) is largely inspired by a discussion in one of my classes, summed up really nicely in [Rec20]. ↩
  5. Concretely, writing sk2=vk⊀Σvks_k^2 = v_k^\top \Sigma v_k for the variance along the unit direction vkv_k, Cauchy-Schwarz gives uk=βˆ₯Ξ£vkβˆ₯/skβ‰₯sku_k = \|\Sigma v_k\|/s_k \geq s_k, with equality exactly when vkv_k is an eigenvector of Ξ£\Sigma. The gap uk2βˆ’sk2u_k^2 - s_k^2 is Var⁑μk(Ξ»)/sk2\operatorname{Var}_{\mu_k}(\lambda)/s_k^2, where ΞΌk\mu_k weights each eigenvalue Ξ»\lambda of Ξ£\Sigma by the squared component of vkv_k along its eigenvector, i.e. the spread of vkv_k across the eigenvalues of the covariance. ↩

References#