Model and Inference EngineeringPost-training and alignmentStaff
What does DPO learn when truncation removes the only difference between preferred and rejected answers?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
Two preference responses share a long opening but end with different action decisions. The training pipeline truncates both before that difference. Explain the effective pair loss and gradient when deterministic scoring uses identical retained tokens and masks, inspect where the preference disappeared, and compare length changes, curation and filtering without losing necessary prompt evidence.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
The loss compares sequence log probabilities of the chosen and rejected completions under the policy and reference model. It cannot learn a distinction that was removed from the actual token sequences. At the extreme, if the two tokenized completions become identical after truncation, the pair contributes no useful preference between those endings. More often they retain a little unrelated difference and the optimizer learns to favor that instead. TRL's DPO configuration documents a maximum tokenized sequence length and a truncation mode, which are part of the effective dataset.
For a hypothetical pair, suppose the retained assistant tokens and their scoring masks become exactly identical. Assuming deterministic, equally configured scoring, the chosen and rejected policy log probabilities are then the same, as are the reference probabilities. Their adjusted margin is zero and the common sigmoid pair loss is ln(2), about 0.693. More importantly, the two identical sequence gradients cancel, so this pair supplies no preference gradient to distinguish the removed endings. Other losses or regularization may still update parameters. A nonzero constant loss is therefore not evidence that this example is teaching the desired preference.
I would inspect tokenized rows after the exact chat template, tokenizer, prompt split and trainer truncation. Compute how often chosen and rejected sequences still differ, where the first differing token falls, how many completion tokens survive, and whether the human reason for the label is still present. Sample the worst cases and decode them. A length histogram alone will miss pairs that technically fit a cap but lose their important tail under a separate prompt limit.
Fixing it is not just setting a huge context window. Longer pairs cost memory and time, and truncating prompts from the other end can remove the facts needed to judge the answer. Curate or shorten prompts while preserving the decision context, raise the length limit where affordable, or filter pairs whose preference cannot survive preprocessing. Keep the same preprocessing in evaluation.
If the interviewer says the raw dataset passed QA, that is exactly why I would look here. The model never trains on a spreadsheet row. It trains on token IDs and masks. The preference needs to remain visible there.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux