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’ssft_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):Vision datasets
The SFT recipe also supports vision-language model training. Use multimodalcontent 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_sizeto control the number of examples per optimizer step. - Resume: Attach to the same trainer with
TrainerConfig(job_id=...)and keep the samelog_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.
Related guides
- Vision Inputs — VLM training with image and text data
- Cookbook DPO — preference optimization
- Cookbook RL (GRPO) — reinforcement learning recipes
- Cookbook Reference — all config classes and parameters
- Loss Functions — API-level SFT loss details