Skip to main content
Preference fine-tuning trains a model on paired examples that show which responses you want it to generate and which it should avoid. Together AI implements this with Direct Preference Optimization (DPO). This is more effective than supervised fine-tuning when you have ranked outputs for the same prompt.

When to use preference tuning

Consider using preference tuning when:
  • You have ranked pairs of responses for the same prompt. Standard supervised fine-tuning (SFT) only learns from a single target completion per example. DPO learns from the gap between good and bad (preferred and dispreferred) responses.
  • You’re polishing a model that already works. DPO is most effective as a refinement step. If your data is far from the base model’s pretraining distribution, run SFT first and continue with DPO from that checkpoint (see Combine SFT and DPO).
  • You want to reduce specific failure modes. Pair the failure as non_preferred_output against the desired behavior.
Skip DPO if your dataset is single-target. Use supervised fine-tuning instead.

Prepare your data

Each line in the JSONL file carries:
  • input.messages: the context, in conversational format.
  • preferred_output: a list containing exactly one assistant message representing the ideal response.
  • non_preferred_output: a list containing exactly one assistant message representing the suboptimal response.
Each output must contain exactly one assistant message. Preference tuning does not support pre-tokenized Parquet datasets. Contact us if you need this feature.
For tool-calling preference data, see data preparation. For reasoning preference data, see reasoning preference format.

Launch a DPO job

Set training_method to "dpo". The full list of DPO parameters lives in the API reference.

DPO parameters

For LoRA long-context fine-tuning, half the context length is used for the preferred response and half for the non-preferred response. On a 32k model, effective context per side is 16k. Preference tuning ignores the train_on_inputs flag because the loss is computed from the preferred and non-preferred outputs.
To stop a DPO run automatically when validation loss plateaus, see early stopping.

DPO metrics

Beyond standard training metrics, DPO jobs report:
  • Accuracy: The share of examples where the reward for the preferred response exceeds the reward for the non-preferred response.
  • KL divergence: How much the trained model’s output distribution has diverged from the reference model’s. Higher values mean the trained model has moved further from the reference.
  • Per-side log probabilities: For both preferred and non-preferred outputs, useful for debugging stalled runs.
For how to retrieve these values during or after a run, see monitoring a fine-tuning job.

Combine SFT and DPO

The recommended workflow when your training data differs substantially from the base model’s pretraining distribution:
  1. Run a supervised fine-tune on the concatenation of context and preferred output, using one of the supported SFT data formats.
  2. Continue training the resulting checkpoint with DPO. Pass the previous job’s checkpoint to from_checkpoint:
Python
SFT first followed by DPO usually produces a noticeably better model than DPO alone for out-of-domain tasks.