Finetuning with Sampling

MCMC avoids catastrophic forgetting in SFT

Supervised Fine-Tuning (SFT) equips LLMs with new knowledge and reasoning capabilities. However, off-policy expert demonstrations may have low likelihood under the base model, requiring substantial distributional shifts that can cause catastrophic forgetting. While techniques, such as experience replay, LoRA, and regularization help mitigate this issue, principled solutions remain elusive.

From Off-Policy Demonstrations to On-Policy Data via MCMC (Karan et al., 2026)

Let \(\mathrm{p(x)}\) denote the base model distribution over trajectories for a given question, and let \(\mathrm{C}\) denote the set of correct trajectories that preserve the expert’s information. Ideally, we want to sample trajectories that satisfy the correctness constraints while remaining as close as possible to the base model:

\[\mathrm{\arg\min_{\pi:\,supp(\pi)\subseteq C}\, D_{KL}(\pi|p)}.\]

Interestingly, the optimal distribution has a simple closed-form solution:

\[\mathrm{p^*(x)=\frac{p(x)\,\mathbf{1}[x\in C]}{\sum_{x'}p(x')\,\mathbf{1}[x'\in C]}.}\]

In other words, the ideal training distribution is the base model distribution conditioned on generating correct, information-preserving solutions \(\mathrm{p^*(x)=p_{base}(x\mid x\in C)}\).

Consider a simple example where the base model assigns probabilities

\[\mathrm{p(a)=0.02,\quad p(b)=0.06,\quad p(c)=0.12,\quad p(d)=0.80,}\]

where \(\mathrm{a,b,c}\) are correct trajectories in \(\mathrm{C}\) and \(\mathrm{d}\) is incorrect.

Conditioning on the set of correct trajectories \(\mathrm{C}\) gives

\[\mathrm{p_C(a)=0.1,\quad p_C(b)=0.3,\quad p_C(c)=0.6.}\]

Instead of directly imitating an arbitrary expert trajectory, the projected distribution favors correct trajectories that are already more natural for the base model.

Sampling Expert-Guided Trajectories

Directly sampling correct trajectories can be extremely inefficient when the model struggles with difficult problems. To address this issue, the authors introduce Projection Sampling, which uses expert demonstrations to guide the generation of new training trajectories.

The solusion is fairly simple. Given a current trajectory \(\mathrm{x}\), an expert solution \(\mathrm{\tau}\), and a base model \(\mathrm{p}\).

Algorithm (Projection Sampling step).

  1. Sample a cut index \(\mathrm{m}\) uniformly from the positions of \(\mathrm{x}\).
  2. Preserve the prefix \(\mathrm{x_{<m}}\) and discard the suffix \(\mathrm{x_{\ge m}}\).
  3. Form a proposal prompt that includes the question, the expert solution \(\mathrm{\tau}\), and the prefix \(\mathrm{x_{<m}}\).
  4. Sample a continuation from the base model in its own reasoning style: \(\mathrm{x'_t \sim p_{proposal}(x_t \mid x'_{<t}, \tau),\qquad m \le t \le T.}\)
  5. Accept the candidate \(\mathrm{x'}\) with probability \(\mathrm{A(x',x)=\min\left\{1,\;\frac{p(x')}{p(x)}\frac{\kappa_C(x\mid x',\tau)}{\kappa_C(x'\mid x,\tau)}\right\},}\) and otherwise keep \(\mathrm{x}\); then repeat.

The third step is particularly important. Without expert guidance, the base model may struggle to complete a difficult reasoning problem correctly. By providing the expert solution as in-context information, the model can use knowledge it may not otherwise possess, while generating the continuation in its own words.

After several sampling iterations, the generated trajectories become more compatible with the base model while retaining the information contained in the expert demonstrations.

The resulting trajectories are then used for standard SFT, without changing the training objective.

Reasoning Performance

Empirically, Projection Sampling improves over standard SFT. On chemistry (Qwen2.5-7B-Instruct), Sampling SFT reaches 66.0% vs. 61.8% for vanilla SFT, while retaining MMLU (69.2% vs. 58.6%). On harder math (Qwen2.5-3B), the gap is larger:

Chemistry & MMLU
MethodChemistryMMLU
Base Model34.3%68.7%
SFT61.8%58.6%
OPSD61.8%65.1%
Sampling SFT66.0%69.2%
Mathematical Reasoning
MethodMath Acc.
Base Model31.5%
SFT24.3%
GRPO45.7%
UFT47.0%
Sampling SFT49.5%

Vanilla SFT underperforms the base model on math, while Sampling SFT beats GRPO and UFT; combining it with RL further reaches 54.5%.

Discussion

The main takeaway is that the effectiveness of SFT depends not only on the correctness of expert demonstrations, but also on how compatible those demonstrations are with the model’s existing distribution.

Rather than designing a more complicated training objective, Projection Sampling improves the distribution of training data before applying standard SFT.

One limitation is that expert-guided generation does not strictly guarantee correctness, and the theoretical distributional guarantees rely on idealized sampling assumptions.

Nevertheless, the paper suggests a promising direction: instead of only asking how to train LLMs more effectively, we should also ask how to sample better data for training.




Citation

@misc{deng2026_sft_sampling,
  title   ={{Finetuning with Sampling}},
  author  ={Wei Deng},
  journal ={A Sampler's Blog},
  year    ={2026},
}
  1. Karan, A., Chen, S., & Du, Y. (2026). Finetuning with Sampling: SFT Learns Better Than You Think. Advances in Neural Information Processing Systems (NeurIPS).