← All courses ← Course home

Lesson 07 of 12 · Phase 4 Post-training

Supervised fine-tuning

SFT is instruction following under a next-token loss. Pack examples honestly and keep a held-out check.

Agent brief (llms.md)

Supervised fine-tuning is next-token prediction on instruction-response text. InstructGPT is the well-known title for the broader post-training stack that starts with SFT. Your replica is smaller: pack prompts, train, and refuse to call it aligned just because loss went down.

What SFT actually does


def sft_labels(input_ids, prompt_len, ignore_index=-100):
    labels = input_ids.clone()
    labels[..., :prompt_len] = ignore_index
    return labels

Use SyntheticInstruction rows plus your 20 human rows. If the model starts parroting the template and ignoring the question, your packing or mask is wrong. Fix the data before you reach for preference tuning.

Assignment

Opinion checkpoint

Write this down. SFT is not alignment. It is a style and format prior. If you skip the held-out read, you are sightseeing with a lower loss.

Core project 5: SFT on typed synthetic plus a few human rows.

Next: Preference tuning, PPO, DPO, and RLHF intuition.

Key concepts

  • SFT is next-token training on instruction text.
  • Masking the prompt is a choice you can defend.
  • InstructGPT names the wider stack. Your replica starts with SFT only.
  • Held-out reading beats a single loss number.

Takeaways

  • Pack, mask, train, read. In that order.
  • Keep the human slice visible in the mix.
  • Record one regression. That is the SFT lesson.