Introduction
Multi-step reasoning enhances language model capabilities by generating intermediate steps before producing a final answer. Specifically, for an input x x x , a model f W f_W f W generates a reasoning sequence ( x , y ^ ( 1 ) , … , y ^ ( T ) ) (x, \hat{y}^{(1)}, \ldots, \hat{y}^{(T)}) ( x , y ^ ( 1 ) , … , y ^ ( T ) ) autoregressively. As the error in previous outputs propagates over the steps, this can destabilize long reasoning and cause severe final prediction errors [38 , 28 ] . However, standard training like supervised fine-tuning does not explicitly control this error accumulation. In this work, we theoretically analyze such error amplification across steps, aiming to identify the key factors governing reasoning stability and design training methods that control accumulated errors.
Understanding such error amplification is valuable in many practical problems, especially for scaling test-time computation [6 , 8 ] . One concrete setting is algorithmic reasoning, where models perform the step-by-step computation of classical algorithms like Bellman-Ford [20 ] . Models are expected to learn these underlying algorithms to generalize and extrapolate to larger, unseen inputs. However, a mistake in the early steps can corrupt the procedure. In our own experiments, we observe that the test error in a fine-tuned language model (e.g., Qwen-1.5B and Gemma-2B) can scale super-linearly with steps, as shown in Figure 1 a. Empirical methods, such as training models to generate fewer steps [5 ] or reason in the continuous feature space [10 ] , have been proposed to reduce these errors. Yet, the reason for their empirical benefits remains underexplored.
Figure 1. We present a bound on the inference loss in multi-step reasoning governed by the product of spectral norms of Jacobians taken through the input space across generation steps. Figure 1a: Our bound (equation (4) ) tracks the inference loss on the Bellman-Ford algorithmic reasoning task, showing that both can scale exponentially with steps. Figure 1b: We design a training method that regularizes the Jacobian spectral norms, which improves the test performance over baselines. Figure 1c: Models fine-tuned with our method exhibit drastically reduced Jacobian spectral norms.
Recent theoretical work has presented convergence and generalization guarantees of transformers trained on specific reasoning tasks, including linear regression [12 , 40 ] , state tracking [14 ] , and path-finding in trees [34 ] . Their analyses focus on the task-specific transformer structures, leaving open the general cases. Studies based on PAC learning theory [1 , 15 ] yield VC-dimension generalization bounds dependent on the entire hypothesis class. This motivates us to conduct a general analysis of multi-step reasoning with computable measures on data and fine-tuned models.
We begin by analyzing the inference error amplification of multi-step reasoning. Our key finding is that the inference loss is governed by the products of the spectral norms of Jacobians taken through the input space across generation steps, which control reasoning stability. The idea is to bound the gap between the T T T -step inference loss, ℓ ( f w ( [ x , y ^ ( 1 ) , … , y ^ ( T − 1 ) ] ) , y ( T ) ) \ell(f_w([x,\hat{y}^{(1)},\ldots,\hat{y}^{(T-1)}]),y^{(T)}) ℓ ( f w ([ x , y ^ ( 1 ) , … , y ^ ( T − 1 ) ]) , y ( T ) ) , and the training loss, ℓ ( f w ( [ x , y ( 1 ) , … , y ( T − 1 ) ] ) , y ( T ) ) \ell(f_w([x,y^{(1)},\ldots,y^{(T-1)}]),y^{(T)}) ℓ ( f w ([ x , y ( 1 ) , … , y ( T − 1 ) ]) , y ( T ) ) , conditioned on the correct steps. Using a first-order approximation in the input space, we show that the prediction errors at step i i i are propagated forward by the Jacobian matrix J i ( t ) J_i^{(t)} J i ( t ) (evaluated at the t t t -th step output to the input y ( i ) y^{(i)} y ( i ) ). Let ρ i ( T ) \rho_i^{(T)} ρ i ( T ) be the sum of products of ∥ J i ( t ) ∥ \lVert J_i^{(t)}\rVert ∥ J i ( t ) ∥ across all paths from step i i i to T T T . Then, recursively decomposing the errors yields a bound for the inference loss governed by ∑ i = 1 T − 1 ρ i ( T ) \sum_{i=1}^{T-1}\rho_i^{(T)} ∑ i = 1 T − 1 ρ i ( T ) (cf. Lemma 3.1 ), which we define as an error amplification factor. Empirically, this bound closely tracks the test losses on fine-tuned language models (including Qwen, Gemma, and Llama models), which can scale exponentially with T T T , as shown in Figure 1 a.
Next, we instantiate this bound by analyzing one-layer multi-head transformers trained on weight-prediction tasks for linear and quadratic functions. In both settings, we prove that the transformer converges to a solution where ∑ i = 1 T − 1 ρ i ( T ) \sum_{i=1}^{T-1}\rho_i^{(T)} ∑ i = 1 T − 1 ρ i ( T ) decays with T T T , with the spectral norm of the Jacobians evaluated at each step strictly less than one. Consequently, the trained transformer achieves a test loss of O ( 1 / poly ( d ) ) O(1/\operatorname{poly}(d)) O ( 1/ poly ( d )) with input dimension d d d and T = Θ ( log d ) T=\Theta(\log d) T = Θ ( log d ) steps (cf. Theorem 3.4 ). Extending prior work on linear functions [12 ] , our analysis for quadratic functions introduces a novel three-head transformer construction that exactly implements gradient descent (cf. Lemma 3.3), a finding that may be of independent interest.
Motivated by this analysis, we propose a training method to control accumulated error by regularizing the Jacobian-based error amplification factor. Our method incorporates chain-of-thought length compression that downsamples the reasoning steps during training, and quantization-aware training [18 , 19 ] that trains weights with gradients computed on the quantized model. We show that our method reduces the Jacobian spectral norms by regularizing the Hessian trace of the model loss during quantized training. We evaluate this method on five algorithmic reasoning tasks [20 ] and two state-tracking tasks from LEGO [39 ] . First, across all seven tasks, our method yields an average test accuracy improvement of 3.5% over baselines, including implicit chain-of-thought [5 ] and Coconut [10 ] , shown in Figure 1 b. Second, on evaluation of length generalization with larger inputs, our method enhances the test performance by 8.2% over baselines. Finally, ablation studies confirm that our method reduces the Jacobian-based error amplification factor by up to 8 × 8\times 8 × compared to existing methods, as shown in Figure 1 c. The code for replicating these empirical findings is available at https://github.com/VirtuosoResearch/Multi-step-reasoning-experiments.
Summary of contributions. First, our analysis reveals that the inference error in multi-step reasoning scales with the product of spectral norms of Jacobians taken through the input space. Second, we theoretically show that transformers trained on linear and quadratic functions converge to a regime where these norms are strictly less than one, yielding near-zero inference error. Finally, we propose a training method that regularizes these input Jacobian norms, empirically enhancing test performance and length generalization across diverse reasoning tasks.
Preliminaries
We now describe the problem setup for multi-step reasoning. Let X \mathcal{X} X denote the feature space. Let f W : X ∗ → X f_W : \mathcal{X}^{*} \to\mathcal{X} f W : X ∗ → X denote a next-token predictor with parameters W ∈ R p W \in\mathbb{R}^{p} W ∈ R p , such as a language model. f W f_W f W takes a sequence of vectors in X \mathcal{X} X of arbitrary length as input and outputs a single vector in X \mathcal{X} X , which is then appended to the sequence before the next prediction during inference.
For an input sequence x ∈ X ∗ \mathbf{x} \in\mathcal{X}^{*} x ∈ X ∗ , we assume that there exists an underlying rule generating a ground-truth sequence [ x , y ( 1 ) , … , y ( T ( x ) ) ] [\mathbf{x}, y^{(1)}, \ldots, y^{(T(\mathbf{x}))}] [ x , y ( 1 ) , … , y ( T ( x )) ] , where y ( t ) ∈ X y^{(t)} \in\mathcal{X} y ( t ) ∈ X is the ground-truth output at step t t t , and T ( x ) T(\mathbf{x}) T ( x ) denotes the total number of steps, which depends on the input x \mathbf{x} x . We denote the maximum number of steps as T T T for a particular task and bounded input lengths. As a concrete example, suppose x \mathbf{x} x contains a graph and a source node; then each y ( i ) y^{(i)} y ( i ) encodes an intermediate execution step of a graph traversal algorithm such as breadth-first search [20 ] .
At inference time, the model f W f_W f W generates T ( x ) T(\mathbf{x}) T ( x ) steps for an input x \mathbf{x} x autoregressively. We denote the prediction at step t t t as
y ^ ( t ) = f W ( [ x , y ^ ( 1 ) , … , y ^ ( t − 1 ) ] ) , with y ^ ( 1 ) = f W ( x ) . \hat{y}^{(t)} = f_W([\mathbf{x}, \hat{y}^{(1)}, \ldots, \hat{y}^{(t-1)}]), \text{ with } \hat{y}^{(1)} = f_W(\mathbf{x}). y ^ ( t ) = f W ([ x , y ^ ( 1 ) , … , y ^ ( t − 1 ) ]) , with y ^ ( 1 ) = f W ( x ) .
For simplicity of notation, we write the generated sequence after t t t steps as
z ^ ( t ) = [ x , y ^ ( 1 ) , … , y ^ ( t ) ] , with z ^ ( 0 ) = [ x ] . \hat{\mathbf{z}}^{(t)} = [\mathbf{x}, \hat{y}^{(1)}, \ldots, \hat{y}^{(t)}], \text{ with } \hat{\mathbf{z}}^{(0)} = [\mathbf{x}]. z ^ ( t ) = [ x , y ^ ( 1 ) , … , y ^ ( t ) ] , with z ^ ( 0 ) = [ x ] .
The corresponding ground-truth sequence with the correct intermediate steps is denoted as
z ( t ) = [ x , y ( 1 ) , … , y ( t ) ] , for t = 1 , … , T ( x ) , and z ( 0 ) = x . \mathbf{z}^{(t)} = [\mathbf{x}, y^{(1)}, \ldots, y^{(t)}], \text{ for } t = 1, \ldots, T(\mathbf{x}), \text{ and } \mathbf{z}^{(0)} = \mathbf{x}. z ( t ) = [ x , y ( 1 ) , … , y ( t ) ] , for t = 1 , … , T ( x ) , and z ( 0 ) = x .
During training, the model f W f_W f W predicts the next step conditioned on the preceding steps that encode the ground truth. Let S = { ( x i , y i ( 1 ) , … , y i ( T ( x i ) ) ) } i = 1 n S = \{(\mathbf{x}_i, y_i^{(1)}, \ldots, y_i^{(T(\mathbf{x}_i))})\}_{i=1}^{n} S = {( x i , y i ( 1 ) , … , y i ( T ( x i )) ) } i = 1 n denote a training dataset of n n n examples, where every x i \mathbf{x}_i x i is drawn independently from an unknown distribution D \mathcal{D} D . Given a loss function ℓ ( ⋅ , ⋅ ) \ell(\cdot,\cdot) ℓ ( ⋅ , ⋅ ) , the training loss is defined as:
L ^ ( f W ; S ) = 1 n ∑ i = 1 n ∑ t = 0 T ( x i ) − 1 ℓ ( f W ( z i ( t ) ) , y i ( t + 1 ) ) . (1) \hat{L}(f_W; S) = \frac{1}{n} \sum_{i=1}^{n} \sum_{t=0}^{T(\mathbf{x}_i)-1} \ell(f_W(\mathbf{z}_i^{(t)}), y_i^{(t+1)}). \tag*{(1)} L ^ ( f W ; S ) = n 1 i = 1 ∑ n t = 0 ∑ T ( x i ) − 1 ℓ ( f W ( z i ( t ) ) , y i ( t + 1 ) ) . (1)
At test time, the model predicts the next step conditioned on previous predictions. The outcome is evaluated by the loss function at the final step. We thus define this test loss over a random sample x \mathbf{x} x drawn from the data distribution D \mathcal{D} D as:
L ( f W ; D ) = E x ∼ D [ ℓ ( f W ( z ^ ( T ( x ) − 1 ) ) , y ( T ( x ) ) ) ] . (2) L(f_W; \mathcal{D}) = \mathbb{E}_{\mathbf{x}\sim\mathcal{D}}\left[\ell(f_W(\hat{\mathbf{z}}^{(T(\mathbf{x})-1)}), y^{(T(\mathbf{x}))})\right]. \tag*{(2)} L ( f W ; D ) = E x ∼ D [ ℓ ( f W ( z ^ ( T ( x ) − 1 ) ) , y ( T ( x )) ) ] . (2)
To be clear, we will call the above equation (2) the inference loss . At training time, minimizing equation (1) measures the loss relative to the ground truth. At inference time, the model assimilates prediction errors that occurred during previous steps back into the model. Thus, the prediction errors during inference can accumulate during long generation steps.
Problem statement. We quantify how inference loss accumulates throughout generation. We study conditions under which multi-step reasoning is stable, where the inference loss L ( f W ; D ) L(f_W; \mathcal{D}) L ( f W ; D ) remains bounded in long chains. Additionally, we design training algorithms to mitigate error accumulation and improve the stability of multi-step reasoning.
Notations. For any matrix X X X , let ∥ X ∥ \lVert X\rVert ∥ X ∥ denote the largest singular value (or spectral norm) of X X X . Let ∥ X ∥ F \lVert X\rVert_F ∥ X ∥ F denote the Frobenius norm of X X X . f ( N ) ≲ g ( N ) f(N) \lesssim g(N) f ( N ) ≲ g ( N ) indicates that there exists a fixed constant c c c that does not grow with N N N such that f ( N ) ≤ c ⋅ g ( N ) f(N) \leq c \cdot g(N) f ( N ) ≤ c ⋅ g ( N ) for large enough integers of N N N .
Theoretical Analysis
This section presents a theoretical analysis of multi-step reasoning in the above setup. First, we present a bound on the inference loss relative to the ground truth generation. We show that this bound depends on an error amplification factor defined by the product of spectral norms of Jacobian matrices measured at the input space. Second, we instantiate this bound in in-context prediction tasks for linear and quadratic functions. We show that transformer models converge to a regime where the error amplification factor decays across steps, thus yielding nearly zero inference loss.
Error Amplification in Multi-Step Reasoning
We now quantify how the inference loss accumulates across generation steps. We write the number of steps as T T T when the input is clear from the context. For an input x \mathbf{x} x , we compare the inference loss ℓ ( f W ( z ^ ( T − 1 ) ) , y ( T ) ) \ell(f_W(\hat{z}^{(T-1)}), y^{(T)}) ℓ ( f W ( z ^ ( T − 1 ) ) , y ( T ) ) of equation (2) with the loss ℓ ( f W ( z ( T − 1 ) ) , y ( T ) ) \ell(f_W(z^{(T-1)}), y^{(T)}) ℓ ( f W ( z ( T − 1 ) ) , y ( T ) ) of the prediction conditioned on the correct steps, which is what training minimizes in equation (1) .
To measure the difference, let e ( t ) ( x ) = f W ( z ( t − 1 ) ) − y ( t ) e^{(t)}(\mathbf{x}) = f_W(z^{(t-1)}) - y^{(t)} e ( t ) ( x ) = f W ( z ( t − 1 ) ) − y ( t ) and e ^ ( t ) ( x ) = f W ( z ^ ( t − 1 ) ) − y ( t ) \hat{e}^{(t)}(\mathbf{x}) = f_W(\hat{z}^{(t-1)}) - y^{(t)} e ^ ( t ) ( x ) = f W ( z ^ ( t − 1 ) ) − y ( t ) denote the prediction error at step t t t conditioned on the correct steps and on the model’s generations, respectively. Consider the first-order Taylor expansion in the input space, for every t t t ,
f W ( z ^ ( t − 1 ) ) − f W ( z ( t − 1 ) ) = ∑ i = 1 t − 1 J i ( t ) ( x ) e ^ ( i ) ( x ) + R ( t ) , where J i ( t ) ( x ) = ∂ f W ( z ( t − 1 ) ) ∂ y ( i ) f_W(\hat{z}^{(t-1)}) - f_W(z^{(t-1)}) = \sum_{i=1}^{t-1} J_i^{(t)}(\mathbf{x}) \hat{e}^{(i)}(\mathbf{x}) + \mathcal{R}^{(t)}, \quad\text{where } J_i^{(t)}(\mathbf{x}) = \frac{\partial f_W(z^{(t-1)})}{\partial y^{(i)}} f W ( z ^ ( t − 1 ) ) − f W ( z ( t − 1 ) ) = i = 1 ∑ t − 1 J i ( t ) ( x ) e ^ ( i ) ( x ) + R ( t ) , where J i ( t ) ( x ) = ∂ y ( i ) ∂ f W ( z ( t − 1 ) )
is the input Jacobian evaluated at step t t t , and R ( t ) \mathcal{R}^{(t)} R ( t ) is the second-order remainder error term. By recursively unrolling this expansion, an error at step i i i affects a later step t t t by first propagating to an intermediate step k k k and then from k k k to t t t . To capture the propagation path, we define a term:
ρ i ( t ) = sup x ∈ X ∗ ∥ J i ( t ) ( x ) ∥ + ∑ k = i + 1 t − 1 ( sup x ∈ X ∗ ∥ J k ( t ) ( x ) ∥ ⋅ ρ i ( k ) ) , with ρ t ( t ) = 1 , \rho_i^{(t)} = \sup_{\mathbf{x}\in\mathcal{X}^*} \lVert J_i^{(t)}(\mathbf{x})\rVert+ \sum_{k=i+1}^{t-1} \left(\sup_{\mathbf{x}\in\mathcal{X}^*} \lVert J_k^{(t)}(\mathbf{x})\rVert\cdot\rho_i^{(k)}\right), \quad\text{with } \rho_t^{(t)} = 1, ρ i ( t ) = x ∈ X ∗ sup ∥ J i ( t ) ( x )∥ + k = i + 1 ∑ t − 1 ( x ∈ X ∗ sup ∥ J k ( t ) ( x )∥ ⋅ ρ i ( k ) ) , with ρ t ( t ) = 1 ,
which sums, over all paths from i i i to t t t , the product of the spectral norms of the input Jacobians along the path. Therefore, an error at step t t t reaches the final step amplified by a factor ρ t ( T ) \rho_t^{(T)} ρ t ( T ) .
Our main result is to incorporate the spectral norm of Jacobians to quantify the accumulation of inference errors across generation steps. For every x \mathbf{x} x in the support of D \mathcal{D} D , we denote the maximum of the two errors, for t t t from 1 1 1 to T − 1 T-1 T − 1 , by
sup x ∈ X ∗ ∥ e ( t ) ( x ) ∥ = ε t , sup x ∈ X ∗ ∥ e ^ ( t ) ( x ) ∥ = r t . (3) \sup_{\mathbf{x}\in\mathcal{X}^*} \lVert e^{(t)}(\mathbf{x})\rVert= \varepsilon_t,\quad\sup_{\mathbf{x}\in\mathcal{X}^*} \lVert\hat{e}^{(t)}(\mathbf{x})\rVert= r_t. \tag*{(3)} x ∈ X ∗ sup ∥ e ( t ) ( x )∥ = ε t , x ∈ X ∗ sup ∥ e ^ ( t ) ( x )∥ = r t . (3)
We present a bound on the (expected) inference loss as follows.
Lemma 3.1. Suppose that f W f_W f W is twice differentiable with respect to its input, the loss function ℓ ( ⋅ , ⋅ ) \ell(\cdot,\cdot) ℓ ( ⋅ , ⋅ ) is C 1 C_1 C 1 -Lipschitz continuous in its first argument, and the Jacobian of f W f_W f W with respect to its input is C 2 C_2 C 2 -Lipschitz continuous. Let L ∗ ( f W ; D ) = E x ∼ D [ ℓ ( f W ( z ( T − 1 ) ) , y ( T ) ) ] L^*(f_W;\mathcal{D}) = \mathbb{E}_{\mathbf{x}\sim\mathcal{D}}\left[\ell(f_W(z^{(T-1)}), y^{(T)})\right] L ∗ ( f W ; D ) = E x ∼ D [ ℓ ( f W ( z ( T − 1 ) ) , y ( T ) ) ] be the expected loss at the final step of the model prediction conditioned on correct steps. Then, for any fixed W ∈ R p W\in\mathbb{R}^p W ∈ R p that satisfies these conditions, and under equation (3) , the inference loss is bounded away from the expected loss as follows:
∣ L ( f W ; D ) − L ∗ ( f W ; D ) ∣ ≤ C 1 ∑ t = 1 T − 1 ρ t ( T ) ε t + C 1 C 2 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 . (4) \left|L(f_W;\mathcal{D}) - L^*(f_W;\mathcal{D})\right| \leq C_1 \sum_{t=1}^{T-1}\rho_t^{(T)}\varepsilon_t + \frac{C_1C_2}{2}\sum_{t=2}^{T}\rho_t^{(T)}\left(\sum_{i=1}^{t-1}r_i\right)^2. \tag*{(4)} ∣ L ( f W ; D ) − L ∗ ( f W ; D ) ∣ ≤ C 1 t = 1 ∑ T − 1 ρ t ( T ) ε t + 2 C 1 C 2 t = 2 ∑ T ρ t ( T ) ( i = 1 ∑ t − 1 r i ) 2 . (4)
The proof involves a decomposition of the error between predictions on the model-generated sequence and the correct step sequence by applying the first-order expansion recursively. The full proof is in Appendix § 9 .§ 1 . Lemma 3.1 highlights that the inference loss is governed by ∑ i = 1 T − 1 ρ i ( T ) \sum_{i=1}^{T-1}\rho_i^{(T)} ∑ i = 1 T − 1 ρ i ( T ) , which we term an error amplification factor. Even if the training error is small, this factor can grow exponentially with T T T , resulting in large inference errors on long reasoning sequences.
Examples. To empirically verify our analysis, we study the scaling of inference losses on graph algorithmic reasoning tasks [20 ] . We fine-tune Qwen-1.5B, Llama-1B, and Gemma-2B models on tasks with graphs of 10 nodes. Inputs are text-based graph descriptions, and intermediate steps are encoded as node labels, such as the nodes along the shortest path. As a reasoning step in text-based datasets typically involves several tokens, we compute the loss, the ℓ 2 \ell_2 ℓ 2 error, and the Jacobian matrices token-by-token within a step, and then aggregate them over the tokens within one step.
For text-based reasoning tasks, we view X \mathcal{X} X as the continuous space of input embeddings. The output of f W f_W f W at step t t t is then the expected embedding of the predicted next token, calculated as the weighted average of all token embeddings based on their predicted softmax probabilities. We compute the Jacobian of the output vector with respect to the input embeddings. We estimate its spectral norm via power iteration using Jacobian-vector products. To approximate sup x ∥ J k ( T ) ∥ \sup_x \lVert J_k^{(T)} \rVert sup x ∥ J k ( T ) ∥ in equation (4) , we take the maximum norm across the dataset.
After minimizing the training loss, we measure the loss gap and the empirical values of our bound in equation (4) , for T T T ranging from 1 to 6. In Figure 2 , the inference loss increases significantly with the number of steps. Our bound, which involves ∑ i = 1 T − 1 ρ i ( T ) \sum_{i=1}^{T-1}\rho_i^{(T)} ∑ i = 1 T − 1 ρ i ( T ) , scales exponentially with T T T , closely tracking the growth in inference loss. We also observe similar results on Llama-1B and Gemma-2B models, which are described in Appendix § 10 . These results demonstrate that controlling input Jacobian norms during training is crucial for reducing accumulated errors in multi-step generation.
Figure 2. We illustrate the loss gap and our bound in equation (4) , which can scale exponentially across generation steps, tracking the growth of the inference loss. Results are evaluated on breadth-first search, Dijkstra, and Prim’s algorithm, using QWen-1.5B. The loss gap and the bound are plotted on separate axes; equation (4) is a worst-case bound and is numerically larger than the gap it bounds. Table 2 in Appendix § 10 reports the corresponding bound-to-gap ratios and constants.
Remark 3.2. Lemma 3.1 provides a worst-case upper bound that may not be numerically tight. Empirically, while we observe a consistent correlation between the bound values and inference losses across models, the numerical scales of the error amplification factor ∑ i = 1 T − 1 ρ i ( T ) \sum_{i=1}^{T-1}\rho_i^{(T)} ∑ i = 1 T − 1 ρ i ( T ) vary significantly. The bound-to-gap ratio is around 8 for Qwen-1.5B and around 10 5 10^5 1 0 5 –10 6 10^6 1 0 6 for Llama-1B and Gemma-2B. We report the empirical loss gap for the bound, the bound-to-gap ratio, both terms of equation (4) , and the estimated constants C 1 C_1 C 1 and C 2 C_2 C 2 , for every model in Appendix § 10 .
Learning Dynamics in Quadratic Models
Next, we explicitly instantiate the bound in Lemma 3.1 in training transformers on an in-context weight prediction task. We show that if the spectral norm of the input Jacobian matrix is less than one, the inference loss can be reduced close to zero.
Based on prior work on in-context learning [40 ] , we study a task that predicts the weight vector θ ∗ ∼ N ( 0 , I d ) \theta^* \sim\mathcal{N}(0,I_d) θ ∗ ∼ N ( 0 , I d ) of a function, given n n n examples ( x i , y i ) (x_i,y_i) ( x i , y i ) where x i ∼ N ( 0 , I d ) x_i \sim\mathcal{N}(0,I_d) x i ∼ N ( 0 , I d ) and y i = g θ ∗ ( x i ) y_i = g_{\theta^*}(x_i) y i = g θ ∗ ( x i ) for a known function g g g . We define the ground-truth steps as iterates by performing gradient descent on the regression examples
θ i + 1 = θ i − η n ∑ k = 1 n ∇ θ g θ i ( x k , y k ) . \theta_{i+1} = \theta_i - \frac{\eta}{n} \sum_{k=1}^{n} \nabla_{\theta} g_{\theta_i}(x_k, y_k). θ i + 1 = θ i − n η k = 1 ∑ n ∇ θ g θ i ( x k , y k ) .
with a learning rate η \eta η and an initialization θ 0 \theta_0 θ 0 .
We consider a one-layer transformer with h h h non-linear self-attention heads:
f W ( Z ) = Z [ : , − 1 ] + ∑ i = 1 h W P V i Z ⋅ ϕ i ( Z T W K Q i Z [ : , − 1 ] n ) , and Z = [ X 0 d ⋯ 0 d y 0 ⋯ 0 0 d × n θ 0 ⋯ θ i 0 1 ⋯ 1 ] , (5) f_W(Z) = Z_{[:, -1]} + \sum_{i=1}^{h} W^{PV_i} Z \cdot\phi_i\left(\frac{Z^{\mathsf{T}}W^{KQ_i}Z_{[:, -1]}}{n}\right), \text{ and } Z = \begin{bmatrix} X & 0_d & \cdots& 0_d \\ y & 0 & \cdots& 0 \\ 0_{d \times n} & \theta_0 & \cdots& \theta_i \\ 0 & 1 & \cdots& 1 \end{bmatrix}, \tag*{(5)} f W ( Z ) = Z [ : , − 1 ] + i = 1 ∑ h W P V i Z ⋅ ϕ i ( n Z T W K Q i Z [ : , − 1 ] ) , and Z = X y 0 d × n 0 0 d 0 θ 0 1 ⋯ ⋯ ⋯ ⋯ 0 d 0 θ i 1 , (5)
where Z ∈ R ( 2 d + 2 ) × ( n + i + 1 ) Z \in\mathbb{R}^{(2d+2)\times(n+i+1)} Z ∈ R ( 2 d + 2 ) × ( n + i + 1 ) is the input embedding, X = [ x 1 , … , x n ] X = [x_1,\ldots,x_n] X = [ x 1 , … , x n ] , and y = [ y 1 , … , y n ] y = [y_1,\ldots,y_n] y = [ y 1 , … , y n ] . The ones in the bottom are appended for formatting convenience. For step T T T , the last column contains the target vector θ ∗ \theta^* θ ∗ . Following prior work [12 , 14 , 34 ] , W P V i W^{PV_i} W P V i and W K Q i W^{KQ_i} W K Q i are the merged projection-value and key-query matrices, ϕ i \phi_i ϕ i is a non-linear function, and Z [ : , − 1 ] Z_{[:, -1]} Z [ : , − 1 ] denotes the last column. We use the squared loss for this setting.
Numerical example. We validate that the transformer can achieve near-zero inference loss in this setting, for both linear and quadratic function classes. The results are shown in Figure 3 . The inference loss converges to near-zero, with longer steps yielding lower inference loss.
Figure 3. We illustrate that, in training transformers on both linear and quadratic functions, the inference loss and the noise-perturbed loss converge close to zero, and become lower with longer steps. We set d = 10 d = 10 d = 10 and train a one-head linear transformer on linear functions (n = 20 n = 20 n = 20 , η = 0.4 \eta= 0.4 η = 0.4 ) and a three-head non-linear transformer on quadratic functions (n = 200 n = 200 n = 200 , η = 10 − 3 \eta= 10^{-3} η = 1 0 − 3 ). For the random Gaussian noise, we set σ = 0.002 \sigma= 0.002 σ = 0.002 . On the right, we consider a slightly different setting by first adding noise to the weights before computing the gradients.
We describe our main results. For linear functions y = θ T X y = \theta^{\mathsf{T}}X y = θ T X , we prove that the model exhibits inference loss of O ( 1 / poly ( d ) ) O(1/\operatorname{poly}(d)) O ( 1/ poly ( d )) with T = Θ ( log d ) T = \Theta(\log d) T = Θ ( log d ) . This is because the transformer converges to a solution where J i − 1 ( i ) ≈ I − 1 n X X T J_{i-1}^{(i)} \approx I - \frac{1}{n}XX^{\mathsf{T}} J i − 1 ( i ) ≈ I − n 1 X X T and ρ i ( T ) ≈ ∥ I − 1 n X X T ∥ T − i \rho_i^{(T)} \approx\left\lVert I - \frac{1}{n}XX^{\mathsf{T}}\right\rVert^{T-i} ρ i ( T ) ≈ I − n 1 X X T T − i . The accumulated errors form a converging geometric series. We present the complete proof in Appendix § 9 .§ 2 .
Next, we present results on quadratic functions y = ( θ T X ) ⊙ 2 y = (\theta^{\mathsf{T}}X)^{\odot2} y = ( θ T X ) ⊙ 2 , which represent a fundamental yet tractable setting for studying gradient descent dynamics [21 , 26 ] . We first establish that a three-head transformer can exactly implement the gradient update step using cubic and squared activations.
Lemma 3.3. There exist weight matrices { W P V h , W K Q h } h = 1 3 \{W^{PV_h}, W^{KQ_h}\}_{h=1}^{3} { W P V h , W K Q h } h = 1 3 and elementwise non-linear functions { ϕ h } h = 1 3 \{\phi_h\}_{h=1}^{3} { ϕ h } h = 1 3 , such that a three-head transformer f W ( Z ^ T − 1 ) f_W(\widehat{Z}_{T-1}) f W ( Z T − 1 ) outputs the T T T -step gradient descent solution with a learning rate η \eta η on the quadratic functions.
We then show that the transformer model converges to this construction during training, yielding near-zero inference loss.
Theorem 3.4. Let κ ∈ ( 0 , 1 / 24 ) \kappa\in(0,1/24) κ ∈ ( 0 , 1/24 ) , μ ∈ ( 0 , 4 ] \mu\in(0,4] μ ∈ ( 0 , 4 ] , and α 0 ∈ [ 3 / 4 , 1 ) \alpha_0 \in[3/4,1) α 0 ∈ [ 3/4 , 1 ) be the constants. Suppose n = Θ ( d 2 log 5 d ) n = \Theta(d^2 \log^5 d) n = Θ ( d 2 log 5 d ) , η = κ / d \eta= \kappa/d η = κ / d , θ 0 = α 0 θ ∗ \theta_0 = \alpha_0\theta^* θ 0 = α 0 θ ∗ , and T = ⌈ C log d ⌉ T = \lceil C \log d\rceil T = ⌈ C log d ⌉ for some C > 0 C > 0 C > 0 with a C > 1 aC > 1 a C > 1 for a = log ( 1 1 − μ η d ) a = \log\left(\frac{1}{1-\mu\eta d}\right) a = log ( 1 − μ η d 1 ) . There exists an initialization such that if we run gradient flow on the training loss, then after time t = O ( log d + log 1 ϵ 0 ) t = O\left(\log d + \log\frac{1}{\epsilon_0}\right) t = O ( log d + log ϵ 0 1 ) , for any ϵ 0 ≥ Θ ( log d d 2 a C − 1 ) \epsilon_0 \ge\Theta\left(\frac{\log d}{d^{2aC-1}}\right) ϵ 0 ≥ Θ ( d 2 a C − 1 l o g d ) , the trained transformer satisfies L ( f W ; D ) ≤ ϵ 1 L(f_W; \mathcal{D}) \le\epsilon_1 L ( f W ; D ) ≤ ϵ 1 for any ϵ 1 ∈ ( Θ ( d − 2 a C + 1 log d ) , 1 ) \epsilon_1 \in\left(\Theta\left(d^{-2aC+1}\log d\right),1\right) ϵ 1 ∈ ( Θ ( d − 2 a C + 1 log d ) , 1 ) .
The proof tracks an ordinary differential equation for the eigenvalues of the weight matrices. In the converged solution, we have
J i − 1 ( i ) ≈ I − 2 η n X D ( θ i ) X ⊤ and ρ i ( T ) ≈ ∥ I − 2 η n X D ( θ i ) X ⊤ ∥ T − i , J_{i-1}^{(i)} \approx I-\frac{2\eta}{n}XD(\theta_i)X^\top\quad\text{and}\quad\rho_i^{(T)} \approx\left\lVert I-\frac{2\eta}{n}XD(\theta_i)X^\top\right\rVert^{T-i}, J i − 1 ( i ) ≈ I − n 2 η X D ( θ i ) X ⊤ and ρ i ( T ) ≈ I − n 2 η X D ( θ i ) X ⊤ T − i ,
where D ( θ i ) = diag ( 3 ( X ⊤ θ i ) ⊙ 2 − ( X ⊤ θ ⋆ ) ⊙ 2 ) D(\theta_i)=\operatorname{diag}\left(3(X^\top\theta_i)^{\odot2}-(X^\top\theta^\star)^{\odot2}\right) D ( θ i ) = diag ( 3 ( X ⊤ θ i ) ⊙ 2 − ( X ⊤ θ ⋆ ) ⊙ 2 ) . Then, the accumulated errors again form a converging geometric series. We present the complete proof in Appendix § 9 .§ 3 .
Comparison with prior work. Prior analyses of transformers trained on multi-step reasoning differ from ours in their attention mechanisms, tasks, and tracked quantities. Previous works have examined one-head softmax attention on state-tracking tasks to demonstrate implicit biases and length generalization [13 , 14 ] . Huang et al. [12 ] study one-head linear attention on in-context linear regression, where the trained transformer implements multi-step gradient descent. Yang et al. [34 ] study multi-head softmax attention on tree path-finding, where different heads specialize and coordinate across subtasks. In contrast, we study multi-head non-linear attention on quadratic regression. We identify the explicit form of Jacobians taken through the inputs at each step at convergence and connect it with the stability of the inference loss.
Proposed Methods
Our analysis suggests two strategies to mitigate accumulated errors: reducing the sequence length to limit the error amplification factor ∑ t = 1 T − 1 ρ t ( T ) \sum_{t=1}^{T-1}\rho_t^{(T)} ∑ t = 1 T − 1 ρ t ( T ) and regularizing the input Jacobian spectral norms ∥ J i ( t ) ∥ \lVert J_i^{(t)}\rVert ∥ J i ( t ) ∥ . Motivated by these insights, we design a training method combining two techniques.
(1) Chain-of-thought length compression. First, we compress the reasoning sequence by subsampling intermediate steps. For a training example ( x , y ( 1 ) , … , y ( T ) ) (x,y^{(1)},\ldots,y^{(T)}) ( x , y ( 1 ) , … , y ( T ) ) and a sampling factor λ ∈ ( 0 , 1 ] \lambda\in(0,1] λ ∈ ( 0 , 1 ] , we uniformly sample T ′ = ⌊ λ ⋅ T ⌋ T'=\lfloor\lambda\cdot T\rfloor T ′ = ⌊ λ ⋅ T ⌋ intermediate steps to form a compressed sequence ( x , y ( 1 ) , … , y ( T ′ ) ) (x,y^{(1)},\ldots,y^{(T')}) ( x , y ( 1 ) , … , y ( T ′ ) ) , and minimize the training loss over the sampled sequence.
As shown in Figure 4 a and Figure 4 b, models trained on subsampled sequences consistently outperform those trained on full steps. Intermediate numbers of steps achieve the lowest inference loss on the Dijkstra and Prim tasks. Notably, subsampling steps reduces the error amplification factor by 92 × 92\times 92 × and 181 × 181\times 181 × compared to training with all steps. Subsampling steps reduces the amplification factor but increases the per-step errors ϵ t \epsilon_t ϵ t . Thus, the best λ \lambda λ is the one that balances these two effects.
Figure 4. Figure 4a and 4b: We show that the models trained with reduced intermediate steps yield lower inference losses than the model trained with longer steps. Correspondingly, the models exhibit lower Jacobian-based error amplification factors. Figure 4c and 4d: We show that quantization-aware training with lower bit-widths further reduces the Jacobian-based error amplification factors, yielding lower inference losses.
(2) Regularization through quantization-aware training. Second, we incorporate quantization during supervised fine-tuning to explicitly regularize the Jacobian spectral norms. This is inspired by observations that quantized training smooths the loss landscape and provides a regularization effect [18 , 19 ] . During the forward pass at training step t t t , we apply a standard uniform quantization function to the full-precision weights W ( t ) W^{(t)} W ( t ) :
Q ( W ( t ) ) = Δ ⋅ Round ( Clamp ( W ( t ) − b , W min , W max ) / Δ ) + b , Q(W^{(t)})=\Delta\cdot\operatorname{Round}\left(\operatorname{Clamp}(W^{(t)}-b,W_{\min},W_{\max})/\Delta\right)+b, Q ( W ( t ) ) = Δ ⋅ Round ( Clamp ( W ( t ) − b , W m i n , W m a x ) /Δ ) + b ,
where Δ \Delta Δ and b b b are bit-width-dependent scaling and bias parameters. We use the straight-through estimator [2 ] to approximate the gradient ∇ W L ^ ( f Q ( W ) ) ≈ ∇ Q ( W ) L ^ ( f Q ( W ) ) \nabla_W\hat{\mathcal{L}}(f_Q(W))\approx\nabla_Q(W)\hat{\mathcal{L}}(f_Q(W)) ∇ W L ^ ( f Q ( W )) ≈ ∇ Q ( W ) L ^ ( f Q ( W )) .
We hypothesize that quantization-aware training acts as a regularizer on the error amplification factor. Under the Pseudo-Quantization Noise model [31 , 9 ] , the quantized model loss can be viewed as the expected loss under mean-zero randomized-rounding noise. Minimizing this loss penalizes the trace of the loss Hessian, which can be decomposed into the Jacobians taken through the input space.
Figure 4 c and Figure 4 d demonstrate this regularization effect. Training with lower bit-widths yields a lower error amplification factor compared to full precision. When combining 1-bit quantization, ∑ t = 1 T − 1 ρ t ( T ) \sum_{t=1}^{T-1}\rho_t^{(T)} ∑ t = 1 T − 1 ρ t ( T ) is further reduced by 3.6 × 3.6\times 3.6 × and 5.8 × 5.8\times 5.8 × , compared to full precision, on the Dijkstra and Prim algorithmic tasks, respectively. We also observe that, while quantization increases the prediction error at each step, it reduces the error amplification factor much more significantly, thus leading to improved performance. We report evaluations under various bit-widths in Appendix § 10 . Taken together, we summarize our approach in Algorithm 1.
Remark 4.1 (Length generalization). For out-of-distribution settings, the test error bound from Lemma 3.1 can increase in two aspects. First, the per-step prediction errors grow due to covariate shift. Second, the error amplification factor accumulates over the additional steps. If the step-to-step Jacobian norm exceeds one, the extra steps multiply the error geometrically, making our regularization approach crucial. Designing training algorithms for length generalization is an interesting direction for future work, and our analysis lays a concrete direction for this.
Experiments
We evaluate our proposed method in a range of algorithmic reasoning tasks. First, our method outperforms baselines by an average of 3.5% across five graph algorithmic and two symbolic reasoning tasks. Second, our method significantly enhances out-of-distribution length generalization, yielding an average 8.2% improvement. Third, empirical analysis confirms that our approach reduces the error amplification factor (measured via Jacobian spectral norms) by up to 8× . Lastly, we also conduct ablation studies for various design choices of our algorithm.
Experimental Setup
Datasets and models. First, we evaluate our algorithm on graph algorithmic tasks from the CLRS-Text benchmark [20 ] , which encodes graphs as flattened adjacency lists and represents the intermediate steps as lists of node labels. We use five classic graph algorithms, including Dijkstra, Bellman-Ford, Prim’s algorithm, breadth-first search, and depth-first search. For each task, we use 2,000 training examples generated on random graphs of 10 nodes and 200 examples for validation and testing. Second, we evaluate on symbolic state-tracking reasoning tasks, namely LEGO [39 ] . We use two task variants: transitive (cyclic) and symmetry group actions. For each task, we use a dataset of 2,000 training examples with k = 8 k = 8 k = 8 variables, and 200 examples each for validation and testing. We evaluate our method in fine-tuning the Qwen-1.5B models.
Baselines. We compare our method with three categories of baselines. First, we consider standard fine-tuning baselines that train without or with the provided chain-of-thought sequences, namely No CoT and SFT-CoT. Second, we consider existing chain-of-thought methods. This includes implicit
Algorithm 1 Jacobian-Regularized Training through Length Compression and Quantization
Input: $n$ training examples with correct sequences $(x_i, y_i^{(1)}, \ldots, y_i^{(T)})$ of length $T$
Require: Pretrained language model $f_{W^{(0)}}$, number of epochs $S$, learning rate $\eta$, a sampling factor $\lambda$, quantization function $Q(\cdot)$
Output: Fine-tuned quantized model $f_{Q(W^{(S)})}$
1: for $t = 0, 1, \ldots, S - 1$ do
2: $(y_i^{(1)}, \ldots, y_i^{(T')}) \leftarrow$ Subsample $T' = \lfloor \lambda \cdot T \rfloor$ steps from example $i$, for $i = 1, \ldots, n$
3: $\hat{L}(f_{Q(W^{(t)})}) \leftarrow$ Compute the training loss of $f_{Q(W^{(t)})}$ on the sampled sequences
4: $W^{(t+1)} \leftarrow W^{(t)} - \eta \cdot \nabla_{Q(W^{(t)})}\hat{L}(f_{Q(W^{(t)})})$
5: end for
6: return $f_{Q(W^{(S)})}$
CoT [5 ] that trains a model to directly predict the final output by gradually removing intermediate steps during training, and the chain of continuous thought (Coconut) [10 ] that trains a model to reason in a continuous latent space by using the hidden state as the next input embedding. Third, we consider noise stability optimization (NSO) [37 ] that regularizes the Hessian trace through random Gaussian noise injection. For each baseline, we evaluate the test accuracy on the final answer.
Implementations. Our algorithm includes key hyperparameters: the sampling factor λ \lambda λ and the quantization bit-width. We vary λ \lambda λ across 0.1, 0.2, 0.5, and 1. The bit-width is varied across 1, 2, 3, and 4 bits. We use the quantization methods from existing methods [19 ] . For the base training method, we use LoRA fine-tuning with a rank between 16 and 64. The training uses the AdamW optimizer with a learning rate in the range of 1 × 10 − 5 1 \times10^{-5} 1 × 1 0 − 5 to 4 × 10 − 5 4 \times10^{-5} 4 × 1 0 − 5 . We report the hyperparameters used for each result in Appendix § 10 .
For the length generalization experiment, we additionally evaluate at 20% longer inputs on all five CLRS-Text tasks. Absolute accuracy degrades sharply for every method, falling below 25%. While our method still leads, at this accuracy level, the input-length bottleneck dominates. We therefore report the 10% setting as our main result. Further improving the length generalization on longer sequences is left for future work.
Experimental Results
Improved multi-step reasoning. Table 1 details the test accuracy of our fine-tuned models across seven reasoning datasets. Our method consistently outperforms all baselines, achieving an average improvement of 3.5% across five graph algorithmic and two symbolic state-tracking tasks. Specifically, by combining sequence compression with quantization-aware training, our algorithm surpasses latent-reasoning baselines (implicit reasoning and Coconut) by up to 6.5%.
Table 1. We report the test accuracy (%) of our method, as compared to supervised fine-tuning, implicit reasoning, and random noise injection. We evaluate five algorithmic reasoning tasks and two symbolic state-tracking reasoning tasks. For length generalization, models are evaluated on inputs 10% longer than the training sequences. All results are averaged over three random seeds.
Enhanced length generalization. Next, we evaluate the trained models on examples with 10% longer input length than training examples in the lower half of Table 1 . Our approach consistently exceeds baseline performance by an average of 8.2%, demonstrating its effectiveness in suppressing error amplification during extended generation.
Reduction of the error amplification factor. Finally, to explain these performance gains, we compare the empirical error amplification factors across methods. Our algorithm drastically reduces this factor by 3 3 3 –8 × 8\times 8 × compared to baselines, validating our method’s regularization on Jacobian spectral norms. Quantitatively, on Qwen-1.5B across the three tasks in Figure 1 c, our method reduces ∑ i = 1 T − 1 ρ i ( T ) \sum_{i=1}^{T-1}\rho_i^{(T)} ∑ i = 1 T − 1 ρ i ( T ) by 43% relative to baselines, with a 72% average reduction in the inference loss.
We further fine-tune Llama-1B and Gemma-2B on Bellman-Ford with SFT-CoT, Coconut, and Algorithm 1, and measure the full decomposition of equation (4) for each. We also find that the ordering of methods by bound value matches their ordering by empirical loss gap on both models. Relative to Coconut, our method reduces the bound by 77% and the empirical test loss gap by 58% on average. The absolute scale of the bound differs sharply between architectures. We report the full results in Table 4 of Appendix § 10 .
Table 4. The error amplification factor tracks the inference loss across base models. We fine-tune Llama-1B and Gemma-2B on Bellman-Ford (T = 5 T = 5 T = 5 ) and report both terms of equation (4) together with the estimated constants; columns are as in Table 2 . Within each model, the ranking of methods by our bound matches their ranking by the loss gap, even though the absolute scale of the bound differs by orders of magnitude between the two models.
Ablation studies. We evaluate the individual components of our method through ablation studies. First, removing either length compression or quantization-aware training degrades performance by 4.3% and 3.2%, confirming both are essential. Second, we compare intermediate step sampling strategies for length compression. We consider random sampling, removing the first, last, or equally spaced steps. Among them, random sampling yields slightly better performance and is thus adopted. Finally, we find that injecting quantization noise during training noticeably outperforms standard random Gaussian noise by 9%.
Related Work
Theoretical understanding of multi-step reasoning. Studying the training dynamics of transformers is key to understanding how multi-step reasoning improves generalization. Prior work analyzes single-head transformers trained on parity-check tasks [13 , 30 ] , and state tracking tasks [14 ] , while [34 ] studies multi-head specialization on path-finding in binary trees. For the in-context weight prediction task, [12 ] establishes convergence for linear targets using single-head linear transformers. We extend the analysis to nonlinear multi-head transformers and quadratic functions. Complementary theoretical analyses include entropy-calibration analyses of error accumulation in autoregressive generation [4 ] and information-theoretic frameworks that quantify per-step information gain in multi-step reasoning [28 ] .
Joshi et al. [15 ] study learning general function classes of next-token generators with CoTs in the realizable setting, showing that the sample complexity scales with the VC dimension of the hypothesis class and log ( T ) \log(T) log ( T ) of the CoT length T T T . Altabaa et al. [1 ] further improve the bound with a notion of CoT-information, which achieves faster rates than applying uniform convergence to training loss on chain-of-thought sequences.
Prior work has also examined the expressiveness of transformers with chain-of-thought. Li et al. [22 ] show that CoT enables transformers to perform computations beyond the expressiveness limits of models without CoT. Expressiveness has been further characterized through circuit complexity under logarithmic, linear, and polynomial generation lengths [25 ] . Increasing CoT length has been shown to outperform parallel scaling of multiple chains on graph connectivity tasks [27 ] .
Generalization of language models. Recent work derives generalization bounds for LLMs via compression and subspace training [23 , 24 ] , with tighter martingale-based extensions that explain empirical pretraining scaling laws [7 ] . A separate line of work derives PAC-Bayes bounds for fine-tuning that depend on the loss Hessian [17 , 16 ] .
Optimization methods for multi-step reasoning. Several recent works aim to improve multi-step reasoning beyond supervised fine-tuning. Yao et al. [35 ] frame this process as a latent-variable problem, minimizing gradient variance to efficiently allocate sampling budgets. A complementary line of work explores implicit reasoning. Implicit chain-of-thought [5 ] gradually removes intermediate steps to internalize computation. Continuous chain-of-thought [10 ] shifts reasoning into a continuous latent space. Semantic chain-of-thought [11 ] aligns implicit and explicit steps via contrastive learning. Empirically, Yeo et al. [36 ] investigate how long reasoning chains emerge in large language models, highlighting training computation and reward shaping as key factors. More broadly, multi-step reasoning traces also appear in experimental design settings [33 , 32 ] , where trajectory-level data is revealed over time.
Conclusion
This work provides an analysis of multi-step reasoning by bounding its inference errors via the product of input Jacobian spectral norms across generation steps. We prove that transformers trained for in-context weight prediction converge to a multi-head construction where this error amplification factor decays, achieving polynomially small test loss. We introduce a training method that explicitly controls this factor using reasoning length compression and quantization-aware training. Across seven algorithmic tasks, our approach consistently improves test accuracy and length generalization, with reduced empirical amplification factors in fine-tuned models.
Acknowledgement
This work received financial support from NSF award IIS-2412008 and a startup fund from Northeastern University. D. Li is supported in part by a JPMorgan Chase PhD Fellowship. Z. Zhang and M. Duan received additional financial support from Khoury PhD fellowships.
Complete Proofs
This appendix provides complete proofs for all theoretical results presented in the main paper. We organize the material in the following structure:
Appendix A.1 provides the full proof for Lemma 3.1 , establishing the error bound between the inference loss and the training loss in T T T -step generation. The proof is via a recursive expansion of the prediction error using first-order Taylor expansion. Then, we derive the bound via spectral norms of Jacobians taken through the input space.
Appendix A.2 establishes the error bounds and noise stability analysis for linear self-attention transformers trained on the weight prediction task for linear functions. We begin with preliminaries that reformulate the training and inference losses, then present the complete proof of Theorem A.5 (Section A.2.1), where standard Gaussian concentration bounds are cited and applied directly.
Appendix A.3 extends the analysis to nonlinear self-attention transformers trained on quadratic functions. We first describe the problem setup, then provide the explicit construction of a three-head transformer that implements gradient descent on quadratic losses (Section A.3.1). We derive the gradient dynamics under chain-of-thought training (Section A.3.2) and prove the convergence in Theorem 3.4 (Section A.3.3).
Notations. For any vector v v v , let ∥ v ∥ \lVert v\rVert ∥ v ∥ be the Euclidean norm of v v v . For any matrix X ∈ R m × n X \in\mathbb{R}^{m \times n} X ∈ R m × n , let ∥ X ∥ F \lVert X\rVert_{F} ∥ X ∥ F be the Frobenius norm and ∥ X ∥ 2 \lVert X\rVert_{2} ∥ X ∥ 2 be the spectral norm of X X X . If X X X is a square matrix, then the trace of X X X , Tr [ X ] \operatorname{Tr}[X] Tr [ X ] , equals the sum of X X X ’s diagonal entries.
For two functions f ( n ) f(n) f ( n ) and g ( n ) g(n) g ( n ) , we write g ( n ) = O ( f ( n ) ) g(n) = O(f(n)) g ( n ) = O ( f ( n )) if there exists a fixed value C C C that does not grow with n n n such that g ( n ) ≤ C ⋅ f ( n ) g(n) \le C \cdot f(n) g ( n ) ≤ C ⋅ f ( n ) when n n n is large enough. We write g ( n ) = Θ ( f ( n ) ) g(n) = \Theta(f(n)) g ( n ) = Θ ( f ( n )) if there exists a fixed value C 1 C_1 C 1 and C 2 C_2 C 2 that do not grow with n n n such that C 1 f ( n ) ≤ g ( n ) ≤ C 2 ⋅ f ( n ) C_1 f(n) \le g(n) \le C_2 \cdot f(n) C 1 f ( n ) ≤ g ( n ) ≤ C 2 ⋅ f ( n ) when n n n is large enough.
Proof of Lemma 3.1
In this section, we provide the full proof for Lemma 3.1 , which shows a bound on the gap between the inference loss and the true prediction loss conditioned on the ground truth.
For a given input x ∼ D x \sim\mathcal{D} x ∼ D , let y ( t ) y^{(t)} y ( t ) denote the ground-truth label at step t t t . We denote the model’s predictions under two regimes:
The prediction conditioned on the ground-truth preceding steps, as in the training loss, is denoted as f W ( z ( t − 1 ) ) f_W(z^{(t-1)}) f W ( z ( t − 1 ) ) .
The prediction based on t t t -step autoregressive generation in the inference loss is denoted as f W ( z ^ ( t − 1 ) ) f_W(\widehat{z}^{(t-1)}) f W ( z ( t − 1 ) ) .
We define their deviations from the label y ( t ) y^{(t)} y ( t ) at step t t t as e ( t ) ( x ) = f W ( z ( t − 1 ) ) − y ( t ) e^{(t)}(x) = f_W(z^{(t-1)}) - y^{(t)} e ( t ) ( x ) = f W ( z ( t − 1 ) ) − y ( t ) , and e ^ ( t ) ( x ) = f W ( z ^ ( t − 1 ) ) − y ( t ) \widehat{e}^{(t)}(x) = f_W(\widehat{z}^{(t-1)}) - y^{(t)} e ( t ) ( x ) = f W ( z ( t − 1 ) ) − y ( t ) . The prediction gap caused by autoregressive accumulation is
Δ ( t ) ( x ) = f W ( z ^ ( t − 1 ) ( x ) ) − f W ( z ( t − 1 ) ( x ) ) . \Delta^{(t)}(x) = f_W(\widehat{z}^{(t-1)}(x)) - f_W(z^{(t-1)}(x)). Δ ( t ) ( x ) = f W ( z ( t − 1 ) ( x )) − f W ( z ( t − 1 ) ( x )) .
By definition, we have the relation:
e ^ ( t ) ( x ) = e ( t ) ( x ) + Δ ( t ) ( x ) . \widehat{e}^{(t)}(x) = e^{(t)}(x) + \Delta^{(t)}(x). e ( t ) ( x ) = e ( t ) ( x ) + Δ ( t ) ( x ) .
For the Jacobian norms, we write ∥ J i ( t ) ∥ : = sup x ∈ X ∗ ∥ J i ( t ) ( x ) ∥ \lVert J_i^{(t)}\rVert:= \sup_{x \in\mathcal{X}^{*}}\lVert J_i^{(t)}(x)\rVert ∥ J i ( t ) ∥ := sup x ∈ X ∗ ∥ J i ( t ) ( x )∥ for the norm with the supremum taken, so that ρ i ( t ) = ∥ J i ( t ) ∥ + ∑ k = i + 1 t − 1 ∥ J k ( t ) ∥ ρ i ( k ) \rho_i^{(t)} = \lVert J_i^{(t)}\rVert+ \sum_{k=i+1}^{t-1}\lVert J_k^{(t)}\rVert\rho_i^{(k)} ρ i ( t ) = ∥ J i ( t ) ∥ + ∑ k = i + 1 t − 1 ∥ J k ( t ) ∥ ρ i ( k ) with ρ i ( t ) = 1 \rho_i^{(t)} = 1 ρ i ( t ) = 1 . Next, we present the complete proof of Lemma 3.1 , based on a recursive decomposition for Δ ( t ) ( x ) \Delta^{(t)}(x) Δ ( t ) ( x ) .
Proof of Lemma 3.1. First, we bound the loss gap via Lipschitz continuity. We evaluate the two losses at step T T T . By the assumption that the loss function ℓ ( ⋅ , ⋅ ) \ell(\cdot,\cdot) ℓ ( ⋅ , ⋅ ) is C 1 C_1 C 1 -Lipschitz continuous with respect to its first argument, the absolute gap between the inference loss and the reference loss for a specific input x x x is bounded by:
∣ ℓ ( f W ( z ^ ( T − 1 ) ( x ) ) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x ) ) , y ( T ) ) ∣ ≤ C 1 ∥ Δ ( T ) ( x ) ∥ . (6) \left|\ell\left(f_W(\widehat{z}^{(T-1)}(x)), y^{(T)}\right) - \ell\left(f_W(z^{(T-1)}(x)), y^{(T)}\right)\right| \le C_1\lVert\Delta^{(T)}(x)\rVert. \tag*{(6)} ℓ ( f W ( z ( T − 1 ) ( x )) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x )) , y ( T ) ) ≤ C 1 ∥ Δ ( T ) ( x )∥ . (6)
To bound the loss gap, we bound the norm of the final prediction gap ∥ Δ ( T ) ( x ) ∥ \lVert\Delta^{(T)}(\mathrm{x})\rVert ∥ Δ ( T ) ( x )∥ . We conduct a recursive expansion of the prediction gap ∥ Δ ( T ) ( x ) ∥ \lVert\Delta^{(T)}(\mathrm{x})\rVert ∥ Δ ( T ) ( x )∥ . At the base case of t = 1 t=1 t = 1 , both predictions rely solely on x \mathrm{x} x . Thus, Δ ( 1 ) ( x ) = 0 \Delta^{(1)}(\mathrm{x})=0 Δ ( 1 ) ( x ) = 0 and ∥ e ^ ( 1 ) ( x ) ∥ = ∥ e ( 1 ) ( x ) ∥ \lVert\widehat{e}^{(1)}(\mathrm{x})\rVert=\lVert e^{(1)}(\mathrm{x})\rVert ∥ e ( 1 ) ( x )∥ = ∥ e ( 1 ) ( x )∥ .
For an arbitrary step t > 1 t>1 t > 1 , we apply first-order Taylor’s expansion to expand the prediction on the generated prefix around the correct step sequence. Subtracting f W ( z ( t − 1 ) ( x ) ) f_W(z^{(t-1)}(\mathrm{x})) f W ( z ( t − 1 ) ( x )) from f W ( z ^ ( t − 1 ) ) f_W(\widehat{z}^{(t-1)}) f W ( z ( t − 1 ) ) , we obtain the prediction gap:
Δ ( t ) ( x ) = ∑ i = 1 t − 1 J i ( t ) ( x ) e ( i ) ( x ) + R ( t ) ( x ) , (7) \Delta^{(t)}(\mathrm{x})=\sum_{i=1}^{t-1}J_i^{(t)}(\mathrm{x})e^{(i)}(\mathrm{x})+\mathcal{R}^{(t)}(\mathrm{x}), \tag*{(7)} Δ ( t ) ( x ) = i = 1 ∑ t − 1 J i ( t ) ( x ) e ( i ) ( x ) + R ( t ) ( x ) , (7)
where J i ( t ) ( x ) J_i^{(t)}(\mathrm{x}) J i ( t ) ( x ) is the step-to-step Jacobian evaluated at the ground-truth context, and R ( t ) ( x ) \mathcal{R}^{(t)}(\mathrm{x}) R ( t ) ( x ) is the higher-order Taylor remainder.
Under the assumption that the Jacobian of f W f_W f W is C 2 C_2 C 2 -Lipschitz continuous, the norm of the remainder R ( t ) ( x ) \mathcal{R}^{(t)}(\mathrm{x}) R ( t ) ( x ) is bounded by a quadratic function of the input deviation, based on the mean value theorem:
∥ R ( t ) ( x ) ∥ ≤ C 2 2 ( ∑ i = 1 t − 1 ∥ e ( i ) ( x ) ∥ ) 2 ≤ C 2 2 ( ∑ i = 1 t − 1 r i ) 2 , (8) \lVert\mathcal{R}^{(t)}(\mathrm{x})\rVert\leq\frac{C_2}{2}\left(\sum_{i=1}^{t-1}\lVert e^{(i)}(\mathrm{x})\rVert\right)^2\leq\frac{C_2}{2}\left(\sum_{i=1}^{t-1}r_i\right)^2, \tag*{(8)} ∥ R ( t ) ( x )∥ ≤ 2 C 2 ( i = 1 ∑ t − 1 ∥ e ( i ) ( x )∥ ) 2 ≤ 2 C 2 ( i = 1 ∑ t − 1 r i ) 2 , (8)
based on equation (3) (with R ( 1 ) ( x ) = 0 \mathcal{R}^{(1)}(\mathrm{x})=0 R ( 1 ) ( x ) = 0 ). Applying the triangle inequality to equation (7) , we have:
∥ Δ ( t ) ( x ) ∥ ≤ ∑ i = 1 t − 1 ∥ J i ( t ) ∥ ∥ e ( i ) ( x ) ∥ + ∥ R ( t ) ( x ) ∥ . (9) \lVert\Delta^{(t)}(\mathrm{x})\rVert\leq\sum_{i=1}^{t-1}\lVert J_i^{(t)}\rVert\lVert e^{(i)}(\mathrm{x})\rVert+\lVert\mathcal{R}^{(t)}(\mathrm{x})\rVert. \tag*{(9)} ∥ Δ ( t ) ( x )∥ ≤ i = 1 ∑ t − 1 ∥ J i ( t ) ∥ ∥ e ( i ) ( x )∥ + ∥ R ( t ) ( x )∥ . (9)
Using e ^ ( t ) ( x ) = e ( t ) ( x ) + Δ ( t ) ( x ) \widehat{e}^{(t)}(\mathrm{x})=e^{(t)}(\mathrm{x})+\Delta^{(t)}(\mathrm{x}) e ( t ) ( x ) = e ( t ) ( x ) + Δ ( t ) ( x ) and applying the triangle inequality, the inference error norm is bounded by:
∥ e ^ ( t ) ( x ) ∥ ≤ ∥ e ( t ) ( x ) ∥ + ∥ Δ ( t ) ( x ) ∥ . \lVert\widehat{e}^{(t)}(\mathrm{x})\rVert\leq\lVert e^{(t)}(\mathrm{x})\rVert+\lVert\Delta^{(t)}(\mathrm{x})\rVert. ∥ e ( t ) ( x )∥ ≤ ∥ e ( t ) ( x )∥ + ∥ Δ ( t ) ( x )∥ .
Substituting equation (9) above yields the full recurrence relation for the inference error:
∥ e ^ ( t ) ( x ) ∥ ≤ s t ( x ) + ∑ i = 1 t − 1 ∥ J i ( t ) ∥ ∥ e ^ ( i ) ( x ) ∥ , where s t ( x ) : = ∥ e ( t ) ( x ) ∥ + ∥ R ( t ) ( x ) ∥ . (10) \lVert\widehat{e}^{(t)}(\mathrm{x})\rVert\leq s_t(\mathrm{x})+\sum_{i=1}^{t-1}\lVert J_i^{(t)}\rVert\lVert\widehat{e}^{(i)}(\mathrm{x})\rVert,\quad\text{where }s_t(\mathrm{x}):=\lVert e^{(t)}(\mathrm{x})\rVert+\lVert\mathcal{R}^{(t)}(\mathrm{x})\rVert. \tag*{(10)} ∥ e ( t ) ( x )∥ ≤ s t ( x ) + i = 1 ∑ t − 1 ∥ J i ( t ) ∥ ∥ e ( i ) ( x )∥ , where s t ( x ) := ∥ e ( t ) ( x )∥ + ∥ R ( t ) ( x )∥ . (10)
To solve this recurrence, we recursively expand ∥ e ^ ( i ) ( x ) ∥ \lVert\widehat{e}^{(i)}(\mathrm{x})\rVert ∥ e ( i ) ( x )∥ in s i ( x ) s_i(\mathrm{x}) s i ( x ) . The first-order components become a sum of all possible directed step-to-step paths. The product of the Jacobian spectral norms along these paths forms the cumulative amplification factor ρ i ( t ) \rho_i^{(t)} ρ i ( t ) , defined recursively as:
ρ i ( t ) = sup x ∈ X ∗ ∥ J i ( t ) ( x ) ∥ + ∑ k = i + 1 t − 1 ( sup x ∈ X ∗ ∥ J k ( t ) ( x ) ∥ ⋅ ρ i ( k ) ) , with ρ t ( t ) = 1. \rho_i^{(t)}=\sup_{\mathrm{x}\in\mathcal{X}^*}\lVert J_i^{(t)}(\mathrm{x})\rVert+\sum_{k=i+1}^{t-1}\left(\sup_{\mathrm{x}\in\mathcal{X}^*}\lVert J_k^{(t)}(\mathrm{x})\rVert\cdot\rho_i^{(k)}\right),\quad\text{with }\rho_t^{(t)}=1. ρ i ( t ) = x ∈ X ∗ sup ∥ J i ( t ) ( x )∥ + k = i + 1 ∑ t − 1 ( x ∈ X ∗ sup ∥ J k ( t ) ( x )∥ ⋅ ρ i ( k ) ) , with ρ t ( t ) = 1.
Formally, we show that
∥ e ^ ( t ) ( x ) ∥ ≤ ∑ i = 1 t ρ i ( t ) s i ( x ) , for every t ≥ 1 , (11) \lVert\widehat{e}^{(t)}(\mathrm{x})\rVert\leq\sum_{i=1}^{t}\rho_i^{(t)}s_i(\mathrm{x}),\quad\text{for every }t\geq1, \tag*{(11)} ∥ e ( t ) ( x )∥ ≤ i = 1 ∑ t ρ i ( t ) s i ( x ) , for every t ≥ 1 , (11)
which holds at t = 1 t=1 t = 1 by the base case. Assuming equation (11) up to step t − 1 t-1 t − 1 , substituting it into equation (10) , we have
∥ e ^ ( t ) ( x ) ∥ ≤ s t ( x ) + ∑ k = 1 t − 1 ( ∑ i = k t − 1 ∥ J i ( t ) ∥ ρ k ( i ) ) s k ( x ) ≤ s t ( x ) + ∑ k = 1 t − 1 ( ∥ J k ( t ) ∥ ρ k ( k ) + ∑ i = k + 1 t − 1 ∥ J i ( t ) ∥ ρ k ( i ) ) s k ( x ) ≤ s t ( x ) + ∑ k = 1 t − 1 ρ k ( t ) s k ( x ) . (12) \begin{aligned}
\lVert\widehat{e}^{(t)}(\mathrm{x})\rVert\leq s_t(\mathrm{x})+\sum_{k=1}^{t-1}\left(\sum_{i=k}^{t-1}\lVert J_i^{(t)}\rVert\rho_k^{(i)}\right)s_k(\mathrm{x}) \\
&\leq s_t(\mathrm{x})+\sum_{k=1}^{t-1}\left(\lVert J_k^{(t)}\rVert\rho_k^{(k)}+\sum_{i=k+1}^{t-1}\lVert J_i^{(t)}\rVert\rho_k^{(i)}\right)s_k(\mathrm{x}) \\
&\leq s_t(\mathrm{x})+\sum_{k=1}^{t-1}\rho_k^{(t)}s_k(\mathrm{x}). \tag*{(12)}
\end{aligned} ∥ e ( t ) ( x )∥ ≤ s t ( x ) + k = 1 ∑ t − 1 ( i = k ∑ t − 1 ∥ J i ( t ) ∥ ρ k ( i ) ) s k ( x ) ≤ s t ( x ) + k = 1 ∑ t − 1 ( ∥ J k ( t ) ∥ ρ k ( k ) + i = k + 1 ∑ t − 1 ∥ J i ( t ) ∥ ρ k ( i ) ) s k ( x ) ≤ s t ( x ) + k = 1 ∑ t − 1 ρ k ( t ) s k ( x ) . (12)
which completes the induction. By replacing ρ i ( T ) \rho_i^{(T)} ρ i ( T ) and carrying each remainder to step T T T by its own factor ρ t ( T ) \rho_t^{(T)} ρ t ( T ) , the final prediction gap at step T T T is bounded by:
∥ Δ ( T ) ( x ) ∥ ≤ ∑ i = 1 T − 1 ρ i ( T ) ∥ e ( i ) ( x ) ∥ + ∑ t = 2 T ρ t ( T ) ∥ R ( t ) ( x ) ∥ . (13) \lVert\Delta^{(T)}(\mathrm{x}) \rVert\le\sum_{i=1}^{T-1} \rho_i^{(T)} \lVert e^{(i)}(\mathrm{x}) \rVert+ \sum_{t=2}^{T} \rho_t^{(T)} \lVert\mathcal{R}^{(t)}(\mathrm{x}) \rVert. \tag*{(13)} ∥ Δ ( T ) ( x )∥ ≤ i = 1 ∑ T − 1 ρ i ( T ) ∥ e ( i ) ( x )∥ + t = 2 ∑ T ρ t ( T ) ∥ R ( t ) ( x )∥ . (13)
Substituting equation (13) into equation (6) , we obtain:
∣ ℓ ( f W ( z ^ ( T − 1 ) ( x ) ) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x ) ) , y ( T ) ) ∣ ≤ C 1 ∑ i = 1 T − 1 ρ i ( T ) ∥ e ( i ) ( x ) ∥ + C 1 ∑ t = 2 T ρ t ( T ) ∥ R ( t ) ( x ) ∥ . (14) \left\lvert\ell(f_W(\hat{\mathrm{z}}^{(T-1)}(\mathrm{x})), y^{(T)}) - \ell(f_W(\mathrm{z}^{(T-1)}(\mathrm{x})), y^{(T)}) \right\rvert
\le C_1 \sum_{i=1}^{T-1} \rho_i^{(T)} \lVert e^{(i)}(\mathrm{x}) \rVert+ C_1 \sum_{t=2}^{T} \rho_t^{(T)} \lVert\mathcal{R}^{(t)}(\mathrm{x}) \rVert. \tag*{(14)} ℓ ( f W ( z ^ ( T − 1 ) ( x )) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x )) , y ( T ) ) ≤ C 1 i = 1 ∑ T − 1 ρ i ( T ) ∥ e ( i ) ( x )∥ + C 1 t = 2 ∑ T ρ t ( T ) ∥ R ( t ) ( x )∥ . (14)
For every x \mathrm{x} x in the support of D \mathcal{D} D , recall from equation (3) that ∥ e ( i ) ( x ) ∥ ≤ ε i \lVert e^{(i)}(\mathrm{x}) \rVert\le\varepsilon_i ∥ e ( i ) ( x )∥ ≤ ε i and ∥ R ( t ) ( x ) ∥ ≤ C 2 2 ( ∑ i < t r i ) 2 \lVert\mathcal{R}^{(t)}(\mathrm{x}) \rVert\le\frac{C_2}{2}\left(\sum_{i<t} r_i\right)^2 ∥ R ( t ) ( x )∥ ≤ 2 C 2 ( ∑ i < t r i ) 2 from equation (8) , we have
∣ ℓ ( f W ( z ^ ( T − 1 ) ( x ) ) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x ) ) , y ( T ) ) ∣ ≤ C 1 ∑ i = 1 T − 1 ρ i ( T ) ε i + C 1 C 2 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 . (15) \left\lvert\ell(f_W(\hat{\mathrm{z}}^{(T-1)}(\mathrm{x})), y^{(T)}) - \ell(f_W(\mathrm{z}^{(T-1)}(\mathrm{x})), y^{(T)}) \right\rvert
\le C_1 \sum_{i=1}^{T-1} \rho_i^{(T)} \varepsilon_i + \frac{C_1 C_2}{2}\sum_{t=2}^{T} \rho_t^{(T)}\left(\sum_{i=1}^{t-1}r_i\right)^2 . \tag*{(15)} ℓ ( f W ( z ^ ( T − 1 ) ( x )) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x )) , y ( T ) ) ≤ C 1 i = 1 ∑ T − 1 ρ i ( T ) ε i + 2 C 1 C 2 t = 2 ∑ T ρ t ( T ) ( i = 1 ∑ t − 1 r i ) 2 . (15)
Taking the expectation over the data distribution x ∼ D \mathrm{x} \sim\mathcal{D} x ∼ D , we have
∣ L ( f W ; D ) − L ⋆ ( f W ; D ) ∣ ≤ E x ∼ D [ ∣ ℓ ( f W ( z ^ ( T − 1 ) ( x ) ) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x ) ) , y ( T ) ) ∣ ] ≤ E x ∼ D [ ∣ ℓ ( f W ( z ^ ( T − 1 ) ( x ) ) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x ) ) , y ( T ) ) ∣ ] ≤ C 1 ∑ i = 1 T − 1 ρ i ( T ) ε i + C 1 C 2 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 , (16) \left\lvert L(f_W;\mathcal{D})-L^\star(f_W;\mathcal{D})\right\rvert
\le\mathbb{E}_{\mathrm{x}\sim\mathcal{D}}\left[\left\lvert\ell(f_W(\hat{\mathrm{z}}^{(T-1)}(\mathrm{x})),y^{(T)})-\ell(f_W(\mathrm{z}^{(T-1)}(\mathrm{x})),y^{(T)})\right\rvert\right]
\le\mathbb{E}_{\mathrm{x}\sim\mathcal{D}}\left[\left\lvert\ell(f_W(\hat{\mathrm{z}}^{(T-1)}(\mathrm{x})),y^{(T)})-\ell(f_W(\mathrm{z}^{(T-1)}(\mathrm{x})),y^{(T)})\right\rvert\right]
\le C_1\sum_{i=1}^{T-1}\rho_i^{(T)}\varepsilon_i+\frac{C_1C_2}{2}\sum_{t=2}^{T}\rho_t^{(T)}\left(\sum_{i=1}^{t-1}r_i\right)^2, \tag*{(16)} ∣ L ( f W ; D ) − L ⋆ ( f W ; D ) ∣ ≤ E x ∼ D [ ℓ ( f W ( z ^ ( T − 1 ) ( x )) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x )) , y ( T ) ) ] ≤ E x ∼ D [ ℓ ( f W ( z ^ ( T − 1 ) ( x )) , y ( T ) ) − ℓ ( f W ( z ( T − 1 ) ( x )) , y ( T ) ) ] ≤ C 1 i = 1 ∑ T − 1 ρ i ( T ) ε i + 2 C 1 C 2 t = 2 ∑ T ρ t ( T ) ( i = 1 ∑ t − 1 r i ) 2 , (16)
which completes the proof of equation (4) .
Proof for the Linear Case
We study the inference loss of a one-layer linear self-attention transformer trained to predict weight vectors of linear functions. Following the setup in § 3.2 , we describe the in-context weight prediction task with linear functions. The weight vector is θ ⋆ ∼ N ( 0 , I d ) \theta^\star\sim\mathcal{N}(0,I_d) θ ⋆ ∼ N ( 0 , I d ) , and the n n n in-context examples are x j ∼ N ( 0 , I d ) x_j \sim\mathcal{N}(0,I_d) x j ∼ N ( 0 , I d ) with labels y j = ⟨ θ ⋆ , x j ⟩ y_j=\langle\theta^\star,x_j\rangle y j = ⟨ θ ⋆ , x j ⟩ for j ∈ [ n ] j\in[n] j ∈ [ n ] , all independent. We write X = [ x 1 , … , x n ] ∈ R d × n X=[x_1,\ldots,x_n]\in\mathbb{R}^{d\times n} X = [ x 1 , … , x n ] ∈ R d × n , y = [ y 1 , … , y n ] = θ ⋆ ⊤ X y=[y_1,\ldots,y_n]=\theta^{\star\top}X y = [ y 1 , … , y n ] = θ ⋆ ⊤ X , and S : = 1 n X X ⊤ S:=\frac{1}{n}XX^\top S := n 1 X X ⊤ . The chain of thought consists of the gradient descent iterates on the squared loss on average over n n n examples with learning rate η \eta η , started at θ 0 = 0 d \theta_0=0_d θ 0 = 0 d :
θ i + 1 = θ i − η S ( θ i − θ ⋆ ) , so that θ i = ( I − ( I − η S ) i ) θ ⋆ for i ≥ 0. (17) \theta_{i+1}=\theta_i-\eta S(\theta_i-\theta^\star),\quad\text{so that}\quad\theta_i=\left(I-(I-\eta S)^i\right)\theta^\star\quad\text{for }i\ge0. \tag*{(17)} θ i + 1 = θ i − η S ( θ i − θ ⋆ ) , so that θ i = ( I − ( I − η S ) i ) θ ⋆ for i ≥ 0. (17)
With d e = 2 d + 2 d_e=2d+2 d e = 2 d + 2 , the input that contains the correct steps θ 0 , … , θ i \theta_0,\ldots,\theta_i θ 0 , … , θ i is
Z i = [ X 0 d 0 d ⋯ 0 d y 0 0 ⋯ 0 0 d × n θ 0 θ 1 ⋯ θ i 0 1 × n 1 1 ⋯ 1 ] ∈ R d e × ( n + i + 1 ) . Z_i=
\begin{bmatrix}
X & 0_d & 0_d & \cdots& 0_d\\
y & 0 & 0 & \cdots& 0\\
0_{d\times n} & \theta_0 & \theta_1 & \cdots& \theta_i\\
0_{1\times n} & 1 & 1 & \cdots& 1
\end{bmatrix}
\in\mathbb{R}^{d_e\times(n+i+1)}. Z i = X y 0 d × n 0 1 × n 0 d 0 θ 0 1 0 d 0 θ 1 1 ⋯ ⋯ ⋯ ⋯ 0 d 0 θ i 1 ∈ R d e × ( n + i + 1 ) .
The label of step i + 1 i+1 i + 1 is θ ˉ i + 1 : = θ i + 1 \bar{\theta}_{i+1}:=\theta_{i+1} θ ˉ i + 1 := θ i + 1 for i ≤ T − 2 i\le T-2 i ≤ T − 2 , and the label of the final step is θ ˉ T : = θ ⋆ \bar{\theta}_T:=\theta^\star θ ˉ T := θ ⋆ .
We first rewrite the training and inference losses. During training, the network is trained to predict the next iterate given the preceding ground-truth sequences. We consider the gradient flow dynamics over the population loss:
L C o T ( f W ) = E X , θ ⋆ [ 1 2 ∑ i = 0 T − 1 ∥ f W ( Z i ) − ( 0 d , 0 , θ ˉ i + 1 , 1 ) ∥ 2 ] . L^{\mathrm{CoT}}(f_W)=\mathbb{E}_{X,\theta^\star}\left[\frac{1}{2}\sum_{i=0}^{T-1}\left\lVert f_W(Z_i)-(0_d,0,\bar{\theta}_{i+1},1)\right\rVert^2\right]. L CoT ( f W ) = E X , θ ⋆ [ 2 1 i = 0 ∑ T − 1 f W ( Z i ) − ( 0 d , 0 , θ ˉ i + 1 , 1 ) 2 ] .
At inference time, we apply the model to generate T T T steps before it outputs the final prediction. Starting from Z 0 Z_0 Z 0 , we define the model prediction at each step as Z ^ i + 1 = [ Z ^ i , f W ( Z ^ i ) ] \widehat{Z}_{i+1} = [\widehat{Z}_i, f_W(\widehat{Z}_i)] Z i + 1 = [ Z i , f W ( Z i )] , for i = 0 , 1 , … , T − 1 i = 0,1,\ldots,T-1 i = 0 , 1 , … , T − 1 , where the last column of Z ^ i \widehat{Z}_i Z i encodes the estimate θ ^ i \widehat{\theta}_i θ i , and θ ^ 0 = θ 0 \widehat{\theta}_0 = \theta_0 θ 0 = θ 0 . Then, the inference loss, in equation (2) , with the squared loss, can be written as:
L ( f W ; D ) = E X , θ ⋆ [ 1 2 ∥ f W ( Z ^ T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) ∥ 2 2 ] . (18) L(f_W;\mathcal{D}) = \mathbb{E}_{X,\theta^\star}\left[\frac{1}{2}\left\|f_W(\widehat{Z}_{T-1})-(0_d,0,\theta^\star,1)\right\|_2^2\right]. \tag*{(18)} L ( f W ; D ) = E X , θ ⋆ [ 2 1 f W ( Z T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) 2 2 ] . (18)
For linear functions, we consider a one-layer linear self-attention transformer with a residual connection. Given an input embedding matrix Z ∈ R d e × m Z \in\mathbb{R}^{d_e \times m} Z ∈ R d e × m of length m m m , we denote
f W ( Z ) = Z [ : , − 1 ] + W P V Z ⋅ Z ⊤ W K Q Z [ : , − 1 ] n . (19) f_W(Z)=Z_{[:, -1]}+W^{PV}Z\cdot\frac{Z^\top W^{KQ}Z_{[:, -1]}}{n}. \tag*{(19)} f W ( Z ) = Z [ : , − 1 ] + W P V Z ⋅ n Z ⊤ W K Q Z [ : , − 1 ] . (19)
We denote W P V ∈ R d e × d e W^{PV}\in\mathbb{R}^{d_e\times d_e} W P V ∈ R d e × d e as the weight matrix that merges the projection and value matrix, and W K Q ∈ R d e × d e W^{KQ}\in\mathbb{R}^{d_e\times d_e} W K Q ∈ R d e × d e is the weight matrix that merges the key and query matrix. [ : , − 1 ] [:, -1] [ : , − 1 ] indicates taking the last column of the matrix. n n n is the number of in-context examples.
Next, we state results from the previous paper [12 ] , which we will reuse in our statements. Under Assumption A.1, prior work [12 ] proves that, if we initialize the weight matrices with the block structure in Assumption A.1, the blocks that are initialized with 0 will remain 0 along the gradient flow trajectory. The initialization method is specified as follows to zero out the irrelevant blocks.
Assumption A.1 (Initialization). Let σ 0 > 0 \sigma_0 > 0 σ 0 > 0 be a constant. We assume the parameters are initialized as
W P V ( 0 ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 1 × 1 0 1 × d 0 1 × 1 W 31 P V ( 0 ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 1 × 1 0 1 × d 0 1 × 1 ] , W K Q ( 0 ) = [ 0 d × d 0 d × 1 W 13 K Q ( 0 ) 0 d × 1 0 1 × d 0 1 × 1 0 1 × d W 24 K Q 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 1 × 1 0 1 × d 0 1 × 1 ] . W^{PV}(0)=\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0_{1\times1} & 0_{1\times d} & 0_{1\times1}\\
W^{PV}_{31}(0) & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0_{1\times1} & 0_{1\times d} & 0_{1\times1}
\end{bmatrix},\quad
W^{KQ}(0)=\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & W^{KQ}_{13}(0) & 0_{d\times1}\\
0_{1\times d} & 0_{1\times1} & 0_{1\times d} & W^{KQ}_{24}\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0_{1\times1} & 0_{1\times d} & 0_{1\times1}
\end{bmatrix}. W P V ( 0 ) = 0 d × d 0 1 × d W 31 P V ( 0 ) 0 1 × d 0 d × 1 0 1 × 1 0 d × 1 0 1 × 1 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 1 × 1 0 d × 1 0 1 × 1 , W K Q ( 0 ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 1 × 1 0 d × 1 0 1 × 1 W 13 K Q ( 0 ) 0 1 × d 0 d × d 0 1 × d 0 d × 1 W 24 K Q 0 d × 1 0 1 × 1 . Here, W 31 P V ( 0 ) = ∑ i = 1 d λ i P V u i u i ⊤ W^{PV}_{31}(0)=\sum_{i=1}^{d}\lambda_i^{PV}u_i u_i^\top W 31 P V ( 0 ) = ∑ i = 1 d λ i P V u i u i ⊤ and W 13 K Q ( 0 ) = ∑ i = 1 d λ i K Q u i u i ⊤ W^{KQ}_{13}(0)=\sum_{i=1}^{d}\lambda_i^{KQ}u_i u_i^\top W 13 K Q ( 0 ) = ∑ i = 1 d λ i K Q u i u i ⊤ , where { u i } i = 1 d \{u_i\}_{i=1}^{d} { u i } i = 1 d is an orthonormal basis. The matrices W 31 P V ( 0 ) W^{PV}_{31}(0) W 31 P V ( 0 ) and W 13 K Q ( 0 ) W^{KQ}_{13}(0) W 13 K Q ( 0 ) are symmetric and simultaneously diagonalizable, with eigenvalues satisfying λ i P V ≤ − σ 0 \lambda_i^{PV}\leq-\sigma_0 λ i P V ≤ − σ 0 , λ i K Q ∈ [ σ 0 , 1 / 2 ] \lambda_i^{KQ}\in[\sigma_0,1/2] λ i K Q ∈ [ σ 0 , 1/2 ] , and for all i ∈ [ d ] i\in[d] i ∈ [ d ] . Finally, we fix W 24 K Q = − 1 W^{KQ}_{24}=-1 W 24 K Q = − 1 for all t ≥ 0 t\geq0 t ≥ 0 .
Lemma A.2 (Block-wise invariance under gradient flow [12 ] ). Under Assumption A.1, consider the gradient flow on the population CoT loss as
d W d t = − ∇ L C o T ( W ) . \frac{dW}{dt}=-\nabla L^{\mathrm{CoT}}(W). d t d W = − ∇ L CoT ( W ) . Then, for all t ≥ 0 t\geq0 t ≥ 0 , the parameters W P V ( t ) , W K Q ( t ) W^{PV}(t),W^{KQ}(t) W P V ( t ) , W K Q ( t ) take the following form:
W P V ( t ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 1 × d 0 W 31 P V ( t ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 1 × d 0 ] , W K Q ( t ) = [ 0 d × d 0 d × 1 W 13 K Q ( t ) 0 d × 1 0 1 × d 0 0 1 × d W 24 K Q 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 1 × d 0 ] . W^{PV}(t)=\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{1\times d} & 0\\
W^{PV}_{31}(t) & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{1\times d} & 0
\end{bmatrix},\quad
W^{KQ}(t)=\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & W^{KQ}_{13}(t) & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{1\times d} & W^{KQ}_{24}\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{1\times d} & 0
\end{bmatrix}. W P V ( t ) = 0 d × d 0 1 × d W 31 P V ( t ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 , W K Q ( t ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q ( t ) 0 1 × d 0 d × d 0 1 × d 0 d × 1 W 24 K Q 0 d × 1 0 .
Then, we can rewrite the linear self-attention model only in terms of W 31 P V W^{PV}_{31} W 31 P V and W 13 K Q W^{KQ}_{13} W 13 K Q .
Definition A.3 (Reduced transformer). Define S : = 1 n X X ⊤ S:=\frac{1}{n}XX^\top S := n 1 X X ⊤ . Under Assumption A.1, for a given input Z i Z_i Z i , we can rewrite the linear self-attention model by
f W ( Z i ) = [ 0 d , 0 , ( θ i + W 31 P V S ( W 13 K Q θ i − θ ⋆ ) ) , 1 ] ⊤ . f_W(Z_i)=\left[0_d,0,\left(\theta_i+W^{PV}_{31}S(W^{KQ}_{13}\theta_i-\theta^\star)\right),1\right]^\top. f W ( Z i ) = [ 0 d , 0 , ( θ i + W 31 P V S ( W 13 K Q θ i − θ ⋆ ) ) , 1 ] ⊤ . where θ i \theta_i θ i is the last column of Z i [ d + 1 : 2 d + 1 , − 1 ] Z_i[d+1:2d+1,-1] Z i [ d + 1 : 2 d + 1 , − 1 ] and θ ⋆ \theta^\star θ ⋆ is the ground-truth weights of the linear function. Then, we can denote a reduced model by:
f ~ W ( Z i ) = θ i + W 31 P V S ( W 13 K Q θ i − θ ⋆ ) . \widetilde{f}_W(Z_i)=\theta_i+W^{PV}_{31}S(W^{KQ}_{13}\theta_i-\theta^\star). f W ( Z i ) = θ i + W 31 P V S ( W 13 K Q θ i − θ ⋆ ) .
The right-hand side depends on Z i Z_i Z i only through its last column. The same formula holds for the inputs during inference Z ^ i \widehat{Z}_i Z i . Below, we write f ~ W ( θ ) : = θ + W 31 P V S ( W 13 K Q θ − θ ⋆ ) \widetilde{f}_W(\theta):=\theta+W_{31}^{PV}S(W_{13}^{KQ}\theta-\theta^\star) f W ( θ ) := θ + W 31 P V S ( W 13 K Q θ − θ ⋆ ) for θ ∈ R d \theta\in\mathbb{R}^d θ ∈ R d , with X X X and θ ⋆ \theta^\star θ ⋆ fixed. This map is affine, and its Jacobian is given by
J : = ∂ f ~ W ( θ ) ∂ θ = I + W 31 P V S W 13 K Q , (20) J:=\frac{\partial\widetilde{f}_W(\theta)}{\partial\theta}=I+W_{31}^{PV}SW_{13}^{KQ}, \tag*{(20)} J := ∂ θ ∂ f W ( θ ) = I + W 31 P V S W 13 K Q , (20)
which does not depend on θ \theta θ .
Theorem A.4 (Global convergence [12 ] ). Suppose n = Θ ( d log 5 d ) n=\Theta(d\log^5d) n = Θ ( d log 5 d ) , η ∈ ( 0.1 , 0.9 ) \eta\in(0.1,0.9) η ∈ ( 0.1 , 0.9 ) , T = ⌈ c log d ⌉ T=\lceil c\log d\rceil T = ⌈ c log d ⌉ , and c log ( 1 1 − η ) > 2 c\log\left(\frac{1}{1-\eta}\right)>2 c log ( 1 − η 1 ) > 2 . Under Assumption A.1 with σ 0 > 3 ( 1 − η ) ( 2 − η ) T \sigma_0>\frac{3(1-\eta)}{(2-\eta)T} σ 0 > ( 2 − η ) T 3 ( 1 − η ) , if we run gradient flow on the population loss L C o T ( f W ) L^{\mathrm{CoT}}(f_W) L CoT ( f W ) , then after time t = O ( log d + log 1 ϵ ) t=O\left(\log d+\log\frac{1}{\epsilon}\right) t = O ( log d + log ϵ 1 ) , for any ϵ ≥ Θ ( log d d c log ( 1 1 − η ) − 2 ) \epsilon\geq\Theta\left(\frac{\log d}{d^{c\log\left(\frac{1}{1-\eta}\right)-2}}\right) ϵ ≥ Θ ( d c l o g ( 1 − η 1 ) − 2 l o g d ) , we have L C o T ( f W ( t ) ) ≤ ϵ L^{\mathrm{CoT}}(f_W(t))\leq\epsilon L CoT ( f W ( t )) ≤ ϵ . Moreover, there exist matrices A A A and B B B , with ∥ A ∥ o p , ∥ B ∥ o p ≤ Θ ( d − 1 2 c log ( 1 1 − η ) + 1 2 ) \lVert A\rVert_{\mathrm{op}},\lVert B\rVert_{\mathrm{op}}\leq\Theta\left(d^{-\frac{1}{2}c\log\left(\frac{1}{1-\eta}\right)+\frac{1}{2}}\right) ∥ A ∥ op , ∥ B ∥ op ≤ Θ ( d − 2 1 c l o g ( 1 − η 1 ) + 2 1 ) , such that W 31 P V ( t ) = ( − η I + A ) W_{31}^{PV}(t)=(-\eta I+A) W 31 P V ( t ) = ( − η I + A ) and W 13 K Q ( t ) = ( I + B ) W_{13}^{KQ}(t)=(I+B) W 13 K Q ( t ) = ( I + B ) .
We state Theorem A.5, which is the main result for the linear case.
Theorem A.5 (Slightly adapted from [12 ] ). Suppose n = Θ ( d log 5 d ) n=\Theta(d\log^5d) n = Θ ( d log 5 d ) , η ∈ ( 0.1 , 0.9 ) \eta\in(0.1,0.9) η ∈ ( 0.1 , 0.9 ) , and T = ⌈ c log d ⌉ T=\lceil c\log d\rceil T = ⌈ c log d ⌉ , with c log ( 1 1 − η ) > 2 c\log\left(\frac{1}{1-\eta}\right)>2 c log ( 1 − η 1 ) > 2 . Under the initialization in Assumption A.1 with σ 0 > 3 ( 1 − η ) ( 2 − η ) T \sigma_0>\frac{3(1-\eta)}{(2-\eta)T} σ 0 > ( 2 − η ) T 3 ( 1 − η ) , if we run gradient flow on the population loss L C o T ( f W ) L^{\mathrm{CoT}}(f_W) L CoT ( f W ) , after time t = O ( log d + log 1 ϵ 0 ) t=O\left(\log d+\log\frac{1}{\epsilon_0}\right) t = O ( log d + log ϵ 0 1 ) , for any ϵ 0 = Θ ( log d d c log ( 1 1 − η ) − 2 ) \epsilon_0=\Theta\left(\frac{\log d}{d^{c\log\left(\frac{1}{1-\eta}\right)-2}}\right) ϵ 0 = Θ ( d c l o g ( 1 − η 1 ) − 2 l o g d ) , we have L ( f W ; D ) ≤ ϵ 1 L(f_W;\mathcal{D})\leq\epsilon_1 L ( f W ; D ) ≤ ϵ 1 , for any ϵ 1 ∈ Θ ( ( ( d − c log ( 1 1 − η ) + 2 log d ) , 1 ) ) \epsilon_1\in\Theta\left(\left((d^{-c\log\left(\frac{1}{1-\eta}\right)+2\log d}),1\right)\right) ϵ 1 ∈ Θ ( ( ( d − c l o g ( 1 − η 1 ) + 2 l o g d ) , 1 ) ) .
Proof of Theorem A.5
Next, we prove the bounds on inference loss and the noise stability measure of the linear self-attention model on the weight prediction task. Recall that, to evaluate the inference loss, we apply the model f W f_W f W to generate T T T steps before it outputs the final prediction. Starting from the input Z 0 Z_0 Z 0 , we denote the model’s generated output at step i i i (also serves as the model input at step i + 1 i+1 i + 1 ) as follows:
Z ^ i + 1 ( W ) : = [ Z ^ i ( W ) , f W ( Z ^ i ( W ) ) ] , i = 0 , 1 , … , T − 1 , \widehat{Z}_{i+1}(W):=[\widehat{Z}_i(W),f_W(\widehat{Z}_i(W))],\qquad i=0,1,\ldots,T-1, Z i + 1 ( W ) := [ Z i ( W ) , f W ( Z i ( W ))] , i = 0 , 1 , … , T − 1 ,
where we denote Z ^ 0 : = Z 0 \widehat{Z}_0:=Z_0 Z 0 := Z 0 . Then, we denote the last column of Z ^ i ( W ) \widehat{Z}_i(W) Z i ( W ) as z ^ i ( W ) : = Z ^ i ( W ) [ : , − 1 ] \widehat{z}_i(W):=\widehat{Z}_i(W)[:, -1] z i ( W ) := Z i ( W ) [ : , − 1 ] and θ ^ i ( W ) : = Z ^ i ( W ) [ d + 1 : 2 d + 1 , − 1 ] \widehat{\theta}_i(W):=\widehat{Z}_i(W)[d+1:2d+1,-1] θ i ( W ) := Z i ( W ) [ d + 1 : 2 d + 1 , − 1 ] . We can write down the block structure of Z ^ i \widehat{Z}_i Z i as
Z ^ i ( W ) = [ X 0 d 0 d ⋯ 0 d y 0 0 ⋯ 0 0 d × n θ 0 θ ^ 1 ( W ) ⋯ θ ^ i ( W ) 0 1 × n 1 1 ⋯ 1 ] . \widehat{Z}_i(W)=
\begin{bmatrix}
X & 0_d & 0_d & \cdots& 0_d\\
y & 0 & 0 & \cdots& 0\\
0_{d\times n} & \theta_0 & \widehat{\theta}_1(W) & \cdots& \widehat{\theta}_i(W)\\
0_{1\times n} & 1 & 1 & \cdots& 1
\end{bmatrix}. Z i ( W ) = X y 0 d × n 0 1 × n 0 d 0 θ 0 1 0 d 0 θ 1 ( W ) 1 ⋯ ⋯ ⋯ ⋯ 0 d 0 θ i ( W ) 1 .
Correspondingly, we denote the ground-truth input with i i i intermediate steps as Z i Z_i Z i , θ i \theta_i θ i as ground-truth weight iterates, and we denote the final label by z T : = ( 0 d , 0 , θ ⋆ , 1 ) z_T:=(0_d,0,\theta^\star,1) z T := ( 0 d , 0 , θ ⋆ , 1 ) . When W W W is fixed, we write θ ^ i \widehat{\theta}_i θ i for θ ^ i ( W ) \widehat{\theta}_i(W) θ i ( W ) .
Proof of Theorem A.5. We will first write the inference error as a sum of prediction errors at each step, each carried to the final step by a power of the Jacobian of the trained transformer. This is a case of Lemma 3.1 , where the Jacobian becomes a single matrix J J J , and the second-order remainder is zero. The inference loss is therefore small once J J J is contractive. At convergence, we will show that J J J is close to the Jacobian I − η S I-\eta S I − η S , whose norm ∥ J ∥ 2 < 1 \lVert J\rVert_2<1 ∥ J ∥ 2 < 1 , and the errors are small, which yields the rate for the inference loss.
Let W = W ( t ) W=W(t) W = W ( t ) be the trained weights at time t t t given by Theorem A.4 . By Definition A.3 , we have the simplified form of the transformer:
θ ^ i = f ~ W ( θ ^ i − 1 ) = θ ^ i − 1 + W 31 P V S ( W 13 K Q θ ^ i − 1 − θ ⋆ ) , \widehat{\theta}_i=\widetilde{f}_W(\widehat{\theta}_{i-1})=\widehat{\theta}_{i-1}+W_{31}^{PV}S(W_{13}^{KQ}\widehat{\theta}_{i-1}-\theta^\star), θ i = f W ( θ i − 1 ) = θ i − 1 + W 31 P V S ( W 13 K Q θ i − 1 − θ ⋆ ) ,
for i = 1 , … , T i=1,\ldots,T i = 1 , … , T , and θ ^ T \widehat{\theta}_T θ T is the θ \theta θ -block of the final output f W ( Z ^ T − 1 ) f_W(\widehat{Z}_{T-1}) f W ( Z T − 1 ) . Therefore, we can write
L ( f W ; D ) = 1 2 E X , θ ⋆ [ ∥ θ ^ T − θ ⋆ ∥ 2 ] . L(f_W;\mathcal{D})=\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\lVert\widehat{\theta}_T-\theta^\star\rVert^2\right]. L ( f W ; D ) = 2 1 E X , θ ⋆ [ ∥ θ T − θ ⋆ ∥ 2 ] .
We compare the generated estimates θ ^ i \widehat{\theta}_i θ i with the gradient descent iterates θ i \theta_i θ i . Let
Δ i : = f ~ W ( θ i − 1 ) − θ i , i = 1 , … , T , \Delta_i := \widetilde{f}_W(\theta_{i-1})-\theta_i,\qquad i=1,\ldots,T, Δ i := f W ( θ i − 1 ) − θ i , i = 1 , … , T ,
be the prediction error of step i i i , when the model is given the correct previous step. Since f ~ W \widetilde{f}_W f W is affine with the Jacobian J J J in equation (20) ,
θ ^ i − θ i = ( f ~ W ( θ ^ i − 1 ) − f ~ W ( θ i − 1 ) ) + Δ i = J ( θ ^ i − 1 − θ i − 1 ) + Δ i . \widehat{\theta}_i-\theta_i=\left(\widetilde{f}_W(\widehat{\theta}_{i-1})-\widetilde{f}_W(\theta_{i-1})\right)+\Delta_i=J(\widehat{\theta}_{i-1}-\theta_{i-1})+\Delta_i. θ i − θ i = ( f W ( θ i − 1 ) − f W ( θ i − 1 ) ) + Δ i = J ( θ i − 1 − θ i − 1 ) + Δ i .
Recursively decomposing the above from θ ^ 0 = θ 0 \widehat{\theta}_0=\theta_0 θ 0 = θ 0 , we have
θ ^ T − θ ⋆ = ( θ T − θ ⋆ ) + ∑ i = 1 T J T − i Δ i . (21) \widehat{\theta}_T-\theta^\star=(\theta_T-\theta^\star)+\sum_{i=1}^{T}J^{T-i}\Delta_i. \tag*{(21)} θ T − θ ⋆ = ( θ T − θ ⋆ ) + i = 1 ∑ T J T − i Δ i . (21)
This equation is the form of Lemma 3.1 for the linear transformer. The first term, θ T − θ ⋆ \theta_T-\theta^\star θ T − θ ⋆ , is the error of T T T gradient descent steps on the given in-context examples, because the final label is θ ⋆ \theta^\star θ ⋆ . Since ∥ J ∥ \lVert J\rVert ∥ J ∥ is not bounded uniformly over Gaussian inputs, we bound equation (21) in expectation rather than with the worst-case constants of Lemma 3.1 . By the Cauchy–Schwarz inequality,
L ( f W ; D ) ≤ T + 1 2 ( E X , θ ⋆ [ ∥ θ T − θ ⋆ ∥ 2 ] + ∑ i = 1 T E X , θ ⋆ [ ∥ J T − i Δ i ∥ 2 ] ) . (22) L(f_W;\mathcal{D})\leq\frac{T+1}{2}\left(\mathbb{E}_{X,\theta^\star}\left[\lVert\theta_T-\theta^\star\rVert^2\right]+\sum_{i=1}^{T}\mathbb{E}_{X,\theta^\star}\left[\lVert J^{T-i}\Delta_i\rVert^2\right]\right). \tag*{(22)} L ( f W ; D ) ≤ 2 T + 1 ( E X , θ ⋆ [ ∥ θ T − θ ⋆ ∥ 2 ] + i = 1 ∑ T E X , θ ⋆ [ ∥ J T − i Δ i ∥ 2 ] ) . (22)
It remains to show that J J J is contractive at convergence and that the residuals are small.
(1) Upper bound of E ∥ J ∥ 2 \mathbb{E}\lVert J\rVert^2 E ∥ J ∥ 2 . Now, we analyze the spectral norm of the Jacobian matrix of the linear transformer, J = I + W 31 P V S W 13 K Q J=I+W_{31}^{PV}SW_{13}^{KQ} J = I + W 31 P V S W 13 K Q . Based on the results in Theorem A.4 , for the trained transformer by running the gradient flow on the population loss on the chain-of-thought sequences, there exists matrix A A A and B B B , such that W 31 = ( − η I + A ) W_{31}=(-\eta I+A) W 31 = ( − η I + A ) and W 13 = ( I + B ) W_{13}=(I+B) W 13 = ( I + B ) with ∥ A ∥ o p , ∥ B ∥ o p ≤ Θ ( d − 1 2 c log ( 1 1 − η ) + 1 2 ) \lVert A\rVert_{\mathrm{op}},\lVert B\rVert_{\mathrm{op}}\leq\Theta\left(d^{-\frac{1}{2}c\log\left(\frac{1}{1-\eta}\right)+\frac{1}{2}}\right) ∥ A ∥ op , ∥ B ∥ op ≤ Θ ( d − 2 1 c l o g ( 1 − η 1 ) + 2 1 ) . We denote
β : = Θ ( d − 1 2 c log ( 1 1 − η ) + 1 2 ) , and a : = c log ( 1 1 − η ) > 2. \beta:=\Theta\left(d^{-\frac{1}{2}c\log\left(\frac{1}{1-\eta}\right)+\frac{1}{2}}\right),\quad\text{and}\quad a:=c\log\left(\frac{1}{1-\eta}\right)>2. β := Θ ( d − 2 1 c l o g ( 1 − η 1 ) + 2 1 ) , and a := c log ( 1 − η 1 ) > 2.
In particular, β = Θ ( d 1 − a 2 ) ≤ d − 1 / 2 \beta=\Theta\left(d^{\frac{1-a}{2}}\right)\leq d^{-1/2} β = Θ ( d 2 1 − a ) ≤ d − 1/2 for a large enough d d d .
Therefore, we have:
J = I + W 31 P V S W 13 K Q = I + ( − η I + A ) S ( I + B ) = I − η S + ( A S − η S B + A S B ) = J 0 + E , \begin{aligned}
J&=I+W_{31}^{PV}SW_{13}^{KQ}\\
&=I+(-\eta I+A)S(I+B)\\
&=I-\eta S+(AS-\eta SB+ASB)\\
&=J_0+E,
\end{aligned} J = I + W 31 P V S W 13 K Q = I + ( − η I + A ) S ( I + B ) = I − η S + ( A S − η S B + A S B ) = J 0 + E ,
where J 0 = I − η S J_0=I-\eta S J 0 = I − η S and E = ( A S − η S B + A S B ) E=(AS-\eta SB+ASB) E = ( A S − η S B + A S B ) .
Recall that S = 1 n X X ⊤ S=\frac{1}{n}XX^\top S = n 1 X X ⊤ where X = [ x 1 , … , x n ] X=[x_1,\ldots,x_n] X = [ x 1 , … , x n ] with x i x_i x i sampled from N ( 0 , I d ) \mathcal{N}(0,I_d) N ( 0 , I d ) . By the Gaussian singular-value bound [29 ] applied to X X X , given n = Θ ( d 2 log 5 d ) n=\Theta(d^2\log^5d) n = Θ ( d 2 log 5 d ) , the event G : = { ∥ S − I ∥ 2 ≤ C d / n } G:=\{\lVert S-I\rVert_2\leq C\sqrt{d/n}\} G := {∥ S − I ∥ 2 ≤ C d / n } has probability at least 1 − 2 e − d / 2 1-2e^{-d/2} 1 − 2 e − d /2 for a constant C C C . On G G G , we have that
∥ J 0 ∥ 2 = ∥ I − η S ∥ 2 ≤ 1 − η + C η d / n = 1 − η + O ( log − 5 / 2 d ) , \lVert J_0\rVert_2=\lVert I-\eta S\rVert_2\leq1-\eta+C\eta\sqrt{d/n}=1-\eta+O(\log^{-5/2}d), ∥ J 0 ∥ 2 = ∥ I − η S ∥ 2 ≤ 1 − η + C η d / n = 1 − η + O ( log − 5/2 d ) ,
and ∥ S ∥ 2 ≤ 2 \lVert S\rVert_2\leq2 ∥ S ∥ 2 ≤ 2 .
For matrix E E E , on G G G , submultiplicativity gives
∥ E ∥ 2 ≤ ( ∥ A ∥ 2 + η ∥ B ∥ 2 + ∥ A ∥ 2 ∥ B ∥ 2 ) ∥ S ∥ 2 = Θ ( d − c log 1 1 − η + 1 ) . \lVert E\rVert_2\leq\left(\lVert A\rVert_2+\eta\lVert B\rVert_2+\lVert A\rVert_2\lVert B\rVert_2\right)\lVert S\rVert_2=\Theta\left(d^{-c\log\frac{1}{1-\eta}+1}\right). ∥ E ∥ 2 ≤ ( ∥ A ∥ 2 + η ∥ B ∥ 2 + ∥ A ∥ 2 ∥ B ∥ 2 ) ∥ S ∥ 2 = Θ ( d − c l o g 1 − η 1 + 1 ) .
Therefore, on G G G ,
∥ J ∥ 2 ≤ ∥ J 0 ∥ 2 + ∥ E ∥ 2 ≤ 1 − η + O ( log − 5 / 2 d ) + Θ ( d − c log 1 1 − η + 1 ) . (23) \lVert J\rVert_2\leq\lVert J_0\rVert_2+\lVert E\rVert_2\leq1-\eta+O(\log^{-5/2}d)+\Theta\left(d^{-c\log\frac{1}{1-\eta}+1}\right). \tag*{(23)} ∥ J ∥ 2 ≤ ∥ J 0 ∥ 2 + ∥ E ∥ 2 ≤ 1 − η + O ( log − 5/2 d ) + Θ ( d − c l o g 1 − η 1 + 1 ) . (23)
Thus, ∥ J ∥ 2 ≤ 1 − η / 2 < 1 \lVert J\rVert_2\leq1-\eta/2<1 ∥ J ∥ 2 ≤ 1 − η /2 < 1 for a large enough d d d .
(2) Upper bound of E ∥ Δ i ∥ 2 \mathbb{E}\lVert\Delta_i\rVert^2 E ∥ Δ i ∥ 2 . We have the one-step gradient descent update as θ i = θ i − 1 − η S ( θ i − 1 − θ ⋆ ) \theta_i=\theta_{i-1}-\eta S(\theta_{i-1}-\theta^\star) θ i = θ i − 1 − η S ( θ i − 1 − θ ⋆ ) . Then, the prediction error of step i i i conditioned on the correct steps is
Δ i = f ~ W ( θ i − 1 ) − θ i = ( W 31 S W 13 + η S ) θ i − 1 − ( W 31 + η I ) S θ ⋆ = ( A S − η S B + A S B ) θ i − 1 − A S θ ⋆ . \begin{aligned}
\Delta_i&=\widetilde{f}_W(\theta_{i-1})-\theta_i\\
&=(W_{31}SW_{13}+\eta S)\theta_{i-1}-(W_{31}+\eta I)S\theta^\star\\
&=(AS-\eta SB+ASB)\theta_{i-1}-AS\theta^\star.
\end{aligned} Δ i = f W ( θ i − 1 ) − θ i = ( W 31 S W 13 + η S ) θ i − 1 − ( W 31 + η I ) S θ ⋆ = ( A S − η S B + A S B ) θ i − 1 − A S θ ⋆ .
Therefore, we have
∥ Δ i ∥ 2 ≤ 2 ( ∥ A S − η S B + A S B ∥ 2 2 ∥ θ i − 1 ∥ 2 + ∥ A S ∥ 2 2 ∥ θ ⋆ ∥ 2 ) . (24) \lVert\Delta_i\rVert^2 \le2\left(\lVert AS-\eta SB+ASB\rVert_2^2\lVert\theta_{i-1}\rVert^2+\lVert AS\rVert_2^2\lVert\theta^\star\rVert^2\right). \tag*{(24)} ∥ Δ i ∥ 2 ≤ 2 ( ∥ A S − η S B + A S B ∥ 2 2 ∥ θ i − 1 ∥ 2 + ∥ A S ∥ 2 2 ∥ θ ⋆ ∥ 2 ) . (24)
Note that θ i \theta_i θ i is the i i i -th iterate of the gradient descent applied to ( X , y ) (X,y) ( X , y ) . Given that θ ⋆ ∼ N ( 0 , I d ) \theta^\star\sim\mathcal{N}(0,I_d) θ ⋆ ∼ N ( 0 , I d ) and S = 1 n X X ⊤ S=\frac{1}{n}XX^\top S = n 1 X X ⊤ , with n = Θ ( d 2 log 5 d ) n=\Theta(d^2\log^5d) n = Θ ( d 2 log 5 d ) , we have E X , θ ⋆ [ ∥ θ i ∥ 2 ] ≤ O ( d ) \mathbb{E}_{X,\theta^\star}\left[\lVert\theta_i\rVert^2\right]\le O(d) E X , θ ⋆ [ ∥ θ i ∥ 2 ] ≤ O ( d ) . Therefore, based on θ i = ( I − ( I − η S ) i ) θ ⋆ \theta_i=(I-(I-\eta S)^i)\theta^\star θ i = ( I − ( I − η S ) i ) θ ⋆ , on G \mathcal{G} G , we have ∥ I − η S ∥ 2 ≤ 1 \lVert I-\eta S\rVert_2\le1 ∥ I − η S ∥ 2 ≤ 1 , so ∥ θ i ∥ ≤ 2 ∥ θ ⋆ ∥ \lVert\theta_i\rVert\le2\lVert\theta^\star\rVert ∥ θ i ∥ ≤ 2 ∥ θ ⋆ ∥ .
On G \mathcal{G} G , we also have ∥ A S − η S B + A S B ∥ 2 ≤ 6 β \lVert AS-\eta SB+ASB\rVert_2\le6\beta ∥ A S − η S B + A S B ∥ 2 ≤ 6 β , and ∥ A S ∥ 2 ≤ 2 β \lVert AS\rVert_2\le2\beta ∥ A S ∥ 2 ≤ 2 β .
Therefore, plug those back to equation (24) , for i = 1 , … , T i=1,\ldots,T i = 1 , … , T , we have:
E [ ∥ Δ i ∥ 2 2 1 G ] ≤ 2 ( 36 β 2 ⋅ 4 d + 4 β 2 d ) = O ( d β 2 ) = O ( d 2 − a ) . \mathbb{E}\left[\lVert\Delta_i\rVert_2^2\mathbf{1}_{\mathcal{G}}\right]\le2(36\beta^2\cdot4d+4\beta^2d)=O(d\beta^2)=O(d^{2-a}). E [ ∥ Δ i ∥ 2 2 1 G ] ≤ 2 ( 36 β 2 ⋅ 4 d + 4 β 2 d ) = O ( d β 2 ) = O ( d 2 − a ) .
Upper bound of L ( f W ; D ) L(f_W;\mathcal{D}) L ( f W ; D ) . Now, we have shown that E [ ∥ Δ i ∥ 2 2 1 G ] = O ( d 2 − a ) \mathbb{E}[\lVert\Delta_i\rVert_2^2\mathbf{1}_{\mathcal{G}}]=O(d^{2-a}) E [∥ Δ i ∥ 2 2 1 G ] = O ( d 2 − a ) for i = 1 , … , T i=1,\ldots,T i = 1 , … , T , and ∥ J ∥ 2 ≤ 1 − η / 2 \lVert J\rVert_2\le1-\eta/2 ∥ J ∥ 2 ≤ 1 − η /2 on G \mathcal{G} G . Then, summing the geometric series gives
∑ i = 1 T E [ ∥ J T − i Δ i ∥ 2 2 1 G ] ≤ ∑ i = 1 T ( 1 − η / 2 ) 2 ( T − i ) E [ ∥ Δ i ∥ 2 2 1 G ] ≤ O ( d 2 − a ) . \sum_{i=1}^{T}\mathbb{E}\left[\lVert J^{T-i}\Delta_i\rVert_2^2\mathbf{1}_{\mathcal{G}}\right]\le\sum_{i=1}^{T}(1-\eta/2)^{2(T-i)}\mathbb{E}\left[\lVert\Delta_i\rVert_2^2\mathbf{1}_{\mathcal{G}}\right]\le O(d^{2-a}). i = 1 ∑ T E [ ∥ J T − i Δ i ∥ 2 2 1 G ] ≤ i = 1 ∑ T ( 1 − η /2 ) 2 ( T − i ) E [ ∥ Δ i ∥ 2 2 1 G ] ≤ O ( d 2 − a ) .
In addition, the first term of equation (22) is the error of exact gradient descent. By equation (17) , θ T − θ ⋆ = − ( I − η S ) T θ ⋆ \theta_T-\theta^\star=-(I-\eta S)^T\theta^\star θ T − θ ⋆ = − ( I − η S ) T θ ⋆ . On G \mathcal{G} G , we have
∥ I − η S ∥ 2 2 T ≤ ( 1 − η ) 2 T ( 1 + C η 1 − η d / n ) 2 T ≤ 2 ( 1 − η ) 2 T . \lVert I-\eta S\rVert_2^{2T}\le(1-\eta)^{2T}\left(1+\frac{C\eta}{1-\eta}\sqrt{d/n}\right)^{2T}\le2(1-\eta)^{2T}. ∥ I − η S ∥ 2 2 T ≤ ( 1 − η ) 2 T ( 1 + 1 − η C η d / n ) 2 T ≤ 2 ( 1 − η ) 2 T .
Since T ≥ c log d T\ge c\log d T ≥ c log d , we have
E [ ∥ θ T − θ ⋆ ∥ 2 1 G ] ≤ 2 ( 1 − η ) 2 T E ∥ θ ⋆ ∥ 2 ≤ 2 d 1 − 2 a . \mathbb{E}\left[\lVert\theta_T-\theta^\star\rVert^2\mathbf{1}_{\mathcal{G}}\right]\le2(1-\eta)^{2T}\mathbb{E}\lVert\theta^\star\rVert^2\le2d^{1-2a}. E [ ∥ θ T − θ ⋆ ∥ 2 1 G ] ≤ 2 ( 1 − η ) 2 T E ∥ θ ⋆ ∥ 2 ≤ 2 d 1 − 2 a .
Combining these results into equation (22) , by the Cauchy–Schwarz inequality, we have
L ( f W ; D ) ≤ T + 1 2 ( 2 d 1 − 2 a + O ( d 2 − a ) + e − Ω ( d ) ) = O ( d 2 − a log d ) , (25) L(f_W;\mathcal{D})\le\frac{T+1}{2}\left(2d^{1-2a}+O(d^{2-a})+e^{-\Omega(d)}\right)=O(d^{2-a}\log d), \tag*{(25)} L ( f W ; D ) ≤ 2 T + 1 ( 2 d 1 − 2 a + O ( d 2 − a ) + e − Ω ( d ) ) = O ( d 2 − a log d ) , (25)
since T + 1 = O ( log d ) T+1=O(\log d) T + 1 = O ( log d ) .
Proof for the Quadratic Case
In this section, we study an in-context weight prediction task where the model is trained to predict the parameters of a quadratic function from n n n examples. Let the quadratic weight vector be θ ⋆ ∈ R d \theta^\star\in\mathbb{R}^d θ ⋆ ∈ R d where θ ⋆ ∼ N ( 0 , I d ) \theta^\star\sim\mathcal{N}(0,I_d) θ ⋆ ∼ N ( 0 , I d ) . We sample n n n in-context examples x i ∼ N ( 0 , I d ) x_i\sim\mathcal{N}(0,I_d) x i ∼ N ( 0 , I d ) with the corresponding labels according to y i = ( θ ⋆ ⊤ x i ) 2 y_i=(\theta^{\star\top}x_i)^2 y i = ( θ ⋆ ⊤ x i ) 2 , for i = 1 , … , n i=1,\ldots,n i = 1 , … , n . The goal is to predict θ ⋆ \theta^\star θ ⋆ given the n n n examples.
Similar to weight prediction for the linear function, define the embedding dimension d e = 2 d + 2 d_e=2d+2 d e = 2 d + 2 . The initial input sequence is constructed as
Z 0 = [ x 1 ⋯ x n 0 y 1 ⋯ y n 0 0 ⋯ 0 θ 0 0 ⋯ 0 1 ] : = [ X 0 d y 0 0 d θ 0 0 1 ] ∈ R d e × ( n + 1 ) , (26) Z_0=
\begin{bmatrix}
x_1 & \cdots& x_n & 0\\
y_1 & \cdots& y_n & 0\\
0 & \cdots& 0 & \theta_0\\
0 & \cdots& 0 & 1
\end{bmatrix}
:=
\begin{bmatrix}
X & 0_d\\
y & 0\\
0_d & \theta_0\\
0 & 1
\end{bmatrix}\in\mathbb{R}^{d_e\times(n+1)}, \tag*{(26)} Z 0 = x 1 y 1 0 0 ⋯ ⋯ ⋯ ⋯ x n y n 0 0 0 0 θ 0 1 := X y 0 d 0 0 d 0 θ 0 1 ∈ R d e × ( n + 1 ) , (26)
where X = [ x 1 , … , x n ] ∈ R d × n X=[x_1,\ldots,x_n]\in\mathbb{R}^{d\times n} X = [ x 1 , … , x n ] ∈ R d × n , y = [ y 1 , … , y n ] ⊤ ∈ R n y=[y_1,\ldots,y_n]^\top\in\mathbb{R}^n y = [ y 1 , … , y n ] ⊤ ∈ R n , and θ 0 ∈ R d \theta_0\in\mathbb{R}^d θ 0 ∈ R d is an initial estimate in the basin of θ ⋆ \theta^\star θ ⋆ . We take θ 0 = α 0 θ ⋆ \theta_0=\alpha_0\theta^\star θ 0 = α 0 θ ⋆ for a constant α 0 ∈ [ 3 / 4 , 1 ) \alpha_0\in[3/4,1) α 0 ∈ [ 3/4 , 1 ) . We also append a dummy constant 1 1 1 to each parameter token for formatting convenience.
We construct the chain-of-thought using gradient descent on the squared loss, i.e., 1 2 n ∑ j = 1 n ( ( θ ⊤ x j ) 2 − y j ) 2 \frac{1}{2n}\sum_{j=1}^n((\theta^\top x_j)^2-y_j)^2 2 n 1 ∑ j = 1 n (( θ ⊤ x j ) 2 − y j ) 2 . Define a residual vector as e ( θ ) = y ^ ( θ ) − y e(\theta)=\widehat{y}(\theta)-y e ( θ ) = y ( θ ) − y , where y ^ j ( θ ) = ( θ ⊤ x j ) 2 \widehat{y}_j(\theta)=(\theta^\top x_j)^2 y j ( θ ) = ( θ ⊤ x j ) 2 . The gradient of the loss is
2 n ∑ j = 1 n ( ( θ ⊤ x j ) 2 − y j ) x j x j ⊤ θ = 2 n X diag ( e ( θ ) ) X ⊤ θ . \frac{2}{n}\sum_{j=1}^n((\theta^\top x_j)^2-y_j)x_jx_j^\top\theta=\frac{2}{n}X\operatorname{diag}(e(\theta))X^\top\theta. n 2 j = 1 ∑ n (( θ ⊤ x j ) 2 − y j ) x j x j ⊤ θ = n 2 X diag ( e ( θ )) X ⊤ θ .
Given a learning rate η \eta η , starting from θ 0 \theta_0 θ 0 , define the gradient descent iterates for i = 1 , … , T i=1,\ldots,T i = 1 , … , T :
θ i = θ i − 1 − η ⋅ 2 n X diag ( e ( θ i − 1 ) ) X T θ i − 1 = θ i − 1 − η ⋅ 2 n X D i + D i − X T θ i − 1 , \theta_i=\theta_{i-1}-\eta\cdot\frac{2}{n}X\operatorname{diag}\left(e(\theta_{i-1})\right)X^\mathsf{T}\theta_{i-1}=\theta_{i-1}-\eta\cdot\frac{2}{n}XD_i^{+}D_i^{-}X^\mathsf{T}\theta_{i-1}, θ i = θ i − 1 − η ⋅ n 2 X diag ( e ( θ i − 1 ) ) X T θ i − 1 = θ i − 1 − η ⋅ n 2 X D i + D i − X T θ i − 1 ,
where D i + = diag ( X T θ i − 1 + X T θ ⋆ ) D_i^{+}=\operatorname{diag}(X^\mathsf{T}\theta_{i-1}+X^\mathsf{T}\theta^{\star}) D i + = diag ( X T θ i − 1 + X T θ ⋆ ) and D i − = diag ( X T θ i − 1 − X T θ ⋆ ) D_i^{-}=\operatorname{diag}(X^\mathsf{T}\theta_{i-1}-X^\mathsf{T}\theta^{\star}) D i − = diag ( X T θ i − 1 − X T θ ⋆ ) .
Using these iterates, we define the ground-truth sequences
Z i = [ x 1 ⋯ x n 0 0 ⋯ 0 y 1 ⋯ y n 0 0 ⋯ 0 0 ⋯ 0 θ 0 θ 1 ⋯ θ i 0 ⋯ 0 1 1 ⋯ 1 ] ∈ R d e × ( n + i + 1 ) , for i = 1 , 2 , … , T . (27) Z_i=
\begin{bmatrix}
x_1 & \cdots& x_n & 0 & 0 & \cdots& 0\\
y_1 & \cdots& y_n & 0 & 0 & \cdots& 0\\
0 & \cdots& 0 & \theta_0 & \theta_1 & \cdots& \theta_i\\
0 & \cdots& 0 & 1 & 1 & \cdots& 1
\end{bmatrix}
\in\mathbb{R}^{d_e\times(n+i+1)},\quad\text{for }i=1,2,\ldots,T. \tag*{(27)} Z i = x 1 y 1 0 0 ⋯ ⋯ ⋯ ⋯ x n y n 0 0 0 0 θ 0 1 0 0 θ 1 1 ⋯ ⋯ ⋯ ⋯ 0 0 θ i 1 ∈ R d e × ( n + i + 1 ) , for i = 1 , 2 , … , T . (27)
Proof of Lemma 3.3
Proof. We now construct a three-head nonlinear self-attention transformer that performs one gradient descent step for the quadratic squared loss. For head h ∈ { 1 , 2 , 3 } h\in\{1,2,3\} h ∈ { 1 , 2 , 3 } , we denote a three-head self-attention model as
f W ( Z ) = Z [ : , − 1 ] + ∑ i = 1 3 W P V i Z ⋅ ϕ i ( Z T W K Q i Z [ : , − 1 ] n ) . f_W(Z)=Z_{[:, -1]}+\sum_{i=1}^{3}W^{PV_i}Z\cdot\phi_i\left(\frac{Z^\mathsf{T}W^{KQ_i}Z_{[:, -1]}}{n}\right). f W ( Z ) = Z [ : , − 1 ] + i = 1 ∑ 3 W P V i Z ⋅ ϕ i ( n Z T W K Q i Z [ : , − 1 ] ) .
Here W V i , W K i , W Q i ∈ R d i × d e W^{V_i},W^{K_i},W^{Q_i}\in\mathbb{R}^{d_i\times d_e} W V i , W K i , W Q i ∈ R d i × d e for i = 1 , 2 , 3 i=1,2,3 i = 1 , 2 , 3 . One can set d 1 , d 2 d_1,d_2 d 1 , d 2 , and d 3 d_3 d 3 separately. We construct the transformer in the following way. Let ϕ ( ⋅ ) \phi(\cdot) ϕ ( ⋅ ) be applied elementwise as
ϕ 1 ( t ) = t ⊙ 3 , ϕ 2 ( t ) = t ⊙ 2 , ϕ 3 ( t ) = t ⊙ 2 . (28) \phi_1(t)=t^{\odot3},\qquad\phi_2(t)=t^{\odot2},\qquad\phi_3(t)=t^{\odot2}. \tag*{(28)} ϕ 1 ( t ) = t ⊙ 3 , ϕ 2 ( t ) = t ⊙ 2 , ϕ 3 ( t ) = t ⊙ 2 . (28)
We then set
W P V 1 = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 − 2 η 2 I d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 1 = [ 0 d × d 0 d × 1 I d 0 d × 1 0 1 × d 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W^{PV_1}=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
-2\eta^2 I_{d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix},
\qquad
W^{KQ_1}=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & I_d & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix}, W P V 1 = 0 d × d 0 1 × d − 2 η 2 I d 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 1 = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 I d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 ,
W P V 2 = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 1 2 η I d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 2 = [ 0 d × d 0 d × 1 I d 0 d × 1 0 1 × d 0 0 d × 1 1 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W^{PV_2}=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
\frac{1}{2}\eta I_d & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix},
\qquad
W^{KQ_2}=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & I_d & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 1\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix}, W P V 2 = 0 d × d 0 1 × d 2 1 η I d 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 2 = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 I d 0 d × 1 0 d × d 0 d × 1 0 d × 1 1 0 d × 1 0 ,
W P V 3 = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 − 1 2 η η I d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 3 = [ 0 d × d 0 d × 1 I d 0 d × 1 0 1 × d 0 0 d × 1 − 1 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] . (29) W^{PV_3}=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
-\frac{1}{2}\eta\eta I_d & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix},
\qquad
W^{KQ_3}=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & I_d & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & -1\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix}. \tag*{(29)} W P V 3 = 0 d × d 0 1 × d − 2 1 η η I d 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 3 = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 I d 0 d × 1 0 d × d 0 d × 1 0 d × 1 − 1 0 d × 1 0 . (29)
Now, we can inductively calculate the i i i -th step of generation, showing that the output is exactly the parameter after the i i i -th gradient step.
f W ( Z i ) = ( 0 d , 0 , θ i , 1 ) + ( 0 d , 0 , − 2 η 2 X ⋅ ϕ 1 ( Z T W K Q 1 Z [ : , − 1 ] n ) , 0 ) f_W(Z_i)=(0_d,0,\theta_i,1)+\left(0_d,0,-2\eta^2X\cdot\phi_1\left(\frac{Z^\mathsf{T}W^{KQ_1}Z_{[:, -1]}}{n}\right),0\right) f W ( Z i ) = ( 0 d , 0 , θ i , 1 ) + ( 0 d , 0 , − 2 η 2 X ⋅ ϕ 1 ( n Z T W K Q 1 Z [ : , − 1 ] ) , 0 )
+ η n 2 X ⋅ ϕ 2 ( Z T W K Q 2 Z [ : , − 1 ] n ) − η n 2 X ⋅ ϕ 3 ( Z T W K Q 3 Z [ : , − 1 ] n ) , 0 ) . \qquad+\frac{\eta n}{2}X\cdot\phi_2(\frac{Z^\mathsf{T}W^{KQ_2}Z_{[:, -1]}}{n})-\frac{\eta n}{2}X\cdot\phi_3(\frac{Z^\mathsf{T}W^{KQ_3}Z_{[:, -1]}}{n}),0). + 2 η n X ⋅ ϕ 2 ( n Z T W K Q 2 Z [ : , − 1 ] ) − 2 η n X ⋅ ϕ 3 ( n Z T W K Q 3 Z [ : , − 1 ] ) , 0 ) .
Based on the construction, we have the following:
X ⋅ ϕ 1 ( Z T W K Q 1 Z [ : , − 1 ] ) = X ( X T θ i ) ⊙ 3 X\cdot\phi_1(Z^\mathsf{T}W^{KQ_1}Z_{[:, -1]})=X(X^\mathsf{T}\theta_i)^{\odot3} X ⋅ ϕ 1 ( Z T W K Q 1 Z [ : , − 1 ] ) = X ( X T θ i ) ⊙ 3
X ⋅ ϕ 2 ( Z T W K Q 2 Z [ : , − 1 ] ) = X ( X T θ i + y T ) ⊙ 2 X\cdot\phi_2(Z^\mathsf{T}W^{KQ_2}Z_{[:, -1]})=X(X^\mathsf{T}\theta_i+y^\mathsf{T})^{\odot2} X ⋅ ϕ 2 ( Z T W K Q 2 Z [ : , − 1 ] ) = X ( X T θ i + y T ) ⊙ 2
X ⋅ ϕ 3 ( Z T W K Q 3 Z [ : , − 1 ] ) = X ( X T θ i − y T ) ⊙ 2 X\cdot\phi_3(Z^\mathsf{T}W^{KQ_3}Z_{[:, -1]})=X(X^\mathsf{T}\theta_i-y^\mathsf{T})^{\odot2} X ⋅ ϕ 3 ( Z T W K Q 3 Z [ : , − 1 ] ) = X ( X T θ i − y T ) ⊙ 2
Therefore, we have
f W ( Z i ) = ( 0 d , 0 , θ i − 2 η n X ( ( X T θ i ) ⊙ 3 − ( X T θ i ) ⊙ y ) , 0 ) = ( 0 d , 0 , θ i − 2 η n X diag ( e ( θ i ) ) X T θ i , 1 ) \begin{aligned}
f_W(Z_i)=(0_d,0,\theta_i-\frac{2\eta}{n}X((X^\mathsf{T}\theta_i)^{\odot3}-(X^\mathsf{T}\theta_i)\odot y),0) \\
&=(0_d,0,\theta_i-\frac{2\eta}{n}X\operatorname{diag}(e(\theta_i))X^\mathsf{T}\theta_i,1)
\end{aligned} f W ( Z i ) = ( 0 d , 0 , θ i − n 2 η X (( X T θ i ) ⊙ 3 − ( X T θ i ) ⊙ y ) , 0 ) = ( 0 d , 0 , θ i − n 2 η X diag ( e ( θ i )) X T θ i , 1 )
where we denote the residual error e ( θ ) = y ^ ( θ ) − y e(\theta)=\hat{y}(\theta)-y e ( θ ) = y ^ ( θ ) − y , where y ^ j ( θ ) = ( θ ⊤ x j ) 2 \hat{y}_j(\theta)=(\theta^{\top}x_j)^2 y ^ j ( θ ) = ( θ ⊤ x j ) 2 .
Then, after T T T steps of applying f W f_W f W , we obtain the T T T -step gradient descent solution using n n n examples of ( x , y ) (x,y) ( x , y ) . Denote the θ T \theta_T θ T as the solution obtained by applying T T T -gradient step. Based on Lemma A.6, we have the test loss of f W f_W f W as
L W = 1 2 E X , θ ⋆ [ ∥ f W ( Z ^ T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) ∥ 2 2 ] = 1 2 E X , θ ⋆ [ ∥ θ T − θ ⋆ ∥ 2 2 ] ≤ O ( d − 2 c log ( 1 1 − η m d ) + 1 ) . L_W=\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\left\|f_W(\widehat{Z}_{T-1})-(0_d,0,\theta^\star,1)\right\|_2^2\right]=\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\|\theta_T-\theta^\star\|_2^2\right]\leq O\left(d^{-2c\log\left(\frac{1}{1-\eta m d}\right)+1}\right). L W = 2 1 E X , θ ⋆ [ f W ( Z T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) 2 2 ] = 2 1 E X , θ ⋆ [ ∥ θ T − θ ⋆ ∥ 2 2 ] ≤ O ( d − 2 c l o g ( 1 − η m d 1 ) + 1 ) .
Lemma A.6. Let θ ⋆ ∼ N ( 0 , I d ) \theta^\star\sim\mathcal{N}(0,\mathrm{I}_d) θ ⋆ ∼ N ( 0 , I d ) and x 1 , … , x n ∼ i . i . d . N ( 0 , I d ) x_1,\ldots,x_n\mathrel{\overset{\mathrm{i.i.d.}}{\sim}}\mathcal{N}(0,\mathrm{I}_d) x 1 , … , x n ∼ i.i.d. N ( 0 , I d ) . Define y j = ( x j ⊤ θ ⋆ ) 2 y_j=(x_j^\top\theta^\star)^2 y j = ( x j ⊤ θ ⋆ ) 2 and the empirical loss
L n ( θ ) : = 1 2 n ∑ j = 1 n ( ( x j ⊤ θ ) 2 − y j ) 2 = 1 2 n ∑ j = 1 n ( ( x j ⊤ θ ) 2 − ( x j ⊤ θ ⋆ ) 2 ) 2 . \mathcal{L}_n(\theta):=\frac{1}{2n}\sum_{j=1}^{n}\left((x_j^\top\theta)^2-y_j\right)^2=\frac{1}{2n}\sum_{j=1}^{n}\left((x_j^\top\theta)^2-(x_j^\top\theta^\star)^2\right)^2. L n ( θ ) := 2 n 1 j = 1 ∑ n ( ( x j ⊤ θ ) 2 − y j ) 2 = 2 n 1 j = 1 ∑ n ( ( x j ⊤ θ ) 2 − ( x j ⊤ θ ⋆ ) 2 ) 2 . Let dist ( θ , { ± θ ⋆ } ) : = min { ∥ θ − θ ⋆ ∥ 2 , ∥ θ + θ ⋆ ∥ 2 } \operatorname{dist}(\theta,\{\pm\theta^\star\}):=\min\{\|\theta-\theta^\star\|_2,\|\theta+\theta^\star\|_2\} dist ( θ , { ± θ ⋆ }) := min { ∥ θ − θ ⋆ ∥ 2 , ∥ θ + θ ⋆ ∥ 2 } . Consider gradient descent θ t + 1 = θ t − η ∇ L n ( θ t ) \theta_{t+1}=\theta_t-\eta\nabla\mathcal{L}_n(\theta_t) θ t + 1 = θ t − η ∇ L n ( θ t ) , t = 0 , 1 , 2 , … , T t=0,1,2,\ldots,T t = 0 , 1 , 2 , … , T . There exist absolute constants 0 < m ≤ L < ∞ 0<m\leq L<\infty 0 < m ≤ L < ∞ and a radius ρ ∈ ( 0 , 1 ) \rho\in(0,1) ρ ∈ ( 0 , 1 ) such that for all θ \theta θ satisfying dist ( θ , { ± θ ⋆ } ) ≤ ρ ∥ θ ⋆ ∥ 2 \operatorname{dist}(\theta,\{\pm\theta^\star\})\leq\rho\|\theta^\star\|_2 dist ( θ , { ± θ ⋆ }) ≤ ρ ∥ θ ⋆ ∥ 2 , the Hessian of L n \mathcal{L}_n L n obeys
m ∥ θ ⋆ ∥ 2 2 I d ⪯ ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d . m\|\theta^\star\|_2^2\mathrm{I}_d\preceq\nabla^2\mathcal{L}_n(\theta)\preceq L\|\theta^\star\|_2^2\mathrm{I}_d. m ∥ θ ⋆ ∥ 2 2 I d ⪯ ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d . Suppose the initialization lies in the basin, i.e., dist ( θ 0 , { ± θ ⋆ } ) ≤ ρ ∥ θ ⋆ ∥ 2 \operatorname{dist}(\theta_0,\{\pm\theta^\star\})\leq\rho\|\theta^\star\|_2 dist ( θ 0 , { ± θ ⋆ }) ≤ ρ ∥ θ ⋆ ∥ 2 . Assume that n ≥ C d 2 log 5 d n\geq Cd^2\log^5d n ≥ C d 2 log 5 d for a sufficiently large constant C > 0 C>0 C > 0 , 0 < η ≤ 1 2 L ∥ θ ⋆ ∥ 2 2 0<\eta\leq\frac{1}{2L\|\theta^\star\|_2^2} 0 < η ≤ 2 L ∥ θ ⋆ ∥ 2 2 1 , and T = ⌈ c log d ⌉ T=\lceil c\log d\rceil T = ⌈ c log d ⌉ . Then, with probability at least 1 − d − 10 1-d^{-10} 1 − d − 10 over ( θ ⋆ , X ) (\theta^\star,X) ( θ ⋆ , X ) , the following holds
dist ( θ T , { ± θ ⋆ } ) 2 ≤ dist ( θ 0 , { ± θ ⋆ } ) 2 ⋅ d 2 c log ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) . \operatorname{dist}(\theta_T,\{\pm\theta^\star\})^2\leq\operatorname{dist}(\theta_0,\{\pm\theta^\star\})^2\cdot d^{2c\log(1-m\eta\|\theta^\star\|_2^2)}. dist ( θ T , { ± θ ⋆ } ) 2 ≤ dist ( θ 0 , { ± θ ⋆ } ) 2 ⋅ d 2 c l o g ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) . Then, given η = Θ ( 1 / d ) \eta=\Theta(1/d) η = Θ ( 1/ d ) and T = Θ ( log d ) T=\Theta(\log d) T = Θ ( log d ) , we have
E X , θ ⋆ [ dist ( θ T , ± θ ⋆ ) 2 ] ≤ O ( d 1 − 2 c log ( 1 1 − m η d ) ) . \mathbb{E}_{X,\theta^\star}\left[\operatorname{dist}(\theta_T,\pm\theta^\star)^2\right]\leq O\left(d^{1-2c\log\left(\frac{1}{1-m\eta d}\right)}\right). E X , θ ⋆ [ dist ( θ T , ± θ ⋆ ) 2 ] ≤ O ( d 1 − 2 c l o g ( 1 − m η d 1 ) ) .
Proof. We prove the claim on a high-probability event under which the empirical loss is uniformly strongly convex and smooth in a neighborhood of { ± θ ⋆ } \{\pm\theta^\star\} { ± θ ⋆ } , and then apply a standard contraction argument for gradient descent. Let x ∈ R d x\in\mathbb{R}^d x ∈ R d and define
ℓ x ( θ ) : = 1 2 ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) 2 . \ell_x(\theta):=\frac{1}{2}\left((x^\top\theta)^2-(x^\top\theta^\star)^2\right)^2. ℓ x ( θ ) := 2 1 ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) 2 .
Then
∇ ℓ x ( θ ) = ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ∇ ( x ⊤ θ ) 2 = 2 ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ( x ⊤ θ ) x , \nabla\ell_x(\theta)=\left((x^\top\theta)^2-(x^\top\theta^\star)^2\right)\nabla(x^\top\theta)^2=2\left((x^\top\theta)^2-(x^\top\theta^\star)^2\right)(x^\top\theta)x, ∇ ℓ x ( θ ) = ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ∇ ( x ⊤ θ ) 2 = 2 ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ( x ⊤ θ ) x ,
and differentiating once more gives
∇ 2 ℓ x ( θ ) = 2 ( ∇ ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ( x ⊤ θ ) + ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ∇ ( x ⊤ θ ) ) x ⊤ = 2 ( 2 ( x ⊤ θ ) x ( x ⊤ θ ) + ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) x ) x ⊤ = 2 ( 3 ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) x x ⊤ . \begin{aligned}
\nabla^2\ell_x(\theta)
&=2\left(\nabla\left((x^\top\theta)^2-(x^\top\theta^\star)^2\right)(x^\top\theta)+\left((x^\top\theta)^2-(x^\top\theta^\star)^2\right)\nabla(x^\top\theta)\right)x^\top\\
&=2\left(2(x^\top\theta)x(x^\top\theta)+\left((x^\top\theta)^2-(x^\top\theta^\star)^2\right)x\right)x^\top\\
&=2\left(3(x^\top\theta)^2-(x^\top\theta^\star)^2\right)xx^\top.
\end{aligned} ∇ 2 ℓ x ( θ ) = 2 ( ∇ ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ( x ⊤ θ ) + ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) ∇ ( x ⊤ θ ) ) x ⊤ = 2 ( 2 ( x ⊤ θ ) x ( x ⊤ θ ) + ( ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) x ) x ⊤ = 2 ( 3 ( x ⊤ θ ) 2 − ( x ⊤ θ ⋆ ) 2 ) x x ⊤ .
Therefore, the empirical Hessian is
∇ 2 L n ( θ ) = 1 n ∑ j = 1 n ∇ 2 ℓ x j ( θ ) = 2 n ∑ j = 1 n ( 3 ( x j ⊤ θ ) 2 − ( x j ⊤ θ ⋆ ) 2 ) x j x j ⊤ . \nabla^2\mathcal{L}_n(\theta)=\frac{1}{n}\sum_{j=1}^{n}\nabla^2\ell_{x_j}(\theta)=\frac{2}{n}\sum_{j=1}^{n}\left(3(x_j^\top\theta)^2-(x_j^\top\theta^\star)^2\right)x_jx_j^\top. ∇ 2 L n ( θ ) = n 1 j = 1 ∑ n ∇ 2 ℓ x j ( θ ) = n 2 j = 1 ∑ n ( 3 ( x j ⊤ θ ) 2 − ( x j ⊤ θ ⋆ ) 2 ) x j x j ⊤ .
Let B : = { θ ∈ R d : dist ( θ , { ± θ ⋆ } ) ≤ ρ ∥ θ ⋆ ∥ 2 } \mathcal{B}:=\{\theta\in\mathbb{R}^d:\operatorname{dist}(\theta,\{\pm\theta^\star\})\leq\rho\|\theta^\star\|_2\} B := { θ ∈ R d : dist ( θ , { ± θ ⋆ }) ≤ ρ ∥ θ ⋆ ∥ 2 } . We use a claim that when n ≥ C d 2 log 5 d n\geq Cd^2\log^5d n ≥ C d 2 log 5 d (for C C C sufficiently large), with probability at least 1 − d − 10 1-d^{-10} 1 − d − 10 over ( θ ⋆ , X ) (\theta^\star,X) ( θ ⋆ , X ) , the following event holds:
E : ∀ θ ∈ B , m ∥ θ ⋆ ∥ 2 2 I d ⪯ ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d , (30) \mathcal{E}:\quad\forall\theta\in\mathcal{B},\qquad m\|\theta^\star\|_2^2\mathrm{I}_d\preceq\nabla^2\mathcal{L}_n(\theta)\preceq L\|\theta^\star\|_2^2\mathrm{I}_d, \tag*{(30)} E : ∀ θ ∈ B , m ∥ θ ⋆ ∥ 2 2 I d ⪯ ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d , (30)
for some absolute constants 0 < m ≤ L < ∞ 0<m\leq L<\infty 0 < m ≤ L < ∞ and ρ ∈ ( 0 , 1 ) \rho\in(0,1) ρ ∈ ( 0 , 1 ) . One can prove E \mathcal{E} E by a standard ε \varepsilon ε -net argument over B \mathcal{B} B together with Gaussian concentration for fourth-order polynomials. For example, see the local regularity condition established (cf. Section 7 of [3 ] ), the empirical Hessian is uniformly well-conditioned in a neighborhood of ± θ ⋆ \pm\theta^\star ± θ ⋆ . We condition on E \mathcal{E} E for the remainder of the proof.
Assume θ 0 ∈ B \theta_0 \in B θ 0 ∈ B . Since on E \mathcal{E} E we have ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d \nabla^2\mathcal{L}_n(\theta) \preceq L\|\theta^\star\|_2^2 I_{d} ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d for all θ ∈ B \theta\in B θ ∈ B , the loss is L ∥ θ ⋆ ∥ 2 2 L\|\theta^\star\|_2^2 L ∥ θ ⋆ ∥ 2 2 -smooth on B B B . With stepsize η ≤ 1 / ( 2 L ∥ θ ⋆ ∥ 2 2 ) \eta\le1/(2L\|\theta^\star\|_2^2) η ≤ 1/ ( 2 L ∥ θ ⋆ ∥ 2 2 ) , the standard descent lemma implies L n ( θ t + 1 ) ≤ L n ( θ t ) \mathcal{L}_n(\theta_{t+1}) \le\mathcal{L}_n(\theta_t) L n ( θ t + 1 ) ≤ L n ( θ t ) as long as θ t ∈ B \theta_t \in B θ t ∈ B . Moreover, since L n ( θ ) \mathcal{L}_n(\theta) L n ( θ ) is strongly convex in a neighborhood of each minimizer ± θ ⋆ \pm\theta^\star ± θ ⋆ on E \mathcal{E} E , and θ ⋆ \theta^\star θ ⋆ is a minimizer with ∇ L n ( θ ⋆ ) = 0 \nabla\mathcal{L}_n(\theta^\star)=0 ∇ L n ( θ ⋆ ) = 0 , the GD iterates remain in the same local basin. Thus θ t ∈ B \theta_t \in B θ t ∈ B for all t ≤ T t \le T t ≤ T .
Next, we show one-step contraction in distance to { ± θ ⋆ } \{\pm\theta^\star\} { ± θ ⋆ } . Fix the sign s ∈ { + 1 , − 1 } s \in\{+1,-1\} s ∈ { + 1 , − 1 } that minimizes ∥ θ 0 − s θ ⋆ ∥ 2 \|\theta_0-s\theta^\star\|_2 ∥ θ 0 − s θ ⋆ ∥ 2 and define
Δ t : = θ t − s θ ⋆ . \Delta_t := \theta_t-s\theta^\star. Δ t := θ t − s θ ⋆ .
On E \mathcal{E} E , for all θ ∈ B \theta\in B θ ∈ B we have
m ∥ θ ⋆ ∥ 2 2 I d ⪯ ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d . m\|\theta^\star\|_2^2 I_{d} \preceq\nabla^2\mathcal{L}_n(\theta) \preceq L\|\theta^\star\|_2^2 I_{d}. m ∥ θ ⋆ ∥ 2 2 I d ⪯ ∇ 2 L n ( θ ) ⪯ L ∥ θ ⋆ ∥ 2 2 I d .
Since ∇ L n ( s θ ⋆ ) = 0 \nabla\mathcal{L}_n(s\theta^\star)=0 ∇ L n ( s θ ⋆ ) = 0 and L n \mathcal{L}_n L n is twice differentiable, the mean value form of the gradient gives
∇ L n ( θ t ) − ∇ L n ( s θ ⋆ ) = ( ∫ 0 1 ∇ 2 L n ( s θ ⋆ + τ ( θ t − s θ ⋆ ) ) d τ ) ( θ t − s θ ⋆ ) = : H t Δ t , \nabla\mathcal{L}_n(\theta_t)-\nabla\mathcal{L}_n(s\theta^\star)=\left(\int_0^1\nabla^2\mathcal{L}_n(s\theta^\star+\tau(\theta_t-s\theta^\star))d\tau\right)(\theta_t-s\theta^\star)=:H_t\Delta_t, ∇ L n ( θ t ) − ∇ L n ( s θ ⋆ ) = ( ∫ 0 1 ∇ 2 L n ( s θ ⋆ + τ ( θ t − s θ ⋆ )) d τ ) ( θ t − s θ ⋆ ) =: H t Δ t ,
where H t H_t H t satisfies the same eigenvalue bounds:
m ∥ θ ⋆ ∥ 2 2 I d ⪯ H t ⪯ L ∥ θ ⋆ ∥ 2 2 I d . m\|\theta^\star\|_2^2 I_{d} \preceq H_t \preceq L\|\theta^\star\|_2^2 I_{d}. m ∥ θ ⋆ ∥ 2 2 I d ⪯ H t ⪯ L ∥ θ ⋆ ∥ 2 2 I d .
Therefore, the GD update can be written as
Δ t + 1 = θ t + 1 − s θ ⋆ = θ t − s θ ⋆ − η ∇ L n ( θ t ) = Δ t − η H t Δ t = ( I − η H t ) Δ t . \Delta_{t+1}=\theta_{t+1}-s\theta^\star=\theta_t-s\theta^\star-\eta\nabla\mathcal{L}_n(\theta_t)=\Delta_t-\eta H_t\Delta_t=(I-\eta H_t)\Delta_t. Δ t + 1 = θ t + 1 − s θ ⋆ = θ t − s θ ⋆ − η ∇ L n ( θ t ) = Δ t − η H t Δ t = ( I − η H t ) Δ t .
Taking norms and using H t ⪰ m ∥ θ ⋆ ∥ 2 2 I d H_t\succeq m\|\theta^\star\|_2^2 I_d H t ⪰ m ∥ θ ⋆ ∥ 2 2 I d yields
∥ Δ t + 1 ∥ 2 ≤ ∥ I − η H t ∥ op ∥ Δ t ∥ 2 ≤ ( 1 − η m ∥ θ ⋆ ∥ 2 2 ) ∥ Δ t ∥ 2 , \|\Delta_{t+1}\|_2\le\|I-\eta H_t\|_{\operatorname{op}}\|\Delta_t\|_2\le(1-\eta m\|\theta^\star\|_2^2)\|\Delta_t\|_2, ∥ Δ t + 1 ∥ 2 ≤ ∥ I − η H t ∥ op ∥ Δ t ∥ 2 ≤ ( 1 − η m ∥ θ ⋆ ∥ 2 2 ) ∥ Δ t ∥ 2 ,
where the last inequality uses η ≤ 1 / ( 2 L ∥ θ ⋆ ∥ 2 2 ) \eta\le1/(2L\|\theta^\star\|_2^2) η ≤ 1/ ( 2 L ∥ θ ⋆ ∥ 2 2 ) so that all eigenvalues of I − η H t I-\eta H_t I − η H t lie in [ 0 , 1 − η m ∥ θ ⋆ ∥ 2 2 ] [0,1-\eta m\|\theta^\star\|_2^2] [ 0 , 1 − η m ∥ θ ⋆ ∥ 2 2 ] . Squaring gives the one-step contraction
∥ Δ t + 1 ∥ 2 2 ≤ ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) 2 ∥ Δ t ∥ 2 2 . \|\Delta_{t+1}\|_2^2\le(1-m\eta\|\theta^\star\|_2^2)^2\|\Delta_t\|_2^2. ∥ Δ t + 1 ∥ 2 2 ≤ ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) 2 ∥ Δ t ∥ 2 2 .
By induction,
∥ Δ T − 1 ∥ 2 2 ≤ ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) 2 T ∥ Δ 0 ∥ 2 2 . \|\Delta_{T-1}\|_2^2\le(1-m\eta\|\theta^\star\|_2^2)^{2T}\|\Delta_0\|_2^2. ∥ Δ T − 1 ∥ 2 2 ≤ ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) 2 T ∥ Δ 0 ∥ 2 2 .
Since ∥ Δ t ∥ 2 = dist ( θ t , { ± θ ⋆ } ) \|\Delta_t\|_2=\operatorname{dist}(\theta_t,\{\pm\theta^\star\}) ∥ Δ t ∥ 2 = dist ( θ t , { ± θ ⋆ }) by construction of s s s , and T = c log d T=c\log d T = c log d ,
dist ( θ T − 1 , { ± θ ⋆ } ) 2 ≤ dist ( θ 0 , { ± θ ⋆ } ) 2 ⋅ ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) 2 c log d = dist ( θ 0 , { ± θ ⋆ } ) 2 ⋅ d 2 c log ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) . \begin{aligned}
\operatorname{dist}(\theta_{T-1},\{\pm\theta^\star\})^2\le\operatorname{dist}(\theta_0,\{\pm\theta^\star\})^2\cdot(1-m\eta\|\theta^\star\|_2^2)^{2c\log d} \\
&=\operatorname{dist}(\theta_0,\{\pm\theta^\star\})^2\cdot d^{2c\log(1-m\eta\|\theta^\star\|_2^2)}.
\end{aligned} dist ( θ T − 1 , { ± θ ⋆ } ) 2 ≤ dist ( θ 0 , { ± θ ⋆ } ) 2 ⋅ ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) 2 c l o g d = dist ( θ 0 , { ± θ ⋆ } ) 2 ⋅ d 2 c l o g ( 1 − m η ∥ θ ⋆ ∥ 2 2 ) .
Finally, the probability statement follows since E \mathcal{E} E holds with probability at least 1 − d − 10 1-d^{-10} 1 − d − 10 .
Gradient Computation
In this subsection, we compute the gradient of the full model and show that under certain initialization, running gradient flow on the training loss converges to the construction in Lemma 3.3.
Recall that we train a three-head nonlinear self-attention transformer, denoted as
f W ( Z ) = Z [ : , − 1 ] + ∑ i = 1 3 W P V i Z ⋅ ϕ i ( Z ⊤ W K Q i Z [ : , − 1 ] n ) . f_W(Z)=Z_{[:, -1]}+\sum_{i=1}^{3}W^{PV_i}Z\cdot\phi_i\left(\frac{Z^\top W^{KQ_i}Z_{[:, -1]}}{n}\right). f W ( Z ) = Z [ : , − 1 ] + i = 1 ∑ 3 W P V i Z ⋅ ϕ i ( n Z ⊤ W K Q i Z [ : , − 1 ] ) .
Here, by the convention in prior work [12 , 34 ] , we merge W P i W^{P_i} W P i and W V i W^{V_i} W V i into a single matrix and merge W K i W^{K_i} W K i and W Q i W^{Q_i} W Q i into a single matrix. W P V i W^{PV_i} W P V i and W K Q i ∈ R d e × d e W^{KQ_i}\in\mathbb{R}^{d_e\times d_e} W K Q i ∈ R d e × d e for i = 1 , 2 , 3 i=1,2,3 i = 1 , 2 , 3 . By the construction, we set ϕ i ( ⋅ ) \phi_i(\cdot) ϕ i ( ⋅ ) as elementwise non-linear functions ϕ 1 ( t ) = t ∘ 3 \phi_1(t)=t^{\circ3} ϕ 1 ( t ) = t ∘ 3 , ϕ 2 ( t ) = t ∘ 2 \phi_2(t)=t^{\circ2} ϕ 2 ( t ) = t ∘ 2 , and ϕ 3 ( t ) = t ∘ 2 \phi_3(t)=t^{\circ2} ϕ 3 ( t ) = t ∘ 2 .
The chain-of-thought training objective is written as
L C o T ( W ) = E x i ∼ N ( 0 , I d ) , θ ⋆ ∼ N ( 0 , I d ) [ 1 2 ∑ i = 0 T − 1 ∥ f W ( Z i ) − ( 0 d , 0 , θ ˉ i + 1 , 1 ) ∥ 2 2 ] . \mathcal{L}^{\mathrm{CoT}}(W)=\underset{x_i\sim\mathcal{N}(0,I_{d}),\theta^\star\sim\mathcal{N}(0,I_d)}{\mathbb{E}}\left[\frac{1}{2}\sum_{i=0}^{T-1}\left\|f_W(Z_i)-(0_d,0,\bar{\theta}_{i+1},1)\right\|_2^2\right]. L CoT ( W ) = x i ∼ N ( 0 , I d ) , θ ⋆ ∼ N ( 0 , I d ) E [ 2 1 i = 0 ∑ T − 1 f W ( Z i ) − ( 0 d , 0 , θ ˉ i + 1 , 1 ) 2 2 ] .
Here, θ ˉ i + 1 : = θ i + 1 \bar{\theta}_{i+1}:=\theta_{i+1} θ ˉ i + 1 := θ i + 1 for i ≤ T − 2 i\leq T-2 i ≤ T − 2 and θ ˉ T : = θ ⋆ \bar{\theta}_T:=\theta^\star θ ˉ T := θ ⋆ . As in the training loss equation (1) , there are T T T steps. The label of the last step is the target θ ⋆ \theta^\star θ ⋆ . The reduced loss and all gradients below use this convention.
At inference time, we apply the model to generate T − 1 T-1 T − 1 steps before it outputs the final prediction. The test loss is written as
L ( W ) = E X , θ ⋆ [ 1 2 ∥ f W ( Z ^ T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) ∥ 2 2 ] . L(W)=\mathbb{E}_{X,\theta^\star}\left[\frac{1}{2}\left\|f_W(\widehat{Z}_{T-1})-(0_d,0,\theta^\star,1)\right\|_2^2\right]. L ( W ) = E X , θ ⋆ [ 2 1 f W ( Z T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) 2 2 ] .
Now, we compute the gradients of W P V i W^{PV_i} W P V i and W K Q i W^{KQ_i} W K Q i based on the loss of each CoT step.
Lemma A.7 (Full model gradient). The gradients of W P V i W^{PV_i} W P V i and W K Q i W^{KQ_i} W K Q i for i = { 1 , 2 , 3 } i=\{1,2,3\} i = { 1 , 2 , 3 } are given by the following.
∇ W P V 1 L C o T ( W ) = E X , θ ⋆ [ ∑ i = 0 T − 1 r i ( Z i ϕ 1 ( Z i ⊤ W K Q 1 Z i [ : , − 1 ] n ) ) ⊤ ] \nabla_{W^{PV_1}}L^{\mathrm{CoT}}(W)=\mathbb{E}_{X,\theta^\star}\left[\sum_{i=0}^{T-1}r_i\left(Z_i\phi_1\left(\frac{Z_i^\top W^{KQ_1}Z_{i[:, -1]}}{n}\right)\right)^\top\right] ∇ W P V 1 L CoT ( W ) = E X , θ ⋆ i = 0 ∑ T − 1 r i ( Z i ϕ 1 ( n Z i ⊤ W K Q 1 Z i [ : , − 1 ] ) ) ⊤ ∇ W P V 2 L C o T ( W ) = E X , θ ⋆ [ ∑ i = 0 T − 1 r i ( Z i ϕ 2 ( Z i ⊤ W K Q 2 Z i [ : , − 1 ] n ) ) ⊤ ] \nabla_{W^{PV_2}}L^{\mathrm{CoT}}(W)=\mathbb{E}_{X,\theta^\star}\left[\sum_{i=0}^{T-1}r_i\left(Z_i\phi_2\left(\frac{Z_i^\top W^{KQ_2}Z_{i[:, -1]}}{n}\right)\right)^\top\right] ∇ W P V 2 L CoT ( W ) = E X , θ ⋆ i = 0 ∑ T − 1 r i ( Z i ϕ 2 ( n Z i ⊤ W K Q 2 Z i [ : , − 1 ] ) ) ⊤ ∇ W P V 3 L C o T ( W ) = E X , θ ⋆ [ ∑ i = 0 T − 1 r i ( Z i ϕ 3 ( Z i ⊤ W K Q 3 Z i [ : , − 1 ] n ) ) ⊤ ] \nabla_{W^{PV_3}}L^{\mathrm{CoT}}(W)=\mathbb{E}_{X,\theta^\star}\left[\sum_{i=0}^{T-1}r_i\left(Z_i\phi_3\left(\frac{Z_i^\top W^{KQ_3}Z_{i[:, -1]}}{n}\right)\right)^\top\right] ∇ W P V 3 L CoT ( W ) = E X , θ ⋆ i = 0 ∑ T − 1 r i ( Z i ϕ 3 ( n Z i ⊤ W K Q 3 Z i [ : , − 1 ] ) ) ⊤ ∇ W K Q 1 L C o T ( W ) = E X , θ ⋆ [ 1 n ∑ i = 0 T − 1 Z i ( Z i ⊤ W P V 1 ⊤ r i ) ⊙ 3 ( Z i ⊤ W K Q 1 Z i [ : , − 1 ] n ) ⊙ 2 Z i [ : , − 1 ] ⊤ ] \nabla_{W^{KQ_1}}L^{\mathrm{CoT}}(W)=\mathbb{E}_{X,\theta^\star}\left[\frac{1}{n}\sum_{i=0}^{T-1}Z_i\left(Z_i^\top W^{PV_1\top}r_i\right)\odot3\left(\frac{Z_i^\top W^{KQ_1}Z_{i[:, -1]}}{n}\right)^{\odot2}Z_{i[:, -1]}^\top\right] ∇ W K Q 1 L CoT ( W ) = E X , θ ⋆ n 1 i = 0 ∑ T − 1 Z i ( Z i ⊤ W P V 1 ⊤ r i ) ⊙ 3 ( n Z i ⊤ W K Q 1 Z i [ : , − 1 ] ) ⊙ 2 Z i [ : , − 1 ] ⊤ ∇ W K Q 2 L C o T ( W ) = E X , θ ⋆ [ 1 n ∑ i = 0 T − 1 Z i ( Z i ⊤ W P V 2 ⊤ r i ) ⊙ 2 ( Z i ⊤ W K Q 2 Z i [ : , − 1 ] n ) Z i [ : , − 1 ] ⊤ ] \nabla_{W^{KQ_2}}L^{\mathrm{CoT}}(W)=\mathbb{E}_{X,\theta^\star}\left[\frac{1}{n}\sum_{i=0}^{T-1}Z_i\left(Z_i^\top W^{PV_2\top}r_i\right)\odot2\left(\frac{Z_i^\top W^{KQ_2}Z_{i[:, -1]}}{n}\right)Z_{i[:, -1]}^\top\right] ∇ W K Q 2 L CoT ( W ) = E X , θ ⋆ [ n 1 i = 0 ∑ T − 1 Z i ( Z i ⊤ W P V 2 ⊤ r i ) ⊙ 2 ( n Z i ⊤ W K Q 2 Z i [ : , − 1 ] ) Z i [ : , − 1 ] ⊤ ] ∇ W K Q 3 L C o T ( W ) = E X , θ ⋆ [ 1 n ∑ i = 0 T − 1 Z i ( Z i ⊤ W P V 3 ⊤ r i ) ⊙ 2 ( Z i ⊤ W K Q 3 Z i [ : , − 1 ] n ) Z i [ : , − 1 ] ⊤ ] \nabla_{W^{KQ_3}}L^{\mathrm{CoT}}(W)=\mathbb{E}_{X,\theta^\star}\left[\frac{1}{n}\sum_{i=0}^{T-1}Z_i\left(Z_i^\top W^{PV_3\top}r_i\right)\odot2\left(\frac{Z_i^\top W^{KQ_3}Z_{i[:, -1]}}{n}\right)Z_{i[:, -1]}^\top\right] ∇ W K Q 3 L CoT ( W ) = E X , θ ⋆ [ n 1 i = 0 ∑ T − 1 Z i ( Z i ⊤ W P V 3 ⊤ r i ) ⊙ 2 ( n Z i ⊤ W K Q 3 Z i [ : , − 1 ] ) Z i [ : , − 1 ] ⊤ ] where we define
r i = ∑ h = 1 3 W P V h Z i ⋅ ϕ h ( Z i ⊤ W K Q h Z i [ : , − 1 ] n ) − ( 0 d , 0 , θ ˉ i + 1 − θ i , 0 ) r_i=\sum_{h=1}^{3}W^{PV_h}Z_i\cdot\phi_h\left(\frac{Z_i^\top W^{KQ_h}Z_{i[:, -1]}}{n}\right)-(0_d,0,\bar{\theta}_{i+1}-\theta_i,0) r i = h = 1 ∑ 3 W P V h Z i ⋅ ϕ h ( n Z i ⊤ W K Q h Z i [ : , − 1 ] ) − ( 0 d , 0 , θ ˉ i + 1 − θ i , 0 ) with θ ˉ i + 1 \bar{\theta}_{i+1} θ ˉ i + 1 defined above.
Proof. For a step index i = 0 , 1 , … , T − 1 i=0,1,\ldots,T-1 i = 0 , 1 , … , T − 1 , write Z ∈ R d e × m Z\in\mathbb{R}^{d_e\times m} Z ∈ R d e × m with m = n + i + 1 m=n+i+1 m = n + i + 1 and z = Z [ : , − 1 ] ∈ R d e z=Z_{[:, -1]}\in\mathbb{R}^{d_e} z = Z [ : , − 1 ] ∈ R d e . We define
s h : = z ⊤ W K Q h z n , v h : = ϕ h ( s h ) , u h : = W P V h Z v h , for h = 1 , 2 , 3. s_h:=\frac{z^\top W^{KQ_h}z}{n},\qquad v_h:=\phi_h(s_h),\qquad u_h:=W^{PV_h}Zv_h,\quad\text{for }h=1,2,3. s h := n z ⊤ W K Q h z , v h := ϕ h ( s h ) , u h := W P V h Z v h , for h = 1 , 2 , 3.
Then, we can write the squared loss in terms of the residual error in each step as
ℓ i ( W ) : = 1 2 ∥ r i ∥ 2 , where r i = ∑ h = 1 3 u h − ( 0 d , 0 , θ i + 1 − θ i , 0 ) , \ell_i(W):=\frac{1}{2}\lVert r_i\rVert^2,\quad\text{where }r_i=\sum_{h=1}^{3}u_h-(0_d,0,\theta_{i+1}-\theta_i,0), ℓ i ( W ) := 2 1 ∥ r i ∥ 2 , where r i = h = 1 ∑ 3 u h − ( 0 d , 0 , θ i + 1 − θ i , 0 ) ,
Then, we compute the gradients by the chain rule. For each head, the dependence of the loss on W P V h W^{PV_h} W P V h is only through u h u_h u h . Hence,
∇ W P V h ℓ i ( W ) = r i ( Z v h ) ⊤ = r i ( Z ϕ h ( Z ⊤ W K Q h z n ) ) ⊤ . \nabla_{W^{PV_h}}\ell_i(W)=r_i(Zv_h)^\top=r_i\left(Z\phi_h\left(\frac{Z^\top W^{KQ_h}z}{n}\right)\right)^\top. ∇ W P V h ℓ i ( W ) = r i ( Z v h ) ⊤ = r i ( Z ϕ h ( n Z ⊤ W K Q h z ) ) ⊤ .
Summing over i i i and taking the expectation yields the stated formula.
Then, we compute the gradient for W K Q h W^{KQ_h} W K Q h . Since v h = ϕ h ( s h ) v_h=\phi_h(s_h) v h = ϕ h ( s h ) is elementwise, we define
q h : = ∂ ℓ i ∂ s h = ( Z ⊤ ( W P V h ) ⊤ r i ) ⊙ ϕ h ′ ( s h ) . q_h:=\frac{\partial\ell_i}{\partial s_h}=\left(Z^\top(W^{PV_h})^\top r_i\right)\odot\phi_h'(s_h). q h := ∂ s h ∂ ℓ i = ( Z ⊤ ( W P V h ) ⊤ r i ) ⊙ ϕ h ′ ( s h ) .
Using the definition of s h s_h s h , we have
∇ W K Q h ℓ i ( W ) = 1 n Z q h z ⊤ = 1 n Z ( Z ⊤ ( W P V h ) ⊤ r i ) ⊙ ϕ h ′ ( s h ) ⊤ . \nabla_{W^{KQ_h}}\ell_i(W)=\frac{1}{n}Z_qh_z^{\top}=\frac{1}{n}Z\left(Z^{\top}(W^{PV_h})^{\top}r_i\right)\odot\phi_h'(s_h)^{\top}. ∇ W K Q h ℓ i ( W ) = n 1 Z q h z ⊤ = n 1 Z ( Z ⊤ ( W P V h ) ⊤ r i ) ⊙ ϕ h ′ ( s h ) ⊤ .
Plugging in ϕ 1 ′ ( t ) = 3 t ⊙ 2 \phi_1'(t)=3t^{\odot2} ϕ 1 ′ ( t ) = 3 t ⊙ 2 and ϕ 2 ′ ( t ) = ϕ 3 ′ ( t ) = 2 t \phi_2'(t)=\phi_3'(t)=2t ϕ 2 ′ ( t ) = ϕ 3 ′ ( t ) = 2 t gives exactly the gradients after summing over i i i and taking the expectation.
According to Lemma 3.3, we use the following specific initialization to zero out the irrelevant blocks.
Assumption A.8 (Initialization). We assume the parameters are initialized as
W P V 1 ( 0 ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 1 ( 0 ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 1 ( 0 ) = [ 0 d × d 0 d × 1 W 13 K Q 1 ( 0 ) W 14 K Q 1 0 1 × d 0 0 d × 1 W 24 K Q 1 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W^{PV_1}(0)=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
W^{PV_1}_{31}(0) & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix},
\qquad
W^{KQ_1}(0)=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & W^{KQ_1}_{13}(0) & W^{KQ_1}_{14}\\
0_{1\times d} & 0 & 0_{d\times1} & W^{KQ_1}_{24}\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix}, W P V 1 ( 0 ) = 0 d × d 0 1 × d W 31 P V 1 ( 0 ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 1 ( 0 ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q 1 ( 0 ) 0 d × 1 0 d × d 0 d × 1 W 14 K Q 1 W 24 K Q 1 0 d × 1 0 , W P V 2 ( 0 ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 2 ( 0 ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 2 ( 0 ) = [ 0 d × d 0 d × 1 W 13 K Q 2 ( 0 ) W 14 K Q 2 0 1 × d 0 0 d × 1 W 24 K Q 2 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W^{PV_2}(0)=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
W^{PV_2}_{31}(0) & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix},
\qquad
W^{KQ_2}(0)=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & W^{KQ_2}_{13}(0) & W^{KQ_2}_{14}\\
0_{1\times d} & 0 & 0_{d\times1} & W^{KQ_2}_{24}\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix}, W P V 2 ( 0 ) = 0 d × d 0 1 × d W 31 P V 2 ( 0 ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 2 ( 0 ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q 2 ( 0 ) 0 d × 1 0 d × d 0 d × 1 W 14 K Q 2 W 24 K Q 2 0 d × 1 0 , W P V 3 ( 0 ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 3 ( 0 ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 3 ( 0 ) = [ 0 d × d 0 d × 1 W 13 K Q 3 ( 0 ) W 14 K Q 3 0 1 × d 0 0 d × 1 W 24 K Q 3 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] . W^{PV_3}(0)=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0\\
W^{PV_3}_{31}(0) & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix},
\qquad
W^{KQ_3}(0)=
\begin{bmatrix}
0_{d\times d} & 0_{d\times1} & W^{KQ_3}_{13}(0) & W^{KQ_3}_{14}\\
0_{1\times d} & 0 & 0_{d\times1} & W^{KQ_3}_{24}\\
0_{d\times d} & 0_{d\times1} & 0_{d\times d} & 0_{d\times1}\\
0_{1\times d} & 0 & 0_{d\times1} & 0
\end{bmatrix}. W P V 3 ( 0 ) = 0 d × d 0 1 × d W 31 P V 3 ( 0 ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 3 ( 0 ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q 3 ( 0 ) 0 d × 1 0 d × d 0 d × 1 W 14 K Q 3 W 24 K Q 3 0 d × 1 0 .
Additionally, we impose a weight-sharing mechanism that ties weights across W P V i W^{PV_i} W P V i matrices and across W K Q i W^{KQ_i} W K Q i matrices. Let two underlying matrices be W 31 P V W^{PV}_{31} W 31 P V and W 13 K Q W^{KQ}_{13} W 13 K Q . We represent the matrices in the transformer with the two matrices as follows:
W 31 P V 1 ( t ) = − 2 η n 2 W 31 P V ( t ) , W 31 P V 2 ( t ) = η n 2 W 31 P V ( t ) , W 31 P V 3 ( t ) = − η n 2 W 31 P V ( t ) W^{PV_1}_{31}(t)=-2\eta n^2W^{PV}_{31}(t),\qquad
W^{PV_2}_{31}(t)=\frac{\eta n}{2}W^{PV}_{31}(t),\qquad
W^{PV_3}_{31}(t)=-\frac{\eta n}{2}W^{PV}_{31}(t) W 31 P V 1 ( t ) = − 2 η n 2 W 31 P V ( t ) , W 31 P V 2 ( t ) = 2 η n W 31 P V ( t ) , W 31 P V 3 ( t ) = − 2 η n W 31 P V ( t )
W 13 K Q 1 ( t ) = W 13 K Q ( t ) , W 13 K Q 2 ( t ) = W 13 K Q ( t ) , W 13 K Q 3 ( t ) = W 13 K Q ( t ) . W^{KQ_1}_{13}(t)=W^{KQ}_{13}(t),\qquad
W^{KQ_2}_{13}(t)=W^{KQ}_{13}(t),\qquad
W^{KQ_3}_{13}(t)=W^{KQ}_{13}(t). W 13 K Q 1 ( t ) = W 13 K Q ( t ) , W 13 K Q 2 ( t ) = W 13 K Q ( t ) , W 13 K Q 3 ( t ) = W 13 K Q ( t ) .
The weight matrices W 31 P V ( t ) W^{PV}_{31}(t) W 31 P V ( t ) and W 13 K Q ( t ) W^{KQ}_{13}(t) W 13 K Q ( t ) are updated with the combined gradient of the corresponding three weights. Further, W 31 P V ( 0 ) = ∑ i = 1 d λ i P V u i u i ⊤ W^{PV}_{31}(0)=\sum_{i=1}^{d}\lambda_i^{PV}u_i u_i^{\top} W 31 P V ( 0 ) = ∑ i = 1 d λ i P V u i u i ⊤ and W 13 K Q ( 0 ) = ∑ i = 1 d λ i K Q u i u i ⊤ W^{KQ}_{13}(0)=\sum_{i=1}^{d}\lambda_i^{KQ}u_i u_i^{\top} W 13 K Q ( 0 ) = ∑ i = 1 d λ i K Q u i u i ⊤ share the same orthonormal basis, which is symmetric and simultaneously diagonalizable. We fix W 24 K Q 1 = 0 W^{KQ_1}_{24}=0 W 24 K Q 1 = 0 , W 24 K Q 2 = 1 W^{KQ_2}_{24}=1 W 24 K Q 2 = 1 , W 24 K Q 3 = − 1 W^{KQ_3}_{24}=-1 W 24 K Q 3 = − 1 , and W 14 K Q 1 = 0 d W^{KQ_1}_{14}=0_d W 14 K Q 1 = 0 d , W 14 K Q 2 = 0 d W^{KQ_2}_{14}=0_d W 14 K Q 2 = 0 d , W 14 K Q 3 = 0 d W^{KQ_3}_{14}=0_d W 14 K Q 3 = 0 d for all t > 0 t>0 t > 0 . We take the initialization to be isotropic, λ i P V = λ V ( 0 ) \lambda_i^{PV}=\lambda_V(0) λ i P V = λ V ( 0 ) and λ i K Q = λ K ( 0 ) \lambda_i^{KQ}=\lambda_K(0) λ i K Q = λ K ( 0 ) for all i ∈ [ d ] i\in[d] i ∈ [ d ] , where for a constant σ ∈ ( 0 , 1 / 4 ) \sigma\in(0,1/4) σ ∈ ( 0 , 1/4 ) ,
λ K ( 0 ) ∈ [ 1 3 + σ , 1 ] , λ V ( 0 ) ∈ ( 0 , 1 / σ ] , λ V ( 0 ) 2 ≥ F ( λ K ( 0 ) 2 ) + σ 2 , \lambda_K(0)\in\left[\frac{1}{\sqrt{3}}+\sigma,1\right],\qquad
\lambda_V(0)\in(0,1/\sigma],\qquad
\lambda_V(0)^2\ge F(\lambda_K(0)^2)+\sigma^2, λ K ( 0 ) ∈ [ 3 1 + σ , 1 ] , λ V ( 0 ) ∈ ( 0 , 1/ σ ] , λ V ( 0 ) 2 ≥ F ( λ K ( 0 ) 2 ) + σ 2 ,
where F ( x ) : = x − 1 3 + 2 9 log 2 3 x − 1 F(x):=\frac{x-1}{3}+\frac{2}{9}\log\frac{2}{3x-1} F ( x ) := 3 x − 1 + 9 2 log 3 x − 1 2 .
We consider the gradient flow trajectory:
d W d t = − ∇ L C o T ( W ) , \frac{dW}{dt}=-\nabla L^{\mathrm{CoT}}(W), d t d W = − ∇ L CoT ( W ) ,
where
W : = [ W K Q 1 / { W 24 K Q 1 , W 14 K Q 1 } , W K Q 2 / { W 24 K Q 2 , W 14 K Q 2 } , W K Q 3 / { W 24 K Q 3 , W 14 K Q 3 } , W P V 1 , W P V 2 , W P V 3 ] . W:=\left[W^{KQ_1}/\{W^{KQ_1}_{24},W^{KQ_1}_{14}\},W^{KQ_2}/\{W^{KQ_2}_{24},W^{KQ_2}_{14}\},W^{KQ_3}/\{W^{KQ_3}_{24},W^{KQ_3}_{14}\},W^{PV_1},W^{PV_2},W^{PV_3}\right]. W := [ W K Q 1 / { W 24 K Q 1 , W 14 K Q 1 } , W K Q 2 / { W 24 K Q 2 , W 14 K Q 2 } , W K Q 3 / { W 24 K Q 3 , W 14 K Q 3 } , W P V 1 , W P V 2 , W P V 3 ] .
Next, we prove that if we initialize those matrices as in Assumption A.8, then the zero blocks will stay at 0 along the gradient descent trajectory.
Lemma A.9. Under Assumption A.8, when the transformer is trained under gradient flow, ∀ t > 0 \forall t > 0 ∀ t > 0 ,
W P V 1 ( t ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 1 × d 0 W 31 P V 1 ( t ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 1 ( t ) = [ 0 d × d 0 d × 1 W 13 K Q 1 ( t ) 0 d × 1 0 1 × d 0 0 1 × d 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W^{PV_1}(t)=\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{1\times d}&0\\W^{PV_1}_{31}(t)&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix},\quad W^{KQ_1}(t)=\begin{bmatrix}0_{d\times d}&0_{d\times1}&W^{KQ_1}_{13}(t)&0_{d\times1}\\0_{1\times d}&0&0_{1\times d}&0\\0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}, W P V 1 ( t ) = 0 d × d 0 1 × d W 31 P V 1 ( t ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 1 × d 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 1 ( t ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q 1 ( t ) 0 1 × d 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W P V 2 ( t ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 1 × d 0 W 31 P V 2 ( t ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 2 ( t ) = [ 0 d × d 0 d × 1 W 13 K Q 2 ( t ) 0 d × 1 0 1 × d 0 0 d × 1 1 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W^{PV_2}(t)=\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{1\times d}&0\\W^{PV_2}_{31}(t)&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix},\quad W^{KQ_2}(t)=\begin{bmatrix}0_{d\times d}&0_{d\times1}&W^{KQ_2}_{13}(t)&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&1\\0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}, W P V 2 ( t ) = 0 d × d 0 1 × d W 31 P V 2 ( t ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 1 × d 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 2 ( t ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q 2 ( t ) 0 d × 1 0 d × d 0 d × 1 0 d × 1 1 0 d × 1 0 , W P V 3 ( t ) = [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 3 ( t ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] , W K Q 3 ( t ) = [ 0 d × d 0 d × 1 W 13 K Q 3 ( t ) 0 d × 1 0 1 × d 0 0 d × 1 − 1 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] . W^{PV_3}(t)=\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\\W^{PV_3}_{31}(t)&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix},\quad W^{KQ_3}(t)=\begin{bmatrix}0_{d\times d}&0_{d\times1}&W^{KQ_3}_{13}(t)&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&-1\\0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}. W P V 3 ( t ) = 0 d × d 0 1 × d W 31 P V 3 ( t ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 , W K Q 3 ( t ) = 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d × 1 0 0 d × 1 0 W 13 K Q 3 ( t ) 0 d × 1 0 d × d 0 d × 1 0 d × 1 − 1 0 d × 1 0 .
Proof. We show that when the irrelevant blocks are 0, the gradients for those blocks are always 0:
W P V 1 Z i ⋅ ϕ 1 ( Z i T W K Q 1 Z i , : − 1 n ) = 1 n 3 [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 1 ( t ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] [ X 0 ⋯ 0 y 0 ⋯ 0 0 d θ 0 ⋯ θ i 0 1 ⋯ 1 ] ( Z i T W K Q 1 [ 0 0 θ i 1 ] ) ⊙ 3 = 1 n 3 [ 0 d × d 0 d ⋯ 0 d 0 1 × d 0 ⋯ 0 W 31 P V 1 ( t ) X 0 d ⋯ 0 d 0 1 × d 0 ⋯ 0 ] [ X 0 ⋯ 0 y 0 ⋯ 0 0 d θ 0 ⋯ θ i 0 1 ⋯ 1 ] T [ W 13 K Q 1 ( t ) θ i 0 0 d 0 ] ⊙ 3 = 1 n 3 [ 0 d × d 0 d ⋯ 0 d 0 1 × d 0 ⋯ 0 W 31 P V 1 ( t ) X 0 d ⋯ 0 d 0 1 × d 0 ⋯ 0 ] [ X T W 13 K Q 1 ( t ) θ i 0 i + 1 ] ⊙ 3 = 1 n 3 [ 0 d 0 W 31 P V 1 ( t ) X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 0 ] . \begin{aligned}
W^{PV_1}Z_i\cdot\phi_1\left(\frac{Z_i^{\mathsf T}W^{KQ_1}Z_{i,:-1}}{n}\right) \\
&=\frac{1}{n^3}\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\\W^{PV_1}_{31}(t)&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}
\begin{bmatrix}X&0&\cdots&0\\y&0&\cdots&0\\0_d&\theta_0&\cdots&\theta_i\\0&1&\cdots&1\end{bmatrix}
\left(Z_i^{\mathsf T}W^{KQ_1}\begin{bmatrix}0\\0\\\theta_i\\1\end{bmatrix}\right)^{\odot3} \\
&=\frac{1}{n^3}\begin{bmatrix}0_{d\times d}&0_d&\cdots&0_d\\0_{1\times d}&0&\cdots&0\\W^{PV_1}_{31}(t)X&0_d&\cdots&0_d\\0_{1\times d}&0&\cdots&0\end{bmatrix}
\begin{bmatrix}X&0&\cdots&0\\y&0&\cdots&0\\0_d&\theta_0&\cdots&\theta_i\\0&1&\cdots&1\end{bmatrix}^{\mathsf T}
\begin{bmatrix}W^{KQ_1}_{13}(t)\theta_i\\0\\0_d\\0\end{bmatrix}^{\odot3} \\
&=\frac{1}{n^3}\begin{bmatrix}0_{d\times d}&0_d&\cdots&0_d\\0_{1\times d}&0&\cdots&0\\W^{PV_1}_{31}(t)X&0_d&\cdots&0_d\\0_{1\times d}&0&\cdots&0\end{bmatrix}
\begin{bmatrix}X^{\mathsf T}W^{KQ_1}_{13}(t)\theta_i\\0_{i+1}\end{bmatrix}^{\odot3} \\
&=\frac{1}{n^3}\begin{bmatrix}0_d\\0\\W^{PV_1}_{31}(t)X\left(X^{\mathsf T}W^{KQ_1}_{13}(t)\theta_i\right)^{\odot3}\\0\end{bmatrix}.
\end{aligned} W P V 1 Z i ⋅ ϕ 1 ( n Z i T W K Q 1 Z i , : − 1 ) = n 3 1 0 d × d 0 1 × d W 31 P V 1 ( t ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 X y 0 d 0 0 0 θ 0 1 ⋯ ⋯ ⋯ ⋯ 0 0 θ i 1 Z i T W K Q 1 0 0 θ i 1 ⊙ 3 = n 3 1 0 d × d 0 1 × d W 31 P V 1 ( t ) X 0 1 × d 0 d 0 0 d 0 ⋯ ⋯ ⋯ ⋯ 0 d 0 0 d 0 X y 0 d 0 0 0 θ 0 1 ⋯ ⋯ ⋯ ⋯ 0 0 θ i 1 T W 13 K Q 1 ( t ) θ i 0 0 d 0 ⊙ 3 = n 3 1 0 d × d 0 1 × d W 31 P V 1 ( t ) X 0 1 × d 0 d 0 0 d 0 ⋯ ⋯ ⋯ ⋯ 0 d 0 0 d 0 [ X T W 13 K Q 1 ( t ) θ i 0 i + 1 ] ⊙ 3 = n 3 1 0 d 0 W 31 P V 1 ( t ) X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 0 .
For the second head, we have
W P V 2 Z i ⋅ ϕ 2 ( Z i T W K Q 2 Z i , : − 1 n ) = 1 n 2 [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 2 ( t ) 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] [ X 0 ⋯ 0 y 0 ⋯ 0 0 d θ 0 ⋯ θ i 0 1 ⋯ 1 ] ( Z i T W K Q 2 [ 0 0 θ i 1 ] ) ⊙ 2 = 1 n 2 [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 2 ( t ) X 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] [ X 0 ⋯ 0 y 0 ⋯ 0 0 d θ 0 ⋯ θ i 0 1 ⋯ 1 ] T [ W 13 K Q 2 ( t ) θ i 1 0 d 0 ] ⊙ 2 = 1 n 2 [ 0 d × d 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 W 31 P V 2 ( t ) X 0 d × 1 0 d × d 0 d × 1 0 1 × d 0 0 d × 1 0 ] [ X T W 13 K Q 2 ( t ) θ i + y T 0 i + 1 ] ⊙ 2 = 1 n 2 [ 0 d 0 W 31 P V 2 ( t ) X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 0 ] . \begin{aligned}
W^{PV_2}Z_i\cdot\phi_2\left(\frac{Z_i^{\mathsf T}W^{KQ_2}Z_{i,:-1}}{n}\right) \\
&=\frac{1}{n^2}\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\\W^{PV_2}_{31}(t)&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}
\begin{bmatrix}X&0&\cdots&0\\y&0&\cdots&0\\0_d&\theta_0&\cdots&\theta_i\\0&1&\cdots&1\end{bmatrix}
\left(Z_i^{\mathsf T}W^{KQ_2}\begin{bmatrix}0\\0\\\theta_i\\1\end{bmatrix}\right)^{\odot2} \\
&=\frac{1}{n^2}\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\\W^{PV_2}_{31}(t)X&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}
\begin{bmatrix}X&0&\cdots&0\\y&0&\cdots&0\\0_d&\theta_0&\cdots&\theta_i\\0&1&\cdots&1\end{bmatrix}^{\mathsf T}
\begin{bmatrix}W^{KQ_2}_{13}(t)\theta_i\\1\\0_d\\0\end{bmatrix}^{\odot2} \\
&=\frac{1}{n^2}\begin{bmatrix}0_{d\times d}&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\\W^{PV_2}_{31}(t)X&0_{d\times1}&0_{d\times d}&0_{d\times1}\\0_{1\times d}&0&0_{d\times1}&0\end{bmatrix}
\begin{bmatrix}X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\\0_{i+1}\end{bmatrix}^{\odot2} \\
&=\frac{1}{n^2}\begin{bmatrix}0_d\\0\\W^{PV_2}_{31}(t)X\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\\0\end{bmatrix}.
\end{aligned} W P V 2 Z i ⋅ ϕ 2 ( n Z i T W K Q 2 Z i , : − 1 ) = n 2 1 0 d × d 0 1 × d W 31 P V 2 ( t ) 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 X y 0 d 0 0 0 θ 0 1 ⋯ ⋯ ⋯ ⋯ 0 0 θ i 1 Z i T W K Q 2 0 0 θ i 1 ⊙ 2 = n 2 1 0 d × d 0 1 × d W 31 P V 2 ( t ) X 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 X y 0 d 0 0 0 θ 0 1 ⋯ ⋯ ⋯ ⋯ 0 0 θ i 1 T W 13 K Q 2 ( t ) θ i 1 0 d 0 ⊙ 2 = n 2 1 0 d × d 0 1 × d W 31 P V 2 ( t ) X 0 1 × d 0 d × 1 0 0 d × 1 0 0 d × d 0 d × 1 0 d × d 0 d × 1 0 d × 1 0 0 d × 1 0 [ X T W 13 K Q 2 ( t ) θ i + y T 0 i + 1 ] ⊙ 2 = n 2 1 0 d 0 W 31 P V 2 ( t ) X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 0 .
Similarly, for the third head, we have
W P V 3 Z i ⋅ ϕ 3 ( Z i T W K Q 3 Z [ i , − 1 ] n ) = 1 n 2 [ W 31 P V 3 ( t ) X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ] . W^{PV_3}Z_i\cdot\phi_3\left(\frac{Z_i^{\mathsf T}W^{KQ_3}Z_{[i,-1]}}{n}\right)=\frac{1}{n^2}\left[W_{31}^{PV_3}(t)X\left(X^{\mathsf T}W_{13}^{KQ_3}(t)\theta_i-y^{\mathsf T}\right)^{\odot2}\right] . W P V 3 Z i ⋅ ϕ 3 ( n Z i T W K Q 3 Z [ i , − 1 ] ) = n 2 1 [ W 31 P V 3 ( t ) X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ] .
Recall that we have the residual for a CoT step defined as
r i = ∑ h = 1 3 W P V h Z i ⋅ ϕ h ( Z i T W K Q h Z [ i , − 1 ] n ) − ( 0 d , 0 , θ i + 1 − θ i , 0 ) T = ( 0 d , 0 , r ^ i − ( θ i + 1 − θ i ) , 0 ) T , r_i=\sum_{h=1}^{3}W^{PV_h}Z_i\cdot\phi_h\left(\frac{Z_i^{\mathsf T}W^{KQ_h}Z_{[i,-1]}}{n}\right)-(0_d,0,\theta_{i+1}-\theta_i,0)^{\mathsf T}=(0_d,0,\hat r_i-(\theta_{i+1}-\theta_i),0)^{\mathsf T}, r i = h = 1 ∑ 3 W P V h Z i ⋅ ϕ h ( n Z i T W K Q h Z [ i , − 1 ] ) − ( 0 d , 0 , θ i + 1 − θ i , 0 ) T = ( 0 d , 0 , r ^ i − ( θ i + 1 − θ i ) , 0 ) T ,
where we define
r ^ i = 1 n 3 W 31 P V 1 X ( X T W 13 K Q 1 θ i ) ⊙ 3 + 1 n 2 W 31 P V 2 X ( X T W 13 K Q 2 θ i + y T ) ⊙ 2 + 1 n 2 W 31 P V 3 X ( X T W 13 K Q 3 θ i − y T ) ⊙ 2 = 1 n 3 W 31 P V 1 X ( X T W 13 K Q 1 θ i ) ⊙ 3 + 4 n 2 W 31 P V 2 X ( X T W 13 K Q 2 θ i ⊙ y T ) . (31) \begin{aligned}
\hat r_i=\frac{1}{n^3}W_{31}^{PV_1}X\left(X^{\mathsf T}W_{13}^{KQ_1}\theta_i\right)^{\odot3}+\frac{1}{n^2}W_{31}^{PV_2}X\left(X^{\mathsf T}W_{13}^{KQ_2}\theta_i+y^{\mathsf T}\right)^{\odot2} \\
&+\frac{1}{n^2}W_{31}^{PV_3}X\left(X^{\mathsf T}W_{13}^{KQ_3}\theta_i-y^{\mathsf T}\right)^{\odot2} \\
&=\frac{1}{n^3}W_{31}^{PV_1}X\left(X^{\mathsf T}W_{13}^{KQ_1}\theta_i\right)^{\odot3}+\frac{4}{n^2}W_{31}^{PV_2}X\left(X^{\mathsf T}W_{13}^{KQ_2}\theta_i\odot y^{\mathsf T}\right). \tag*{(31)}
\end{aligned} r ^ i = n 3 1 W 31 P V 1 X ( X T W 13 K Q 1 θ i ) ⊙ 3 + n 2 1 W 31 P V 2 X ( X T W 13 K Q 2 θ i + y T ) ⊙ 2 + n 2 1 W 31 P V 3 X ( X T W 13 K Q 3 θ i − y T ) ⊙ 2 = n 3 1 W 31 P V 1 X ( X T W 13 K Q 1 θ i ) ⊙ 3 + n 2 4 W 31 P V 2 X ( X T W 13 K Q 2 θ i ⊙ y T ) . (31)
The second step is because of the symmetry in Assumption A.8 that W 31 P V 2 = − W 31 P V 3 W_{31}^{PV_2}=-W_{31}^{PV_3} W 31 P V 2 = − W 31 P V 3 and W 13 K Q 2 = W 13 K Q 3 W_{13}^{KQ_2}=W_{13}^{KQ_3} W 13 K Q 2 = W 13 K Q 3 .
Now, we consider the gradient for W P V h W^{PV_h} W P V h . Denote the loss at step i i i as L i ( W ) L_i(W) L i ( W ) . For an X X X and θ ∗ \theta^* θ ∗ ,
∇ W 31 P V 1 L i ( W ) = r i ( Z i ϕ 1 ( Z i T W K Q 1 Z [ i , − 1 ] n ) ) T = 1 n 3 r i ( Z i [ X T W 13 K Q 1 ( t ) θ i 0 i + 1 ] ⊙ 3 ) T = 1 n 3 [ 0 d 0 r ^ i − ( θ i + 1 − θ i ) 0 ] [ X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 y ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 0 d 0 ] T = 1 n 3 [ 0 d × d 0 d 0 d × d 0 d 0 1 × d 0 0 1 × d 0 ∇ W 31 P V 1 L i ∇ W 32 P V 1 L i 0 d × d 0 d 0 1 × d 0 0 1 × d 0 ] \begin{aligned}
\nabla_{W_{31}^{PV_1}}L_i(W)=r_i\left(Z_i\phi_1\left(\frac{Z_i^{\mathsf T}W^{KQ_1}Z_{[i,-1]}}{n}\right)\right)^{\mathsf T}=\frac{1}{n^3}r_i\left(Z_i\left[\begin{array}{c}X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\\0_{i+1}\end{array}\right]^{\odot3}\right)^{\mathsf T} \\
&=\frac{1}{n^3}\left[\begin{array}{c}0_d\\0\\\hat r_i-(\theta_{i+1}-\theta_i)\\0\end{array}\right]\left[\begin{array}{c}X\left(X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\right)^{\odot3}\\y\left(X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\right)^{\odot3}\\0_d\\0\end{array}\right]^{\mathsf T} \\
&=\frac{1}{n^3}\left[\begin{array}{cccc}
0_{d\times d}&0_d&0_{d\times d}&0_d\\
0_{1\times d}&0&0_{1\times d}&0\\
\nabla_{W_{31}^{PV_1}}L_i&\nabla_{W_{32}^{PV_1}}L_i&0_{d\times d}&0_d\\
0_{1\times d}&0&0_{1\times d}&0
\end{array}\right]
\end{aligned} ∇ W 31 P V 1 L i ( W ) = r i ( Z i ϕ 1 ( n Z i T W K Q 1 Z [ i , − 1 ] ) ) T = n 3 1 r i ( Z i [ X T W 13 K Q 1 ( t ) θ i 0 i + 1 ] ⊙ 3 ) T = n 3 1 0 d 0 r ^ i − ( θ i + 1 − θ i ) 0 X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 y ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 0 d 0 T = n 3 1 0 d × d 0 1 × d ∇ W 31 P V 1 L i 0 1 × d 0 d 0 ∇ W 32 P V 1 L i 0 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d 0 0 d 0
where
∇ W 31 P V 1 L i = r ^ i ( X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T − ( θ i + 1 − θ i ) ( X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T \nabla_{W_{31}^{PV_1}}L_i=\hat r_i\left(X\left(X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\right)^{\odot3}\right)^{\mathsf T}-(\theta_{i+1}-\theta_i)\left(X\left(X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\right)^{\odot3}\right)^{\mathsf T} ∇ W 31 P V 1 L i = r ^ i ( X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T − ( θ i + 1 − θ i ) ( X ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T
∇ W 32 P V 1 L i = r ^ i ( y ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T − ( θ i + 1 − θ i ) ( y ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T . \nabla_{W_{32}^{PV_1}}L_i=\hat r_i\left(y\left(X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\right)^{\odot3}\right)^{\mathsf T}-(\theta_{i+1}-\theta_i)\left(y\left(X^{\mathsf T}W_{13}^{KQ_1}(t)\theta_i\right)^{\odot3}\right)^{\mathsf T}. ∇ W 32 P V 1 L i = r ^ i ( y ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T − ( θ i + 1 − θ i ) ( y ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 3 ) T .
Similarly, we calculate the gradient of W P V 2 W^{PV_2} W P V 2 . We have
∇ W P V 2 L i ( W ) = r i ( Z i ϕ 2 ( Z i T W K Q 2 Z [ i , − 1 ] n ) ) T = 1 n 2 r i ( Z i [ X T W 13 K Q 2 ( t ) θ i + y T 0 i + 1 ] ⊙ 2 ) T = 1 n 2 [ 0 d 0 r ^ i − ( θ i + 1 − θ i ) 0 ] [ X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 y ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 0 d 0 ] T = 1 n 2 [ 0 d × d 0 d 0 d × d 0 d 0 1 × d 0 0 1 × d 0 ∇ W 31 P V 2 L i ∇ W 32 P V 2 L i 0 d × d 0 d 0 1 × d 0 0 1 × d 0 ] , where \begin{aligned}
\nabla_{W^{PV_2}}L_i(W)=r_i\left(Z_i\phi_2\left(\frac{Z_i^{\mathsf T}W^{KQ_2}Z_{[i,-1]}}{n}\right)\right)^{\mathsf T}=\frac{1}{n^2}r_i\left(Z_i\left[\begin{array}{c}X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\\0_{i+1}\end{array}\right]^{\odot2}\right)^{\mathsf T} \\
&=\frac{1}{n^2}\left[\begin{array}{c}0_d\\0\\\hat r_i-(\theta_{i+1}-\theta_i)\\0\end{array}\right]\left[\begin{array}{c}X\left(X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\\y\left(X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\\0_d\\0\end{array}\right]^{\mathsf T} \\
&=\frac{1}{n^2}\left[\begin{array}{cccc}
0_{d\times d}&0_d&0_{d\times d}&0_d\\
0_{1\times d}&0&0_{1\times d}&0\\
\nabla_{W_{31}^{PV_2}}L_i&\nabla_{W_{32}^{PV_2}}L_i&0_{d\times d}&0_d\\
0_{1\times d}&0&0_{1\times d}&0
\end{array}\right],\quad\text{where}
\end{aligned} ∇ W P V 2 L i ( W ) = r i ( Z i ϕ 2 ( n Z i T W K Q 2 Z [ i , − 1 ] ) ) T = n 2 1 r i ( Z i [ X T W 13 K Q 2 ( t ) θ i + y T 0 i + 1 ] ⊙ 2 ) T = n 2 1 0 d 0 r ^ i − ( θ i + 1 − θ i ) 0 X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 y ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 0 d 0 T = n 2 1 0 d × d 0 1 × d ∇ W 31 P V 2 L i 0 1 × d 0 d 0 ∇ W 32 P V 2 L i 0 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d 0 0 d 0 , where
∇ W 31 P V 2 L i = r ^ i ( X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T \nabla_{W_{31}^{PV_2}}L_i=\hat r_i\left(X\left(X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\right)^{\mathsf T}-(\theta_{i+1}-\theta_i)\left(X\left(X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\right)^{\mathsf T} ∇ W 31 P V 2 L i = r ^ i ( X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( X ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T
∇ W 32 P V 2 L i = r ^ i ( y ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( y ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T . \nabla_{W_{32}^{PV_2}}L_i=\hat r_i\left(y\left(X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\right)^{\mathsf T}-(\theta_{i+1}-\theta_i)\left(y\left(X^{\mathsf T}W_{13}^{KQ_2}(t)\theta_i+y^{\mathsf T}\right)^{\odot2}\right)^{\mathsf T}. ∇ W 32 P V 2 L i = r ^ i ( y ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( y ( X T W 13 K Q 2 ( t ) θ i + y T ) ⊙ 2 ) T .
Also, the gradient for W 3 P V W^{PV}_{3} W 3 P V is as follows:
∇ W 3 P V L i ( W ) = r i ( Z i ϕ 3 ( Z i T W 13 K Q 3 Z i , [ − 1 ] n ) T ) = 1 n 2 r i ( Z i [ X T W 13 K Q 3 ( t ) θ i − y T 0 i + 1 ] ⊙ 2 ) T = 1 n 2 [ 0 d 0 r ^ i − ( θ i + 1 − θ i ) 0 ] [ X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 T y ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 T 0 d 0 ] T = 1 n 2 [ 0 d × d 0 d 0 d × d 0 d 0 1 × d 0 0 1 × d 0 ∇ W 31 P V L i ∇ W 32 P V L i 0 d × d 0 d 0 1 × d 0 0 1 × d 0 ] , where \begin{aligned}
\nabla_{W^{PV}_{3}} L_i(W) = r_i\left(Z_i\phi_3\left(\frac{Z_i^{\mathsf{T}}W^{KQ_3}_{13}Z_{i,[-1]}}{n}\right)^{\mathsf{T}}\right) = \frac{1}{n^2}r_i\left(Z_i\left[\frac{X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}}}{0_{i+1}}\right]^{\odot2}\right)^{\mathsf{T}} \\
&= \frac{1}{n^2}
\begin{bmatrix}
0_d\\
0\\
\hat r_i-(\theta_{i+1}-\theta_i)\\
0
\end{bmatrix}
\begin{bmatrix}
X(X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}})^{\odot2\mathsf{T}}\\
y(X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}})^{\odot2\mathsf{T}}\\
0_d\\
0
\end{bmatrix}^{\mathsf{T}} \\
&= \frac{1}{n^2}
\begin{bmatrix}
0_{d\times d} & 0_d & 0_{d\times d} & 0_d\\
0_{1\times d} & 0 & 0_{1\times d} & 0\\
\nabla_{W^{PV}_{31}}L_i & \nabla_{W^{PV}_{32}}L_i & 0_{d\times d} & 0_d\\
0_{1\times d} & 0 & 0_{1\times d} & 0
\end{bmatrix},
\quad\text{where}
\end{aligned} ∇ W 3 P V L i ( W ) = r i Z i ϕ 3 ( n Z i T W 13 K Q 3 Z i , [ − 1 ] ) T = n 2 1 r i Z i [ 0 i + 1 X T W 13 K Q 3 ( t ) θ i − y T ] ⊙ 2 T = n 2 1 0 d 0 r ^ i − ( θ i + 1 − θ i ) 0 X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 T y ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 T 0 d 0 T = n 2 1 0 d × d 0 1 × d ∇ W 31 P V L i 0 1 × d 0 d 0 ∇ W 32 P V L i 0 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d 0 0 d 0 , where
∇ W 31 P V L i = r ^ i ( X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T \nabla_{W^{PV}_{31}}L_i = \hat r_i\left(X(X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}})^{\odot2}\right)^{\mathsf{T}}-(\theta_{i+1}-\theta_i)\left(X(X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}})^{\odot2}\right)^{\mathsf{T}} ∇ W 31 P V L i = r ^ i ( X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( X ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T
∇ W 32 P V L i = r ^ i ( y ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( y ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T . \nabla_{W^{PV}_{32}}L_i = \hat r_i\left(y(X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}})^{\odot2}\right)^{\mathsf{T}}-(\theta_{i+1}-\theta_i)\left(y(X^{\mathsf{T}}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf{T}})^{\odot2}\right)^{\mathsf{T}}. ∇ W 32 P V L i = r ^ i ( y ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T − ( θ i + 1 − θ i ) ( y ( X T W 13 K Q 3 ( t ) θ i − y T ) ⊙ 2 ) T .
Next, we calculate the gradient for W K Q 1 W^{KQ_1} W K Q 1 . We write r i θ : = r ^ i − ( θ ˉ i + 1 − θ i ) r_i^\theta:=\hat r_i-(\bar\theta_{i+1}-\theta_i) r i θ := r ^ i − ( θ ˉ i + 1 − θ i ) for the θ \theta θ -block of r i r_i r i . Thus, r i = ( 0 d , 0 , r i θ , 0 ) r_i=(0_d,0,r_i^\theta,0) r i = ( 0 d , 0 , r i θ , 0 ) , and Z i T W h P V r i = [ X T W 31 P V 1 r i θ ; 0 i + 1 ] Z_i^{\mathsf{T}}W^{PV}_{h}r_i=[X^{\mathsf{T}}W^{PV_1}_{31}r_i^\theta;0_{i+1}] Z i T W h P V r i = [ X T W 31 P V 1 r i θ ; 0 i + 1 ] . Then, we have
∇ W K Q 1 L i = 1 n Z i ( ( Z i T W P V 1 r i ) ⊙ 3 ( Z i T W 13 K Q 1 Z i , [ − 1 ] n ) ⊙ 2 ) Z i , [ − 1 ] T = 1 n Z i ( [ X T W 31 P V 1 ( t ) r i θ 0 i + 1 ] ⊙ 3 n 2 [ [ X T W 13 K Q 1 ( t ) θ i 0 i + 1 ] ⊙ 2 ] ) Z i , [ − 1 ] T = 3 n 3 Z i [ [ X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 0 i + 1 ] ] Z i , [ − 1 ] T = 3 n 3 [ X ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) y ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) 0 d 0 ] [ 0 d 0 θ i T 1 ] = 3 n 3 [ 0 d × d 0 d ∇ W 13 K Q 1 L i ∇ W 14 K Q 1 L i 0 1 × d 0 ∇ W 23 K Q 1 L i ∇ W 24 K Q 1 L i 0 d × d 0 d 0 d × d 0 0 1 × d 0 0 1 × d 0 ] , where \begin{aligned}
\nabla_{W^{KQ_1}}L_i=\frac{1}{n}Z_i\left((Z_i^{\mathsf{T}}W^{PV_1}r_i)\odot3\left(\frac{Z_i^{\mathsf{T}}W^{KQ_1}_{13}Z_{i,[-1]}}{n}\right)^{\odot2}\right)Z_{i,[-1]}^{\mathsf{T}} \\
&=\frac{1}{n}Z_i\left(
\begin{bmatrix}
X^{\mathsf{T}}W^{PV_1}_{31}(t)r_i^\theta\\
0_{i+1}
\end{bmatrix}
\odot\frac{3}{n^2}
\left[
\begin{bmatrix}
X^{\mathsf{T}}W^{KQ_1}_{13}(t)\theta_i\\
0_{i+1}
\end{bmatrix}^{\odot2}
\right]\right)Z_{i,[-1]}^{\mathsf{T}} \\
&=\frac{3}{n^3}Z_i\left[
\begin{bmatrix}
X^{\mathsf{T}}W^{PV_1}_{31}(t)r_i^\theta\odot(X^{\mathsf{T}}W^{KQ_1}_{13}(t)\theta_i)^{\odot2}\\
0_{i+1}
\end{bmatrix}
\right]Z_{i,[-1]}^{\mathsf{T}} \\
&=\frac{3}{n^3}
\begin{bmatrix}
X\left(X^{\mathsf{T}}W^{PV_1}_{31}(t)r_i^\theta\odot(X^{\mathsf{T}}W^{KQ_1}_{13}(t)\theta_i)^{\odot2}\right)\\
y\left(X^{\mathsf{T}}W^{PV_1}_{31}(t)r_i^\theta\odot(X^{\mathsf{T}}W^{KQ_1}_{13}(t)\theta_i)^{\odot2}\right)\\
0_d\\
0
\end{bmatrix}
\begin{bmatrix}
0_d & 0 & \theta_i^{\mathsf{T}} & 1
\end{bmatrix} \\
&=\frac{3}{n^3}
\begin{bmatrix}
0_{d\times d} & 0_d & \nabla_{W^{KQ_1}_{13}}L_i & \nabla_{W^{KQ_1}_{14}}L_i\\
0_{1\times d} & 0 & \nabla_{W^{KQ_1}_{23}}L_i & \nabla_{W^{KQ_1}_{24}}L_i\\
0_{d\times d} & 0_d & 0_{d\times d} & 0\\
0_{1\times d} & 0 & 0_{1\times d} & 0
\end{bmatrix},
\quad\text{where}
\end{aligned} ∇ W K Q 1 L i = n 1 Z i ( Z i T W P V 1 r i ) ⊙ 3 ( n Z i T W 13 K Q 1 Z i , [ − 1 ] ) ⊙ 2 Z i , [ − 1 ] T = n 1 Z i ( [ X T W 31 P V 1 ( t ) r i θ 0 i + 1 ] ⊙ n 2 3 [ [ X T W 13 K Q 1 ( t ) θ i 0 i + 1 ] ⊙ 2 ] ) Z i , [ − 1 ] T = n 3 3 Z i [ [ X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 0 i + 1 ] ] Z i , [ − 1 ] T = n 3 3 X ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) y ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) 0 d 0 [ 0 d 0 θ i T 1 ] = n 3 3 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d 0 0 d 0 ∇ W 13 K Q 1 L i ∇ W 23 K Q 1 L i 0 d × d 0 1 × d ∇ W 14 K Q 1 L i ∇ W 24 K Q 1 L i 0 0 , where
∇ W 13 K Q 1 L i = X ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) θ i T \nabla_{W^{KQ_1}_{13}}L_i=X\left(X^{\mathsf{T}}W^{PV_1}_{31}(t)r_i^\theta\odot(X^{\mathsf{T}}W^{KQ_1}_{13}(t)\theta_i)^{\odot2}\right)\theta_i^{\mathsf{T}} ∇ W 13 K Q 1 L i = X ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) θ i T
∇ W 23 K Q 1 L i = y ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) θ i T , \nabla_{W^{KQ_1}_{23}}L_i=y\left(X^{\mathsf{T}}W^{PV_1}_{31}(t)r_i^\theta\odot(X^{\mathsf{T}}W^{KQ_1}_{13}(t)\theta_i)^{\odot2}\right)\theta_i^{\mathsf{T}}, ∇ W 23 K Q 1 L i = y ( X T W 31 P V 1 ( t ) r i θ ⊙ ( X T W 13 K Q 1 ( t ) θ i ) ⊙ 2 ) θ i T ,
and we fix W 24 K Q 1 = 0 W_{24}^{KQ_1}=0 W 24 K Q 1 = 0 and W 14 K Q 1 = 0 d W_{14}^{KQ_1}=0_d W 14 K Q 1 = 0 d for t > 0 t>0 t > 0 . Then, for head two, we have
∇ W K Q 2 L i = 1 n Z i ( Z i T W 31 P V 2 r i θ ) ⊙ 2 ( Z i T W 13 K Q 2 Z i [ : , − 1 ] n ) Z i [ : , − 1 ] T = 1 n Z i ( [ X T W 31 P V 2 ( t ) r i θ ] ⊙ 2 n [ ( X T W 13 K Q 2 ( t ) θ i + y T ) ] ) Z i [ : , − 1 ] T = 2 n 2 Z i [ ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) ] 0 i + 1 Z i [ : , − 1 ] T = 2 n 2 [ X ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) y ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) 0 d 0 ] [ 0 d 0 θ i T 1 ] = 2 n 2 [ 0 d × d 0 d ∇ W 13 K Q 2 L i ∇ W 14 K Q 2 L i 0 1 × d 0 ∇ W 23 K Q 2 L i ∇ W 24 K Q 2 L i 0 d × d 0 d 0 d × d 0 0 1 × d 0 0 1 × d 0 ] , \begin{aligned}
\nabla_{W^{KQ_2}} L_i
&=\frac{1}{n}Z_i\left(Z_i^{\mathsf T}W^{PV_2}_{31}r_i^\theta\right)\odot2\left(\frac{Z_i^{\mathsf T}W^{KQ_2}_{13}Z_{i[:, -1]}}{n}\right)Z_{i[:, -1]}^{\mathsf T}\\
&=\frac{1}{n}Z_i\left(\left[X^{\mathsf T}W^{PV_2}_{31}(t)r_i^\theta\right]\odot\frac{2}{n}\left[\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)\right]\right)Z_{i[:, -1]}^{\mathsf T}\\
&=\frac{2}{n^2}Z_i\left[\left(X^{\mathsf T}W^{PV_2}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)\right)\right]_{0_{i+1}}Z_{i[:, -1]}^{\mathsf T}\\
&=\frac{2}{n^2}
\begin{bmatrix}
X\left(X^{\mathsf T}W^{PV_2}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)\right)\\
y\left(X^{\mathsf T}W^{PV_2}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)\right)\\
0_d\\
0
\end{bmatrix}
\begin{bmatrix}
0_d & 0 & \theta_i^{\mathsf T} & 1
\end{bmatrix}\\
&=\frac{2}{n^2}
\begin{bmatrix}
0_{d\times d} & 0_d & \nabla_{W^{KQ_2}_{13}}L_i & \nabla_{W^{KQ_2}_{14}}L_i\\
0_{1\times d} & 0 & \nabla_{W^{KQ_2}_{23}}L_i & \nabla_{W^{KQ_2}_{24}}L_i\\
0_{d\times d} & 0_d & 0_{d\times d} & 0\\
0_{1\times d} & 0 & 0_{1\times d} & 0
\end{bmatrix},
\end{aligned} ∇ W K Q 2 L i = n 1 Z i ( Z i T W 31 P V 2 r i θ ) ⊙ 2 ( n Z i T W 13 K Q 2 Z i [ : , − 1 ] ) Z i [ : , − 1 ] T = n 1 Z i ( [ X T W 31 P V 2 ( t ) r i θ ] ⊙ n 2 [ ( X T W 13 K Q 2 ( t ) θ i + y T ) ] ) Z i [ : , − 1 ] T = n 2 2 Z i [ ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) ] 0 i + 1 Z i [ : , − 1 ] T = n 2 2 X ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) y ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) 0 d 0 [ 0 d 0 θ i T 1 ] = n 2 2 0 d × d 0 1 × d 0 d × d 0 1 × d 0 d 0 0 d 0 ∇ W 13 K Q 2 L i ∇ W 23 K Q 2 L i 0 d × d 0 1 × d ∇ W 14 K Q 2 L i ∇ W 24 K Q 2 L i 0 0 ,
where
∇ W 13 K Q 2 L i = X ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) θ i T \nabla_{W^{KQ_2}_{13}}L_i=X\left(X^{\mathsf T}W^{PV_2}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)\right)\theta_i^{\mathsf T} ∇ W 13 K Q 2 L i = X ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) θ i T
∇ W 23 K Q 2 L i = y ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) θ i T , \nabla_{W^{KQ_2}_{23}}L_i=y\left(X^{\mathsf T}W^{PV_2}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_2}_{13}(t)\theta_i+y^{\mathsf T}\right)\right)\theta_i^{\mathsf T}, ∇ W 23 K Q 2 L i = y ( X T W 31 P V 2 ( t ) r i θ ⊙ ( X T W 13 K Q 2 ( t ) θ i + y T ) ) θ i T ,
and we fix W 24 K Q 2 = 1 W_{24}^{KQ_2}=1 W 24 K Q 2 = 1 and W 14 K Q 2 = 0 d W_{14}^{KQ_2}=0_d W 14 K Q 2 = 0 d for t > 0 t>0 t > 0 . Similarly, we have the gradient for W K Q 3 W^{KQ_3} W K Q 3 as follows.
∇ W 13 K Q 3 L i = X ( X T W 31 P V 3 ( t ) r i θ ⊙ ( X T W 13 K Q 3 ( t ) θ i − y T ) ) θ i T \nabla_{W^{KQ_3}_{13}}L_i=X\left(X^{\mathsf T}W^{PV_3}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf T}\right)\right)\theta_i^{\mathsf T} ∇ W 13 K Q 3 L i = X ( X T W 31 P V 3 ( t ) r i θ ⊙ ( X T W 13 K Q 3 ( t ) θ i − y T ) ) θ i T
∇ W 23 K Q 3 L i = y ( X T W 31 P V 3 ( t ) r i θ ⊙ ( X T W 13 K Q 3 ( t ) θ i − y T ) ) θ i T , \nabla_{W^{KQ_3}_{23}}L_i=y\left(X^{\mathsf T}W^{PV_3}_{31}(t)r_i^\theta\odot\left(X^{\mathsf T}W^{KQ_3}_{13}(t)\theta_i-y^{\mathsf T}\right)\right)\theta_i^{\mathsf T}, ∇ W 23 K Q 3 L i = y ( X T W 31 P V 3 ( t ) r i θ ⊙ ( X T W 13 K Q 3 ( t ) θ i − y T ) ) θ i T ,
and we fix W 24 K Q 3 = − 1 W_{24}^{KQ_3}=-1 W 24 K Q 3 = − 1 and W 14 K Q 3 = 0 d W_{14}^{KQ_3}=0_d W 14 K Q 3 = 0 d for t > 0 t>0 t > 0 .
Now, we are going to show that the expected gradients with respect to the irrelevant blocks are zero, i.e., ∇ W 32 P V 1 L i \nabla_{W^{PV_1}_{32}}L_i ∇ W 32 P V 1 L i , ∇ W 32 P V 2 L i \nabla_{W^{PV_2}_{32}}L_i ∇ W 32 P V 2 L i , ∇ W 32 P V 3 L i \nabla_{W^{PV_3}_{32}}L_i ∇ W 32 P V 3 L i , ∇ W 23 K Q 1 L i \nabla_{W^{KQ_1}_{23}}L_i ∇ W 23 K Q 1 L i , ∇ W 23 K Q 2 L i \nabla_{W^{KQ_2}_{23}}L_i ∇ W 23 K Q 2 L i , ∇ W 23 K Q 3 L i \nabla_{W^{KQ_3}_{23}}L_i ∇ W 23 K Q 3 L i . We will show that E X , θ ⋆ [ ∇ W 32 P V 1 L i ] = 0 \mathbb{E}_{X,\theta^\star}\left[\nabla_{W^{PV_1}_{32}}L_i\right]=0 E X , θ ⋆ [ ∇ W 32 P V 1 L i ] = 0 , and proofs for others follow similarly.
We use the sign-flip symmetry of the Gaussian distribution to prove this fact. Denote g i : = y T a i ⊙ 3 g_i:=y^{\mathsf T}a_i^{\odot3} g i := y T a i ⊙ 3 and a i : = X T W 13 K Q 1 θ i a_i:=X^{\mathsf T}W^{KQ_1}_{13}\theta_i a i := X T W 13 K Q 1 θ i . Define a sign-flip transformation T : ( X , θ ⋆ ) ↦ ( − X , θ ⋆ ) \mathcal{T}:(X,\theta^\star)\mapsto(-X,\theta^\star) T : ( X , θ ⋆ ) ↦ ( − X , θ ⋆ ) . Since X X X has i.i.d. standard Gaussian columns, the distribution of ( X , θ ⋆ ) (X,\theta^\star) ( X , θ ⋆ ) is invariant under T \mathcal{T} T .
The parameter token θ i \theta_i θ i and the target increment θ i + 1 − θ i \theta_{i+1}-\theta_i θ i + 1 − θ i used in Z i Z_i Z i are generated by the deterministic gradient descent on the quadratic squared loss. Thus, θ i \theta_i θ i is invariant under T \mathcal{T} T . Then, based on the definitions, we have y y y is invariant under T \mathcal{T} T , and g i g_i g i will be flipped to − g i -g_i − g i under T \mathcal{T} T .
Moreover, we can show r ^ i \hat r_i r ^ i is even under T \mathcal{T} T . Under the block expressions, we have
r i θ = r ^ i − ( θ i + 1 − θ i ) = 1 n 3 W 31 P V 1 X ( X T W 13 K Q 1 θ i ) ⊙ 3 + 4 n 2 W 31 P V 2 X ( X T W 13 K Q 2 θ i ⊙ y T ) − ( θ i + 1 − θ i ) \begin{aligned}
r_i^\theta=\hat r_i-(\theta_{i+1}-\theta_i) \\
&=\frac{1}{n^3}W^{PV_1}_{31}X\left(X^{\mathsf T}W^{KQ_1}_{13}\theta_i\right)^{\odot3}+\frac{4}{n^2}W^{PV_2}_{31}X\left(X^{\mathsf T}W^{KQ_2}_{13}\theta_i\odot y^{\mathsf T}\right)-(\theta_{i+1}-\theta_i)
\end{aligned} r i θ = r ^ i − ( θ i + 1 − θ i ) = n 3 1 W 31 P V 1 X ( X T W 13 K Q 1 θ i ) ⊙ 3 + n 2 4 W 31 P V 2 X ( X T W 13 K Q 2 θ i ⊙ y T ) − ( θ i + 1 − θ i )
One can verify that r i θ r_i^\theta r i θ is invariant under the transformation T \mathcal{T} T . Thus, ∇ W 32 P V 1 L i ( W ) = r i g i \nabla_{W^{PV_1}_{32}}L_i(W)=r_i g_i ∇ W 32 P V 1 L i ( W ) = r i g i is odd under T \mathcal{T} T . Combining the above sign-flipping results and using the distributional invariance, we have
E X , θ ⋆ [ ∇ W 32 P V 1 L i ( W ) ] = E T ( X , θ ⋆ ) [ ∇ W 32 P V 1 L i ( W ) ∘ T ] = − E X , θ ⋆ [ ∇ W 32 P V 1 L i ( W ) ] , \mathbb{E}_{X,\theta^\star}\left[\nabla_{W^{PV_1}_{32}}L_i(W)\right]
=\mathbb{E}_{\mathcal{T}(X,\theta^\star)}\left[\nabla_{W^{PV_1}_{32}}L_i(W)\circ\mathcal{T}\right]
=-\mathbb{E}_{X,\theta^\star}\left[\nabla_{W^{PV_1}_{32}}L_i(W)\right], E X , θ ⋆ [ ∇ W 32 P V 1 L i ( W ) ] = E T ( X , θ ⋆ ) [ ∇ W 32 P V 1 L i ( W ) ∘ T ] = − E X , θ ⋆ [ ∇ W 32 P V 1 L i ( W ) ] ,
Therefore, E X , θ ⋆ [ ∇ W 32 P V 1 L i ( W ) ] = 0 \mathbb{E}_{X,\theta^\star}\left[\nabla_{W^{PV_1}_{32}}L_i(W)\right]=0 E X , θ ⋆ [ ∇ W 32 P V 1 L i ( W ) ] = 0 . □
Notice that the final loss only depends on the ( d + 2 ) (d+2) ( d + 2 ) to ( 2 d + 1 ) (2d+1) ( 2 d + 1 ) entries of the transformer’s output. We can simplify the model by pruning the irrelevant and zero blocks. We can define a simplified transformer, where the dynamics of the equivalent model are exactly the same as the original model.
Definition A.10. Under Assumption A.8, by Lemma A.9, for a given input Z i Z_i Z i , we can rewrite the one-layer non-linear transformer by
f W ( Z i ) = [ 0 d , 0 , ( θ i − 2 η n W 31 P V X ( X ⊤ W 13 K Q θ i ) ⊙ 3 + 2 η n W 31 P V X ( X ⊤ W 13 K Q θ i ⊙ y ⊤ ) ) , 1 ] ⊤ . f_W(Z_i)=\left[0_d,0,\left(\theta_i-\frac{2\eta}{n}W_{31}^{PV}X\left(X^\top W_{13}^{KQ}\theta_i\right)^{\odot3}+\frac{2\eta}{n}W_{31}^{PV}X\left(X^\top W_{13}^{KQ}\theta_i\odot y^\top\right)\right),1\right]^\top. f W ( Z i ) = [ 0 d , 0 , ( θ i − n 2 η W 31 P V X ( X ⊤ W 13 K Q θ i ) ⊙ 3 + n 2 η W 31 P V X ( X ⊤ W 13 K Q θ i ⊙ y ⊤ ) ) , 1 ] ⊤ . where θ i \theta_i θ i is the last column of Z i [ d + 2 : 2 d + 1 , − 1 ] Z_i[d+2:2d+1,-1] Z i [ d + 2 : 2 d + 1 , − 1 ] and y ⊤ = ( X ⊤ θ ⋆ ) ⊙ 2 y^\top=(X^\top\theta^\star)^{\odot2} y ⊤ = ( X ⊤ θ ⋆ ) ⊙ 2 where θ ⋆ \theta^\star θ ⋆ is the ground-truth weights of the function. Then, we can denote a reduced model by:
f ~ W ( Z i ) = θ i − 2 η n W 31 P V X ( X ⊤ W 13 K Q θ i ) ⊙ 3 + 2 η n W 31 P V X ( X ⊤ W 13 K Q θ i ⊙ y ⊤ ) . (32) \widetilde{f}_W(Z_i)=\theta_i-\frac{2\eta}{n}W_{31}^{PV}X\left(X^\top W_{13}^{KQ}\theta_i\right)^{\odot3}+\frac{2\eta}{n}W_{31}^{PV}X\left(X^\top W_{13}^{KQ}\theta_i\odot y^\top\right). \tag*{(32)} f W ( Z i ) = θ i − n 2 η W 31 P V X ( X ⊤ W 13 K Q θ i ) ⊙ 3 + n 2 η W 31 P V X ( X ⊤ W 13 K Q θ i ⊙ y ⊤ ) . (32) For the ease of notations, we will write f ~ W ( Z i ) = f ~ ( θ i ) \widetilde{f}_W(Z_i)=\widetilde{f}(\theta_i) f W ( Z i ) = f ( θ i ) , where θ i \theta_i θ i denotes the ( d + 2 ) (d+2) ( d + 2 ) to ( 2 d + 1 ) (2d+1) ( 2 d + 1 ) entries of the last column of Z i Z_i Z i .
In the following sections, we will consider the equivalent form of the transformer. Here we present the gradient with respect to the reduced model.
Lemma A.11. The gradients of W 31 P V W_{31}^{PV} W 31 P V and W 13 K Q W_{13}^{KQ} W 13 K Q are given by the following expectations:
∇ W 31 P V L C o T ( W ) = ∑ i = 0 T − 1 E X , θ ⋆ [ − 2 η n ( f ~ W ( θ i ) − θ i + 1 ) ( ( X ( X ⊤ W 13 K Q θ i ) ⊙ 3 ) ⊤ − ( X ( X ⊤ W 13 K Q θ i ⊙ y ⊤ ) ) ⊤ ) ] + E X , θ ⋆ [ − 2 η n ( θ T − θ ⋆ ) ( ( X ( X ⊤ W 13 K Q θ T − 1 ) ⊙ 3 ) ⊤ − ( X ( X ⊤ W 13 K Q θ T − 1 ⊙ y ⊤ ) ) ⊤ ) ] , \begin{aligned}
\nabla_{W_{31}^{PV}}L^{\mathrm{CoT}}(W)
&=\sum_{i=0}^{T-1}\mathbb{E}_{X,\theta^\star}\left[-\frac{2\eta}{n}(\widetilde{f}_W(\theta_i)-\theta_{i+1})\left(\left(X(X^\top W_{13}^{KQ}\theta_i)^{\odot3}\right)^\top-\left(X(X^\top W_{13}^{KQ}\theta_i\odot y^\top)\right)^\top\right)\right]\\
&\quad+\mathbb{E}_{X,\theta^\star}\left[-\frac{2\eta}{n}(\theta_T-\theta^\star)\left(\left(X(X^\top W_{13}^{KQ}\theta_{T-1})^{\odot3}\right)^\top-\left(X(X^\top W_{13}^{KQ}\theta_{T-1}\odot y^\top)\right)^\top\right)\right],
\end{aligned} ∇ W 31 P V L CoT ( W ) = i = 0 ∑ T − 1 E X , θ ⋆ [ − n 2 η ( f W ( θ i ) − θ i + 1 ) ( ( X ( X ⊤ W 13 K Q θ i ) ⊙ 3 ) ⊤ − ( X ( X ⊤ W 13 K Q θ i ⊙ y ⊤ ) ) ⊤ ) ] + E X , θ ⋆ [ − n 2 η ( θ T − θ ⋆ ) ( ( X ( X ⊤ W 13 K Q θ T − 1 ) ⊙ 3 ) ⊤ − ( X ( X ⊤ W 13 K Q θ T − 1 ⊙ y ⊤ ) ) ⊤ ) ] , and
∇ W 13 K Q L C o T ( W ) = ∑ i = 0 T − 1 E X , θ ⋆ [ − 2 η n X ( X ⊤ W 31 P V ⊤ ( f ~ W ( θ i ) − θ i + 1 ) ⊙ ( 3 ( X ⊤ W 13 K Q θ i ) ⊙ 2 − y ⊤ ) ) θ i ⊤ ] + E X , θ ⋆ [ − 2 η n X ( X ⊤ W 31 P V ⊤ ( θ T − θ ⋆ ) ⊙ ( 3 ( X ⊤ W 13 K Q θ T − 1 ) ⊙ 2 − y ⊤ ) ) θ T − 1 ⊤ ] . \begin{aligned}
\nabla_{W_{13}^{KQ}}L^{\mathrm{CoT}}(W)
&=\sum_{i=0}^{T-1}\mathbb{E}_{X,\theta^\star}\left[-\frac{2\eta}{n}X\left(X^\top W_{31}^{PV\top}(\widetilde{f}_W(\theta_i)-\theta_{i+1})\odot\left(3(X^\top W_{13}^{KQ}\theta_i)^{\odot2}-y^\top\right)\right)\theta_i^\top\right]\\
&\quad+\mathbb{E}_{X,\theta^\star}\left[-\frac{2\eta}{n}X\left(X^\top W_{31}^{PV\top}(\theta_T-\theta^\star)\odot\left(3(X^\top W_{13}^{KQ}\theta_{T-1})^{\odot2}-y^\top\right)\right)\theta_{T-1}^\top\right].
\end{aligned} ∇ W 13 K Q L CoT ( W ) = i = 0 ∑ T − 1 E X , θ ⋆ [ − n 2 η X ( X ⊤ W 31 P V ⊤ ( f W ( θ i ) − θ i + 1 ) ⊙ ( 3 ( X ⊤ W 13 K Q θ i ) ⊙ 2 − y ⊤ ) ) θ i ⊤ ] + E X , θ ⋆ [ − n 2 η X ( X ⊤ W 31 P V ⊤ ( θ T − θ ⋆ ) ⊙ ( 3 ( X ⊤ W 13 K Q θ T − 1 ) ⊙ 2 − y ⊤ ) ) θ T − 1 ⊤ ] .
Proof. Based on the simplified form of the transformer in Definition A.10, we can rewrite the CoT training loss as follows.
L C o T ( W ) = 1 2 E X , θ ⋆ [ ∑ i = 0 T − 2 ∥ f W ( Z i ) − ( 0 d , 0 , θ i + 1 , 1 ) ∥ 2 2 ] + 1 2 E X , θ ⋆ [ ∥ f W ( Z T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) ∥ 2 2 ] = 1 2 E X , θ ⋆ [ ∑ i = 0 T − 2 ∥ f ~ W ( θ i ) − θ i + 1 ∥ 2 2 ] + 1 2 E X , θ ⋆ [ ∥ f ~ W ( θ T − 1 ) − θ ⋆ ∥ 2 2 ] . \begin{aligned}
L^{\mathrm{CoT}}(W)
&=\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\sum_{i=0}^{T-2}\left\|f_W(Z_i)-(0_d,0,\theta_{i+1},1)\right\|_2^2\right]+\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\left\|f_W(Z_{T-1})-(0_d,0,\theta^\star,1)\right\|_2^2\right]\\
&=\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\sum_{i=0}^{T-2}\left\|\widetilde{f}_W(\theta_i)-\theta_{i+1}\right\|_2^2\right]+\frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\left\|\widetilde{f}_W(\theta_{T-1})-\theta^\star\right\|_2^2\right].
\end{aligned} L CoT ( W ) = 2 1 E X , θ ⋆ [ i = 0 ∑ T − 2 ∥ f W ( Z i ) − ( 0 d , 0 , θ i + 1 , 1 ) ∥ 2 2 ] + 2 1 E X , θ ⋆ [ ∥ f W ( Z T − 1 ) − ( 0 d , 0 , θ ⋆ , 1 ) ∥ 2 2 ] = 2 1 E X , θ ⋆ [ i = 0 ∑ T − 2 f W ( θ i ) − θ i + 1 2 2 ] + 2 1 E X , θ ⋆ [ f W ( θ T − 1 ) − θ ⋆ 2 2 ] .
Here, we split the loss between the last step output and the ground-truth weights θ ⋆ \theta^\star θ ⋆ .
Then, based on the gradient computation in Lemma A.9, we can write out the gradient for the weight matrix W P V W^{PV} W P V in the transformer. Recall that in Assumption A.8, we use a weight-sharing mechanism that defines W 31 P V 1 ( t ) = − 2 η n − 2 W 31 P V ( t ) W_{31}^{PV1}(t)=-2\eta n^{-2}W_{31}^{PV}(t) W 31 P V 1 ( t ) = − 2 η n − 2 W 31 P V ( t ) , W 31 P V 2 ( t ) = η n 2 W 31 P V ( t ) W_{31}^{PV2}(t)=\frac{\eta}{n^2}W_{31}^{PV}(t) W 31 P V 2 ( t ) = n 2 η W 31 P V ( t ) , W 31 P V 3 ( t ) = − η n 2 W 31 P V ( t ) W_{31}^{PV3}(t)=-\frac{\eta}{n^2}W_{31}^{PV}(t) W 31 P V 3 ( t ) = − n 2 η W 31 P V ( t ) . Therefore,
∇ W 31 P V L C o T ( W ) = − 2 η n 2 ∇ W 31 P V 1 L C o T ( W ) + η n 2 ∇ W 31 P V 2 L C o T ( W ) − η n 2 ∇ W 31 P V 3 L C o T ( W ) = ∑ i = 0 T − 2 E X , θ ∗ [ − 2 η n ( f ~ W ( θ i ) − θ i + 1 ) ( X ( X T W 13 K Q θ i ) ⊙ 3 ) T ] + E X , θ ∗ [ − 2 η n ( f ~ W ( θ T − 1 ) − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ) ⊙ 3 ) T ] − ∑ i = 0 T − 2 E X , θ ∗ [ − 2 η n ( f ~ W ( θ i ) − θ i + 1 ) ( X ( X T W 13 K Q θ i ⊙ y T ) ) T ] − E X , θ ∗ [ − 2 η n ( f ~ W ( θ T − 1 ) − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ⊙ y T ) ) T ] = ∑ i = 0 T − 1 E X , θ ∗ [ − 2 η n ( f ~ W ( θ i ) − θ i + 1 ) ( ( X ( X T W 13 K Q θ i ) ⊙ 3 ) T − ( X ( X T W 13 K Q θ i ⊙ y T ) ) T ) ] + E X , θ ∗ [ − 2 η n ( θ T − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ) ⊙ 3 ) T + 2 η n ( θ T − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ⊙ y T ) ) T ] . \begin{aligned}
\nabla_{W_{31}^{PV}}L^{\mathrm{CoT}}(W)
&=-2\eta n^2\nabla_{W_{31}^{PV_1}}L^{\mathrm{CoT}}(W)+\frac{\eta n}{2}\nabla_{W_{31}^{PV_2}}L^{\mathrm{CoT}}(W)-\frac{\eta n}{2}\nabla_{W_{31}^{PV_3}}L^{\mathrm{CoT}}(W)\\
&=\sum_{i=0}^{T-2}\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_i)-\theta_{i+1}\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_i\right)^{\odot3}\right)^{\mathsf T}\right]\\
&\quad+\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_{T-1})-\theta^*\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\right)^{\odot3}\right)^{\mathsf T}\right]\\
&\quad-\sum_{i=0}^{T-2}\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_i)-\theta_{i+1}\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_i\odot y^{\mathsf T}\right)\right)^{\mathsf T}\right]\\
&\quad-\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_{T-1})-\theta^*\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\odot y^{\mathsf T}\right)\right)^{\mathsf T}\right]\\
&=\sum_{i=0}^{T-1}\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_i)-\theta_{i+1}\right)\left(\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_i\right)^{\odot3}\right)^{\mathsf T}-\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_i\odot y^{\mathsf T}\right)\right)^{\mathsf T}\right)\right]\\
&\quad+\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\theta_T-\theta^*\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\right)^{\odot3}\right)^{\mathsf T}+\frac{2\eta}{n}\left(\theta_T-\theta^*\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\odot y^{\mathsf T}\right)\right)^{\mathsf T}\right].
\end{aligned} ∇ W 31 P V L CoT ( W ) = − 2 η n 2 ∇ W 31 P V 1 L CoT ( W ) + 2 η n ∇ W 31 P V 2 L CoT ( W ) − 2 η n ∇ W 31 P V 3 L CoT ( W ) = i = 0 ∑ T − 2 E X , θ ∗ [ − n 2 η ( f W ( θ i ) − θ i + 1 ) ( X ( X T W 13 K Q θ i ) ⊙ 3 ) T ] + E X , θ ∗ [ − n 2 η ( f W ( θ T − 1 ) − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ) ⊙ 3 ) T ] − i = 0 ∑ T − 2 E X , θ ∗ [ − n 2 η ( f W ( θ i ) − θ i + 1 ) ( X ( X T W 13 K Q θ i ⊙ y T ) ) T ] − E X , θ ∗ [ − n 2 η ( f W ( θ T − 1 ) − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ⊙ y T ) ) T ] = i = 0 ∑ T − 1 E X , θ ∗ [ − n 2 η ( f W ( θ i ) − θ i + 1 ) ( ( X ( X T W 13 K Q θ i ) ⊙ 3 ) T − ( X ( X T W 13 K Q θ i ⊙ y T ) ) T ) ] + E X , θ ∗ [ − n 2 η ( θ T − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ) ⊙ 3 ) T + n 2 η ( θ T − θ ∗ ) ( X ( X T W 13 K Q θ T − 1 ⊙ y T ) ) T ] .
The last step is because we subtract
E X , θ ∗ [ − 2 η n ( f ~ W ( θ T − 1 ) − θ T ) ( X ( X T W 13 K Q θ T − 1 ) ⊙ 3 ) T ] \mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_{T-1})-\theta_T\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\right)^{\odot3}\right)^{\mathsf T}\right] E X , θ ∗ [ − n 2 η ( f W ( θ T − 1 ) − θ T ) ( X ( X T W 13 K Q θ T − 1 ) ⊙ 3 ) T ]
from the second term and put it into the first term, then subtract
E X , θ ∗ [ − 2 η n ( f ~ W ( θ T − 1 ) − θ T ) ( X ( X T W 13 K Q θ T − 1 ⊙ y T ) ) ] \mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}\left(\widetilde{f}_W(\theta_{T-1})-\theta_T\right)\left(X\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\odot y^{\mathsf T}\right)\right)\right] E X , θ ∗ [ − n 2 η ( f W ( θ T − 1 ) − θ T ) ( X ( X T W 13 K Q θ T − 1 ⊙ y T ) ) ]
from the fourth term and put it into the third term.
Similarly, we can break down the gradient for W 13 K Q W_{13}^{KQ} W 13 K Q . Recall that in Assumption A.8 , we use a weight-sharing mechanism that defines W 13 K Q 1 ( t ) = W 13 K Q ( t ) , W 13 K Q 2 ( t ) = W 13 K Q ( t ) , W 13 K Q 3 ( t ) = W 13 K Q ( t ) W_{13}^{KQ_1}(t)=W_{13}^{KQ}(t), W_{13}^{KQ_2}(t)=W_{13}^{KQ}(t), W_{13}^{KQ_3}(t)=W_{13}^{KQ}(t) W 13 K Q 1 ( t ) = W 13 K Q ( t ) , W 13 K Q 2 ( t ) = W 13 K Q ( t ) , W 13 K Q 3 ( t ) = W 13 K Q ( t ) . Therefore, we have
∇ W 13 K Q L C o T ( W ) = ∇ W 13 K Q 1 L C o T ( W ) + ∇ W 13 K Q 2 L C o T ( W ) + ∇ W 13 K Q 3 L C o T ( W ) = ∑ i = 0 T − 1 E X , θ ∗ [ − 6 η n X ( X T W 31 P V T ( f ~ W ( θ i ) − θ i + 1 ) ⊙ ( X T W 13 K Q θ i ) ⊙ 2 ) θ i T ] + E X , θ ∗ [ − 6 η n X ( X T W 31 P V T ( θ T − θ ∗ ) ⊙ ( X T W 13 K Q θ T − 1 ) ⊙ 2 ) θ T − 1 T ] − ∑ i = 0 T − 1 E X , θ ∗ [ − 2 η n X ( X T W 31 P V T ( f ~ W ( θ i ) − θ i + 1 ) ⊙ y T ) θ i T ] − E X , θ ∗ [ − 2 η n X ( X T W 31 P V T ( θ T − θ ∗ ) ⊙ y T ) θ T − 1 T ] = ∑ i = 0 T − 1 E X , θ ∗ [ − 2 η n X ( X T W 31 P V T ( f ~ W ( θ i ) − θ i + 1 ) ⊙ ( 3 ( X T W 13 K Q θ i ) ⊙ 2 − y T ) ) θ i T ] + E X , θ ∗ [ − 2 η n X ( X T W 31 P V T ( θ T − θ ∗ ) ⊙ ( 3 ( X T W 13 K Q θ T − 1 ) ⊙ 2 − y T ) ) θ T − 1 T ] . \begin{aligned}
\nabla_{W_{13}^{KQ}}L^{\mathrm{CoT}}(W)
&=\nabla_{W_{13}^{KQ_1}}L^{\mathrm{CoT}}(W)+\nabla_{W_{13}^{KQ_2}}L^{\mathrm{CoT}}(W)+\nabla_{W_{13}^{KQ_3}}L^{\mathrm{CoT}}(W)\\
&=\sum_{i=0}^{T-1}\mathbb{E}_{X,\theta^*}\left[-\frac{6\eta}{n}X\left(X^{\mathsf T}W_{31}^{PV^{\mathsf T}}\left(\widetilde{f}_W(\theta_i)-\theta_{i+1}\right)\odot\left(X^{\mathsf T}W_{13}^{KQ}\theta_i\right)^{\odot2}\right)\theta_i^{\mathsf T}\right]\\
&\quad+\mathbb{E}_{X,\theta^*}\left[-\frac{6\eta}{n}X\left(X^{\mathsf T}W_{31}^{PV^{\mathsf T}}\left(\theta_T-\theta^*\right)\odot\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\right)^{\odot2}\right)\theta_{T-1}^{\mathsf T}\right]\\
&\quad-\sum_{i=0}^{T-1}\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}X\left(X^{\mathsf T}W_{31}^{PV^{\mathsf T}}\left(\widetilde{f}_W(\theta_i)-\theta_{i+1}\right)\odot y^{\mathsf T}\right)\theta_i^{\mathsf T}\right]\\
&\quad-\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}X\left(X^{\mathsf T}W_{31}^{PV^{\mathsf T}}\left(\theta_T-\theta^*\right)\odot y^{\mathsf T}\right)\theta_{T-1}^{\mathsf T}\right]\\
&=\sum_{i=0}^{T-1}\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}X\left(X^{\mathsf T}W_{31}^{PV^{\mathsf T}}\left(\widetilde{f}_W(\theta_i)-\theta_{i+1}\right)\odot\left(3\left(X^{\mathsf T}W_{13}^{KQ}\theta_i\right)^{\odot2}-y^{\mathsf T}\right)\right)\theta_i^{\mathsf T}\right]\\
&\quad+\mathbb{E}_{X,\theta^*}\left[-\frac{2\eta}{n}X\left(X^{\mathsf T}W_{31}^{PV^{\mathsf T}}\left(\theta_T-\theta^*\right)\odot\left(3\left(X^{\mathsf T}W_{13}^{KQ}\theta_{T-1}\right)^{\odot2}-y^{\mathsf T}\right)\right)\theta_{T-1}^{\mathsf T}\right].
\end{aligned} ∇ W 13 K Q L CoT ( W ) = ∇ W 13 K Q 1 L CoT ( W ) + ∇ W 13 K Q 2 L CoT ( W ) + ∇ W 13 K Q 3 L CoT ( W ) = i = 0 ∑ T − 1 E X , θ ∗ [ − n 6 η X ( X T W 31 P V T ( f W ( θ i ) − θ i + 1 ) ⊙ ( X T W 13 K Q θ i ) ⊙ 2 ) θ i T ] + E X , θ ∗ [ − n 6 η X ( X T W 31 P V T ( θ T − θ ∗ ) ⊙ ( X T W 13 K Q θ T − 1 ) ⊙ 2 ) θ T − 1 T ] − i = 0 ∑ T − 1 E X , θ ∗ [ − n 2 η X ( X T W 31 P V T ( f W ( θ i ) − θ i + 1 ) ⊙ y T ) θ i T ] − E X , θ ∗ [ − n 2 η X ( X T W 31 P V T ( θ T − θ ∗ ) ⊙ y T ) θ T − 1 T ] = i = 0 ∑ T − 1 E X , θ ∗ [ − n 2 η X ( X T W 31 P V T ( f W ( θ i ) − θ i + 1 ) ⊙ ( 3 ( X T W 13 K Q θ i ) ⊙ 2 − y T ) ) θ i T ] + E X , θ ∗ [ − n 2 η X ( X T W 31 P V T ( θ T − θ ∗ ) ⊙ ( 3 ( X T W 13 K Q θ T − 1 ) ⊙ 2 − y T ) ) θ T − 1 T ] .
Proof of Theorem 3.4
With the above computed gradients, we now prove the main theorem on the convergence of transformers trained on quadratic functions. We characterize the training dynamics using ordinary differential equations in terms of the eigenvalues of the transformer weights. We first characterize the gradient of the CoT objective as a main term plus interaction terms, which yields an ordinary differential equation for the eigenvalues of the two trained blocks. Then, we analyze the ordinary differential equation in stages.
Proof. We first use the gradient computation in Lemma A.11 and derive ordinary differential equations for the eigenvalues of the weight matrices W 31 P V W_{31}^{PV} W 31 P V and W 13 K Q W_{13}^{KQ} W 13 K Q . By Assumption A.8 , we have weight matrices in the form for all t ≥ 0 t \ge0 t ≥ 0 :
W 31 P V ( t ) = λ V ( t ) I d , W 13 K Q ( t ) = λ K ( t ) I d , W_{31}^{PV}(t) = \lambda_V(t) I_{d}, \qquad W_{13}^{KQ}(t) = \lambda_K(t) I_{d}, W 31 P V ( t ) = λ V ( t ) I d , W 13 K Q ( t ) = λ K ( t ) I d ,
where the dynamics reduce to the two eigenvalues λ V ( t ) \lambda_V(t) λ V ( t ) and λ K ( t ) \lambda_K(t) λ K ( t ) . Consider that the gradient descent initialization satisfies θ 0 = α 0 θ ⋆ \theta_0 = \alpha_0 \theta^\star θ 0 = α 0 θ ⋆ with a constant α 0 ∈ [ 3 / 4 , 1 ) \alpha_0 \in[3/4, 1) α 0 ∈ [ 3/4 , 1 ) , and take n = Θ ( d 2 log 5 d ) n = \Theta(d^2 \log^5 d) n = Θ ( d 2 log 5 d ) . We will show that the gradients in the eigenbasis admit the following decomposition
∇ W 31 P V L C o T ( W ) = ( g V ( λ V , λ K ) + Δ V ) I d , \nabla_{W_{31}^{PV}} L^{\mathrm{CoT}}(W) = \left(g_V(\lambda_V,\lambda_K) + \Delta^V\right) I_d, ∇ W 31 P V L CoT ( W ) = ( g V ( λ V , λ K ) + Δ V ) I d ,
∇ W 13 K Q L C o T ( W ) = ( g K ( λ V , λ K ) + Δ K ) I d , \nabla_{W_{13}^{KQ}} L^{\mathrm{CoT}}(W) = \left(g_K(\lambda_V,\lambda_K) + \Delta^K\right) I_d, ∇ W 13 K Q L CoT ( W ) = ( g K ( λ V , λ K ) + Δ K ) I d ,
where g V , g K g_V, g_K g V , g K are explicit main terms, and Δ V , Δ K \Delta^V, \Delta^K Δ V , Δ K are interaction terms. The induced eigenvalue ODEs can be represented by
λ ˙ V ( t ) = − g V ( λ V ( t ) , λ K ( t ) ) − Δ V ( t ) , λ ˙ K ( t ) = − g K ( λ V ( t ) , λ K ( t ) ) − Δ K ( t ) , \dot{\lambda}_V(t) = -g_V(\lambda_V(t),\lambda_K(t)) - \Delta^V(t), \qquad\dot{\lambda}_K(t) = -g_K(\lambda_V(t),\lambda_K(t)) - \Delta^K(t), λ ˙ V ( t ) = − g V ( λ V ( t ) , λ K ( t )) − Δ V ( t ) , λ ˙ K ( t ) = − g K ( λ V ( t ) , λ K ( t )) − Δ K ( t ) ,
In particular, by expanding the main terms around the construction λ V = λ K = 1 \lambda_V = \lambda_K = 1 λ V = λ K = 1 , we will show that
g V ( λ V , λ K ) = 36 κ 2 ∑ i = 0 T − 1 β i ( 1 − β i ) [ ( 1 − β i ) ( λ V − 1 ) + ( 1 − 3 β i ) ( λ K − 1 ) ] + O ( ∣ λ V − 1 ∣ 2 + ∣ λ K − 1 ∣ 2 ) , g_V(\lambda_V,\lambda_K) = 36\kappa^2 \sum_{i=0}^{T-1} \beta_i(1-\beta_i)\left[(1-\beta_i)(\lambda_V-1) + (1-3\beta_i)(\lambda_K-1)\right]
+ O\left(|\lambda_V-1|^2 + |\lambda_K-1|^2\right), g V ( λ V , λ K ) = 36 κ 2 i = 0 ∑ T − 1 β i ( 1 − β i ) [ ( 1 − β i ) ( λ V − 1 ) + ( 1 − 3 β i ) ( λ K − 1 ) ] + O ( ∣ λ V − 1 ∣ 2 + ∣ λ K − 1 ∣ 2 ) ,
g K ( λ V , λ K ) = 36 κ 2 ∑ i = 0 T − 1 β i ( 1 − 3 β i ) [ ( 1 − β i ) ( λ V − 1 ) + ( 1 − 3 β i ) ( λ K − 1 ) ] + O ( ∣ λ V − 1 ∣ 2 + ∣ λ K − 1 ∣ 2 ) , g_K(\lambda_V,\lambda_K) = 36\kappa^2 \sum_{i=0}^{T-1} \beta_i(1-3\beta_i)\left[(1-\beta_i)(\lambda_V-1) + (1-3\beta_i)(\lambda_K-1)\right]
+ O\left(|\lambda_V-1|^2 + |\lambda_K-1|^2\right), g K ( λ V , λ K ) = 36 κ 2 i = 0 ∑ T − 1 β i ( 1 − 3 β i ) [ ( 1 − β i ) ( λ V − 1 ) + ( 1 − 3 β i ) ( λ K − 1 ) ] + O ( ∣ λ V − 1 ∣ 2 + ∣ λ K − 1 ∣ 2 ) ,
where the coefficients depend only on ( T , κ , α 0 ) (T,\kappa,\alpha_0) ( T , κ , α 0 ) , and the weights β i ∈ [ α 0 2 , 1 ) \beta_i \in[\alpha_0^2,1) β i ∈ [ α 0 2 , 1 ) .
Now, we derive the explicit forms of the ODE. Based on Lemma A.9, if the parameters are initialized as in Assumption A.8 , then under gradient flow all zero blocks remain zero for all t > 0 t > 0 t > 0 . Hence, the model dynamics are fully characterized by the two matrices W 31 P V ( t ) W_{31}^{PV}(t) W 31 P V ( t ) and W 13 K Q ( t ) W_{13}^{KQ}(t) W 13 K Q ( t ) . Then, we write the reduced form of the transformer as in Equation (32) .
The chain-of-thought training loss can be written as
L C o T ( W ) = 1 2 E X , θ ⋆ [ ∑ i = 0 T − 2 ∥ f ~ W ( θ i ) − θ i + 1 ∥ 2 2 + ∥ f ~ W ( θ T − 1 ) − θ ⋆ ∥ 2 2 ] . L^{\mathrm{CoT}}(W) = \frac{1}{2}\mathbb{E}_{X,\theta^\star}\left[\sum_{i=0}^{T-2}\left\|\widetilde f_W(\theta_i)-\theta_{i+1}\right\|_2^2 + \left\|\widetilde f_W(\theta_{T-1})-\theta^\star\right\|_2^2\right]. L CoT ( W ) = 2 1 E X , θ ⋆ [ i = 0 ∑ T − 2 f W ( θ i ) − θ i + 1 2 2 + f W ( θ T − 1 ) − θ ⋆ 2 2 ] .
with the residuals defined as
e i : = { f ~ W ( θ i ) − θ i + 1 , i = 0 , … , T − 2 , f ~ W ( θ T − 1 ) − θ ⋆ , i = T − 1. e_i := \begin{cases}
\widetilde f_W(\theta_i)-\theta_{i+1}, & i=0,\ldots,T-2,\\
\widetilde f_W(\theta_{T-1})-\theta^\star, & i=T-1.
\end{cases} e i := { f W ( θ i ) − θ i + 1 , f W ( θ T − 1 ) − θ ⋆ , i = 0 , … , T − 2 , i = T − 1.
Let
Ψ ( θ ) : = X ( ( X ⊤ W 13 K Q θ ) ⊙ 3 − ( X ⊤ W 13 K Q θ ) ⊙ y ⊤ ) . \Psi(\theta) := X\left((X^\top W_{13}^{KQ}\theta)^{\odot3} - (X^\top W_{13}^{KQ}\theta)\odot y^\top\right). Ψ ( θ ) := X ( ( X ⊤ W 13 K Q θ ) ⊙ 3 − ( X ⊤ W 13 K Q θ ) ⊙ y ⊤ ) .
Then the gradients of the reduced parameters are
∇ W 31 P V L C o T ( W ) = E [ ∑ i = 0 T − 1 2 η n e i Ψ ( θ i ) ⊤ ] (33) \nabla_{W_{31}^{PV}} L^{\mathrm{CoT}}(W) = \mathbb{E}\left[\sum_{i=0}^{T-1}\frac{2\eta}{n}e_i\Psi(\theta_i)^\top\right] \tag*{(33)} ∇ W 31 P V L CoT ( W ) = E [ i = 0 ∑ T − 1 n 2 η e i Ψ ( θ i ) ⊤ ] (33)
∇ W 13 K Q L C o T ( W ) = E [ ∑ i = 0 T − 1 2 η n X ( ( X ⊤ W 31 P V e i ) ⊙ ( 3 ( X ⊤ W 13 K Q θ i ) ⊙ 2 − y ⊤ ) ) θ i ⊤ ] . (34) \nabla_{W_{13}^{KQ}} L^{\mathrm{CoT}}(W) = \mathbb{E}\left[\sum_{i=0}^{T-1}\frac{2\eta}{n}X\left((X^\top W_{31}^{PV}e_i)\odot\left(3(X^\top W_{13}^{KQ}\theta_i)^{\odot2}-y^\top\right)\right)\theta_i^\top\right]. \tag*{(34)} ∇ W 13 K Q L CoT ( W ) = E [ i = 0 ∑ T − 1 n 2 η X ( ( X ⊤ W 31 P V e i ) ⊙ ( 3 ( X ⊤ W 13 K Q θ i ) ⊙ 2 − y ⊤ ) ) θ i ⊤ ] . (34)
As in Assumption A.8, assume W 31 P V ( t ) W_{31}^{\mathrm{PV}}(t) W 31 PV ( t ) and W 13 K Q ( t ) W_{13}^{\mathrm{KQ}}(t) W 13 KQ ( t ) are symmetric and share an orthonormal eigenbasis U U U . Rotating all variables by U T U^{\mathsf{T}} U T leaves the data distribution invariant, so we can work in the basis where U = I d U=I_d U = I d and both matrices are diagonal. Thus, the isotropy is preserved. The dynamics reduce to ODEs for the eigenvalues λ V ( t ) \lambda_V(t) λ V ( t ) and λ K ( t ) \lambda_K(t) λ K ( t ) .
Then, we further write the ODE as the expectation over θ ⋆ \theta^\star θ ⋆ and X X X . Let θ ⋆ ∼ N ( 0 , I d ) \theta^\star\sim\mathcal{N}(0,I_d) θ ⋆ ∼ N ( 0 , I d ) and initialize θ 0 = α 0 θ ⋆ \theta_0=\alpha_0\theta^\star θ 0 = α 0 θ ⋆ with α 0 ∈ [ 3 / 4 , 1 ) \alpha_0\in[3/4,1) α 0 ∈ [ 3/4 , 1 ) . Then, gradient descent on the quadratic functions preserves collinearity, so θ i = α i θ ⋆ \theta_i=\alpha_i\theta^\star θ i = α i θ ⋆ , α i + 1 = α i − 6 η ∥ θ ⋆ ∥ 2 α i ( α i 2 − 1 ) \alpha_{i+1}=\alpha_i-6\eta\lVert\theta^\star\rVert^2\alpha_i(\alpha_i^2-1) α i + 1 = α i − 6 η ∥ θ ⋆ ∥ 2 α i ( α i 2 − 1 ) . Here, α i \alpha_i α i are scalars that only depend on the data ∥ θ ⋆ ∥ 2 \lVert\theta^\star\rVert^2 ∥ θ ⋆ ∥ 2 . Let α ˉ i \bar{\alpha}_i α ˉ i follow the same recursion with ∥ θ ⋆ ∥ 2 \lVert\theta^\star\rVert^2 ∥ θ ⋆ ∥ 2 replaced by its mean d d d , and let β i : = α ˉ i 2 \beta_i:=\bar{\alpha}_i^2 β i := α ˉ i 2 . The empirical iterates θ i \theta_i θ i stay close to α i θ ⋆ \alpha_i\theta^\star α i θ ⋆ , and ∥ θ ⋆ ∥ 2 \lVert\theta^\star\rVert^2 ∥ θ ⋆ ∥ 2 is close to d d d .
Given W 31 P V = λ V I d W_{31}^{\mathrm{PV}}=\lambda_V I_d W 31 PV = λ V I d and W 13 K Q = λ K I d W_{13}^{\mathrm{KQ}}=\lambda_K I_d W 13 KQ = λ K I d , let
s : = 1 − λ V λ K 3 , τ : = 1 − λ V λ K , s:=1-\lambda_V\lambda_K^3,\qquad\tau:=1-\lambda_V\lambda_K, s := 1 − λ V λ K 3 , τ := 1 − λ V λ K ,
which both vanish at the construction λ V = λ K = 1 \lambda_V=\lambda_K=1 λ V = λ K = 1 . Then, we have
Ψ ( θ ) = λ K 3 X ( X T θ ) ⊙ 3 − λ K X ( ( X T θ ) ⊙ y T ) , \Psi(\theta)=\lambda_K^3X(X^{\mathsf{T}}\theta)^{\odot3}-\lambda_KX((X^{\mathsf{T}}\theta)\odot y^{\mathsf{T}}), Ψ ( θ ) = λ K 3 X ( X T θ ) ⊙ 3 − λ K X (( X T θ ) ⊙ y T ) ,
for i ≤ T − 2 i\leq T-2 i ≤ T − 2 ,
e i = 2 η n ( s X ( X T θ i ) ⊙ 3 − τ X ( ( X T θ i ) ⊙ y T ) ) , e_i=\frac{2\eta}{n}\left(sX(X^{\mathsf{T}}\theta_i)^{\odot3}-\tau X((X^{\mathsf{T}}\theta_i)\odot y^{\mathsf{T}})\right), e i = n 2 η ( s X ( X T θ i ) ⊙ 3 − τ X (( X T θ i ) ⊙ y T ) ) ,
and e T − 1 e_{T-1} e T − 1 is the same expression plus θ T − θ ⋆ \theta_T-\theta^\star θ T − θ ⋆ . As the other terms do not depend on ( λ V , λ K ) (\lambda_V,\lambda_K) ( λ V , λ K ) , L C o T L^{\mathrm{CoT}} L CoT is exactly a quadratic function of ( s , τ ) (s,\tau) ( s , τ ) .
Then, we apply the expectation to the Gaussian moment. for x ∼ N ( 0 , I d ) x\sim\mathcal{N}(0,I_d) x ∼ N ( 0 , I d ) and fixed vectors v , w ∈ R d v,w\in\mathbb{R}^d v , w ∈ R d , we have E [ x ( x T v ) 3 ] = 3 ∥ v ∥ 2 v \mathbb{E}[x(x^{\mathsf{T}}v)^3]=3\lVert v\rVert^2v E [ x ( x T v ) 3 ] = 3 ∥ v ∥ 2 v , E [ x ( x T v ) ( x T w ) 2 ] = ∥ w ∥ 2 v + 2 ( v T w ) w \mathbb{E}[x(x^{\mathsf{T}}v)(x^{\mathsf{T}}w)^2]=\lVert w\rVert^2v+2(v^{\mathsf{T}}w)w E [ x ( x T v ) ( x T w ) 2 ] = ∥ w ∥ 2 v + 2 ( v T w ) w . Applying these identities yields the population expectation
E X [ Ψ ( θ ) ∣ θ , θ ⋆ ] = n ( 3 λ K 3 ∥ θ ∥ 2 θ − λ K ( ∥ θ ⋆ ∥ 2 θ + 2 ( θ T θ ⋆ ) θ ⋆ ) ) . (35) \mathbb{E}_X[\Psi(\theta)\mid\theta,\theta^\star]=n\left(3\lambda_K^3\lVert\theta\rVert^2\theta-\lambda_K\left(\lVert\theta^\star\rVert^2\theta+2(\theta^{\mathsf{T}}\theta^\star)\theta^\star\right)\right). \tag*{(35)} E X [ Ψ ( θ ) ∣ θ , θ ⋆ ] = n ( 3 λ K 3 ∥ θ ∥ 2 θ − λ K ( ∥ θ ⋆ ∥ 2 θ + 2 ( θ T θ ⋆ ) θ ⋆ ) ) . (35)
In particular, at θ = α θ ⋆ \theta=\alpha\theta^\star θ = α θ ⋆ the expectations of 1 n X ( X T θ ) ⊙ 3 \frac{1}{n}X(X^{\mathsf{T}}\theta)^{\odot3} n 1 X ( X T θ ) ⊙ 3 and 1 n X ( ( X T θ ) ⊙ y T ) \frac{1}{n}X((X^{\mathsf{T}}\theta)\odot y^{\mathsf{T}}) n 1 X (( X T θ ) ⊙ y T ) are 3 α 3 ∥ θ ⋆ ∥ 2 θ ⋆ 3\alpha^3\lVert\theta^\star\rVert^2\theta^\star 3 α 3 ∥ θ ⋆ ∥ 2 θ ⋆ and 3 α ∥ θ ⋆ ∥ 2 θ ⋆ 3\alpha\lVert\theta^\star\rVert^2\theta^\star 3 α ∥ θ ⋆ ∥ 2 θ ⋆ .
We keep only the population parts and replace ∥ θ ⋆ ∥ 2 \lVert\theta^\star\rVert^2 ∥ θ ⋆ ∥ 2 by d d d and α i \alpha_i α i by α ˉ i \bar{\alpha}_i α ˉ i , which defines the main terms. The remaining terms are the interaction terms. Then, taking the exact expectation over θ ⋆ \theta^\star θ ⋆ and X X X , the population gradient-flow dynamics of the eigenvalues are given by
λ ˙ V = 36 κ 2 λ K ∑ i = 0 T − 1 β i ( β i s − τ ) ( λ K β i − 1 ) − Δ V , (36) \dot{\lambda}_V=36\kappa^2\lambda_K\sum_{i=0}^{T-1}\beta_i(\beta_i s-\tau)(\lambda_K\beta_i-1)-\Delta^V, \tag*{(36)} λ ˙ V = 36 κ 2 λ K i = 0 ∑ T − 1 β i ( β i s − τ ) ( λ K β i − 1 ) − Δ V , (36)
λ ˙ K = 36 κ 2 λ V ∑ i = 0 T − 1 β i ( β i s − τ ) ( 3 λ K 2 β i − 1 ) − Δ K . (37) \dot{\lambda}_K=36\kappa^2\lambda_V\sum_{i=0}^{T-1}\beta_i(\beta_i s-\tau)(3\lambda_K^2\beta_i-1)-\Delta^K. \tag*{(37)} λ ˙ K = 36 κ 2 λ V i = 0 ∑ T − 1 β i ( β i s − τ ) ( 3 λ K 2 β i − 1 ) − Δ K . (37)
The interaction terms Δ V \Delta^V Δ V and Δ K \Delta^K Δ K are the differences between the exact expressions and the main terms in equation (36) and equation (37). On any bounded set of ( λ V , λ K ) (\lambda_V,\lambda_K) ( λ V , λ K ) , their orders are as follows
∣ Δ V ∣ + ∣ Δ K ∣ = O ( 1 log d ( ∑ i = 0 T − 1 β i ∣ β i s − τ ∣ + ∣ s ∣ + ∣ τ ∣ ) ) + O ( d − a C ) . |\Delta^V|+|\Delta^K|=O\left(\frac{1}{\log d}\left(\sum_{i=0}^{T-1}\beta_i|\beta_i s-\tau|+|s|+|\tau|\right)\right)+O(d^{-aC}). ∣ Δ V ∣ + ∣ Δ K ∣ = O ( log d 1 ( i = 0 ∑ T − 1 β i ∣ β i s − τ ∣ + ∣ s ∣ + ∣ τ ∣ ) ) + O ( d − a C ) .
The first part vanishes at the construction where s = τ = 0 s=\tau=0 s = τ = 0 . The second part is set by the length of training examples. Consequently, the population dynamics close exactly in terms of ( λ V , λ K ) (\lambda_V,\lambda_K) ( λ V , λ K ) and the deterministic weights β i \beta_i β i , up to the interaction terms, yielding a finite-dimensional ODE.
Now, we prove the convergence of training transformers on quadratic functions based on the above forms of ODEs. By Lemma A.9, the block-sparse structure is preserved under gradient flow, so the dynamics are fully characterized by the two reduced matrices W 31 P V ( t ) W_{31}^{\mathrm{PV}}(t) W 31 PV ( t ) and W 13 K Q ( t ) W_{13}^{\mathrm{KQ}}(t) W 13 KQ ( t ) . We further use an isotropic symmetry: W 13 K Q ( t ) = λ K ( t ) I d W_{13}^{\mathrm{KQ}}(t)=\lambda_K(t)I_d W 13 KQ ( t ) = λ K ( t ) I d , W 31 P V ( t ) = λ V ( t ) I d , ∀ t ≥ 0 W_{31}^{\mathrm{PV}}(t)=\lambda_V(t)I_d,\forall t\geq0 W 31 PV ( t ) = λ V ( t ) I d , ∀ t ≥ 0 , in order to identify the fixed point for the ODE. Then, the model reduces to scalars ( λ K ( t ) , λ V ( t ) ) (\lambda_K(t),\lambda_V(t)) ( λ K ( t ) , λ V ( t )) .
We now show the convergence in two stages. In the first stage, using the structure of the ODE and the condition (here enforced by the colinear initialization θ 0 = α 0 θ ⋆ \theta_0=\alpha_0\theta^\star θ 0 = α 0 θ ⋆ with α 0 ∈ [ 3 / 4 , 1 ) \alpha_0\in[3/4,1) α 0 ∈ [ 3/4 , 1 ) ), we show. that whenever ( λ K , λ V ) (\lambda_K,\lambda_V) ( λ K , λ V ) is outside a small neighborhood of ( 1 , 1 ) (1,1) ( 1 , 1 ) , the gradient norm is bounded below by a positive quantity depending at most polylogarithmically on d d d : ∥ ∇ L C o T ( λ K , λ V ) ∥ 2 2 ≥ c 1 L C o T ( λ K , λ V ) \|\nabla L^{\mathrm{CoT}}(\lambda_K,\lambda_V)\|_2^2 \ge c_1 L^{\mathrm{CoT}}(\lambda_K,\lambda_V) ∥∇ L CoT ( λ K , λ V ) ∥ 2 2 ≥ c 1 L CoT ( λ K , λ V ) , when ∥ ( λ K , λ V ) − ( 1 , 1 ) ∥ ≥ δ 0 \|(\lambda_K,\lambda_V)-(1,1)\| \ge\delta_0 ∥ ( λ K , λ V ) − ( 1 , 1 ) ∥ ≥ δ 0 , for some constants c 1 > 0 c_1 > 0 c 1 > 0 and δ 0 = O ( 1 log d ) \delta_0 = O\left(\frac{1}{\log d}\right) δ 0 = O ( l o g d 1 ) . This yields an exponential decrease of L C o T L^{\mathrm{CoT}} L CoT until the trajectory enters the δ 0 \delta_0 δ 0 -ball around ( 1 , 1 ) (1,1) ( 1 , 1 ) , in time t 1 = O ( log d ) t_1 = O(\log d) t 1 = O ( log d ) .
In the second stage, inside the δ 0 \delta_0 δ 0 -ball of ( 1 , 1 ) (1,1) ( 1 , 1 ) , L C o T L^{\mathrm{CoT}} L CoT is smooth, and its Hessian is positive definite (this follows from the identifiability of the construction in the assumption). Hence a local PL-condition inequality holds: ∥ ∇ L C o T ( λ K , λ V ) ∥ 2 2 ≥ c 2 L C o T ( λ K , λ V ) \|\nabla L^{\mathrm{CoT}}(\lambda_K,\lambda_V)\|_2^2 \ge c_2 L^{\mathrm{CoT}}(\lambda_K,\lambda_V) ∥∇ L CoT ( λ K , λ V ) ∥ 2 2 ≥ c 2 L CoT ( λ K , λ V ) , when ∥ ( λ K , λ V ) − ( 1 , 1 ) ∥ ≤ δ 0 \|(\lambda_K,\lambda_V)-(1,1)\| \le\delta_0 ∥ ( λ K , λ V ) − ( 1 , 1 ) ∥ ≤ δ 0 , for some c 2 > 0 c_2 > 0 c 2 > 0 . This implies L C o T ( t ) ≤ L C o T ( t 1 ) exp ( − c 2 ( t − t 1 ) ) L^{\mathrm{CoT}}(t) \le L^{\mathrm{CoT}}(t_1)\exp(-c_2(t-t_1)) L CoT ( t ) ≤ L CoT ( t 1 ) exp ( − c 2 ( t − t 1 )) , so reaching L C o T ( t ) ≤ ε L^{\mathrm{CoT}}(t) \le\varepsilon L CoT ( t ) ≤ ε takes an additional t 2 = O ( log 1 ε ) t_2 = O\left(\log\frac{1}{\varepsilon}\right) t 2 = O ( log ε 1 ) time. Thus, the transformer converges to the construction as described in Lemma 3.3. Following Lemma 3.3 and Theorem A.5 , we similarly obtain the rate of the inference loss when training converges.
Omitted Experimental Results
Evaluations of the Stability Measure
Recall that Lemma 3.1 is a worst-case upper bound, and the figures in the main text compare it to the measured loss gap on separate axes. We report the difference in scale explicitly. For each model and each reasoning length T T T , we report six quantities:
The loss gap ∣ L ( f W ; D ) − L ∗ ( f W ; D ) ∣ |L(f_W;\mathcal{D})-L^*(f_W;\mathcal{D})| ∣ L ( f W ; D ) − L ∗ ( f W ; D ) ∣ between the inference loss and the reference loss;
The value of our bound, i.e., the right-hand side of equation (4) ;
The bound-to-gap ratio, i.e., the ratio of the previous two quantities;
The first-order term C 1 ∑ t = 1 T − 1 ρ t ( T ) ε t C_1\sum_{t=1}^{T-1}\rho_t^{(T)}\varepsilon_t C 1 ∑ t = 1 T − 1 ρ t ( T ) ε t ;
The second-order term C 1 C 2 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 \frac{C_1C_2}{2}\sum_{t=2}^{T}\rho_t^{(T)}\left(\sum_{i=1}^{t-1}r_i\right)^2 2 C 1 C 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 ;
The two constants entering the bound: the Lipschitz constant C 1 C_1 C 1 of the loss function, and the Lipschitz constant C 2 C_2 C 2 of the model’s input Jacobian.
We estimate C 1 C_1 C 1 as the maximum norm of the loss gradient with respect to the model output over the evaluation set, and C 2 C_2 C 2 as the maximum finite-difference change in the input Jacobian over pairs of nearby inputs from the same set. Table 2 reports all six quantities for Qwen-1.5B, Llama-1B, and Gemma-2B trained on the Bellman-Ford task, for T = 1 , … , 5 T=1,\ldots,5 T = 1 , … , 5 . At T = 1 T=1 T = 1 there is no accumulated error, and both the gap and the bound are zero.
Table 2: Decomposition of the bound in equation (4) for three models trained on the Bellman-Ford task. Loss gap denotes ∣ L ( f W ; D ) − L ∗ ( f W ; D ) ∣ \lvert L(f_W;\mathcal{D}) - L^*(f_W;\mathcal{D})\rvert ∣ L ( f W ; D ) − L ∗ ( f W ; D )∣ , Bound denotes the right-hand side of equation (4) , and Ratio denotes the bound value divided by the loss gap. The first- and second-order terms are C 1 ∑ t = 1 T − 1 ρ t ( T ) ϵ t C_1\sum_{t=1}^{T-1}\rho_t^{(T)}\epsilon_t C 1 ∑ t = 1 T − 1 ρ t ( T ) ϵ t and C 1 C 2 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 \frac{C_1C_2}{2}\sum_{t=2}^{T}\rho_t^{(T)}\left(\sum_{i=1}^{t-1}r_i\right)^2 2 C 1 C 2 ∑ t = 2 T ρ t ( T ) ( ∑ i = 1 t − 1 r i ) 2 . The absolute scale of the bound varies by orders of magnitude across architectures. At T = 1 T=1 T = 1 there is no accumulated error, so the loss gap and the bound value are zero.
Table 2.
We report the results in Table 2 . First, the bound is relatively tight on Qwen-1.5B, where the bound-to-gap ratio stays between 6 and 9 across all T T T . On Llama-1B and Gemma-2B, the ratio reaches 2.3 × 10 6 2.3\times10^6 2.3 × 1 0 6 and 1.5 × 10 5 1.5\times10^5 1.5 × 1 0 5 at T = 5 T=5 T = 5 . Second, this difference is attributed to the constants. C 1 C_1 C 1 is small and comparable across all three models (between 0.01 and 0.07), while C 2 C_2 C 2 differs by roughly three orders of magnitude, from around 5 on Qwen-1.5B to above 3 × 10 3 3\times10^3 3 × 1 0 3 on Llama-1B. Since C 2 C_2 C 2 multiplies the squared accumulated deviations in the second-order term, a large C 2 C_2 C 2 increases the bound value. Third, the second-order term grows faster in T T T than the first-order term. For Llama-1B and Gemma-2B, it dominates the bound from T = 3 T=3 T = 3 onward. On Qwen-1.5B, the first-order term remains the larger of the two.
In Figure 5 , we measure the loss gap and the error amplification factor ∑ t = 1 T − 1 ρ t ( T ) \sum_{t=1}^{T-1}\rho_t^{(T)} ∑ t = 1 T − 1 ρ t ( T ) for T T T ranging from 1 to 5. We report the results evaluated with Gemma-2B and Llama-1B models on the Bellman-Ford and Prim’s algorithms. The inference loss increases significantly with the number of steps. The error amplification factor scales exponentially with T T T , closely tracking the growth in the inference loss.
Figure 5. We illustrate the loss gap and our bound in equation (4) , which can scale exponentially across generation steps, closely tracking the growth of the inference loss. Results are evaluated on Bellman-Ford and Prim’s algorithm, using Gemma-2B and Llama-1B models. The two quantities are plotted on separate axes and differ in absolute scale; see Table 2 for the bound-to-gap ratios.
Evaluations of the bound under quantization. Table 3 decomposes equation (4) across bit-widths for Qwen-1.5B on three tasks. Lowering the bit-width has two opposing effects on the bound. First, it reduces the error amplification factor: from full precision to 1 bit, ∑ t ρ t ( T ) \sum_t \rho_t^{(T)} ∑ t ρ t ( T ) decreases by 3.7 × 3.7\times 3.7 × on the Dijkstra task, 5.9 × 5.9\times 5.9 × on the Prim task, and 1.2 × 1.2\times 1.2 × on the Bellman-Ford task. Second, the quantized model fits the training data less well, so the per-step prediction errors tend to grow.
Table 3: Decomposition of equation (4) under quantization-aware training, for Qwen-1.5B at T = 5 T=5 T = 5 . Lowering the bit-width monotonically reduces the error amplification factor ∑ t = 1 T − 1 ρ t ( T ) \sum_{t=1}^{T-1}\rho_t^{(T)} ∑ t = 1 T − 1 ρ t ( T ) and increases the per-step prediction errors, summarized by ∑ t = 1 T − 1 ϵ t \sum_{t=1}^{T-1}\epsilon_t ∑ t = 1 T − 1 ϵ t ; the bound and the test accuracy are determined by the balance of the two. The best bit-width per task is in bold.
Table 3.
In practice, we observe that QAT reduces the error amplification factor more significantly than it increases prediction errors. As a result, lower bit-width quantization typically achieves a reduction in the bound, leading to improved test accuracy. On Dijkstra and Prim, the prediction errors increase by only 1.6 × 1.6\times 1.6 × and 1.3 × 1.3\times 1.3 × . The bound decreases monotonically as the bit-width is lowered, by 6.8 × 6.8\times 6.8 × and 2.5 × 2.5\times 2.5 × at 1 bit. The test accuracy improves by 3.1% and 4.0% over full precision. On Bellman-Ford, the reduction of ∑ t ρ t ( T ) \sum_t \rho_t^{(T)} ∑ t ρ t ( T ) is small, while the prediction errors double from 4 bits to 1 bit. Therefore, the bound and the test accuracy are both best at 4 bits. The bit-width at which the growth of the error levels begins to dominate depends on the task, and we select it on the validation set.
Evaluations of our bound across algorithms. To evaluate whether the relationship between our bound and the inference loss extends beyond Qwen-1.5B, we apply Algorithm 1 to Llama-1B and Gemma-2B on Bellman-Ford with T = 5 T = 5 T = 5 , and compare it with standard chain-of-thought fine-tuning (SFT-CoT) and continuous chain-of-thought (Coconut) [10 ] . As shown in Table 4 , our algorithm attains the lowest loss gap and the lowest bound on both models. Compared with Coconut, it reduces the loss gap by 58% on average and the bound by 78% on average. Compared with SFT-CoT, it lowers the bound by 330× and 65×. This confirms that the reduction in test loss correlates with the reduction of our bound components.
Numerical evaluation of Jacobian norms. We further analyze the training dynamics by examining the Hessian trace of models fine-tuned with chain-of-thought on linear and quadratic functions. Specifically, we evaluate the norm of the Jacobian matrix product as a function of the reasoning length T T T and report results for both settings. As shown in Figure 6 , as the reasoning length T T T increases, the norm of the Jacobian matrix product converges to a value. This behavior is consistent and aligned with our analysis of the gradient descent update rule for linear and quadratic functions.
Figure 6. We illustrate how transformers realize multi-step gradient descent behavior when trained on linear and quadratic functions. We verify that the Jacobian matrix norm is a converging series on linear functions and quadratic functions. The Jacobian norm of linear functions is ∑ i = 1 T ∥ ( I − η n X X T ) i ∥ 2 2 \sum_{i=1}^{T}\left\|\left(I-\frac{\eta}{n}XX^{\mathsf{T}}\right)^{i}\right\|_{2}^{2} ∑ i = 1 T ( I − n η X X T ) i 2 2 and the Jacobian norm of quadratic functions is ∑ i = 1 T ∥ ( I − 2 η n X D ( θ i ) X T ) i ∥ 2 2 \sum_{i=1}^{T}\left\|\left(I-\frac{2\eta}{n}XD(\theta_i)X^{\mathsf{T}}\right)^{i}\right\|_{2}^{2} ∑ i = 1 T ( I − n 2 η X D ( θ i ) X T ) i 2 2 .
Sample Complexity Comparison
We compare models fine-tuned with a varied number of training examples between 1000, 2000, and 5000. We also evaluate a model fine-tuned without intermediate steps. After training, we evaluate the noise stability using the fine-tuned model. We inject isotropic Gaussian noise with standard deviation σ = 0.005 \sigma= 0.005 σ = 0.005 into the model weights and measure the increase in the inference loss. We compute the average loss increase with 10 random seeds. We evaluate the noise stability of models fine-tuned with chain-of-thought on a range of algorithmic reasoning tasks, including DFS, Dijkstra, Prim, and DAG shortest path.
First, we find that increasing the number of training samples leads to improved noise stability across all tasks. This suggests a strong correlation between generalization performance and robustness to weight noise. For the algorithms of the same task, we noted a difference in noise stability. Specifically, models fine-tuned with the Dijkstra algorithm have more than 2 × 2\times 2 × lower Hessian traces than the Bellman-Ford algorithm. Additionally, models fine-tuned by Kruskal’s algorithm yield 15 × 15\times 15 × lower Hessian trace values than Prim’s.
Second, we study the effect of intermediate steps on the sample complexity. We randomly subsample the intermediate steps T T T to 20, 10, 5, 2, and 0 where T = 0 T = 0 T = 0 indicates training without intermediate steps. We find that a larger T T T substantially reduces sample complexity. Using intermediate steps consistently achieves better sample complexity compared to training without intermediate steps.
Hyperparameters. We report the hyperparameters used in our experiments in Table 5 .
Table 5. Summary of the hyperparameters used for each reasoning task. The exact configurations are selected from the defined search spaces during supervised fine-tuning.
Discussions
Our formulation targets supervised fine-tuning on ground-truth steps. Reinforcement learning methods like Group Relative Policy Optimization or Proximal Policy Optimization optimize over the model’s own rollouts. Our analysis extends to reinforcement learning in two key ways. First, because test-time generation is independent of the training objective, our stability analysis applies equally to models trained with reinforcement learning. Second, our work can be applied to study whether policy-gradient training implicitly regularizes input Jacobian norms along high-reward trajectories. We leave the formal extension of our bounds to the reinforcement learning setting for future work.
Lastly, we discuss several limitations of this work. First, our method regularizes these Jacobian norms during training. Future work could develop test-time regularization strategies that adapt to each input example during inference. Second, for black-box models, where gradients and Jacobians are not directly accessible, proxy stability measures based on noise perturbations may provide a practical alternative. Finally, extending the Jacobian-based error accumulation analysis to broader language-model tasks, including tool use, generation, and question answering, remains an interesting direction.