---
title: "Supervised fine-tuning"
lesson_id: "07"
---

# Supervised fine-tuning

- **Lesson ID:** 07
- **Goal:** SFT is instruction following under a next-token loss. Pack examples honestly and keep a held-out check.
- **Human lesson:** [07-supervised-fine-tuning.html](07-supervised-fine-tuning.html)
- **Phase:** Phase 4 Post-training

## Prerequisites

- The previous week's artifact, or a written note if this is week 1.
- Python 3.11+ and a laptop. CUDA is useful from week 5 onward and not required to read.

## Inputs, outputs, and artifacts

- **Inputs:** The replica from the prior week.
- **Outputs:** Core project 5: SFT on typed synthetic plus a few human rows.
- **Artifacts:** Lesson notes plus the code named in the human page.

## Agent build steps

1. State the week 1 principle: you do not need to pretrain an 800B model to understand the shape of the problem; you do need progressively realistic replicas.
2. Teach the topics on the human page without inventing paper URLs or news claims.
3. Keep starter code in fenced blocks that match the human lesson.
4. End with the assignment and the opinion checkpoint.
5. Use Edge FDE tone: ship, do not sightseeing. Opinion checkpoints matter.

## Constraints

Plain spoken English. No quizzes. No em dashes. No invented metrics, dates, or citations. Brand Edge FDE only. Name well-known papers by title only: Attention Is All You Need, InstructGPT, Direct Preference Optimization, ZeRO, PagedAttention/vLLM, FlashAttention, Scaling Laws for Neural Language Models.

## 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.

## Acceptance checks

- Human HTML has Key concepts and Takeaways.
- Opinion checkpoint is present.
- No em dash and no fake URL.
- [ ] Proceed to [lesson 08 brief](08-preference-tuning-and-rlhf.llms.md).
