Skip to main content

What this is

Supervised Fine-Tuning (SFT) trains the model to produce desired outputs by minimizing cross-entropy loss on (prompt, response) pairs. The cookbook’s sft_loop recipe handles data loading, tokenization, batching, gradient accumulation, and checkpointing automatically.

Using the recipe

batch_size controls examples per optimizer batch. SFT keeps controlled dataset batches and does not need rollout streaming.

Dataset format

SFT datasets use the standard messages format (JSONL with one example per line):
Multi-turn conversations are supported:
The recipe automatically tokenizes conversations using the chat template, masking context tokens and normalizing trainable response loss within each example.

Vision datasets

The SFT recipe also supports vision-language model training. Use multimodal content arrays with image_url objects in your JSONL, and specify a VLM training shape and tokenizer. See Vision Inputs for dataset format details and a full walkthrough.

Checkpointing and resume

By default, sft_loop needs only a trainer. It supports DCP checkpointing and resume; optional generation_eval=True samples held-out text after training using SDK-managed sampling resources:

Operational guidance

  • Set trainer.training_shape_id — cookbook trainer launches use training shapes.
  • Only one trainer job needed — SFT does not require a reference trainer.
  • No sampling deployment is required by default — optional generation evaluation uses the SDK-managed sampler.
  • Use batch_size to control the number of examples per optimizer step.
  • Resume: Attach to the same trainer with TrainerConfig(job_id=...) and keep the same log_path; the recipe restores the saved training state and data cursor. See checkpoints.
  • Periodic checkpoints are disabled by default (dcp_save_interval=0); successful runs save final state by default. Set a positive interval (e.g., 50) to recover progress from an interrupted run.