Context-Free Synthetic Data Mitigates Forgetting

Parikshit Bansal, Sujay Sanghavi · DOI

Abstract

Fine-tuning Large Language Models (LLMs) on specialized datasets often leads to "catastrophic forgetting" of general-purpose capabilities. This paper introduces Context-Free Synthetic Data (CFS), a method that regularizes fine-tuning using unconditional samples generated by the model itself. CFS requires only model weights, making it ideal for data-oblivious settings where original pre-training data is unavailable. Experimental results on OLMo-1B and R1-Distill-Llama-8B demonstrate that CFS effectively preserves general reasoning and zero-shot performance while achieving high accuracy on new target tasks.

Introduction

When an LLM is fine-tuned for a specific domain—such as medical reasoning or mathematics—its weights shift to optimize for the new distribution. This shift frequently degrades the model's original "out-of-the-box" abilities, a phenomenon known as catastrophic forgetting.

Mitigating this is particularly challenging in "data-oblivious" scenarios. Many developers work with open-weight models (e.g., Llama, OLMo) without access to the massive, multi-terabyte datasets used for their initial pre-training. Traditional "replay" methods, which mix old and new data, are thus infeasible. Common alternatives like Low-Rank Adaptation (LoRA) or $\ell_2$ regularization often force a significant trade-off between new task performance and the retention of old capabilities.

Methodology: Context-Free Generation (CFS)

The proposed CFS approach involves two primary steps:

  1. Unconditional Sampling: The original model is prompted with only its "beginning of sentence" token (e.g., <|endoftext|> for OLMo or <|begin_of_sentence|> for Llama) and allowed to generate text. Without input context, the model samples from its broad, underlying probability distribution.
  2. Joint Fine-tuning: The model is fine-tuned using a weighted loss function that combines a standard supervised loss on the new downstream dataset with a "pre-training style" loss (all-token log-likelihood) on the synthetic context-free data.

Mathematically, training on these unconditional samples provides an approximate unbiased estimate of the KL-divergence between the original and fine-tuned models. By minimizing this loss, the fine-tuned model remains "probabilistically close" to its original state.

Experimental Setup

The researchers evaluated CFS across two architectures:

  • OLMo-1B: Fine-tuned on MetaMathQA to enhance mathematical reasoning.
  • R1-Distill-Llama-8B: Fine-tuned on MedReason for medical specialization.

Evaluation benchmarks included general zero-shot tasks (MMLU, BigBench Hard, AGIEval, and Commonsense reasoning) and specialized reasoning tasks (GSM8K, AIME24, MATH500, LiveCodeBench, and GPQA-Diamond).

Key Results and Insights

CFS demonstrated a superior ability to balance task-specific gains with general capability retention compared to standard fine-tuning, LoRA, and weight-averaging techniques.

Performance on OLMo-1B

Standard fine-tuning on math data improved GSM8K accuracy from 1.59% to 29.49% but caused a drop in general task performance from 29.50% to 23.55%. CFS achieved a near-identical 29.34% on GSM8K while maintaining a 28.24% average on general tasks.

Comparison of CFS against standard fine-tuning and weight-space regularization on OLMo-1B. CFS maintains high general accuracy while matching fine-tuned performance on GSM8K.

Performance on R1-Distill-Llama-8B

For the larger 8B reasoning model, CFS outperformed LoRA and Wise-FT when specializing for medical tasks. Notably, it achieved the highest scores on math (84.60 on MATH500) and coding (49.75 on LCB) among all mitigation strategies.

Accuracy across diverse benchmarks for R1-Distill-Llama-8B. CFS (ours) consistently preserves or improves performance across medical, math, and coding tasks compared to baselines.

Key Insights

  • Context-Free vs. Contextual: Generating synthetic data based on new task prompts (contextual) was less effective than context-free generation. Context-free data captures the model's entire distribution, whereas contextual data is too narrow and can introduce incorrect reasoning into the training mix.
  • Efficiency: CFS outperformed using actual original pre-training data (Dolma) in some tests. The authors suggest that the model's own generations act as a "distilled," cleaner version of its knowledge.
  • Preserving Reasoning Chains: For reasoning models like DeepSeek-R1-Distill, CFS successfully preserved self-correction behaviors (e.g., "Wait, let me rethink..."), which are often lost during standard fine-tuning.

Conclusion and Future Work

CFS provides a simple, data-oblivious method to mitigate catastrophic forgetting. It is robust to sampling temperatures and remains effective even with relatively small amounts of synthetic data (as little as 10% of the fine-tuning data volume).

Future research is needed to evaluate the scalability of CFS to much larger models (70B+) and its effectiveness over multiple sequential rounds of fine-tuning. Additionally, while CFS is memory-efficient, the sequential nature of synthetic data generation introduces a computational overhead that could be optimized in future implementations.

Summary updated

BibTeX
@misc{bansal2025context,
  author = {Parikshit Bansal and Sujay Sanghavi},
  title = {{Context-Free Synthetic Data Mitigates Forgetting}},
  year = {2025},
  eprint = {2505.13811},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.13811},
}
Figure