The collator's job
A data collator takes a list of tokenized examples (ragged lengths) and produces a single batch tensor (uniform shape). The standard ones:
DataCollatorWithPadding— padsinput_idsto the longest in the batch.DataCollatorForLanguageModeling— for MLM (masked) or CLM (causal) pre-training.mlm=Truerandomly masks tokens.DataCollatorForSeq2Seq— pads encoder + decoder side independently for encoder-decoder models.- Older
trlshippedDataCollatorForCompletionOnlyLM; it is gone. TodaySFTConfig'scompletion_only_loss(on by default for prompt-completion data) andassistant_only_loss=True(for conversational data) mask the prompt so loss only flows over the assistant response.
Why collators matter for SFT
If you train on chat data without that masking, the model is also learning to predict the user prompt. That's wasted gradient and often degrades chat behavior. Response-only loss is the right default for instruction tuning.