Supervised Fine-Tuning (SFT) is the foundation of the RLHF pipeline. The quality of the SFT model determines the ceiling of what RL can achieve: RL can refine and improve a behaviour, but it cannot reliably introduce a behaviour that is entirely absent from the SFT model. This section covers the key techniques for effective SFT.

Sequence Packing for Efficiency

Sequence packing concatenates multiple short examples into a single sequence of length max_seq_length, separated by EOS tokens. The attention mask ensures that tokens from different examples do not attend to each other:

  1. Sort examples by length (optional, improves packing efficiency).
  2. Greedily pack examples into bins of size max_seq_length.
  3. Use a block-diagonal attention mask to prevent cross-example attention.
  4. Compute loss only on non-padding tokens.

Chat Templates and Formatting

ChatML is the most widely used chat template:

# ChatML format
template = """<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{user_message}<|im_end|>
<|im_start|>assistant
{assistant_message}<|im_end|>"""

Llama 3 uses a different template with special tokens:

# Llama 3 format
template = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
{system_message}<|eot_id|><|start_header_id|>user<|end_header_id|>
{user_message}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
{assistant_message}<|eot_id|>"""

Completion-Only Masking

Data Mixing Strategies for Multi-Task SFT

Sample from each dataset proportionally to its size:

pk=Nk∑j=1KNj,

where Nk is the number of examples in dataset k. This is the default in most frameworks and works well when datasets are of similar quality.

Apply a temperature T to smooth the proportions:

pk∝Nk1/T.

T=1: proportional mixing. T→∞: uniform mixing. T<1: over-samples large datasets. T>1: over-samples small datasets.

Weight datasets by estimated quality (e.g., perplexity under a reference model, human quality ratings):

pk∝Nk⋅qk,

where qk is the quality score for dataset k.

When SFT Hurts – Catastrophic Forgetting and Alignment Tax

As LLMs transition through sequential training phases — pre-training → continued pre-training → SFT → RLHF/DPO — performance degradation frequently manifests on standard benchmarks. Two fundamentally distinct phenomena drive these regressions, and confusing them leads to wrong mitigation strategies.

Catastrophic Forgetting (Structural Erasure)

Symptoms:

  • Complete breakdown on tasks not in fine-tuning data (e.g., model forgets how to do math after SFT on chat data)
  • Loss of language diversity — model only generates in the narrow style of fine-tuning distribution
  • Reduced factual accuracy on knowledge not reinforced during fine-tuning
  • Degraded multilingual ability after English-only SFT

Mechanistic cause — Fisher Information perspective: The Fisher Information Matrix F of Task A identifies which parameters are “important” for 𝒟A:

F=𝔼x∼𝒟A​[∇θ​log​πθ​(x)​∇θ​log​πθ​(x)T](10.2)

Parameters with high Fisher eigenvalues are critical for Task A. Unconstrained gradient descent on Task B ignores these eigenvalues entirely — Δ​θ points along ∇ℒB regardless of whether it destroys high-Fisher directions for ℒA.

Alignment Tax (Behavioral Constraint)

The alignment tax is a deliberate, expected trade-off: the model’s raw capability (unconstrained generation, maximal reasoning bandwidth) decreases because the policy is constrained to produce safe, well-formatted, preference-aligned outputs.

Mechanism: During DPO/PPO, the policy πθ is penalized for deviating from the reference πref via KL divergence:

rimplicit​(x,y)=β​log⁡πθ​(y|x)πref​(y|x)(10.3)

This leash constrains the model’s output distribution — it cannot explore high-variance reasoning paths that deviate too far from the reference. The knowledge is not erased; it’s suppressed. The model still “knows” the answer but its distribution is flattened toward safe, generic responses.

Symptoms:

  • Over-refusal (“I can’t help with that” for benign queries)
  • Stylistic stiffness — hedge words, excessive caveats, verbose safety disclaimers
  • Lower scores on raw capability benchmarks (MMLU, HumanEval) while improving on preference benchmarks (MT-Bench, AlpacaEval)
  • Reduced ability to produce complex, high-entropy outputs (creative writing, novel algorithms)

Comparative Taxonomy

DimensionCatastrophic ForgettingAlignment Tax
IntentionalityUnintentional (optimization artifact)Expected trade-off (incurred deliberately for safety/helpfulness)
Parameter statePrior knowledge physically overwrittenLatent distributions constrained/truncated
InformationDestroyed: weights no longer encode the capabilitySuppressed: knowledge exists but is harder to trigger
Dominant phaseSequential SFT, domain continued pre-trainingPreference optimization (PPO, DPO, KTO, RLHF)
Primary symptomComplete breakdown of baseline capabilitiesOver-refusal, stylistic stiffness, lower raw benchmark scores
ReversibilityIrreversible without retraining from checkpointPartially reversible: adjust β, system prompt, or fine-tune
DetectionPerplexity on pre-training eval set spikesPerplexity stable but win-rate on capability benchmarks drops
Scales with model sizeSimilar across scalesSmaller models pay a larger alignment tax

Table 10.1:Catastrophic Forgetting vs. Alignment Tax — complete comparison.

Mitigation Strategies

For Catastrophic Forgetting:

  1. Data replay: Mix 5–10% of pre-training data into SFT dataset. Ensures gradient updates don’t completely neglect pre-training distribution.
  2. Elastic Weight Consolidation (EWC)[186]: Add regularization Ω⁡(θ)=λ2​∑iFi​(θi−θi∗)2 that penalizes changes to parameters with high Fisher information for the original task.
  3. LoRA / Parameter-efficient fine-tuning: Train only low-rank adapters (<1% of parameters), leaving base weights completely frozen. This prevents permanent destruction of pre-trained knowledge — you can always remove the adapter and recover the original model. However, while the adapter is active, the combined system (W0+B​A) can still exhibit forgetting: the adapter may shift the model’s effective behavior away from old skills. LoRA protects the checkpoint, not the active inference behavior.
  4. Conservative learning rate: Use 1–5×10−6 with few epochs (1–3). Larger rates accelerate forgetting.
  5. Progressive training: Mix distributions gradually, increasing SFT data proportion over time rather than switching abruptly.

For Alignment Tax:

  1. Tune β carefully: Lower β gives the model more freedom (reduces the tax) but may sacrifice safety. Optimal β∈[0.05,0.3] for most settings.
  2. High-quality, diverse SFT data: Part of the alignment tax comes from SFT narrowing the output distribution; broader, more diverse SFT data reduces this component. The RL phase adds further constraint via KL regularization [280].
  3. Conditional alignment: Train the model to be aligned only when a safety flag is active. At inference, disable constraints for benchmarking (research-only technique).
  4. Constitutional AI / RLAIF: Use model-generated feedback to create more nuanced preference data that preserves capability while improving alignment.
  5. Targeted RL budget: Don’t over-train with RL. Monitor capability benchmarks and stop when the tax exceeds acceptable thresholds (typically 2–5% MMLU regression).

Connection to RL – SFT Quality Determines RL Ceiling

  1. SFT data quality: use high-quality, diverse data. A small amount of high-quality data is better than a large amount of low-quality data.
  2. SFT data coverage: ensure the SFT data covers the tasks you want to improve with RL. If a task is not in the SFT data, RL will struggle.
  3. SFT training duration: do not over-train the SFT model. Over-training reduces diversity and makes RL exploration harder.
  4. Warm-up: consider a short SFT warm-up on task-specific data before RL, even if the base model is already instruction-tuned.