Source-linked AI summary

On the Stability of Fine-tuning BERT: Misconceptions, Explanations, and Strong Baselines

Marius Mosbach, Maksym Andriushchenko, Dietrich Klakow

arXiv:2006.04884v3cs.LGstat.ML

TL;DR

Fine-tuning pre-trained language models is powerful but unstable across random seeds, and existing explanations do not account for that instability. The paper analyzes failed runs across BERT-family models and GLUE datasets, linking instability to vanishing gradients and generalization differences, then proposes a stronger stability baseline.

  • Problem

    Fine-tuning performs strongly on NLP benchmarks but can vary substantially across random seeds, while catastrophic forgetting and small datasets have been proposed as explanations without sufficient support.

  • Method

    The paper analyzes fine-tuning failures across BERT-family models and GLUE datasets, examining optimization, generalization, and proposed explanations for instability.

  • Results

    The two common hypotheses fail to explain instability; early vanishing gradients and late generalization differences characterize distinct sources of variation.

  • Takeaways & Limitations

    A simple baseline significantly improves fine-tuning stability and overall performance over previous work across the studied settings.

  • Takeaways & Limitations

    Resolving the observed vanishing gradients is constrained by preserving the pre-trained weights, and increased iterations are suggested only for small datasets.

Abstract

from arXiv · show

Fine-tuning pre-trained transformer-based language models such as BERT has become a common practice dominating leaderboards across various NLP benchmarks. Despite the strong empirical performance of fine-tuned models, fine-tuning is an unstable process: training the same model with multiple random seeds can result in a large variance of the task performance. Previous literature (Devlin et al., 2019; Lee et al., 2020; Dodge et al., 2020) identified two potential reasons for the observed instability: catastrophic forgetting and small size of the fine-tuning datasets. In this paper, we show that both hypotheses fail to explain the fine-tuning instability. We analyze BERT, RoBERTa, and ALBERT, fine-tuned on commonly used datasets from the GLUE benchmark, and show that the observed instability is caused by optimization difficulties that lead to vanishing gradients. Additionally, we show that the remaining variance of the downstream task performance can be attributed to differences in generalization where fine-tuned models with the same training loss exhibit noticeably different test performance. Based on our analysis, we present a simple but strong baseline that makes fine-tuning BERT-based models significantly more stable than the previously proposed approaches. Code to reproduce our results is available online: https://github.com/uds-lsv/bert-stable-fine-tuning.

1 INTRODUCTION

Fine-tuning achieves strong benchmark performance but remains unstable across random seeds and poorly understood. This paper rejects two common explanations, identifies optimization and generalization problems, and proposes a more stable baseline.

  • Fine-tuning BERT, RoBERTa, and ALBERT dominates many NLP benchmarks but can show large performance variation across random seeds.
  • The paper asks why fine-tuning fails and how its stability can be improved.
  • Catastrophic forgetting and small fine-tuning datasets do not sufficiently explain the observed instability.
  • Fine-tuning instability reflects early optimization difficulties with vanishing gradients and late generalization differences among runs with nearly equivalent training loss.
  • The proposed baseline significantly improves fine-tuning stability over previous approaches and applies to BERT, RoBERTa, and ALBERT.

2 RELATED WORK

Prior work documents substantial fine-tuning instability and proposes intermediate training or regularization, but its explanations and comparability remain limited. Optimization research highlights learning-rate warmup, while focusing on pre-training rather than fine-tuning.

  • BERT fine-tuning can vary dramatically across restarts, especially for BERTLARGE and small datasets.
  • STILTS uses intermediate task training before fine-tuning and reports improved GLUE performance and stability, but is not directly comparable to this work.
  • Mixout is a regularization technique reported to improve fine-tuning stability, which its authors attribute to preventing catastrophic forgetting.
  • Related optimization studies emphasize learning-rate warmup during pre-training and are viewed as orthogonal to this fine-tuning study.

3 BACKGROUND

The study evaluates fine-tuning stability across four GLUE datasets using standard task-specific metrics and a specified BERT training recipe. It defines stability through development-set performance variation and identifies failed runs by comparison with majority classifiers.

  • Datasets: The evaluation covers CoLA, MRPC, RTE, and QNLI from the GLUE benchmark.
  • Datasets: CoLA is sentence classification measured by Matthew’s correlation coefficient, while MRPC is sentence-pair paraphrase classification measured by F1.
  • Datasets: RTE is a sentence-pair entailment task measured by accuracy and is the second smallest GLUE dataset.
  • Datasets: QNLI is a sentence-pair classification task derived from SQuAD and measured by accuracy.
  • Fine-tuning: The default BERT recipe uses batch size 16, learning rate 2e−5 with 10% warmup, dropout p = 0.1, weight decay λ = 0.01, three epochs, gradient clipping, and AdamW without bias correction.
  • Fine-tuning: Fine-tuning stability is the standard deviation of development-set performance across algorithmic randomness, using accuracy, MCC, or F1 as appropriate.
  • Fine-tuning: A failed run ends with accuracy less than or equal to the respective dataset’s majority-classifier accuracy.

4 INVESTIGATING PREVIOUS HYPOTHESES FOR FINE-TUNING INSTABILITY

The paper finds that catastrophic forgetting and dataset size do not explain fine-tuning instability. Instead, failed runs reflect optimization problems, while instability associated with smaller datasets is tied to fewer training iterations.

  • Catastrophic forgetting: Resetting around 10 of BERT’s 24 top layers often restores pre-training language-modeling ability in both failed and successful runs.Successful runs show a much smaller perplexity increase after fine-tuning.
  • Catastrophic forgetting: The experiment tests catastrophic forgetting by measuring WikiText-2 masked-language-modeling perplexity after fine-tuning BERT on RTE.The comparison uses three successful and three failed fine-tuning runs.
  • Catastrophic forgetting: Catastrophic forgetting does not causally explain fine-tuning instability, because failed runs often do not successfully learn the downstream task.Failed runs have majority-classifier development accuracy and trivial training loss near −ln(1/2).
  • Training dataset size: Using fewer training examples increases variance mainly because it reduces the number of training iterations under a fixed three-epoch schedule.The study compares 1,000-sample subsets of CoLA, MRPC, and QNLI with training for the full-data iteration count.
  • Training dataset size: Training dataset size per se is orthogonal to fine-tuning stability; the number of training iterations is the crucial factor.More iterations improve stability, partly by changing the effective learning-rate schedule.

5 DISENTANGLING OPTIMIZATION AND GENERALIZATION IN FINE-TUNING

Fine-tuning instability reflects both optimization failures and generalization differences rather than catastrophic forgetting or dataset size alone. Vanishing gradients explain failed runs, while bias correction and longer training improve stability across BERT-based models.

  • Fine-tuning instability combines optimization difficulties with generalization differences, while catastrophic forgetting and dataset size do not cause it.
  • 5.1 THE ROLE OF OPTIMIZATION: Failed runs exhibit vanishing gradients in bottom layers, whereas successful runs develop substantially larger gradients as training proceeds.The successful run's gradient norms become nearly 2× orders of magnitude larger than the failed run's by the end of fine-tuning.
  • 5.1 THE ROLE OF OPTIMIZATION: Bias correction improves stability for BERT and ALBERT and provides additional improvement for RoBERTa, especially when combined with warmup.Bias correction reduces ADAM's initial step size through an iteration-dependent multiplicative factor, functioning similarly to warmup early in training.
  • 5.1 THE ROLE OF OPTIMIZATION: Training longer with a smaller learning rate can also produce much more stable fine-tuning than the default three-epoch setup.Bias correction is useful for obtaining the best performance within 3 epochs, while longer training offers an alternative stabilization strategy.
  • 5.1 THE ROLE OF OPTIMIZATION: Loss-surface visualizations show failed runs converging to a sub-optimal valley separated from the successful solution by a barrier across RTE, MRPC, and CoLA.The similar geometry across all three datasets supports interpreting instability primarily as an optimization issue.

6 A SIMPLE BUT HARD-TO-BEAT BASELINE FOR FINE-TUNING BERT

The paper proposes a simple baseline targeting vanishing gradients and late-training generalization differences, substantially improving fine-tuning stability. It uses bias correction, a small learning rate, and considerably longer training for small datasets.

  • The authors recommend small learning rates with bias correction to avoid early vanishing gradients and more iterations to approach zero training loss.
  • The baseline uses Adam with bias correction, a 2e−5 learning rate, 20 epochs, warmup over the first 10% of steps, and linear decay afterward.Other hyperparameters remain unchanged.
  • The proposed strategy produces significantly smaller final-performance standard deviations than previous approaches across RTE, MRPC, and CoLA.Stability is evaluated over multiple fine-tuning runs.
  • Levene’s tests find p-values below 0.001 for variance comparisons between the proposed method and the second-smallest-variance method on all three datasets.
  • The method achieves higher mean performance on all three datasets and comparable or better maximum performance on MRPC and CoLA.
  • The increased iteration count is recommended only for small datasets, limiting the practical impact of its additional computational cost.Improved stability may also reduce the number of necessary fine-tuning runs.

7 CONCLUSIONS

The paper concludes that fine-tuning instability is not sufficiently explained by catastrophic forgetting or dataset size. Instead, it reflects early optimization difficulties with vanishing gradients and late differences in generalization, motivating a stronger baseline.

  • The paper reports significantly improved stability and overall results on commonly used GLUE datasets.
  • Neither catastrophic forgetting nor small dataset sizes sufficiently explain fine-tuning instability.
  • Instability comprises early optimization difficulties characterized by vanishing gradients and late generalization differences among runs with similar training performance.
  • The proposed BERT baseline outperforms previous works in both fine-tuning stability and overall performance.

APPENDIX

The appendix defines fine-tuning stability as variance in performance across randomized fine-tuning runs and distinguishes it from per-point stability. It also documents dataset availability and majority baselines.

  • Fine-tuning stability is defined as the variance of the performance metric across randomized fine-tuning algorithms.This measures expected performance differences across repeated fine-tuning runs.
  • The paper studies accuracy in a two-class setting, with a randomized algorithm producing classifier f_A from data drawn from D.
  • Per-point stability interchanges expectation and variance to measure how much classifiers differ on the same data point.
  • The studied datasets are publicly available, with GLUE datasets and SciTail provided through their respective repositories.
  • Dataset statistics and majority baselines are reported in Table 2.

7.3 HYPERPARAMETERS

The appendix reports hyperparameter settings and an RTE ablation varying training duration, learning rate, and bias correction. Longer training with bias correction gives the best ablation performance.

  • Hyperparameters for BERT, RoBERTa, and ALBERT used in the experiments are listed in Table 3.
  • The RTE ablation varies learning rate, training epochs, and bias correction while holding all other hyperparameters unchanged.
  • With only 3 training epochs, disabling bias correction clearly hurts performance.
  • Bias correction permits training with larger learning rates, while combining it with more epochs produces the best performance.
  • Each RTE ablation setting is evaluated by fine-tuning 25 models.

7.5 ADDITIONAL GRADIENT NORM VISUALIZATIONS

Additional visualizations show that failed fine-tuning runs converge to regions with vanishing gradients, while top-layer gradients may remain large. Training curves and loss surfaces indicate an optimization problem separating failed and successful solutions.

  • Gradient norm visualizations: ALBERT visualizations include pooler, classification, and one hidden layer because weight sharing limits the distinct layers shown.The hidden layer is referred to as layer0.
  • Gradient norm visualizations: Pooler and classification gradients remain large in failed BERT runs even as gradients across most layers vanish.The remaining top-layer updates explain the large increase in MLM perplexity observed for failed models.
  • Gradient norm visualizations: Contour plots show a barrier between failed and successful solutions and a low-gradient valley around the failed solution.This pattern appears for BERT fine-tuned on RTE, MRPC, and CoLA.
  • Training curves: All 10 failed RTE runs keep training loss close to its initialization value throughout training.The shared pattern indicates an optimization problem and motivates reconsidering the optimization scheme.

7.8 ADDITIONAL FINE-TUNING RESULTS

Additional experiments extend the analysis beyond the main GLUE settings, showing that stability depends on training iterations and that the findings generalize across models and datasets. SciTail results further distinguish large-data stability from the benefits of additional iterations on smaller subsets.

  • Additional datasets: SciTail experiments were added to test whether the findings generalize to datasets from other domains.The results are reported in Table 4.
  • Additional datasets: 28k-sample SciTail is already stable with the Devlin et al. (2019) scheme after 3 epochs, while the proposed scheme performs similarly.This behavior is comparable to the reported QNLI results.
  • Additional visualizations: Figures 10–12 visualize gradient norms for failed and successful BERT, RoBERTa, and ALBERT RTE runs.The plots use a logarithmic scale and show additional weight matrices.
  • Additional visualizations: Figure 13 plots two-dimensional gradient-norm surfaces using directions from the pretrained model to failed and successful solutions.The surfaces cover BERT fine-tuned on RTE, MRPC, and CoLA.
  • Additional datasets: On a 1k-sample SciTail subset, using more training iterations improves fine-tuning stability.The same pattern was observed for MRPC, CoLA, and QNLI.
  • Additional datasets: The findings and guidelines generalize beyond particular datasets because fixed-epoch training can provide too few iterations as data size changes.The authors characterize insufficient iterations, rather than dataset identity, as the source of the observed instability in this experiment.
Loading 2006.04884v3…