Loss Spike in Training Neural Networks
In this work, we investigate the mechanism underlying loss spikes observed
during neural network training. When the training enters a region with a
lower-loss-as-sharper (LLAS) structure, the training becomes unstable, and the
loss exponentially increases once the loss landscape is too sharp, resulting in
the rapid ascent of the loss spike. The training stabilizes when it finds a
flat region. From a frequency perspective, we explain the rapid descent in loss
as being primarily influenced by low-frequency components. We observe a
deviation in the first eigendirection, which can be reasonably explained by the
frequency principle, as low-frequency information is captured rapidly, leading
to the rapid descent. Inspired by our analysis of loss spikes, we revisit the
link between the maximum eigenvalue of the loss Hessian
($\lambda_{\mathrm{max}}$), flatness and generalization. We suggest that
$\lambda_{\mathrm{max}}$ is a good measure of sharpness but not a good measure
for generalization. Furthermore, we experimentally observe that loss spikes can
facilitate condensation, causing input weights to evolve towards the same
direction. And our experiments show that there is a correlation (similar trend)
between $\lambda_{\mathrm{max}}$ and condensation. This observation may provide
valuable insights for further theoretical research on the relationship between
loss spikes, $\lambda_{\mathrm{max}}$, and generalization.
Xiaolong Li, Zhi-Qin John Xu, Zhongwang Zhang
# Loss Spike in Training Neural Networks

###### Abstract

In this work, we study the mechanism underlying loss spikes observed during neural network training. When the training enters a region, which has a smaller-loss-as-sharper (SLAS) structure, the training becomes unstable and loss exponentially increases once it is too sharp, i.e., the rapid ascent of the loss spike. The training becomes stable when it finds a flat region. The deviation in the first eigen direction (with maximum eigenvalue of the loss Hessian (\(\lambda_{\max}\)) is found to be dominated by low-frequency. Since low-frequency is captured very fast (frequency principle), the rapid descent is then observed. Inspired by our analysis of loss spikes, we revisit the link between \(\lambda_{\max}\) flatness and generalization. For real datasets, low-frequency is often dominant and well-captured by both the training data and the test data. Then, a solution with good generalization and a solution with bad generalization can both learn low-frequency well, thus, they have little difference in the sharpest direction. Therefore, although \(\lambda_{\max}\) can indicate the sharpness of the loss landscape, deviation in its corresponding eigen direction is not responsible for the generalization difference. We also find that loss spikes can facilitate condensation, i.e., input weights evolve towards the same, which may be the underlying mechanism for why the loss spike improves generalization, rather than simply controlling the value of \(\lambda_{\max}\).

## 1 Introduction

Many experiments have observed a phenomenon, called the edge of stability (EoS) (Wu et al., 2018; Cohen et al., 2021; Arora et al., 2022), that during the neural network (NN) training, the maximum eigenvalue of the loss Hessian, \(\lambda_{\max}\), progressively increases until it reaches \(2/\eta\) (\(\eta\) is learning rate), and then \(\lambda_{\max}\) stays around \(2/\eta\). At the EoS stage, the loss would continuously decrease, sometimes with slight oscillation. Training with a larger learning rate leads to a solution with smaller \(\lambda_{\max}\). Since \(\lambda_{\max}\) is often used to indicate the sharpness of the loss landscape, a larger learning rate results in a flatter solution. Intuitively as shown in Fig. 1, the flat solution is more robust to perturbation and has better generalization performance (Keskar et al., 2016; Hochreiter and Schmidhuber, 1997). Therefore, training with a larger learning rate would achieve better generalization performance. In this work, we argue this intuitive analysis in Fig. 1 with \(\lambda_{\max}\) as the sharpness measure, which encounters difficulty in NNs through the study of loss spikes.

In a neural network training process, one may sometimes observe a phenomenon of loss spike, where the loss rapidly ascends and then descends to the value before the ascent. Typical examples are shown in Fig. 2. We show a special loss landscape structure underlying the loss spike, which is called a smaller-loss-as-sharper (SLAS) structure. In the SLAS structure, the training is driven by descending the loss while entering an increasingly sharp region. Once the sharpness is too large, the loss would ascend exponentially fast. To explain why the loss can descend so fast, we provide a frequency
perspective analysis. We find that the deviation in the ascending stage is dominated by low-frequency components. Based on the frequency principle (Xu et al., 2019, 2020) that low-frequency converges faster than high-frequency, we rationalize the fast descent.

The study of loss spike provides an important information that the deviation at the first eigen direction is dominated by low-frequency. We then further argue the link between \(\lambda_{\max}\) flatness and generalization. In practical datasets, low-frequency information is often dominant and shared by both the training and the test datasets. Therefore, the training can learn low-frequency well. Since the sharpest direction, indicated by the maximum eigenvalue of the loss Hessian, relates more to the low-frequency, a solution with good generalization and a solution with bad generalization have little difference in the sharpest direction, verified by a series of experiments. Hence, \(\lambda_{\max}\) with the intuitive explanation in Fig. 1 encounters difficulty in understanding the generalization of neural networks, such as why a larger learning rate results in better generalization for networks with EoS training.

We also find that a loss spike can facilitate condensation, that is, the input weights of different neurons in the same layer evolve towards the same, which would reduce the network's effective size. Condensation is a non-linear feature learning phenomenon in neural networks, which may be the underlying mechanism for why the loss spike improves generalization (He et al., 2019; Jastrzebski et al., 2017), rather than simply controlling the value of \(\lambda_{\max}\).

This work studies the loss spike from the landscape perspective and the frequency perspective, and revisits the relation between the generalization and the flatness, defined by the maximum eigenvalue of the loss Hessian. This work also conjectures the loss spike may improve generalization via the facilitation of condensation.

## 2 Related works

Previous works (Cohen et al., 2021; Wu et al., 2018; Xing et al., 2018; Ahn et al., 2022; Lyu et al., 2022; Wang et al., 2022) conduct an extensive study of the EoS phenomenon under various settings. Lewkowycz et al. (2020) observe that when the initial sharpness exceeds \(2/\eta\), gradient descent "catapults" into a stable region and converges. Arora et al. (2022) analyze progressive sharpening and the edge of stability phenomenon under specific settings, such as normalized gradient descent. Damian et al. (2022) show that the third-order terms bias towards flatter minima to understand EoS.

Ma et al. (2022) attribute the progressive sharpening to a subquadratic structure of the loss landscape, i.e., the maximum eigenvalue of the loss Hessian is larger when the loss is smaller in a direction. They also propose a flatness-driven motion to study the EoS stage, that is, the training would move towards a flatter minimum, such that the fixed flatness can correspond to points with smaller and smaller loss values due to the subquadratic property. We call this structure a smaller-loss-as-flatter (SAF) structure. The SLAF structure should expect a continuous decrease in the loss rather than a loss spike. Agarwala et al. (2022) use a quadratic regression model with MSE to study EoS. Similarly, in their model, the loss spike can not happen. Ma et al. (2022) study the loss spike from the perspective of

Figure 1: Schematic illustration of an ideal explanation for why flat solutions generalize well (Keskar et al., 2016).
adaptive gradient optimization algorithms, while we focus on the loss landscape structure and use gradient descent training in this paper.

A series of works link the generalization performance of solutions to the landscape of loss functions through the observation that flat minima tend to generalize better (Hochreiter and Schmidhuber, 1997; Wu et al., 2017; Ma and Ying, 2021). Algorithms that favor flat solutions are designed to improve the generalization of the model (Izmailov et al., 2018; Chaudhari et al., 2019; Lin et al., 2018; Zheng et al., 2021; Foret et al., 2020). On the other hand, Dinh et al. (2017) show that sharp minimum can also generalize well by rescaling the parameters at a flat minimum with ReLU activation. In this work, we study the relationship between flatness and generalization from a new perspective, i.e., the frequency perspective, without the limitation of the activation function.

Luo et al. (2021); Zhou et al. (2022) mainly identify the linear regime and the condensed regime of the parameter initialization for two-layer and three-layer wide ReLU NNs, which determines the final fitting result of the network. In the linear regime (Jacot et al., 2018; Arora et al., 2019), the training dynamics of NNs are approximately linear and similar to a random feature model. On the contrary, in the condensed regime, active neurons are condensed at several discrete orientations. At this point, the network is equivalent to another network with a reduced width, which may explain why NNs outperform traditional algorithms (Breiman, 1995; Zhang et al., 2021). For the initial stage of training, A series of works (Zhou et al., 2021; Chen et al., 2023; Maennel et al., 2018; Pellegrini and Biroli, 2020) study the characteristics of the initial condensation for different activation functions. Andriushchenko et al. (2022) find that stochastic gradient descent (SGD) with a large learning rate can facilitate sparse solutions and attributes it to the noise structure of SGD. In our work, we find that for the noise-free full-batch gradient descent algorithm, the loss spike can also facilitate the condensation phenomenon, implying that the noise structure is not the intrinsic cause of condensation.

The frequency principle is examined in extensive datasets and deep neural network models (Xu et al., 2019; Xu and Zhou, 2021; Rahaman et al., 2019). Subsequent theoretical studies show that the frequency principle holds in the general setting with infinite samples (Luo et al., 2021). An overview for frequency principle is referred to Xu et al. (2022). Based on the theoretical understanding, the frequency principle inspires the design of deep neural networks to learn a function with high-frequency fast (Liu et al., 2020; Jagtap et al., 2020; Biland et al., 2019).

## 3 Preliminary: Linear stability in training quadratic model

We consider a simple quadratic model with the loss \(R(\theta)=\lambda\theta^{2}/2\) trained by gradient descent with learning rate \(\eta\), \(\theta(t+1)=\theta(t)-\eta\cdot dR(\theta)/d\theta\). To ensure the linear stability of the training, it requires \(|\theta(t+1)|<|\theta(t)|\), which implies \(|1-\lambda\eta|<1\), i.e., otherwise, the training will diverge. Note that \(\lambda\) is the Hessian of \(R(\theta)\). Similarly, to ensure the linear stability of training a neural network, it requires that the maximum eigenvalue of the loss Hessian is smaller than \(2/\eta\), i.e., 2 over the learning rate. Therefore, the maximum eigenvalue of the loss Hessian is often used as the measure of the sharpness of the loss landscape.

## 4 Loss spike

In this section, we study the phenomenon of loss spike, where the loss would suddenly increase and decrease rapidly. For example, as shown in Fig. 2(a, d), we train a tanh fully-connected neural network (FNN) with 20 hidden neurons for a one-dimensional fitting problem, and a ReLU convolutional neural network (CNN) for the CIFAR10-1k classification problem with MSE. Both two models experience loss spikes. The red curves, i.e., the \(\lambda_{\max}\) value, show that the loss spikes occur at the EoS stage.

### Typical loss spike experiments

To observe the loss spike clearly, we zoom in on the training epochs around the spike, shown in Fig. 2(b, e). The selected epochs are marked green in Fig. 2(a, d). When the maximum eigenvalue of Hessian \(\lambda_{\max}\) (red) exceeds \(2/\eta\) (black dashed line), the loss increases, and when \(\lambda_{\max}<2/\eta\), the loss decreases, which are consistent with the linear stability analysis.
We then study the parameter space for more detailed characterization. Given \(t\) training epochs, and let \(\mathbf{\theta}_{i}\) denote model parameters at epoch \(i\), we apply PCA to the matrix \(M=[\mathbf{\theta}_{1}-\mathbf{\theta}_{t},\cdots,\mathbf{\theta}_{t}-\mathbf{\theta}_{t}]\), and then select the first two eigen directions \(\mathbf{e}_{1}\), \(\mathbf{e}_{2}\). The two-dimensional loss surface based on \(\mathbf{e}_{1}\) and \(\mathbf{e}_{2}\) can be calculated by \(R_{S}(\mathbf{\theta}_{t}+\alpha\mathbf{e}_{1}+\beta\mathbf{e}_{2})\), where \(\alpha\), \(\beta\) are the step sizes, and \(R_{S}\) is the loss function under the dataset \(S\). The trajectory point of parameter \(\mathbf{\theta}_{i}\) can be calculated by the projection of \(\mathbf{\theta}_{i}-\mathbf{\theta}_{t}\) in the PCA directions, i.e., \(((\mathbf{\theta}_{i}-\mathbf{\theta}_{t},\mathbf{e}_{1}),\langle\mathbf{\theta}_{i}-\mathbf{ \theta}_{t},\mathbf{e}_{2}\rangle)\). Parameter trajectories (blue dots) and loss surfaces along PCA directions are shown in Fig. 2(c, f). In two distinct examples, they exhibit similar behaviors. At the beginning of the ascent stage of the spike, the parameter is at a small-loss region, where the opening of the contour lines is towards the left, indicating a leftward component of descent direction. In the left region, the contour lines are denser, implying a sharper loss surface. Once \(\lambda_{\max}>2/\eta\), the parameters become unstable, and the loss value increases exponentially. In the large-loss region, the opening of the contour shifts to the right, indicating a rightward component of the descent direction, resulting in a sparser contour, i.e., a flatter loss surface. After several steps, when \(\lambda_{\max}<2/\eta\), the training returns to the stable stage.

### Smaller-loss-as-sharper (SLAS) structure

The above experiments reveal a common structure that causes a loss spike, namely, the \(\lambda_{\max}\) sharpness increases in the direction of decreasing loss. We call this structure smaller-loss-as-sharper (SLAS) structure. The SLAS structure differs from the SLAF (smaller-loss-as-flatter) structure studied in Ma et al. (2022), which is also common in the EoS stage as shown in Fig. 3(a). A toy example of the SLAS structure is shown in Fig. 3(b). The left cross-section of the loss landscape has a flatter curvature while the right one has a sharper curvature. At the minimum of the left cross-section (the \(L_{1}\) dashed line), the opening of the contour lines towards the right and the parameter point will also move right, which makes the curvature sharper. Once \(\eta>2/\lambda_{\max}\), it starts to diverge to a large-loss region and the opening of the contour turns left (the \(L_{2}\) dashed line), which makes the curvature flatter.

The following quadratic model is a simple example of SLAS structure,

\[f(x,y)=(50x+200)y^{2}-x+5, \tag{1}\]

Figure 2: (a, d) The loss value (black) and \(\lambda_{\max}\) (red) vs. training epoch, where the \(\lambda_{\max}\) is calculated every 100 epoch. (b, e) The loss value and \(\lambda_{\max}\) of a specific epoch interval, which is marked green in (a, d), respectively. (c, f) The loss surface and the trajectory of the model parameters along the first two PCA directions. (a, b, c) Two-layer tanh NN with width 20. The sum of the explained variance ratios of the first two PCA directions is 0.9895. (d, e, f) Two-layer ReLU CNN with Max Pooling. The sum of the explained variance ratios of the first two PCA directions is 0.9882.
where \((x,y)\in(-4,+\infty)\times\mathbb{R}\). For any constant \(C\), \(y=0\) is the minimum point of \(f(C,y)\), and the larger \(x\) is, the sharper the loss landscape in the \(y\)-direction. As shown in Fig. 3(c, d), the loss curve and the trajectory of parameters are similar to the realistic example above, where the parameters move toward the sharp direction at the beginning of the loss spike, and then move toward the flat direction. The intuitive explanation for the above phenomenon is that as \(x\) increases, \(f(x,0)\) decreases, which means that \(f(x,0)\) has a smaller value at the sharp region, i.e., the SLAS structure, which makes the opening of the contour lines towards different directions at different loss levels.

For this example, we can exactly compute the derivative of Eq. (1) as follows:

\[\frac{\partial f(x,y)}{\partial x}=50y^{2}-1.\]

Thus we have

\[\frac{\partial f(x,y)}{\partial x}\begin{cases}>0&\text{if }f(x,y)<9\\ =0&\text{if }f(x,y)=9\\ <0&\text{if }f(x,y)>9\end{cases},\]

which indicates that the toy model has a positive gradient component in the \(x\) direction when the parameters are in the small-loss region (\(f(x,y)<9\)), while a negative gradient component in the \(x\) direction when the parameters are in the large-loss region (\(f(x,y)>9\)).

Although the SLAS structure can explain the mechanism of the ascent stage based on the toy model, it can not explain the reason for the rapid descent of the loss in the descent phase of the loss spike, which takes much fewer steps than the training from the same level loss at the initialization. For instance, for the quadratic model in the Preliminary section, the descent would be very slow if the learning rate is slightly smaller than \(2/\lambda_{\max}\). Moreover, due to the high dimensionality of the parameter space, the parameter trajectory does not always align with the first eigen direction, otherwise, as shown in the toy model, the loss would not decrease continuously. In the following, we take a step toward understanding the rapid decrease from the frequency perspective.

### Frequency perspective for understanding descent stage

In this subsection, we study the mechanism of the rapid loss descent during the descent stage in a loss spike from the perspective of frequency.

We base our analysis on a common phenomenon of frequency principle (Xu et al., 2019, 2020; Zhang et al., 2021; Luo et al., 2021; Rahaman et al., 2019; Ronen et al., 2019), which states that deep NNs often fit target functions from low to high frequencies during the training. A series of frequency principle works show that low-frequency can converge faster than high-frequency. Compared to the peak point of the loss spike with the point with the same loss value at the initial training, the descent during the spike should eliminate more low-frequency with a fast speed while the descent from the initial model should eliminate more high-frequency with a slow speed. To verify this conjecture, we study the frequency distribution of the converged part during the descent stage.

Figure 3: (a) The loss surface and the trajectory of the model parameters along the first two PCA directions in the EoS stage. (b) Schematic illustration of SLAS structure. (c) The loss value and the maximum eigenvalue of the Hessian matrix of a loss spike process of the toy model. (d) The loss surface and the GD trajectory of the two-dimensional parameters of the toy model.
The peak of the loss spike is denoted as \(\mathbf{\theta}_{\max}\), the initial point which has the similar loss of \(\mathbf{\theta}_{\max}\) is denoted as \(\mathbf{\theta}_{\rm ini,m}\), the parameter at the end of the loss spike (a point is roughly selected when the descent is slow) is denoted as \(\mathbf{\theta}_{\rm end}\). We then study the frequency distribution of spike output difference \(f_{\rm peak,diff}:=f_{\mathbf{\theta}_{\max}}-f_{\mathbf{\theta}_{\rm end}}\) and initial output difference \(f_{\rm ini,diff}:=f_{\mathbf{\theta}_{\rm ini,m}}-f_{\mathbf{\theta}_{\rm end}}\).

For comparison, we also randomly select parameter \(\mathbf{\theta}_{\rm rnd}:=\mathbf{\theta}_{\rm end}+(\|\mathbf{\theta}_{\rm end}-\mathbf{ \theta}_{\max}\|_{2}/\|\varepsilon\|_{2})\varepsilon\), where \(\varepsilon\sim N(0,I)\) is a random variable. We then study the frequency distribution of random output difference \(f_{\rm rnd,diff}:=f_{\mathbf{\theta}_{\rm end}}-f_{\mathbf{\theta}_{\rm end}}\).

We characterize the frequency distribution by taking different low-frequency thresholds to study low-frequency proportion. For a low-frequency threshold \(K\), a low-frequency proportion (LFP) is defined as follows to characterize the power proportion of the low-frequency component over the whole spectrum,

\[\mathrm{LFP}(K)=\frac{\sum_{k\leq K}\|\hat{f}_{\mathbf{\theta}}(k)\|^{2}}{\sum_{k }\|\hat{f}_{\mathbf{\theta}}(k)\|^{2}}, \tag{2}\]

where \(\hat{f}_{\mathbf{\theta}}\) indicates the Fourier transform of function \(f_{\mathbf{\theta}}\).

As shown in Fig. 4, the low-frequency proportion of the spike output difference is significantly larger than the low-frequency proportion of the initial output difference and the random output difference, where we take 100 samples of random variable \(\varepsilon\) for the mean value and the error bar for each low-frequency threshold. The large low-frequency proportion of the spike output difference is the key reason for the rapid drop in the loss value during the descent stage, as suggested by the frequency principle.

## 5 Revisit the flatness-generalization picture

Motivated by the loss spike analysis from the frequency perspective, we further revisit the common flatness-generalization picture. A series of previous works (Hochreiter and Schmidhuber, 1997; Li et al., 2017) attempt to link the flatness of the loss landscape with generalization, so as to characterize the model through flatness conveniently. A classic empirical illustration is shown in Fig. 1, which vividly expresses the reason why flat solutions tend to have better generalization. Usually, the training loss landscape and the test landscape do not exactly coincide due to sampling noise. A flat solution would be robust to the perturbation while a sharp solution would not. For such a one-dimensional case, this analysis is valid, but the loss landscape of a NN case is very high-dimensional, and such simple visualization or explanation is yet to be validated.

The first eigen direction of the loss Hessian, i.e., the eigen direction corresponding to the maximum eigenvalue, is the sharpest direction. Based on the flatness-generalization picture, it is natural to use the maximum eigenvalue as the measure for the flatness, which can also indicate generalization. However, this naive analysis is not always correct for neural networks.

Figure 4: Low-frequency proportion for different low-frequency thresholds. The NN we used is a two-layer tanh NN with width 20. For the random output difference, we calculate the mean value and the error bar with 100 random samples.
### Frequency perspective

Since the maximum eigenvalue of the loss Hessian can indicate the linear stability of the training, it is often used as a measure for flatness/sharpness, that is, a larger maximum eigenvalue indicates a sharper loss landscape. As shown by the linear stability analysis, once the maximum eigenvalue is larger than \(2/\eta\), the training would oscillate and diverge along the first eigen direction. Meanwhile, as the parameter moves away from the minimum point along the first eigen direction, the loss spike is mainly due to the large low-frequency difference as shown in Fig. 4. Therefore, the deviation in the first eigen direction of the loss Hessian mainly leads to the deviation of low-frequency components.

In order to examine the above analysis, we first obtain the model parameter \(\mathbf{\theta}_{\rm train}\) with poor generalization by training the model initialized in the linear regime (Luo et al., 2021), and then further train the model parameter \(\mathbf{\theta}_{\rm train}\) on the test dataset with a small learning rate to obtain the model parameter \(\mathbf{\theta}_{\rm test}\).

We study the impact of each eigen direction on the test loss by eliminating the difference between \(\mathbf{\theta}_{\rm train}\) and \(\mathbf{\theta}_{\rm test}\) in the \(i\)-th eigen direction \(\mathbf{\nu}_{i}\), where \(i\) is the index of eigenvalues. As shown in Fig. 5(a), we study the change of the test loss \(L(i)\) with the eigenvalue index \(i\) as follows to study the effect of eigenvectors on generalization,

\[L(i)=R_{S_{\rm test}}\left(\mathbf{\theta}_{\rm train}+\sum_{j=1}^{i}\langle\mathbf{ \theta}_{\rm test}-\mathbf{\theta}_{\rm train},\mathbf{\nu}_{j}\rangle\mathbf{\nu}_{j} \right)\,,\]

where \(S_{\rm test}\) is the test dataset. The movement of parameters on the eigenvectors corresponding to large eigenvalues has a weak impact on the test loss, while the movement of parameters on the eigenvectors corresponding to small eigenvalues has a significant impact on the test loss.

A reasonable explanation from the perspective of frequency is as follows. In common datasets, low-frequency components often dominate over high-frequency ones. For noisy sampling, the dominant low-frequency is shared by both the training and the test data. When the parameters move along the eigen directions corresponding to the large eigenvalues, the network output often changes at low-frequency, which is already captured by both \(\mathbf{\theta}_{\rm train}\) and \(\mathbf{\theta}_{\rm test}\). Therefore, the improvement of model generalization often requires certain high-frequency changes. As shown in Fig. 5(b), we move the corresponding \(\mathbf{\theta}_{\rm train}\) along the first nine eigen directions, and show the difference between the network outputs before and after the movement, i.e., \(f_{\mathbf{\theta}_{\rm train}+\mathbf{\nu}_{i}/\sqrt{\lambda_{i}}}-f_{\mathbf{\theta}_{ \rm train}}\), where the \(1/\sqrt{\lambda_{i}}\) item is to make the loss of the network moved in different eigen directions approximately the same. From the difference between the outputs before and after the movement, it can be seen that when the parameters move along the eigen direction corresponding to the larger eigenvalue, the change of the model output is often less oscillated, i.e., dominated by the lower-frequency. Since the low-frequency is captured by both \(\mathbf{\theta}_{\rm train}\) and \(\mathbf{\theta}_{\rm test}\), they should be close in the eigen directions corresponding to large eigenvalues, which is verified in the following subsection.

### Difference on each eigen direction

We then examine the projection of \(\mathbf{\theta}_{\rm test}-\mathbf{\theta}_{\rm train}\) in each eigen direction of \(H(\mathbf{\theta}_{\rm train})\). As shown in Fig. 6, we show the projection of \(\mathbf{\theta}_{\rm test}-\mathbf{\theta}_{\rm train}\) on each eigenvector \(\mathbf{\nu}_{i}\) (blue bar) for the FNN on function fitting problem and the CNNs on CIFAR10 classification problem. Due to the high complexity of calculating the eigenvectors of the large-size Hessian matrix, we use the Lanczos method (Cullum and Willoughby, 2002) to numerically compute the first \(N\) eigenvalues and their corresponding eigenvectors. For \(n<N\), we use \(\sum_{i=1}^{n}\lambda_{i}^{2}/\sum_{i=1}^{N}\lambda_{i}^{2}\) to represent the explained variance ratio, i.e., to measure how much flatness information the first \(n\) eigen directions (orange line) can explain. For different network structures and model tasks, the projection value of \(\mathbf{\theta}_{\rm test}-\mathbf{\theta}_{\rm train}\) on the eigenvector \(\mathbf{\nu}_{i}\) has a positive correlation with the eigenvalue index \(i\), which confirms that \(\mathbf{\theta}_{\rm train}\) and \(\mathbf{\theta}_{\rm test}\) have little difference on low-frequency part. Note that in Fig. 6(d), the two minima, \(\mathbf{\theta}_{\rm small}\) and \(\mathbf{\theta}_{\rm large}\), are found by small and large batch sizes, respectively, and they also have little difference in eigen directions corresponding to large eigenvalues.

### Implications

The above analysis suggests the following implications: i) The maximum eigenvalue of the loss Hessian is a good measure of sharpness for whether the training is linearly stable but not a good
measure for generalization; ii) The common low-dimensional flatness-generalization picture suffers difficulty in understanding the high-dimensional loss landscape of neural network. The generalization performance is a combined effect of most eigen directions, including those with small eigenvalues.

## 6 Loss spike facilitates condensation

From the analysis above, the restriction on \(\lambda_{\max}\) does not seem to be the essential reason why loss spike affects the generalization of the model. In this section, we study the effect of loss spike on condensation, which may improve the model's generalization in some situations (He et al., 2019; Jastrzebski et al., 2017). A condensed network, which refers to a network with neurons condensing in several discrete directions, is equivalent to another smaller network (Zhou et al., 2021; Luo et al., 2021). It has a lower effective complexity than it appears. The embedding principle (Zhang et al., 2021, 2022; Fukumizu et al., 2019; Simsek et al., 2021) shows that a condensed network, although equivalent to a smaller one in approximation, has more degeneracy and descent directions that may accelerate the training process. The low effective complexity and simple training process may be underlying reasons for good generalization. We show that the loss spike can facilitate the condensation phenomenon for the noise-free full-batch gradient descent algorithm.

As shown in Fig. 7, we train a tanh NN with 100 hidden neurons for the one-dimensional fitting problem to fit the data using MSE as the loss function. Additional experimental verification on ReLU NNs is provided in Appendix B.1. To clearly study the effect of loss spike on condensation, we

Figure 5: Two-layer tanh FNN with a width of 500. (a) The variation of the test loss with the eigenvalue index \(i\) when eliminating the difference between \(\mathbf{\theta}_{\rm train}\) and \(\mathbf{\theta}_{\rm test}\) in the first \(i\) eigen directions. (b) The output difference before and after moving \(\theta_{\rm train}\) in the first nine eigen directions of its Hessian matrix. Each subset corresponds to the case of one eigen direction.

Figure 6: Blue bar: (a, b, c) show the projection values of in each eigen direction of \(H(\mathbf{\theta}_{\rm train})\) for \(\mathbf{\theta}_{\rm test}-\mathbf{\theta}_{\rm train}\), and (d) for \(\mathbf{\theta}_{\rm large}-\mathbf{\theta}_{\rm small}\). Orange line: the sum of the first \(n\) eigenvalues over all eigenvalues. (a) Two-layer tanh FNN for the one-dimensional fitting problem. (b) Two-layer ReLU CNN with Max Pooling for the CIFAR10 classification problem. (c) Three-layer ReLU CNN with Max Pooling for the CIFAR10 classification problem. (d) Five-layer ReLU CNN with Max Pooling for the CIFAR10 classification problem.
take the parameter initialization distribution in the linear regime (Luo et al., 2021) that does not induce condensation without additional constraints. For NNs with identical initialization, we train the network separately with a small learning rate (blue) and a large learning rate (orange). For the left subfigure in Fig. 7, the loss value has a significant spike for the large learning rate, but not for the small one. At the same time, the middle subfigure reveals that the model output without a loss spike (blue) during the training process has more oscillation than the model output with a loss spike (orange). We study the features of parameters to understand the underlying effect of loss spike better.

To study the parameter features, we measure each parameter pair \((a_{j},\mathbf{w}_{j})\) by the feature direction \(\hat{\mathbf{w}}_{j}=\mathbf{w}_{j}/\|\mathbf{w}_{j}\|_{2}\) and amplitude 2\(A_{j}=|a_{j}|\|\mathbf{w}_{j}\|_{2}\). For a NN with one-dimensional input, after incorporating the bias term, \(\mathbf{w}_{j}\) is two-dimensional, and we use the angle between \(\mathbf{w}_{j}\) and the unit vector \((1,0)\) to indicate the orientation of each neuron. The scatter plots of \(\{(\hat{\mathbf{w}}_{j},|a_{j}|)\}_{j=1}^{m}\) and \(\{(\hat{\mathbf{w}}_{j},\|\mathbf{w}_{j}\|_{2})\}_{j=1}^{m}\) of tanh activation are presented in Appendix B to eliminate the impact of the non-homogeneity of tanh activation.

Footnote 2: The amplitude accurately describes the contribution of ReLU neurons due to the homogeneity. For tanh neurons, there is a positive correlation between their amplitude and contribution. Appendix B provides a more refined characterization of tanh network features.

The scatter plots of \(\{(\hat{\mathbf{w}}_{j},A_{j})\}_{j=1}^{m}\) of the NN is shown in the right subfigure of Fig. 7. Parameters without loss spikes (blue) are closer to the initial values (green) than those with loss spikes (orange). For the case with loss spikes, non-zero parameters tend to condense in several discrete orientations, showing a tendency to condensation.

## 7 Conclusion and discussion

In this work, we provide an explanation for loss spikes in neural network training. We explain the ascent stage based on the landscape structure, i.e., the SLAS structure, and for the descent stage, we explain it from the perspective of frequency. We revisit the common flatness-generalization picture based on the frequency analysis. We also find that noise-free gradient descent with loss spikes can facilitate condensation, which may be an underlying reason for the good generalization in some situations. Obviously, many questions remain open. For example, why the eigen direction corresponding to a large eigenvalue is dominated by low-frequency? Why the loss spike can facilitate the condensation? We leave the discussion of these important questions to future work.

## Acknowledgments

This work is sponsored by the National Key R&D Program of China Grant No. 2022YFA1008200, the Shanghai Sailing Program, the Natural Science Foundation of Shanghai Grant No. 20ZR1429000, the National Natural Science Foundation of China Grant No. 62002221, Shanghai Municipal of Science

Figure 7: Comparison of two-layer tanh NNs with identical initialization but different learning rates \(\eta\). The loss spike occurs at a large learning rate (orange), while not at a small learning rate (blue). Left: loss vs. epoch. The small picture in the upper right corner shows the occurrence of the loss spike in more detail. Middle: output. Right: The weight feature distribution of the trained models and the initial one.
and Technology Major Project No. 2021SHZDZX0102, and the HPC of School of Mathematical Sciences and the Student Innovation Center, and the Siyuan-1 cluster supported by the Center for High Performance Computing at Shanghai Jiao Tong University.
