A Theoretical Analysis of Fine-tuning with Linear Teachers

Gal Shachaf, Alon Brutzkus, Amir Globerson

TL;DR

This paper provides a formal theoretical analysis of fine-tuning, demonstrating that its generalization success depends on a fine-grained alignment between task differences and the target data's covariance structure. It reveals that network depth helps mitigate scale differences between source and target tasks, while warning that the common empirical practice of freezing early layers can completely stall learning in deep linear settings.

What Problem Does This Problem Address?

Fine-tuning pretrained models on downstream tasks is a cornerstone of modern deep learning success. Despite its ubiquity, fine-tuning presents a major theoretical conundrum: why do heavily overparameterized models, when further trained on a very small target dataset, generalize so well instead of overfitting catastrophically?

Conventional learning theory often attributes this to the model staying close to its initialization. However, this explanation fails to capture how the optimization dynamics of gradient descent interact with the underlying structure of the data and the network architecture. This paper addresses this gap by analyzing the sample complexity—how much data is needed to learn effectively—and the inductive bias of fine-tuning across linear regression, deep linear networks, and shallow ReLU networks.

Methods

The authors analyze fine-tuning by splitting the process into two phases: perfect pretraining on a source task (yielding weights $\Theta_S$), followed by fine-tuning via gradient descent or gradient flow on a target task.

To derive realistic generalization bounds, they leverage several advanced mathematical frameworks:

  • For Linear Regression: They apply the Davis-Kahan $\sin(\Theta)$ theorem to decompose the task differences into components aligned with the top and bottom eigenvectors of the data's covariance matrix.
  • For Deep Linear Networks: They study gradient flow under the assumption of 0-balanced initialization (where weight matrices across layers are tightly coupled in norm). They derive a closed-form solution for the learned predictor as network depth approaches infinity ($L \to \infty$).
  • For Shallow ReLU Networks: They extend the analysis to non-linear architectures by operating within the Neural Tangent Kernel (NTK) regime, bounding the population risk based on the distance between pretrained and target outputs.

Datasets

The theoretical insights are validated using two main setups:

  1. Synthetic Data: Custom-generated datasets with controlled covariance structures and linear teachers, designed to explicitly test how alignment with data eigenvectors affects sample complexity.
  2. MNIST: The classic handwritten digits dataset is adapted for binary classification transfer tasks (e.g., pretraining on digits 2 vs. 3, then fine-tuning on digits 5 vs. 6) to evaluate how well the theoretical bounds correlate with real-world performance.

Key Insights and Ideas

  • It's Not Just Distance, It's Alignment: The success of fine-tuning isn't determined solely by the Euclidean distance between the source and target parameters ($\|\theta_T - \theta_S\|$). Instead, it depends heavily on how this difference vector aligns with the eigenvectors of the target data's covariance matrix.
  • Depth Normalizes Scale: In deep linear networks, increasing depth acts as an automatic scale normalizer. It cancels out pure magnitude differences between the source and target tasks, meaning fine-tuning can succeed even if the source and target tasks are far apart, provided they share directional alignment.
  • The Danger of Freezing Layers: "Freezing" early layers is a common trick used by practitioners to avoid catastrophic forgetting. However, the authors prove that in deep linear networks with balanced initialization, freezing the first layer completely degenerates the training process, locking the model into the source task regardless of how much target data is provided.

Key Results

  • Eigen-Alignment Effects: Theorem 4.2 shows that if the task difference aligns with the top eigenvectors of the data ("Top Eigen Align"), the model generalizes remarkably well with very few samples. Conversely, alignment with bottom eigenvectors ("Bottom Eigen Align") requires more samples but drops to zero error faster as data scales.
Figure 1: Comparison between different θT −θS. ”Top Eigen Align” is the linear predictor initialized with P≤m(θT −θS) = 0 and ”Bottom Eigen Align” is the linear predictor initialized with P>m(θT −θS) = 0, for m=50. The top m eigenvalues have the value 1.5, compared to the rest which have the value 0.3.
  • Depth vs. Single-Layer Performance: For directionally aligned tasks ($\theta_T = \alpha \theta_S$), an infinitely deep linear network achieves zero generalization error from just a single target sample, whereas a standard single-layer linear model's error remains heavily dependent on sample size $n$.
Figure 2: (a) The effect of depth on fine-tuning when θT is a α scaled, ϵ noised version of θS with d/10 samples. (b) The effect of changing the scale of either source weights or target weights in a 7-layers model.
  • Empirical Validation on MNIST: The authors' proposed covariance-dependent bound showed a significantly higher correlation ($R^2$ up to 0.89) with actual test errors on MNIST transfer tasks compared to standard norm-based bounds.
Table 1: Correlation coefficient R2 between the accuracy on different transfer tasks in MNIST and various population risk upper bounds. Each value is a mean over 10 calculations of R2 with different initialization, and each R2 is calculated from 20 points, each one representing a mean accuracy value of 25 random samples.
  • Freezing Failure Confirmed: Experiments empirically verified that fixing the first layer results in a flat, unyielding generalization loss, confirming the degeneration effect predicted by Theorem 5.5.
Figure 3: A network whose first layer is fixed has a constant generalization loss due to degeneration effect in Theorem 5.5.

Limitations and Future Work

While providing valuable theoretical foundations, the paper notes several limitations:

  1. Simplicity of Teachers: The analysis assumes linear teachers and zero label noise, which does not fully mirror the noisy, non-linear nature of practical deep learning.
  2. Strict Initialization Requirements: The deep linear proofs rely on exact 0-balanced initialization, which is less common than standard normalized initializers like Xavier or He initialization.
  3. NTK Regime Constraints: The non-linear analysis is restricted to shallow ReLU networks within the NTK regime, where weights change infinitesimally—a regime that doesn't fully capture the feature-learning capabilities of deep networks.

The authors suggest that future work should focus on extending these covariance-based bounds to the Reproducing Kernel Hilbert Space (RKHS) of the NTK and exploring classification settings using exponential losses.

Summary updated

Abstract

Fine-tuning is a common practice in deep learning, achieving excellent generalization results on downstream tasks using relatively little training data. Although widely used in practice, it is lacking strong theoretical understanding. We analyze the sample complexity of this scheme for regression with linear teachers in several architectures. Intuitively, the success of fine-tuning depends on the similarity between the source tasks and the target task, however measuring it is non trivial. We show that a relevant measure considers the relation between the source task, the target task and the covariance structure of the target data. In the setting of linear regression, we show that under realistic settings a substantial sample complexity reduction is plausible when the above measure is low. For deep linear regression, we present a novel result regarding the inductive bias of gradient-based training when the network is initialized with pretrained weights. Using this result we show that the similarity measure for this setting is also affected by the depth of the network. We further present results on shallow ReLU models, and analyze the dependence of sample complexity there on source and target tasks. We empirically demonstrate our results for both synthetic and realistic data.
BibTeX
@inproceedings{shachaf2021theoretical,
  author = {Gal Shachaf and Alon Brutzkus and Amir Globerson},
  title = {{A Theoretical Analysis of Fine-tuning with Linear Teachers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=DyE8hmj2dse},
}
Figure