Same Pre-training Loss, Better Downstream:
Implicit Bias Matters for Language Models
October 25, 2022
Language modeling on large-scale datasets leads to impressive performance gains on various downstream language tasks. The validation pre-training loss (or perplexity in autoregressive language modeling) is often used as the evaluation metric when developing language models since the pre-training loss tends to be well-correlated with downstream performance (which is itself difficult to evaluate comprehensively). Contrary to this conventional wisdom, this paper shows that 1) pre-training loss cannot fully explain downstream performance and 2) flatness of the model is well-correlated with downstream performance where pre-training loss is not. On simplified datasets, we identify three ways to produce models with the same (statistically optimal) pre-training loss but different downstream performance: continue pre-training after convergence, increasing the model size, and changing the training algorithm. These experiments demonstrate the existence of implicit bias of pre-training algorithms/optimizers—among models with the same minimal pre-training loss, they implicitly prefer more transferable ones. Toward understanding this implicit bias, we prove that SGD with standard mini-batch noise implicitly prefers flatter minima in language models, and empirically observe a strong correlation between flatness and downstream performance among models with the same minimal pre-training loss. We also prove in a synthetic language setting that among the models with the minimal pre-training loss, the flattest model transfers to downstream tasks.
Large language models (LLMs) pre-trained on internet-scale data have improved performance on a wide array of downstream tasks [1]–[5]. These models are trained with a language modeling pre-training loss to “fill in the blanks"—either predicting the next token/word (autoregressive language modeling loss, or perplexity) or masked tokens (masked language modeling (MLM) loss).
In common practice, the validation pre-training loss is used to monitor the training process [5], [6] and compare different models since the pre-training loss is generally strongly correlated with downstream performance [7]. Moreover, theoretical works on understanding LLMs also focus on how the pre-training loss affects downstream performance. [8]–[10] show that good pre-training loss, or fitting the language modeling conditional probability well, is a main reason for downstream success of LLMs. Their analyses generally treat the language models as blackboxes and do not take into account how the models represents the conditional probability.
In this paper, we question the conventional wisdom on the correlation between the validation pre-training loss and downstream performance for language modeling. Recent works have demonstrated that models with different architectures may have the same pre-training loss but different performance [11], [12]. Due to the expressivity of modern neural nets, many parameter configurations even within the same architecture can still have the same pre-training loss. A priori, it is unclear why all these configurations should have the same downstream performance.
We find that different parameter configurations with the same pre-training loss can indeed have different downstream performance, especially when the pre-training loss reaches a near-optimal level. Concretely, using simplified text datasets, we find three situations that demonstrate such a phenomenon:
Even after the pre-training loss converges, models at a later time step still tend to perform better.
Models trained by standard algorithms have better performance than adversarially trained models with the same pre-training loss.
Larger models perform better downstream than smaller models even if they have the same pre-training loss.
These situations are most prominent in the saturation regime, where the models are close to the minimal possible pre-training loss (aka the entropy of the conditional probability, which can be estimated in our simplified datasets). In the saturation regime, the pre-training loss of all models are almost the same, but the transferability to downstream tasks varies. Interestingly, this phenomenon also holds when linear probing on contextualized presentations is used for evaluating downstream performance instead of finetuning. Thus, even though the predicted conditional probabilities of two models are the same (and correct), the contextualized representations can behave differently.
In each of the first two cases above, we find two models with the same pre-training loss and the same architecture; but one has a better performance than the other. They only differ by the training algorithms that are used to produce them. Therefore, this suggests the training algorithms have an implicit bias toward one of these models—standard algorithms with more training steps biases towards parameter configurations that transfer better to downstream tasks. The third case has a more subtle but similar interpretation. There exists a hypothetical large model that represents the smaller model with worse downstream performance (by filling zeros in the weights or replicating the weights of the smaller model). The training algorithm on the large architecture could have chosen it, but did not. This suggests the algorithm has an implicit bias against the hypothetical model (which has an equally good loss).
In supervised settings, optimizers are known to have an implicit bias toward selecting generalizable models among all models with small empirical loss. E.g., see [13], [14], which show that SGD implicitly biases toward flatter minima, and references therein. However, the role of implicit bias in self-supervised learning has not been studied and is conceptually different. Unlike in supervised learning, the gap between empirical and population self-supervised losses is typically small, and thus implicit bias does not seem to contribute to bridging this gap. Instead, the implicit bias selects local minima of the population self-supervised loss that transfer better to downstream tasks.
Why do the algorithms bias toward some type of models? In Section 4, we provide a first-cut theoretical analysis of the implicit bias in language modeling. Fortunately, despite the conceptual differences, mathematical tools from supervised settings can be straightforwardly adapted to language modeling settings. We prove that mini-batch SGD prefers flatter minima of population pre-training loss among all minima in the saturation regime. Interestingly, we obtain cleaner theoretical results for the standard mini-batch SGD, without the artificial label noise introduced in prior works [13], [14], partly because the mini-batch noise for LLMs does not vanish even at convergence.
We corroborate our theory with empirical evidence in Section 5. We show that for models with the same pre-training loss in the three situations above, flatness of the model (measured by the trace of Hessian of the loss, as predicted by the theory) strongly correlates with the downstream performance.
Finally, to complement the theory and experiments above, we also rigorously formalize the connection between flatness and downstream performance in a simplified Dyck language setting in Section 6. In this setting, we prove that there are many models with good MLM pre-training loss; among them, the flattest model learns the most useful features for downstream tasks. Here, results from the supervised setting cannot be readily adapted since they are obtained (partially) via generalization bounds [15], [16], which do not apply to the language modeling setting where the implicit bias is not related to the gap between the empirical and population loss. Proving the correlation between flatness and downstream performance in more general settings likely requires highly non-trivial and novel theoretical tools, and we hope to motivate future work on this topic.


Figure 1: Models at a later time step performs better, even after the pre-training loss converges. (a) A model with 41M parameters pre-trained on the PCFG-generated dataset, and evaluated on task C. (b) A model with 235M parameters pre-trained on the OPT-generated dataset, and evaluated on QNLI. The error bar in (a) shows the standard deviation of 5 random seeds in linear probe. We do not provide error bars in (b) due to the limitation of computation resources. Also note that the pre-training loss is approaching its minimal value (3.196 for the PCFG-generated dataset and 1.865 for the OPT-generated dataset) as we increase the number of steps. In Section 8.6, we further provide evaluation of the pre-training loss with the KL divergence..
Large language modeling has revolutionized the NLP field. Starting from [1], a line of works improve the downstream performance on a wide range of tasks with increasing model size and data amount [2]–[5]. LLMs even exhibit unexpected emergent behaviors, such as in-context learning [10], [17], step-by-step reasoning [18], and zero-shot learning [5]. [7], [19] study the behavior of language models with increasing size, and find out that the pre-training loss is typically correlated with downstream performance as model size increases. In practice, the pre-training loss is used as an evaluation metric for language models. A notable example is the efficient transformer line of works, which benchmark the pre-training loss given the same computation constraint [20]–[24].
Empirical works on understanding MLM find out that the representations of language models encode rich semantic and syntactic information [25]–[28]. Theoretical works show that good LM loss, or the ability to fit the LM conditional probability, is a sufficient condition for good performance on downstream tasks. [29] show MLM representations recover latent variables in graphical models. [8] introduce the natural assumption, which states that downstream tasks can be solved linearly with the true conditional probability. [9] instantiate MLM on datasets generated by HMMs and show linear probe on top of MLM models solves downstream tasks. In contrast, our empirical evidence indicates that other factors related to the architecture and optimization also contribute to the performance beyond the natural assumption—somewhat surprisingly, we show that linear probe on top of the features of language models is better than linear probe on top of true conditional probability.
Recent works also provide empirical evidence that good pre-training loss cannot fully explain the downstream success. [12] find out that a narrow but deep transformer is better than a wide but shallow transformer with the same pre-training loss. [30] demonstrate that Albert [31] generalizes better to OOD tasks than Bert on a synthetic reasoning task. These works indicate that the architecture is an important factor for good downstream performance beyond pre-training loss. This paper discovers the implicit bias in language modeling on models with the same architecture and the same pre-training loss. Similar to our findings, [10] also observe that despite similar perplexity, larger models are better than smaller modes for in-context learning, while in this paper, we focus on the standard fine-tuning and linear probe evaluation of language models, and provide a novel understanding of the mechanism behind the superiority of large models over small models.
Our work is also related to the broader theoretical self-supervised learning literature. This line of works study why a seemingly unrelated self-supervised objective helps improve the performance on downstream tasks. [32] prove that contrastive learning representations work on downstream linear classification tasks. [33] study reconstruction-based self-supervised learning algorithms and show that linear probe on top of the self-supervised representations solves downstream tasks. [34] show that the contrastive learning loss can be viewed as a principled spectral clustering objective. With the spectral contrastive loss, self-supervised representations recover the cluster structure in the augmentation graph. Recently, [11] introduce the disjoint augmentation regime, where the minimizer of the contrastive learning loss can perform poorly on downstream tasks. Empirically, they find out that subtracting the mean of the representations of each class makes self-supervised models perform worse on downstream tasks, and ResNet [35] can have better downstream performance on downstream tasks than ViT [36] and MLP-Mixer [37] on modified images. This indicates that pre-training loss is not all that matters for good downstream performance in self-supervised learning.
The training algorithm chooses solutions with certain properties, and usually leads to better generalization [38]–[46]. Recently, [13], [14], [47] demonstrate label noise SGD biases the models toward flatter minima. However, the setting of implicit bias in supervised learning is different from language modeling. In language modeling, we have access to gigantic corpus, and cannot interpolate the pre-training dataset. Moreover, we care about the adaptability of the solution on downstream tasks instead of generalization in distribution.
In this section, we systematically investigate the relationship between pre-training loss and downstream performance with experiments. We find out that models with the same pre-training loss but different training procedures can have different downstream performance.
Consider a vocabulary \(W=\{0,1,\ldots,c\}\), where \(0\) is a special token for the mask. Let \(x=[x_1,\ldots,x_T]\) denote the input sequence of length \(T\), and \(x_{-t}=[x_1,\ldots,x_{t-1},0,x_{t+1},\ldots,x_T]\) denote the masked sentence, where \(t\) is sampled uniformly randomly and independently from \([T]\).1 The MLM conditional probability refers to the probability of \(x_t\) given the rest of the sequence \(\Pr\left(x_t\mid x_{-t}\right)\). We use \(\Pr\left(\cdot \mid x_{-t}\right)\) to denote the \(c\)-dimensional probability vector \(\Pr\left(\cdot \mid x_{-t}\right) := [\Pr\left(x_t=1\mid x_{-t}\right),\ldots,\Pr\left(x_t=c\mid x_{-t}\right)]\in \mathbb{R}^c\). In MLM pre-training, the model \(f_{\theta}(\cdot)\) (parameterized by \(\theta\)) outputs the predicted MLM conditional probability vector \(f_{\theta}(x_{-t}) \in \mathbb{R}^c\). The model is trained to predict the masked token \(x_t\) given the rest of the sentence \(x_{-t}\) with cross entropy loss, \(L(\theta) = \mathrm{\mathbb{E}}_{x,t}[\ell(f_\theta(x_{-t}),x_t)]=\mathrm{\mathbb{E}}_{x,t}[-\log([f_\theta(x_{-t})]_{x_t})]\).
The language model\(f_{\theta}\) is composed of a feature extractor \(h_{\psi}\), which outputs a sequence of contextual representations, and a linear classifier that outputs the
conditional probability at every position. On downstream tasks, we use a randomly initialized \(g_{\phi}\) on top of the pre-trained \(h_{\psi}\). In fine-tuning, both \(g_\phi\) and \(h_{\psi}\) are trained, while in linear probe, only \(g_\phi\) is updated. For fine-tuning, we use the contextual representations of the
cls token. For linear probe, we concatenate the contextual representations of all the tokens together.
To study models with the same pre-training loss, we introduce the saturation regime in this paper, where the model output equals the true conditional probability, \(f_{\theta}(x_{-t})=\Pr\left(\cdot \mid x_{-t}\right)\). In the saturation regime, the MLM loss is equal to the entropy of the true conditional probability \(L(\theta) = \mathrm{\mathbb{E}}_{x,t}[-\log(\Pr\left(x_t \mid x_{-t}\right))]=\frac{1}{T}\sum_{t=1}^T H(x_t \mid x_{-t})\), which is also the optimal pre-training loss. Thus, all models in the saturation regime have the same, optimal pre-training loss, and we will show that they behave differently on downstream tasks. Our experiments use expressive enough architectures such that there are multiple parameter configurations in the saturation regime for our simplified datasets. For real large-scale data, it is currently computationally challenging to arrive at the saturation regime. However, we hope that our experiments can provide insights for even larger models in the future and for other regimes where pre-training loss does not explain downstream performance.
We design controlled experiments to study the correlation between pre-training loss and downstream performance. In particular, we will find a set of models with almost the same pre-training loss. We effectively use the same architecture family so that the main difference between the models only stems from training algorithms. More details are provided in Section 8.
We introduce three generative models to produce simplified datasets, with which we can study various factors systematically. With the knowledge of the true generative models that generate the data, we can compute the true conditional probability and scale up the models until they approach the saturation regime to ensure they have almost the same pre-training loss. Moreover, we can generate unlimited amount of text for pre-training to avoid overfitting to the empirical pre-training loss.
PCFG-generated dataset. PCFG [48] generates sentences with probabilistic trees and is widely used to understand natural language [49]–[52]. We randomly generate the production rules which satisfy the Chomsky Normal Form [48]. The non-terminal symbols in the parse tree can be viewed as intrinsic quantities associated with the sentence such as sentiment and syntax. Thus we design three downstream tasks A, B, and C to classify non-terminal symbols at different positions of the parse trees.
HMM-generated dataset. HMM samples the hidden variables from the transition probabilities and the tokens from the emission probabilities. [9], [10] also analyze the properties of pre-trained language models with HMMs. We generate the transition and emission probabilities as random block-diagonal stochastic matrices. The downstream task is to classify the hidden variable in the sentence. We use task-\(k\) to refer to classifying the \(k\)-th hidden variable.
OPT-generated dataset. We also introduce a more realistic pre-training dataset generated by the OPT models [6]. Starting from the
bos token, we sample each token from the conditional probability output by the OPT model. For computational feasibility we only allow to generate the top-2000 most frequent tokens in the OPT vocabulary. We use QNLI and SST-2 from GLUE [53] as downstream tasks.



Figure 2: Larger models perform better downstream than smaller models, even with almost the same pre-training loss. (a) Pre-train on the PCFG-generated dataset and evaluate on task B. (b) Pre-train on the HMM-generated dataset and evaluate on task-10. (c) Pre-train on the OPT-generated dataset and evaluate on QNLI. See Section 3 and Section 8 for details..
Note that the true conditional probability can be computed efficiently for the three datasets given the knowledge of the generated models. For PCFG and HMM-generated datasets, we can compute the true conditional probability with the inside algorithm [54] and the Viterbi algorithm [55], respectively. For the OPT-generated dataset, we can calculate the MLM conditional probability from the joint probability, and the joint probability can be decomposed into the autoregressive conditional probability of the OPT model. With the true conditional probability, we can evaluate the pre-training loss more accurately. The cross entropy loss can be decomposed into the KL divergence between the predicted and true conditional probability and the entropy of the true conditional probability. In addition to the cross entropy loss, we also report the log of the KL divergence in Section 8.6.
For the PCFG- and HMM-generated datasets, the pre-training and downstream distributions are the same. We mainly focus on this in-distribution evaluation to better control various factors and avoid complications. We will leave more systematic out-of-distribution evaluation for future work. We mainly focus on the in-domain evaluation because we can already see the interesting phenomenon that models can have the same pre-training loss but different downstream performance, and this indicates the implicit bias is not specific to the shift in the data distribution.
For PCFG- and OPT-generated datasets, we use transformers [56] following the implementation of BERT [1]. We use different model sizes ranging from 2M to 730M. For the HMM generated dataset, we use LSTM [57] from 10M to 135M. In pre-training, all the models are pre-trained with AdamW following the protocol of [58]. We use batch size 4096, and train each model for more than 30K steps until the pre-training loss converges. Besides varying the hyper-parameters such as training steps and model size, we also consider two other approaches that produce models with the same pre-training loss and evaluate their downstream performance. First, inspired by [59], [60], we pre-train models with an additional meta-learning objective that intends to mess up the downstream performance while keeping the same pre-training loss. The second approach is to virtually implement a model that produces the exactly correct conditional probabilities as the representations of the sentences, and we call such a model a look-up table. Note that such a model has a perfect pre-training loss if the output embeddings matrix is simply the identity matrix, and can be implemented by a sufficiently large transformers because transformer are universal approximators [61], [62]. Because we have access to the true conditional probability, we can evaluate the linear probe performance of the “look-up table” model by training linear head on top of the concatenated conditional probabilities, without explicitly constructing parameters of the transformer that implements the look-up table.
We compare the downstream performance of models with the same pre-training loss in the following situations: (2) training for different number of steps after the pre-training loss converges, (2) using different model sizes, and (3) training with normal training algorithms vs. adversarial training algorithms.
In Figure 1, we plot the validation pre-training loss and the downstream performance of different models checkpoints along pre-training. After the pre-training loss converges, although the pre-training loss does not improve, the downstream accuracy continues increasing.
Even with the same pre-training loss, larger models are better than smaller models. In Figure 2, we plot the pre-training loss and the downstream performance of models with different sizes. As we increase the model size, the pre-training loss approaches the entropy of the true conditional probability, which is 3.196, 3.758, and 1.865 for PCFG, HMM, and OPT respectively. For PCFG and OPT-generated datasets, we use the vertical dashed line to indicate the place where the pre-training loss saturates as we scale up the model. For the much simpler HMM, the smallest 4M model can fit pre-training close to the entropy of the true conditional probability. With the same pre-training loss, scaling up the models improves linear probe performance by \(6.9\%\), \(4.5\%\), and \(2.0\%\), on PCFG, HMM, and OPT generated data, respectively. See Section 8 for results on other downstream tasks.
r7.5cm
| Method | Pre-training | Task A \(\%\) | Task B \(\%\) |
|---|---|---|---|
| AdamW | 3.204 | 89.9 \(\pm\)0.3 | 49.2\(\pm\)0.8 |
| Adversarial | 3.206 | 83.1 \(\pm\)0.6 | 42.3\(\pm\)1.5 |
| Lookup table | 3.196 | 71.2 | 39.7 |
Naturally trained transformers are better than adversarially trained ones. In Table ¿tbl:table1?, we evaluate the 235M transformers on PCFG tasks A and B with different pre-training algorithms. Although the adversarially trained transformer has almost the same pre-training loss as the normally trained 235M transformer, it is more than 6\(\%\) worse than the normal 235M model, and even worse than a normal 9M model on the downstream task B. This indicates that we can still mess up the downstream performance without changing the pre-training loss and the architecture. The lookup table has perfect pre-training loss, but it performs worse than all normally trained transformers in Figure 2 (a) on task B. In other words, the transformer model that implements the lookup table does not perform as well as the naturally trained transformer.
Moreover, comparing the lookup table row and the first row of Table ¿tbl:table1? suggests that linear probe on top of the representations of standard transformers is better than linear probe on top of the true conditional probability. This indicates that learning the conditional probability well cannot fully explain the success of language models and that the natural assumption in [8] cannot not fully explain the performance of language models. Also note that our experiment is different from the label-orthogonal training in [11]. They find models with the same pre-training loss and different downstream performance by subtracting the mean of the representations in each class, which essentially changes the model architecture, while our experiments compare models within the same architecture.
The experiments above indicate that for models with the same architecture family and the same pre-training loss, the choice of training algorithms, model sizes, and the number of steps that the optimizer works can affect the downstream performance. This indicates the existence of implicit bias of the training algorithms toward choosing more transferable parameter configurations among those with the same pre-training loss and architecture.
As discussed in the introduction, the difference between the role of implicit bias in supervised learning and language modeling is conceptual, because the gap between empirical and population self-supervised loss is small and thus implicit bias is not needed for bridging this gap. Instead, the implicit bias benefits the performance on downstream tasks by picking networks that are more adaptable to those tasks.
Fortunately, the mathematical tools developed for supervised learning can be adapted to language modeling, which even allows cleaner results by removing some artificial assumptions like adding label noise. Concretely, we show that mini-batch SGD can find models in the flatter areas of pre-training loss landscape. The flatness is measured by the trace of Hessian of the pre-training loss \(\mathrm{Tr}[\nabla^2 L(\theta)]\). See Figure 4 (Left) for an illustration of the implicit bias.
We analyze SGD on the population cross-entropy loss \(L(\theta)= \mathrm{\mathbb{E}}_{x,t}[-\log([f_\theta(x_{-t})]_{x_t})]\) with freshly sampled data at every iteration, because, as argued, the difference between empirical and population pre-training loss is not our focus. For simplicity, we present the results for batch size \(= 1\) , though they can be generalized to arbitrary batch size (see discussion below Theorem 1). Let \(\eta\) be the learning rate and let \(\theta^\eta_k\) denote the parameter at step \(k\). We drop the superscript \(\eta\) when there is no ambiguity. We will show that the implicit bias kicks in when SGD reaches a global minimizer—it drives the iterate towards flatter global minimizers. For simplicity of demonstration, we analyze the process starting from a global minimizer \(\overline{\theta}\), i.e., we assume that \(\theta^\eta_0=\overline{\theta}\) (for all \(\eta\)). At each iteration \(k\), we get a fresh sample \((x,t)\), where \(x\) is a sentence and \(t\) is the position of the masked token, and update the parameter \(\theta\) by \(\theta_{k+1} = \theta_k - \eta \nabla_\theta\ell(f_{\theta_k}(x_{-t}), x_{t})\). We assume the network is sufficiently expressive such that there are many fundamentally different global minimizers of the pre-training loss \(L\). As a (non-trivial) regularity condition, following prior works [14], [63], [64], we also assume that the minimizers of the loss function \(L\) are connected and form a smooth manifold.
Assumption 1. Assume that the loss \(L\) is a \(\mathcal{C}^{3}\)-smooth function, and that the set of global minimizers, \(\Gamma\), is a \((d-M)\)-dimensional \(\mathcal{C}^{2}\)-submanifold of \(\mathbb{R}^{d}\) for some integer \(1 \leq M \leq d\), where for all \(\theta\in \Gamma, \operatorname{rank}\left(\nabla^{2} L(\theta)\right)=M\).
A key observation for language model is that even if the model reaches the saturation regime, that is, the model reaches a point on the manifold \(\Gamma\) of the minimizers, the optimization process still has non-vanishing gradient noise, because the cross-entropy loss is typically non-zero at the global minimizers and thus the stochastic gradient variance is also non-zero.2 Therefore, the dynamics of SGD do not completely stop; instead, the iterate oscillates around the manifold \(\Gamma\). It turns out that this oscillation in turn encourages the parameter to move in a certain direction along the manifold, determined by the covariance structure of the stochastic gradient. The following lemma shows that the covariance of stochastic gradient for language models in the saturating regime has a favorable property, i.e., it is equal to the Hessian of pre-training loss.
Lemma 1 (Bartlett identity). For any \(\theta\in\Gamma\), \(\Sigma(\theta) =\nabla^2 L(\theta)\), where \(\Sigma(\theta)\) is the covariance of the stochastic gradient at \(\theta\), that is, \(\Sigma(\theta) = \mathrm{\mathbb{E}}_{t,x}\left[\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} (\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t})^\top\right] - \nabla L(\theta)^\top \nabla L(\theta)\).
Though we give a proof of the lemma in Appendix 10 for completeness, the formula holds for the MLE loss of any well-specified probabilistic models at a global minimizer, and both the gradient covariance and the Hessian equals to the Fisher information matrix.
With Lemma 1, we can invoke Corollary 5.2 of [14] to derive the following theorem which says that SGD will locally decrease the trace of Hessian along the solution of ordinary differential equation 1 defined below. \[\begin{align} \label{eq:limiting95diffusion95final} \mathrm{d}\hat{\theta}(t) = -\frac{1}{4}\nabla_\Gamma \mathrm{Tr}[\nabla^2 L(\hat{\theta}(t))] \mathrm{d}t, \quad \hat{\theta}(0)=\overline{\theta} \end{align}\tag{1}\] where \(\nabla_\Gamma = P^\perp_\Gamma\nabla\) is the Riemannian gradient on manifold \(\Gamma\), or just the ordinary gradient projected back to the tangent space of \(\Gamma\) at \(\theta\). In other words, the ODE 1 is essentially a projected gradient descent algorithm with loss function \(\mathrm{Tr}[\nabla^2 L(\theta)]\), the constraint set \(\Gamma\), and infinitesimal learning rate. We show that SGD effectively minimizes the trace of the Hessian \(\mathrm{Tr}[\nabla^2 L(\theta)]\) with the constraint set \(\Gamma\) similarly to ODE in 1 .
Theorem 1. Suppose the loss function \(L\) and the manifold of global minimizers \(\Gamma\) satisfy Assumption 1. For any \(K>0\) such that ODE 1 has a solution \(\{\hat{\theta}(t)\}_{t=0}^K\), it holds that \(\theta^\eta_{K/\eta^2}\) converges in distribution to \(\hat{\theta}(K)\) as \(\eta\to 0\).
Finally, we note that the above result can be extended to an arbitrary batch size \(B\). The covariance of stochastic gradient at \(\theta\) with batch size, denoted by \(\Sigma_B(\theta)\), satisfies that \(\Sigma_B(\theta) = \frac{1}{B}\Sigma(\theta)\). Therefore \(\Sigma_B(\theta) = \frac{1}{B} \nabla^2 L(\theta)\) and we can again invoke Corollary 5.2 of [14] to derive the same result as in Theorem 1 but with the coefficient \(\frac{1}{4}\) in equation 1 replaced by \(\frac{1}{4B}\).


Figure 3: The trace of Hessian correlates with downstream performance for model checkpoints with different number of steps after the pre-training loss converges. Left: A model with 235M parameters pre-trained on the PCFG-generated dataset, and evaluated on task C. Right: A model with 67M parameters model pre-trained on the HMM-generated dataset, and evaluated on task-10..
In this section, we demonstrate with experiments that the flatness is well correlated with downstream performance in the setting introduced in Section 3.

Figure 4: Left: The role of implicit bias. After the pre-training loss converges, the implicit bias drives the model toward flat minima, as predicted by Theorem 1. Right: The interaction between model size and implicit bias. The implicit bias drives the model toward flat minima on both larger models and smaller models. The smaller model architecture can be viewed as a subset of the larger model architecture. Therefore, larger models can achieve flatter minima than smaller models..
As in Theorem 1, we measure the flatness of different models in Section 3 by the trace of Hessian of the pre-training loss (smaller trace of Hessian indicates flatter minima.) Note that when the model approaches the saturation regime, the trace of Hessian is approximately the second order derivative times the square of the norm of the Jacobian, which is a high-dimensional matrix. For computational feasibility, we adopt a technique inspired by Lemma 1 and [65] to unbiasedly estimate the trace of Hessian with random samples. Details are provided in Section 9.1.
r7.44cm
| Method | Pre-training | Acc \(\%\) | Tr(H) |
|---|---|---|---|
| AdamW | 3.20 | 55.7\(\pm\)0.6 | 8.01\(\pm\)0.73 |
| Adversarial | 3.20 | 50.2\(\pm\)1.0 | 19.34\(\pm\)0.92 |
In Figure 3, we compare the downstream accuracy and the trace of Hessian of different checkpoints obtained at different times during pre-training. On the PCFG and HMM datasets, the trace of Hessian demonstrates a clear decreasing trend after the validation pre-training loss converges, following the prediction of Theorem 1. Furthermore, as the trace of Hessian decreases, the downstream performance improves by 1.6\(\%\) and 4.0\(\%\) on the PCFG and HMM datasets, respectively.
We compare the trace of Hessian of the models pre-trained with adversarial algorithm and standard AdamW in Table ¿tbl:table2?. The trace of Hessian of the adversarially pre-trained model is 2 times larger than the normally pre-trained model, corresponding to a drop of 5.5\(\%\) in downstream performance.
In Figure 5, we compare the downstream accuracy and the trace of Hessian of transformers with different sizes. We view all the transformers of various sizes as some parameter configurations within a large transformer architecture, and then compare the trace of Hessian of the new views of these models. Intuitively, we can view a small transformer as a large one by filling zeros into the additional parameters or replicating the parameters of the smaller models. For vanilla MLPs, both ways maintain the input-output functionality and the trace of Hessian. Although the layer-norm in transformers causes subtleties, we can still keep the functionality and the trace of Hessian with respect to most parameters unchanged by replicating the models properly (See Section 9.4 for details). Therefore, the views of these models have the same parameterization/architecture and the same pre-training loss (because they have the same representations as the corresponding original smaller models), and we evaluate the relationship between the their trace of Hessian and their downstream performance.
On the dataset generated by the PCFG, the pre-training loss is almost the same for models (technically, the new views of these models) that are larger than 9M. As we increase the model size, the trace of Hessian of the pre-training loss decreases from 19.8 to 12.6, correlating with the increase of linear probe accuracy from 40.4\(\%\) to 50.5\(\%\). On the OPT-generated dataset, we can also observe an increase in linear probe accuracy that co-occurs with a sharp decrease in the trace of Hessian, as we increase the model size.
Intuitively, the implicit bias drives the model toward flat minima on both larger models and smaller models. As demonstrated above, the smaller transformer architecture is a subset of the larger transformer architecture family. Thus the flattest minimum found within a larger transformer is flatter than the flattest minimum found within a smaller transformer, and performs better downstream. (See Figure 4 (Right).)


Figure 5: The trace of Hessian correlates with downstream performance for models with different sizes and almost the same pre-training loss. As we increase the model size, the trace of the Hessian continues to decrease, as the performance on downstream tasks increases..

Figure 6: The synthetic language setting. Left: An example of input encodings with sentence length \(T=6\). Right: Illustration of the two solutions. The softmax attention can sum the token encodings into \(z\). Solution (1) contains two features transferable to the downstream task. The neurons in solution (2) are sampled from Gaussian distribution, and not related to the downstream task. Both solutions can output the correct prediction for MLM pre-training, but solution (1) has much smaller trace of Hessian..
Toward formally proving the connection between the flatness regularization (introduced by the stochastic gradient as argued in Section 4) and the downstream performance, we consider a setting with synthetic Dyck language. The simplicity of the data allows us to sharply analyze the internal working of a single-layer transformer (with an attention layer and an MLP layer) for masked language modeling. We show that multiple parameter configurations can predict the conditional probability well, including one ideal model that learns the correct representations capturing the intrinsic structure of the sentence, and many “cheating” models that essentially memorize the conditional probability using random features. We will prove that the flattest model is the desired model that transfers to downstream tasks.
Consider a variant of the Dyck language [66] consisting of matching brackets. The vocabulary of the language has two brackets \(\langle\) and \(\rangle\). Each sentence is composed of a sequence of tokens such that the total numbers of \(\langle\)’s and \(\rangle\)’s are equal. To sample from the pre-training distribution \(P\), we first draw a sentence uniformly over all valid sentences with even length \(T\). Then, we randomly select one position in \([T]\) and replace the bracket with a mask token.
The most intrinsic property about the synthetic language is the difference in the number of left and right brackets in a prefix, and thus we use it as the downstream task. Concretely, for any sequence \(x\) in \(\{\langle, \rangle \}^*\) of length \(T\), let \(g^*(x)\) count the number of mismatches in \(x\): \[\begin{align} g^*(x) \triangleq \mathrm{\# of \rangle's in x - \# of \langle's in x} \end{align}\] Thus, the sentence \(x\) is a valid string in the language if and only if \(g^*(x)=0\). For MLM, the masked token can also be recovered from \(g^*(x)\): \(g^*(x) = 1\) if the masked token is \(\langle\), and \(g^*(x) = -1\) if the masked token is \(\rangle\). To evaluate if the model learns the structure, we consider a downstream distribution of sentences which do not necessarily belong to the the language. Each token is sampled from \(\{\langle, \rangle \}\) uniformly, randomly, and independently.
With a slight abuse of notation, we also denote by \(x_t\) the encoding of the \(t\)-th token. We encode the input as a one-hot vector in dimension \(d=2T\), where the index of the nonzero element encodes the position and the sign encodes the bracket. Concretely, let \(e_t\in \mathbb{R}^{d}\) be the natural basis vector where the \(t\)-th entry is 1. Let \(x_t = e_t\) if the \(t\)-th token is \(\langle\) and \(x_t = -e_t\) otherwise. If the position \(t\) is a mask, we set \(x_t\) to \(v\), where \(v\sim\mathrm{Unif}(\{\pm e_{t+T}\})\). Examples of the encodings with \(T=6\) are provided in Figure 6 (Left). Note that the target function can be expressed as \(g^{\star}(x) = -\langle \mathbf{1}_{T} , [\sum_{t=1}^{T}x_t]_{1:T} \rangle\) with this input encoding, where \(\mathbf{1}_{T}\) is the all one vector in \(\mathbb{R}^T\) and \([a]_{1:T}\) refers to the first \(T\) coordinates in \(a\).
Suppose \(Q,K \in \mathbb{R}^{k\times d}\) are the query and key matrices, \(V\in\mathbb{R}^{m \times d}\) is the value matrix and \(u\in\mathbb{R}^{m}\) is the parameter of the output layer. Let \(\psi = (Q,K,V)\). A single-layer transformer is composed of an attention layer and an MLP layer. \([\mathrm{Attn}_{\psi,u}(x)]_t =\frac{1}{m} u^\top \sigma(\sum_{j=1}^{T} a_{t,j} V x_j)\), where the attention score \(a_{t,1:T} = \mathrm{softmax}(\langle Qx_t, Kx_t\rangle,\cdots\langle Qx_t, Kx_{T}\rangle)\). \(\sigma(x)=\max\{x,0\}\) is the relu activation. We use the output of the first token, \(f_{\psi,u}(x)=[\mathrm{Attn}_{\psi,u}(x)]_1\).
We use the squared loss for both MLM and downstream adaptation. The loss function of MLM is \(L(\psi,u)\). In downstream adaptation, we have a finite dataset \(\{x^{(i)}\}_{i=1}^{n}\) sampled i.i.d. from \(P_{\mathrm{ds}}\). The training loss with \(n\) data is \(\widehat{L}^{P_{\mathrm{ds}}}(\psi,u)\), and the population loss for the downstream task is \(L^{P_{\mathrm{ds}}}(\psi,u)\).
We are interested in two kinds of parameter configurations both with good pre-training loss: (1) learning the natural and transferable features \(\mathbf{1}_T\) and (2) fitting the pre-training task by memorizing the masked sentences. We construct the two solutions as follows. For solution (1), first note that the softmax attention layer can take the average of all the token encodings \([x_t]_{t=1}^{T}\) in a sentence. Let us denote the sum by \(z\in\mathbb{R}^{d}\), \(z = \sum_{t=1}^{T}x_t\). Note that the first \(T\) coordinates in \(z\) are \(\pm 1\) indicating the bracket type and the last \(T\) coordinates indicate the position of the mask (See Figure 6 (Right)). On top of \(z\), two neurons can predict the masked token in MLM perfectly. Consider the two neurons \(V_1 = [\mathbf{1}_T;\mathbf{0}_T]\), \(V_2 = [-\mathbf{1}_T;\mathbf{0}_T]\). Then \(g^*(x) = \sigma(V_2^\top z) - \sigma(V_1^\top z)\), which is the transferable solution. For solution (2), we set the entries in \(V\) to i.i.d. samples from \(\mathcal{N}(0,T)\). If \(m\) is sufficiently large, we can find the coefficient \(u\) to express \(g^{*}(x)\) with random Gaussian features, i.e. \(g^{*}(x) = u^\top\sigma(Vz)\).
We observe that the trace of Hessian of configuration (1) is smaller than configuration (2), due to a main difference between them–the cancellation between activated neurons. In configuration (1), for every possible input, only one of the neurons \(\sigma(V_1^\top z)\) and \(\sigma(V_2^\top z)\) is activated. In contrast, in configuration (2), many neurons can be activated at the same time. Among them, the output coefficient \(u_i\)’s contain both positive and negative values, leading to cancellation between activated neurons. In Lemma 2, we link the trace of the Hessian with the cancellation between neurons. Indeed, we show that the mimimum of trace of the Hessian can be achieved only if there is no such cancellation. Therefore solution (1) is also the minimizer of the trace of Hessian. The intuitions are formalized in Theorem 2.
Theorem 2. Suppose \(m\ge 2\) and \(T\ge 6\). Consider minimizing the trace of Hessian among all the solutions to the MLM pre-training task: \(\mathrm{minimize}_{\psi,u}\mathrm{Tr}[\nabla^2_\psi L(\psi,u)] + \mathrm{Tr}[\nabla^2_u L(\psi,u)]\), subject to \(L(\psi,u) = 0\). The flattest solution \(\hat{\psi}, \hat{u}\) are defined as the solution of the optimization problem above. \(\tilde{u}\) is the minimizer of downstream training loss on top of \(\hat{\psi}\), \(\tilde{u}\in\mathop{\arg\min}_{u}\|u\|_2\) subject to \(\widehat{L}^{P_{\mathrm{ds}}}(\hat{\psi},u)=0\). Then with probability at least \(1-2^{-n}\), \(L^{P_{\mathrm{ds}}}(\hat{\psi},\tilde{u})=0.\)
We study the relationship between pre-training loss and downstream performance on language models. We discover that implicit bias matters beyond pre-training loss, and explore the mechanism of implicit bias in language modeling. For downstream evaluation, we also focus on in-distribution data to better control various factors. Future works can study the effect of implicit bias on out-of-distribution tasks. Our experiments also focus on simplified datasets due to constraint of computational resources. We hope that the phenomenon can predict the implicit bias on more complex datasets as the community scale the models to even larger. Theoretically we provide cases where the flatness regularization can decide the performance on downstream performance. We wish this motivates future works on the relationship between implicit bias and the feature representations of the models.
We thank Jeff Z. HaoChen, Yining Chen, Garrett Thomas and Ananya Kumar for valuable feedbacks. HL is supported by the Stanford Graduate Fellowship. SMX is supported by an NDSEG Fellowship. The authors would like to thank the support from NSF IIS 2045685.
PCFG-generated dataset. We consider a PCFG with vocabulary size 200. The state space is \(S\), and \(|S| = 50\). All the production rules have two symbols on the right side. The sentence length is limited to 32, which means the depth of the parse tree is limited to 6. We generate a total of \(2\times 10^7\) sentences, which is \(3.4\times 10^8\) tokens. The downstream tasks are classifying the non-terminal symbols in the parse tree of the PCFG (50-way classification). The label is defined as \(y = \mathop{\arg\max}_{s\in S}\Pr\left(s \mid x_1,x_2,\ldots,x_{1+L}\right)\). Tasks A, B and C are defined on the symbols corresponding to span length \(L=32, 16\;\text{and}\;8\), respectively. Each of the downstream task contains 0.1M examples. Examples of the generated trees are provided in Figure 7.

Figure 7: An example of the genearated PCFG sentence..
HMM-generated dataset. We consider an HMM with vocabulary size 200 and state space size 100. The sentence length is restricted to 16. We generate a total of \(1\times 10^7\) sentences, which is \(1.6\times 10^7\) tokens. The downstream task is to classify the latent variable in the HMM generative model. We consider task-6 and task-10, which classify the 6-th and 10-th hidden variables respectively. Each of the downstream task contains 0.1M examples.
OPT-generated dataset. We use the 125M OPT model to generate the training dataset. To simplify the dataset, we further process the logit of OPT to select only from the top-2000 tokens in the vocabulary. Starting from the bos token, we sample every token of the sentence from the predicted autoregressive LM probability. The sentence length is restricted to 24. We generate a total of \(2\times 10^8\) sentences, which is \(3.2 \times 10^9\) tokens. Examples of the generated text are provided in Figure 8.

Figure 8: An example of the genearated OPT sentence..
We can compute the true MLM conditional probability \(\Pr\left(x_t \mid x_{-t}\right)\) from the joint probability \(\Pr\left(x_t, x_{-t}\right)\), \[\begin{align} \Pr\left(x_t = c \mid x_{-t}\right) = \frac{\Pr\left(x_t = c , x_{-t}\right)}{\sum_{c\in W}\Pr\left(x_t = c , x_{-t}\right)}. \end{align}\] Since we already know the generative model, we can compute the joint probability efficiently. For PCFG, we can compute the joint probability with the inside algorithm, which decomposes the joint probability into lower layers in the parse tree. For HMM, we can compute the joint probability with the Viterbi algorithm. For OPT, we have \(\Pr\left(x_1,\ldots,x_T\right) = \Pr\left(x_1\right)\prod_{t=1}^{T-1}\Pr\left(x_{t+1} \mid x_1,\ldots,x_t\right)\).
We use transformers on PCFG and OPT-generated datasets. We use learning rate 1e-3 and warmup proportion 0.06. All the models are trained based on the implementation of [58]. We list the sizes of the transformers in Table ¿tbl:fig:size?. d-model is the size of the hidden layers. d-inter is the size of the intermediate layers in MLP. n-head is the number of heads per layer. \(\#\)layers is the number of layers. For LSTMs, we use the implementation of PyTorch. We consider d-hidden in [128,256,512,768,1024], and \(\#\)layers in [4,6,8,12,16].
| d-model | n-nead | \(\#\)layers | d-inter |
|---|---|---|---|
| 64 | 1 | 1 | 256 |
| 128 | 2 | 4 | 512 |
| 192 | 3 | 5 | 768 |
| 256 | 4 | 6 | 1024 |
| 512 | 8 | 8 | 2048 |
| 768 | 12 | 12 | 3072 |
| 1024 | 16 | 16 | 4096 |
| 1280 | 20 | 20 | 5120 |
| 1536 | 24 | 24 | 6144 |
The lookup table. To evaluate the downstream performance of the lookup table, we first create the lookup table with the data of the downstream task. With the method mentioned in Section 8.2, we can generate the true conditional probability of each token and use it as the contextual embeddings.
The adversarial algorithm. The adversarial algorithm we use to mess up the downstream performance is maximizing a meta-learning objective in pre-training. Suppose the linear head of the downstream task is \(g_\phi\) and the feature representation is \(h_{\psi}\). The meta-learning algorithm first trains the head \(g_\phi\) to minimize the training loss of the downstream task, and then update \(h_{\psi}\) to maximize the validation loss on the downstream tasks. Concretely, we randomly sample two disjoint subsets \(D_1\) and \(D_2\) from the downstream training dataset \(D\). We train \(g_\phi\) to minimize the loss of downstream tasks on \(D_1\), \(\hat{\phi} (\psi)\in \arg\min \frac{1}{|D_1|}\sum_{(x,y)\in D_1}\ell(g_\phi(h_{\psi}(x)),y)\). Then we train \(h_{\psi}\) to maximize the validation loss on \(D_2\) during pre-training, \(\mathrm{minimize}_{\psi}L(\psi) -\lambda\frac{1}{|D_2|}\sum_{(x,y)\in D_2}\ell(g_{\hat{\phi}(\psi)}(h_{\psi}(x)),y)\). The optimization can be efficiently carried out with closed form solution of \(\phi\) as shown in [59].
Fine-tuning. Following the standard protocol of [1], we use the contextual embeddings of the CLS token for fine-tuning. We use AdamW with learning rate 1e-4. We perform 200 warmup steps and train on the downstream tasks for 10 epochs.
Linear probe. Since the CLS token is not trained in pre-training, we concatenate embeddings of all the tokens in the sentence as the representations. We use AdamW with learning rate 1e-3 to train the linear head. We train on the downstream tasks for 100 epochs. Note that to make the capacity of the linear probe itself controlled, we adopt a random Gaussian projection to dimension 512 on the concatenation of the embeddings and find out that this does not affect the final performance. Therefore we report the results of standard linear probe by default.
We report the standard deviation of linear probe and fine-tuning from 5 random seeds.
Evaluation of pre-training loss. Since we have access calculate the true conditional probability, we can calculate the cross entropy loss as the sum of the entropy of the true conditional probability and the KL divergence between the predicted and true conditional probabilities. This is more accurate than evaluating on the validation datasets in the standard ways. We report the number of pre-training loss with \(10^6\) sentences, and calculate the standard deviation on 5 subsets, each of which has size \(2\times10^5\).
We also provide results on other downstream tasks in this subsection. On PCFG Task A, OPT SST-2 and the Task-6 of HMM, we can also observe the increase in downstream performance as we scale up the models in the saturation regime.



Figure 9: The downstream accuracy continues to rise as we increase the model size, althought the pre-training loss remains unchanged..
Since we have access to the true conditional probability from the generative models, we can decompose the cross entropy into the KL divergence between prediction and true conditional probability plus the entropy of the true conditional probability. When comparing different models in the saturation regime, we can use the KL divergence to reduce the variance of the loss evaluation. We provide the results with KL divergence evaluation in Figure 10. Even with the log of the KL divergence as the pre-training loss, we can still observe the models are saturating as training proceeds or as we scale up the models.


Figure 10: Results with KL divergence evaluation..
Evaluating the trace of Hessian requires the norm of the Jacobian \(\nabla_{\theta} \log [f_\theta(x_{-t})]\). Since the output dimension \(c\) and the number of parameters are all very large, computing the Jacobian \(\nabla_{\theta} \log [f_\theta(x_{-t})]\) will be very inefficient. Instead, we can estimate the trace of Hessian unbiasedly with random samples as follows. Suppose \(f_\theta(x_{-t})\) is the predicted probability of the conditional probability. In the saturation regime, as \(f_\theta(x_{-t})\) approaches the true conditional probability, the Hessian of the pre-training loss w.r.t. the parameters can be expressed as \[\begin{align} \nabla^2 L(\theta) =\mathrm{\mathbb{E}}_{t,x_{-t}} \mathrm{\mathbb{E}}_{x_t\mid t,x_{-t}}\left[\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} (\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t})^\top\right]. \end{align}\] Therefore we have \[\begin{align} \mathrm{Tr}(\nabla^2 L(\theta)) =\mathrm{\mathbb{E}}_{t,x_{-t}} \mathrm{\mathbb{E}}_{x_t\mid t,x_{-t}}\left\|\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} \right\|_2^2. \end{align}\]
To approximate this expectation, we can first sample \(t,x_{-t}\) from the language, then draw i.i.d. samples \(x_t\) from \((f_\theta(x_{-t}))\), and use the average as the unbiased estimate. For all experiments, we sample 10000 \(x_{-t}\) and sample 50 \(x_t\) for each \(x_{-t}\).
To verify Theorem 1 that SGD biases the model towards flatter minima, we conduct MLM on PCFG and HMM-generated datasets with SGD. We set the proportion of warmup stage to 12\(\%\) total number of steps, and fix the learning rate to 1e-3 after the warmup. We evaluate the downstream performance and the trace of Hessian of different checkpoints along pre-training. The standard deviation of trace of Hessian is calculated based on 5 times of sampling 50 examples as mentioned above. Apart from the PCFG task C and HMM task-10, we also provide results on PCFG tasks A, B and HMM task-6 in Figure 11.



Figure 11: The trace of Hessian correlates with downstream performance for model checkpoints with different number of steps after the pre-training loss converges..
To compare the trace of Hessian of transformers with different sizes, we need to embed the smaller transformers into larger transformers. However, this requires the width of the larger transformers to be a multiple of the width of the smaller transformers. We set the width of the largest transformer to the least common multiple of the width of the smaller transformers as in Table ¿tbl:fig:size4?. For evaluation, we still use linear probe, and follow the setting of Section 3.
| d-model | n-nead | \(\#\)layers | d-inter |
|---|---|---|---|
| 128 | 2 | 4 | 512 |
| 192 | 3 | 5 | 768 |
| 320 | 5 | 6 | 1024 |
| 384 | 6 | 7 | 2048 |
| 640 | 10 | 12 | 3072 |
| 960 | 15 | 16 | 4096 |
| 1920 | 30 | 20 | 5120 |
In this subsection, we show that a smaller transformer can be embed into a larger transformer without changing the functionality. We enable the embedding by considering two techniques (1) adding additional layers using residual connections without changing the functionality and (2) increasing feature dimension / adding more attention heads without change the functionality by duplicating the weights.
To gain some insights of how to increase the feature dimension without changing the functionality, we start with vanilla MLPs without layer-norm [67] and residual connections [35]. Consider a multi-layer MLP \(f_{W,a}(x)\). The weight matrices are \(W=[W_0, \ldots, W_{L-1}]\).The dimensionality is \(W_l \in \mathbb{R}^{d_{l+1}\times d_l}\). The representations are defined recursively, \(h_{l+1}(x) = \sigma(W_l h_l(x))\). We denote the input by \(h_0(x) = x\) and the final output is defined as \(f_{W,a}(x) = a^\top h_L(x)\). The activation \(\sigma\) here is relu or leaky relu. We aim to embed \(f_{W,a}(x)\) into \(f_{\tilde{W},\tilde{a}}(x)\), where \(\tilde{W}=[\tilde{W}_0, \ldots,\tilde{W}_{L-1}]\) and \(\tilde{W}_l \in \mathbb{R}^{2d_{l+1}\times 2d_l}\). We need to make sure \(f_{W,a}(x) = f_{\tilde{W}, \tilde{a}}(x)\) for all \(x\).
For this case, we can set \(\tilde{W}_l = 1/2\begin{bmatrix} W_l & W_l \\ W_l & W_l \end{bmatrix}\) for \(l\in[L-1]\), \(\tilde{W}_0 = \frac{1}{\sqrt{2}}\begin{bmatrix} W \\ W \end{bmatrix}\), and \(\tilde{a} = \frac{1}{\sqrt{2}}\begin{bmatrix} a \\ a \end{bmatrix}\). We can verify that \(\tilde{h}_l(x) = \frac{1}{\sqrt{2}}\begin{bmatrix} h_l(x) \\ h_l(x) \end{bmatrix}\) inductively. Therefore we have \[\begin{align} f_{\tilde{W}, \tilde{a}}(x) =& \tilde{a}^\top \tilde{h}_L(x) \\ =& \frac{1}{\sqrt{2}}[a^\top, a^\top] \frac{1}{\sqrt{2}} \begin{bmatrix} h_L(x) \\ h_L(x) \end{bmatrix}\\ =& \frac{1}{2}f_{W,a}(x) + \frac{1}{2}f_{W,a}(x)\\ =&f_{W,a}(x). \end{align}\]
Next we turn to transformers with residual connections and layer norm. We first use the same strategy as the MLP case to add additional feature dimension and attention heads by replicating the weights, and then show how to add new layers using residual connections. At a high level, replicating the weight maintains the mean and the variance calculated by the layernorm. Therefore the representations inside the transformer also get replicated, without changing the values in each of the replicated groups.
A transformer is composed of an input embedding \(W_E\), \(L\) blocks of self-attention, and an output layer. Transformers also contain layer-norm and residual connections. Suppose the input \(x = [x_1, \ldots, x_T]\), where \(x_i\in \mathbb{R}^{d}\). Each block of the self-attention contains of an attention layer and an MLP layer, both equipped with residual connections and layer-norm. Let us denote by \([h_0(x)]_i = \mathrm{LN}(W_E x_i)\) the input embeddings. Suppose the hidden size is \(d_h\), i.e. \([h_l(x)]_i\in \mathbb{R}^{d_h}\). The attention layer is defined as \([v_{l}(x)]_i = \mathrm{LN}([h_l(x)]_i + [\text{Attn}_l(h_l(x))]_i)\), and the MLP layer is defined as \([h_{l+1}(x)]_i = \mathrm{LN}([v_{l}(x)]_i + U_{l}\sigma(W_{l}[v_{l}(x)]_i+b_{l}))\). The activation \(\sigma\) is GeLU. The final output is \([f(x)]_i = W_E^\top [h_L(x)]_i\). Note that \(W_E\) is both the input embedding and the weight of the output layer. They are tied in training.
The layer norm is on the feature dimension. \([\mathrm{LN}(x_i)]_j = \gamma_j * \hat{x}_{ij} + \beta_j\). \(\hat{x}_i\) is the normalized version of \(x_i\) with zero mean and unit variance. \(\gamma\) and \(\beta\) are trainable.
The multi-head attention consists of \(n_h\) self-attention heads. The definition of the multi-head attention is \(\text{Attn}_l(h_l(x)) = [(A_{l1}h_l(x)V_{l1})^\top, \ldots, (A_{ln_h}h_l(x)V_{ln_h})^\top]^\top O_l\). The output matrix \(O_l \in \mathbb{R}^{d_h \times d_h}\). The attention heads composes of the attention score times the feature matrix times the value matrix. The attention score \(A_{lk}\in\mathbb{R}^{d' \times d'}\) is computed with softmax dot product. For each \(k\in[n_h]\), \(A_{lk} = \text{softmax}(h_l(x)Q_{lk}K_{lk}^\top h_l(x)^\top)\).
Following the implementation of [1], the dimension of the attention head is always \(d' = 64\), thus \(d_h = 64 n_h\). The dimension of the intermediate layer in the MLP is set to \(4d_h\), which means \(U_l \in \mathbb{R}^{d_h \times 4d_h}\) and \(W_l \in \mathbb{R}^{4d_h \times d_h}\).
We aim to embed the smaller transformer \(f(x)\) into \(\tilde{f}(x)\), where \(\tilde{d}_h = 2 d_h\), \(\tilde{n}_h = 2 n_h\), and \(\tilde{L} = L+L'\).
Although the transformers have layer-norm and residual connections, we can still modify the strategy in the base case with MLPs slightly to increase the width of the model and the number of attention heads without changing the functionality. Consider the following weight replication method. For \(l\in[0,\ldots,L-1]\), \[\begin{align} \tilde{W}_E = \frac{1}{2}\begin{bmatrix} W_E \\ W_E \end{bmatrix}, \;\tilde{\gamma}_l = \begin{bmatrix} \gamma_l \\ \gamma_l \end{bmatrix} , \;\tilde{b}_l = \begin{bmatrix} b_l \\ b_l \end{bmatrix} , \;\tilde{\beta}_l = \begin{bmatrix} \beta_l \\ \beta_l \end{bmatrix}, \;\tilde{W}_l = \frac{1}{2} \begin{bmatrix} W_l & W_l \\ W_l & W_l \end{bmatrix}, \;\tilde{U}_l = \frac{1}{2} \begin{bmatrix} U_l & U_l \\ U_l & U_l \end{bmatrix}, \;\tilde{O}_l = \frac{1}{2} \begin{bmatrix} O_l & O_l \\ O_l & O_l \end{bmatrix}, \end{align}\] \[\begin{align} \;\tilde{Q}_{lk} = \frac{1}{2}[Q_{lk},Q_{lk}], \;\tilde{K}_{lk} = \frac{1}{2}[K_{lk},K_{lk}], \;\tilde{V}_{lk} = \frac{1}{2}[V_{lk},V_{lk}] \; \mathrm{for} \;k \in [1,\ldots ,n_h], \end{align}\] \[\begin{align} \;\tilde{Q}_{lk} = \frac{1}{2}[Q_{l(k - n_h)},Q_{l(k - n_h)}], \;\tilde{K}_{lk} = \frac{1}{2}[K_{l(k - n_h)},K_{l(k - n_h)}], \;\tilde{V}_{lk} = \frac{1}{2}[V_{l(k - n_h)},V_{l(k - n_h)}] \; \mathrm{for} \;k \in [n_h+1,\ldots ,2n_h]. \end{align}\]
We observe that the intermediate layers of the transformers are also replicated for the first \(L\) blocks, i.e. \(\tilde{h}_l(x) = \begin{bmatrix} h_l(x) \\ h_l(x) \end{bmatrix}\) and \(\tilde{v}_l(x) = \begin{bmatrix} v_l(x) \\ v_l(x) \end{bmatrix}\) for \(l\in [1,\ldots,L]\). First note that \([h_0(x)]_i = \mathrm{LN}(W_E x_i)\). Since replicating the features will not change the mean and the variance, we have \(\tilde{h}_0(x) = \begin{bmatrix} h_0(x) \\ h_0(x) \end{bmatrix}\). Then we can show that replicating the features will not change the attention scores as well. This makes \(\tilde{v}_l(x) = \begin{bmatrix} v_l(x) \\ v_l(x) \end{bmatrix}\). Finally note that we can apply the base case of the MLP to reason about the MLP layer, and show \(\tilde{h}_{l+1}(x) = \begin{bmatrix} h_{l+1}(x) \\ h_{l+1}(x) \end{bmatrix}\). Therefore we have shown \(\tilde{h}_l(x) = \begin{bmatrix} h_l(x) \\ h_l(x) \end{bmatrix}\) inductively.
We have demonstrated that \(\tilde{h}_l(x) = \begin{bmatrix} h_l(x) \\ h_l(x) \end{bmatrix}\) for \(l\in [0,\ldots,L]\). Now let’s consider the added \(L'\) blocks on top of the small model. Since the transformer contains residual connections, we can add new blocks on top of a small model and fill in zeros to the added parameters. We will show that in this way, \(\tilde{h}_l(x)=\tilde{h}_L(x)\), for any \(l \in [L,\ldots,L+L']\). This will indicate that \(\tilde{h}_{L + L'}(x)=\tilde{h}_L(x) = \begin{bmatrix} h_l(x) \\ h_l(x) \end{bmatrix}\). Recall that \(\tilde{W}_E = \frac{1}{2}\begin{bmatrix} W_E \\ W_E \end{bmatrix}\). This indicate that \[\begin{align} [\tilde{f}(x)]_i =& \tilde{W}_E^\top \tilde{h}_{L+L'}(x) \\ =& \frac{1}{2}[W_E^\top, W_E^\top] \begin{bmatrix} h_L(x) \\ h_L(x) \end{bmatrix}\\ =& \frac{1}{2}[f(x)]_i + \frac{1}{2}[f(x)]_i\\ =&[f(x)]_i, \end{align}\] which means we can add new layers on top of a small transformer without changing the functionality.
Now we show that \(U_l=0\) and \(O_l=0\) for \(l\in [L, \ldots L+L'-1]\) will make \(\tilde{h}_l(x)=\tilde{h}_L(x)\), for any \(l \in [L,\ldots,L+L']\). This holds because \([v_{l}(x)]_i = \mathrm{LN}([h_l(x)]_i + [\text{Attn}_l(h_l(x))]_i)\) and \([h_{l+1}(x)]_i = \mathrm{LN}([v_{l}(x)]_i + U_{l}\sigma(W_{l}[v_{l}(x)]_i+b_{l}))\). If \(O_l=0\), we have \(v_{l}(x) = h_l(x)\) from the first equation. If \(U_l=0\), we have \(h_{l+1}(x) = v_{l}(x)\) from the second equation. Therefore we have \(\tilde{h}_l(x)=\tilde{h}_L(x)\), for any \(l \in [L,\ldots,L+L']\).
As demonstrated above, smaller transformers can be embedded into larger transformers with functionality preserved. The smaller transformer architecture can therefore be viewed as a subset of the larger transformer architecture. In this sense, a set of transformers with different sizes and the same pre-training loss found in Section 3 can be viewed as a set of transformers with the same size after the embedding. Note that the training algorithm only finds out the natural larger models, instead of the larger models which are embedded from the smaller models. This indicates that the implicit bias of the optimizer can interact with the model architecture. The implicit bias drives the model toward flat minima on both larger models and smaller models. The smaller transformer architecture is a subset of the larger transformer architecture, thus the flattest minima found with a larger transformer is flatter than the minima found with a smaller transformer. (See Figure 6).
Proof of Lemma 1. We first recall loss \[L(\theta) = \mathrm{\mathbb{E}}_{x,t}\left[ -\log\; [f_\theta(x_{-t})]_{x_t}\right] = \mathrm{\mathbb{E}}_{t, x_{-t}} \mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ -\log\; [f_\theta(x_{-t})]_{x_t}\right].\]
Note that conditioned on any \(x_{-t},t\), it holds that \[\begin{align} &\mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ - \nabla_{\theta} ^2 \log\; [f_\theta(x_{-t})]_{x_t}\right]\\ = & \mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ - \frac{\nabla_{\theta} ^2 [f_\theta(x_{-t})]_{x_t}}{[f_\theta(x_{-t})]_{x_t}}\right] + \mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ \frac{\nabla_{\theta} [f_\theta(x_{-t})]_{x_t} (\nabla_{\theta} [f_\theta(x_{-t})]_{x_t})^\top}{[f_\theta(x_{-t})]_{x_t}^2}\right]\\ = & 0 + \mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ \nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} (\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t})^\top\right], \end{align}\] where in the last step, we use the assumption that \(\theta\in\Gamma\), that is, for all \(x,t\), \(f_\theta(x_{-t}) = \Pr\left(\cdot\mid x_{-t}\right)\), which implies the following \[\begin{align} \mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ - \frac{\nabla_{\theta} ^2 [f_\theta(x_{-t})]_{x_t}}{[f_\theta(x_{-t})]_{x_t}}\right] = -\sum_{x_t=1}^{c} \nabla_{\theta} ^2 [f_\theta(x_{-t})]_{x_t} = -\nabla_{\theta} ^2\sum_{x_t=1}^{c} [f_\theta(x_{-t})]_{x_t} = - \nabla_{\theta}^2 1 =0. \end{align}\]
Since \(\theta\) is a global minimizer of \(L\), we have that \(\nabla L(\theta) = \mathrm{\mathbb{E}}_{t,x} \nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} =0\). Therefore, we have that \[\begin{align} \Sigma(\theta) = &\mathrm{\mathbb{E}}_{t,x}\left[\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} (\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t})^\top\right] \\ & - \mathrm{\mathbb{E}}_{t,x} \nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} \left( \mathrm{\mathbb{E}}_{t,x} \nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} \right)^\top \\ = & \mathrm{\mathbb{E}}_{t,x_{-t}} \mathrm{\mathbb{E}}_{x_t\mid t,x_{-t}}\left[\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t} (\nabla_{\theta} \log [f_\theta(x_{-t})]_{x_t})^\top\right]\\ = & \mathrm{\mathbb{E}}_{t, x_{-t}} \nabla^2_\theta\left(\mathrm{\mathbb{E}}_{x_t\mid t, x_{-t}}\left[ -\log\; [f_\theta(x_{-t})]_{x_t}\right]\right) \\ = & \nabla^2 L(\theta), \end{align}\] which completes the proof. ◻
Recall that the loss function of MLM is \(L(\psi,u)=\mathrm{\mathbb{E}}_{x\sim P}[(f_{\psi,u}(x)-g^*(x))^2]\). In downstream adaptation, we have access to a finite dataset \(\{x^{(i)}\}_{i=1}^{n}\) sampled i.i.d. from \(P_{\mathrm{ds}}\). The training loss is \(\widehat{L}^{P_{\mathrm{ds}}}(\psi,u)=\frac{1}{n}\sum_{i=1}^{n}[(f_{\psi,u}(x^{(i)})-g^*(x^{(i)}))^2]\), and the population loss for the downstream task is \(L^{P_{\mathrm{ds}}}(\psi,u)=\mathrm{\mathbb{E}}_{x\sim P_{\mathrm{ds}}}[(f_{\psi,u}(x)-g^*(x))^2]\).
Proof of Theorem 2. We first calculate the trace of Hessian of the pre-training loss and then derive a lower bound for it in Lemma 2. We then show that the lower bound can be achieved only if the output of the attention are in one direction for all the downstream input in Lemma 3. This translates to constant sample complexity for the downstream task.
Lemma 2. Denote by \(h_{Q,K}(x)=\sum_{j=1}^{T}a_jx_j\) the output of the attention head. In the setting of Theorem 2, \(I_{+}=\{i\in[m] \mid u_i>0\}\) and \(I_{-}=\{i\in[m] \mid u_i<0\}\). The trace of Hessian can be lower bounded, \[\begin{align} \mathrm{Tr}[\nabla^2_\psi L(\psi,u)] + \mathrm{Tr}[\nabla^2_u L(\psi,u)] \ge \sqrt{\frac{4}{T}}, \end{align}\] where the lower bound is achieved if and only if the following conditions are satisfied, \[\begin{align} \forall \;i\in[m], x\in\{x \mid V_i^\top h_{Q,K}(x) > 0\}, \quad V_i^\top h_{Q,K}(x) = |u_i| \left\lVert h_{Q,K}(x)\right\rVert_2\label{eqn:same95value95activate}, \end{align}\qquad{(1)}\] \[\begin{align} \forall x,\;i\in I_{+},\;i'\in I_{-},\quad V_i^\top x V_{i'}^\top x \le 0\label{eqn:no95cancellation95neuron}, \end{align}\qquad{(2)}\] \[\begin{align} \forall x,\; j\in[T],\quad a_j=\frac{1}{T} \label{eqn:uniform95attention}. \end{align}\qquad{(3)}\]
Denote by \(D_{+} = \{x \mid y=1\}\) and \(D_{-} = \{x \mid y=-1\}\). \(I_{x}\) is the set of index of neurons which is activated on \(x\), \(I_{x} = \{i\in[T] \mid V_i^\top x > 0\}\). By the condition in equation ?? , the attention is taking the average of \([x_t]_{t=1}^{T}\). We can map \(D_{+}\) and \(D_{-}\) to the feature space, \(H_{+} = \{h_{Q,K}(x) \mid y = 1\}\) and \(H_{-} = \{h_{Q,K}(x) \mid y = -1\}\). We first show that one neuron cannot be activated on inputs from both \(D_{+}\) and \(D_{-}\), and all non zero neuron has to be activated on some input. Also note that a neuron cannot be activated on no input, unless the weight is \(0\).
Fact 3. (1) \(\forall x \in D_{+}\), \(I_{x} \subseteq I_{+}\). Similarly we have \(\forall x \in D_{-}\), \(I_{x} \subseteq I_{-}\). (2) Suppose \(V_i\neq0\), then there exists \(h \in H_{+} \cup H_{-}\), \(V_i^\top h > 0\).
Proof of Fact 3. (1) Otherwise, suppose \(j \in I_{x} \cap I_{-}\), since \(y=\frac{1}{m}\sum_{i=1}^{m}u_i\sigma(V_i^\top h_{Q,K}(x) ) > 0\), there has to be \(j' \in I_{x} \cap I_{+}\), which contradicts the condition in equation ?? . (2) Suppose \(v^\top h \le 0\) for all \(h \in H_{+} \cup H_{-}\). Then we have \(v^\top h = 0\) for all \(h\), since \(v^\top h < 0\) indicates \(v^\top (-h) > 0\), and \(-h\) belongs to the support of \(P\) due to the symmetry of the distribution. However, in Lemma 5, we show that the matrix stacking all input together has full row rank, thus \(v\) has to be \(0\), leading to a contradiction. ◻
We have the following lemma characterizing the solutions achieving all the qualities in Lemma 2. Intuitively, all the neurons can be divided into two sets, and each input can only activate neurons in one of the sets, leading to no cancellation between activated neurons. This holds because of equation ?? and the properties of the input distribution.
Lemma 3. Suppose \(Q,K,V\) satisfy the equality in Lemma 2. For all \(i\in I_{-}\), on downstream data \(x\), if \(g^*(x) = 1\), we have \(V_i^\top h_{Q,K}(x) = c_i>0\). \(c_i\) is a constant which holds for every \(x\) if \(g^*(x) = 1\). If \(g^*(x) = -1\), we have \(V_i^\top h_{Q,K}(x) = 0\).
For all \(i\in I_{+}\), on downstream data \(x\), if \(g^*(x) = -1\), we have \(V_i^\top h_{Q,K}(x) = c_i>0\). \(c_i\) is a constant which holds for every \(x\) if \(g^*(x) = 1\). If \(g^*(x) = 1\), we have \(V_i^\top h_{Q,K}(x) = 0\).
Now let us consider the downstream task. It suffices to consider the constant vector \(c\). If samples satisfying \(g^*(x)=1\) and \(g^*(x)=-1\) both show up in the downstream dataset, the minimal norm solution \(\tilde{u}\) is \(\tilde{u}_{I_{-}} = \frac{mc_{I_{-}}}{\left\lVert c_{I_{-}}\right\rVert_2^2}\), \(\tilde{u}_{I_{+}} = \frac{-mc_{I_{+}}}{\left\lVert c_{I_{+}}\right\rVert_2^2}\), and \(\tilde{u}_{[m]\backslash (I_{+}\cup I_{-})}=0\). Then we can verify that \[\begin{align} f_{\hat{\psi}, \tilde{u}}(x) = & \frac{1}{m}\left[\sum_{i \in I_{+}}\frac{-m c_i}{\left\lVert c_{I_{+}}\right\rVert_2^2} \sigma(V_i^\top h_{Q,K}(x)) + \sum_{i \in I_{-}}\frac{m c_i}{\left\lVert c_{I_{-}}\right\rVert_2^2} \sigma(V_i^\top h_{Q,K}(x))\right]\\ = & \frac{1}{m}\left[\sum_{i \in I_{+}}\frac{-m c_i}{\left\lVert c_{I_{+}}\right\rVert_2^2} c_i \mathbb{I}[g^*(x)= -1] + \sum_{i \in I_{-}}\frac{m c_i}{\left\lVert c_{I_{-}}\right\rVert_2^2} c_i\mathbb{I}[g^*(x) =1]\right]\\ =&\mathbb{I}[g^*(x) = 1]-\mathbb{I}[g^*(x) = -1]\\ =&g^*(x). \end{align}\] Therefore, \(L^{P_{\mathrm{ds}}}(\hat{\psi},\tilde{u}) = \mathrm{\mathbb{E}}_{x\sim P_{\mathrm{ds}}}[(f_{\hat{\psi},\tilde{u}}(x)-g^*(x))^2]=0\), which completes the proof. ◻
We first show that when the pre-training loss equals \(0\), the trace of Hessian equals the square of the norm of the gradient.
Lemma 4. For any parameters \(\theta\), if the pre-training loss \(L(\theta)=\mathrm{\mathbb{E}}_{x}[(f_{\theta}(x)-y)^2]=0\), the trace of Hessian equals the square of the norm of the gradient, \[\begin{align} \mathrm{Tr} [\nabla^2_\theta L(\theta)] = \mathrm{\mathbb{E}}[\left\lVert\nabla_\theta f_{\theta}(x)\right\rVert_2^2]. \end{align}\]
Proof of Lemma 4. We can express the Hessian as follows. \[\begin{align} \nabla^2_\theta L(\theta) =& \mathrm{\mathbb{E}}_x[\ell'(f_\theta(x),y)\nabla^2_\theta f_\theta(x)] + \mathrm{\mathbb{E}}_x[\frac{1}{2}\ell''(f_\theta(x),y)\nabla_\theta f_\theta(x)\nabla_\theta f_\theta(x)^\top]. \end{align}\] Since \(L(\theta)=\mathrm{\mathbb{E}}_{x}[(f_{\theta}(x)-y)^2]=0\), we have with probability \(1\), \(\ell'(f_\theta(x),y)=0\) and \(\ell''(f_\theta(x),y) = 2\) is a constant. ◻
Proof of Lemma 2. \[\begin{align} \mathrm{Tr}[\nabla^2_\psi L(\psi,u)] +& \mathrm{Tr}[\nabla^2_u L(\psi,u)] = \sum_{\theta \in [Q,K,V,u]}\mathrm{\mathbb{E}}[\left\lVert\nabla_\theta f_{\psi,u}(x)\right\rVert_2^2] }\nonumber\\ \ge& \mathrm{\mathbb{E}}[\left\lVert\nabla_V f_{\psi,u}(x)\right\rVert_2^2 + \left\lVert\nabla_u f_{\psi,u}(x)\right\rVert_2^2] \tag{2}\\ =& \frac{1}{m}\mathrm{\mathbb{E}}\left[\left\lVert\sigma({Vh_{Q,K}(x)})\right\rVert_2^2 + \left\lVert h_{Q,K}(x)(\mathbb{I}[Vh_{Q,K}(x)>0]\odot u)^\top\right\rVert_2^2\right] \nonumber\\ =& \frac{1}{m}\mathrm{\mathbb{E}}\left[\sum_{i=1}^{m}\sigma({V_i^\top h_{Q,K}(x)})^2 + \left\lVert h_{Q,K}(x)\right\rVert_2^2\mathbb{I}[V_i^\top h_{Q,K}(x)>0] u_i^2\right] \nonumber \\ \ge& \frac{2}{m} \mathrm{\mathbb{E}}\left[\sum_{i=1}^{m}\sigma({V_i^\top h_{Q,K}(x)}) \left\lVert h_{Q,K}(x)\right\rVert_2 |u_i|\right] \tag{3}\\ \ge& \frac{2}{m}\mathrm{\mathbb{E}}\left[\left\lVert h_{Q,K}(x)\right\rVert_2 \left|\sum_{i=1}^{m}\sigma({V_i^\top h_{Q,K}(x)})u_i\right|\right] \tag{4}\\ =& 2\mathrm{\mathbb{E}}\left[\left\lVert h_{Q,K}(x)\right\rVert_2|f_{\theta,u}(x)|\right] \nonumber\\ \ge& \sqrt{\frac{4}{T}} \tag{5}. \end{align}\] The equality in step 2 is achieved if and only if the gradient of \(Q\) and \(K\) is \(0\). Equation 3 is from AM-GM, and the equality is achieved iff \[\begin{align} V_i^\top h_{Q,K}(x) = |u_i|\left\lVert h_{Q,K}(x)\right\rVert_2 \quad \forall \;i\in[m], x\in\{x \mid V_i^\top h_{Q,K}(x) > 0\}. \end{align}\] The equality in step 4 is achieved iff on all input, there is no cancellation between activated neurons, \[\begin{align} \forall x,\;i\in I_{+},\;i'\in I_{-},\quad V_i^\top x V_{i'}^\top x \le 0. \end{align}\] Since the attention score \(a_j\) satisfies \(a_j>0\) and \(\sum_{j=1}^{T}a_j=1\), and all embeddings \(x_t\) in one masked sentence are orthogonal to each other with norm \(1\), we have \(\|h_{Q,K}(x)\|_2 \ge \frac{1}{\sqrt{T}}\). The equality is achieved iff \(a_j=\frac{1}{T}\) for all \(x\) and all \(j\in[T]\). ◻
Proof of Lemma 3 . Suppose \(V_i\) is a neuron with \(i \in I_{-}\). Then there exists \(h \in H_{-}\), \(V_i^\top h > 0\). Without loss of generality, suppose the masked position in \(h\) is \(1\), i.e. \(h_1 = 0\), \(h_2 = 1\). Now let us consider the components in \(V_i\) corresponding to the input positions and the mask positions separately. \(V_{i}^{(c)} = [V_{i,1},V_{i,2},\ldots,V_{i,T}]\) and \(V_{i}^{(p)} = [V_{i,T+1},V_{i,T+2},\ldots,V_{i,2T}]\).
We claim that \({V_i^{(c)}}_{2:T} = c \mathbf{1}\) for some \(c > 0\) and \({V_i^{(p)}}_{1}\) is either \(0\) or \(c\). To prove this, consider \(\tilde{h}\), which is only different from \(h\) on the mask, \(h - \tilde{h} = 2e_2\). Also consider \(-h\) and \(-\tilde{h}\). Due to the symmetry of the distribution, \(-h\) and \(-\tilde{h}\) are in \(H_{+}\). By Fact 3, \(V_i^\top (-h) \le 0\) and \(V_i^\top (-\tilde{h}) \le 0\). \(V_i^\top (-h)\) cannot be \(0\), because this will leads to \(V_i^\top h = 0\).
Case 1. \(V_i^\top (-h) < 0\) and \(V_i^\top (-\tilde{h}) < 0\). We have \(V_i^\top h = V_i^\top \tilde{h} > 0\), indicating that \(V_i^\top( h - \tilde{h}) = 2{V_i^{(p)}}_{1} = 0\). Now we show that \({V_i^{(c)}}_{2:T} = c\mathbf{1}\). Due to the condition of equation ?? , we know that for any \(h \in H_{-}\) masked on the first token, either \(V_i^\top h = 0\) or they equal to the same positive value \(c\) for all \(h\). We claim that \(V_i^\top h = c\) for any \(h \in H_{-}\). Otherwise there exist \(H_{-,1}\) and \(H_{-,0}\), \(H_{-,0} \cap H_{-,1} = \emptyset\) and \(H_{-,0} \cup H_{-,1} = H_{-}\cap\{h \mid h_2 = \pm 1\}\). \(V_i^\top h = c\) for any \(h \in H_{-,1}\) and \(V_i^\top h = 0\) for any \(h \in H_{-,0}\). This cannot happen for \(T\ge6\). By Lemma 5 we know that the matrix stacking all such \(h_{2:T}\) together has full row rank, thus \({V_i^{(c)}}_{2:T} = c \mathbf{1}\) for some \(c > 0\) and \({V_i^{(p)}}_{1}=0\).
Case 2. \(V_i^\top (-h) < 0\) and \(V_i^\top (-\tilde{h}) = 0\), which indicates \(V_i^\top h = {V_i^{(p)}}_{1}\). Consider another \(h'\in H_{-}\) which is not equal to \(h\) and \(h'_2 = 1\). Similarly we can find \(\tilde{h}'\), \(h' - \tilde{h}' = 2e_2\). Still we have \(V_i^\top (-h') < 0\) and \(V_i^\top (-\tilde{h}') = 0\), this tells us \(V_i^\top h' = V_i^\top h\), due to the condition of equation ?? . Applying this to different \(h'\)s, we have that \(V_i^\top h\) equals the same positive value for all \(h\in H_{-}\) and the masked position is \(0\). By Lemma 5 we know that the matrix stacking all such \(h_{2:T}\) together has full row rank, thus \({V_i^{(c)}}_{2:T} = c \mathbf{1}\) for some \(c > 0\) and \({V_i^{(p)}}_{1}=c\).
We have proved that \({V_i^{(c)}}_{2:T} = c \mathbf{1}\) for some \(c > 0\) and \({V_i^{(p)}}_{1}\) is either \(0\) or \(c\). We continue to show that \({V_i^{(c)}} = c\mathbf{1}\) for the same \(c > 0\) and either \({V_i^{(p)}}\) is \(0\) or its coordinates is \(\pm c\).
For case 1, consider \(h'' \in H_{-}\) whose masked position is \(2\), \(h''_4 = 1\). Also suppose that \(h''_1 = 1\) By Fact 3, we know that \(V_i^\top (-h'') \le 0\) and \(V_i^\top (-\tilde{h}'') \le 0\), this implies that \(-{V_i^{(c)}}_{1}\le {V_i^{(p)}}_2 \le{V_i^{(c)}}_{1}\). Applying the same argument above, we know that either \({V_i^{(p)}}_2 = 0\) or \({V_i^{(p)}}_2 = \pm {V_i^{(c)}}_{1}\), otherwise both \(V_i^\top h'' > 0\) and \(V_i^\top \tilde{h}'' > 0\) hold, and \(V_i^\top h'' \neq V_i^\top \tilde{h}''\), contradicting condition in equation ?? . If \({V_i^{(p)}}_2 = {V_i^{(c)}}_{1}\), from equation ?? we know \(V_i^\top h'' = V_i^\top h\), which indicates \({V_i^{(p)}}_2 = {V_i^{(c)}}_{1} = \frac{c}{2}\). In this case we can find another \(h'''\) whose masked position is \(2\), \(h'''_4 = 1\) but \(h'''_1 = -1\). Then \(V_i^\top h''' \neq V_i^\top h\), contradicting equation ?? . Thus \({V_i^{(p)}}_2 \neq {V_i^{(c)}}_{1}\). Similarly \({V_i^{(p)}}_2 \neq- {V_i^{(c)}}_{1}\). The only possible situation is \({V_i^{(p)}}_2 = 0\). Applying the argument in this paragraph to other masked position, we have \({V_i^{(p)}}=0\). Since \(H_{-}\) is invariant under permutation, \({V_i^{(c)}}_1 = c\), and \({V_i^{(c)}} = c\mathbf{1}\).
For case 2, exactly the same argument as the above paragraph with the same \(h''\) and \(h'''\) shows that the coordinates of \({V_i^{(p)}}\) is \(\pm c\).
Therefore, we have shown that for any \(i\in I_{-}\), \({V_i^{(c)}} = c\mathbf{1}\) for same \(c > 0\). The symmetry of distribution immediately tells us for any \(i\in I_{+}\), \({V_i^{(c)}} = c\mathbf{1}\) for \(c < 0\).
On the downstream distribution \(P_*\), since there is no masked token, only \({V_i^{(c)}}\) is working. Since \({V_i^{(c)}} = c\mathbf{1}\) always holds, we complete the proof. ◻
Lemma 5. Suppose \(M \in \mathbb{R}^{(2k+1)\times(2k+1)}\) is a matrix composed of \(\pm 1\). The first row of \(M\) is \([\underbrace{1,\ldots,1}_{\mathrm{k+1 1's}}, \underbrace{-1,\ldots,-1}_{\mathrm{k -1's}}]\). Define a permutation \(\rho(1) = 2,\;\rho(2) = 3\)...\(\rho(2k+1) = 1\). For all \(i\ge2\), \(M_{i,\rho(j)}= M_{i-1,j}\). Then the rank of \(M\) is \(2k+1\).
Proof of Lemma 5. Note that \(M_i+M_{\rho^{k+1}(i)}=2e_i\) for all \(i\in[2k+1]\), which means we can express the orthonormal basis as linear combination of the rows in \(M\). Therefore, the rank of \(M\) is \(2k+1\). ◻
Theorem 4. Suppose \(m\ge \tilde{O}(2^{T}T^3\epsilon^{-2})\), and \(V_i\sim\mathcal{N}(0,TI_{2T})\) for all \(i\in [m]\). With probability at least \(1-\delta\) over \(V\), there exists \(\psi', u'\), satisfying \(L(\psi', u')\le\epsilon\) and \(\|u'\|^2_2\le O(T^2\delta^{-1})\).
Proof of Theorem 4. Since the number of possible input in pre-training is finite, we can invoke Lemma 9 in [68] to show that random Gaussian features can fit the pre-training task.
Lemma 6 (Lemma 9 in [68]). Suppose \(\left\lVert h\right\rVert_2 = \sqrt{\frac{1}{T}}\), \(v \sim \mathcal{N}(0,TI_{2T})\). There exists a random variable \(a(v)\) such that \[\begin{align} \mathrm{\mathbb{E}}[\sigma(v^\top h)a] = -\sqrt{T}\mathbf{1}^\top h \end{align}\] and \(a\) satisfies \(\mathrm{\mathbb{E}}_v[a^2] = O(T^2)\).
Consider \(Q=K=0\). In this case we have \(h_{Q,K}(x) = \frac{1}{T}\sum_{j=1}^{T}x_j\). Also note that for the pre-training task, \(y=-\sqrt{T}\mathbf{1}^\top h_{Q,K}(x)\) for all \(x\). Since \(x_j\) are norm \(1\) orthogonal to each other, we have \(\left\lVert h_{Q,K}(x)\right\rVert_2=\frac{1}{T}\) for all \(x\). Now we can show that \(V_i \sim \mathcal{N}(0,TI_{2T})\), \(i\in[m]\) independently is the random feature solution which can solve the pre-training task.
Suppose \(g(h)=\frac{1}{m} \sum_{r=1}^m \sigma(V_r^\top h)a(V_r)\), and \(g_{(R)}(h) := \frac{1}{m} \sum_{r=1}^m \sigma(V_r^\top h)a(V_r)\mathbb{I}(\left\lVert V_r\right\rVert_2 \le \sqrt{T}R)\). \(R\) is large enough such that \(\Pr\left(\mathop{\sup}_{r\in [m]}\left\lVert V_r\right\rVert_2 \ge \sqrt{T}R\right) \ge 1 - \delta / 2\). We have \(g(h) = g_{(R)}(h)\) on this event. Let \(g^*_{(R)}(h)\) be the truncated version of \(g^*(h)=-\sqrt{T}\mathbf{1}^\top h\), \(g^*(h)_{(R)}=\mathrm{\mathbb{E}}_{v}[\sigma(v^\top h)a(v)\mathbb{I}(\left\lVert v\right\rVert_2 \le \sqrt{T}R)]\). We have \[\begin{align} \mathrm{\mathbb{E}}_{V}[(g(h) - g^*(h)_{(R)})] \le \frac{1}{m} \mathrm{\mathbb{E}}_{v} [\sigma(v^\top h)^2a(v)^2\mathbb{I}(\left\lVert v\right\rVert_2 \ge \sqrt{T}R)] \le C\frac{R^2T^2}{m}. \end{align}\] By Chebyshev and a union bound, we have \[\begin{align} \Pr\left(\max_h |g(h) - g^*(h)_{(R)}| \ge t\right) \le C\frac{n(h)R^2T^2}{mt^2}. \end{align}\] For \(t=\frac{\epsilon}{2}\), we have \(m\ge n(h)R^2T^2\epsilon^{-2}\). \[\begin{align} |g^*_{(R)}(h) - g^*(h)| =& \mathrm{\mathbb{E}}_{v}[\sigma(v^\top h)a(v)\mathbb{I}(\left\lVert v\right\rVert_2 \ge \sqrt{T}R)]\\ \le & \mathrm{\mathbb{E}}_{v}[a(v)^2]^\frac{1}{2} \mathrm{\mathbb{E}}_{v}[\sigma(v^\top h)^4]^\frac{1}{4}\Pr\left(\left\lVert v\right\rVert_2>\sqrt{T}R\right)^\frac{1}{4}\\ \le& C T \Pr\left(\left\lVert v\right\rVert>\sqrt{T}R\right)^\frac{1}{4}. \end{align}\] Choosing \(R=\tilde{O}(\sqrt(T))\) will make \(\Pr\left(\left\lVert v\right\rVert>\sqrt{T}R\right)^\frac{1}{4}\le\frac{c\epsilon}{T}\). Also note that \(n(h) = (T/2-1) {T \choose {T/2+1}}\). Thus \(m\ge\tilde{O}(2^{T}T^3\epsilon^{-2})\) suffices. ◻
For simplicity, we only consider masking out one one token in each sentence.↩︎
This is in contrast with typical supervised setting where the empirical 0-1 loss and cross-entropy loss can both achieve zero and consequently the mini-batch noise vanishes. Such a difference enables us to prove cleaner results (without the label noise) than in the supervised setting [13], [14].↩︎