Preference optimization (DPO)

Direct preference optimization (DPO) trains a model to prefer a chosen answer over a rejected answer to the same prompt. If each prompt has one correct answer you can demonstrate, start with SFT.

When to use it

Use DPO when you have pairs that distinguish:

  • Helpful answers from answers that miss the request.

  • The tone or format you want from an unwanted alternative.

  • Correct tool choices from incorrect calls.

DPO can refine an SFT model. If you have a verifier rather than ranked pairs, use reinforcement learning.

Prepare your data

Each JSONL row contains prompt, an array of messages, and two assistant messages, chosen and rejected:

{"prompt":[{"role":"user","content":"My card still has not arrived. What should I do?"}],"chosen":{"role":"assistant","content":"Check the delivery estimate in your account. If it has passed, request a replacement from the card menu."},"rejected":{"role":"assistant","content":"Your card is probably lost. Order another one."}}

The answers must differ. Keep the prompt plus the longer answer within maxSeqLength; increase that limit or shorten a pair that does not fit. See Preference pairs for tools and registration rules.

Register the file:

akka optimize registry datasets register triage/preferences -f preferences.jsonl

Start a run

With a training project and selected base model, save this plan as run.yaml:

kind: run
project: triage
baseModel: unsloth/Llama-3.2-1B-Instruct
config:
  dataset: triage/preferences
  method: dpo

Validate the plan, then start training:

akka optimize training runs start -f run.yaml --dry-run
akka optimize training runs start -f run.yaml --wait --exit-status

To start from an SFT adapter, name its model version as source.model, or use a weights branch. Either way, the run measures its rewards against a frozen copy of that adapter. See Start from existing weights.

DPO trains on one GPU or several GPUs of one node, up to the MAX CLAIM shown by akka optimize training capacity for the selected device profile. Set execution.gpus accordingly and use at least as many pairs as GPUs. A paused run resumes with the same GPU count.

Key parameters

These fields are under config:

Field Default Purpose

hyperparams.optimizer.learningRate

0.000005

Peak learning rate.

hyperparams.training.epochs

3

Passes over the pairs.

preference.beta

0.1

A larger value holds the adapter closer to its reference.

preference.lossType

sigmoid

Preference loss; ipo selects a squared loss.

data.validationDataset

None

Separate preference dataset for validation.

For memory, batching and loss settings, see Run plan reference. One update contains microBatchPerGpu × gradientAccumulation × gpus pairs. Divide accumulation by the GPU count when increasing GPUs to keep that update size.

What to watch

Use akka optimize training runs get RUN_ID to read Preference and Validation preference:

  • Accuracy is the share of pairs where the chosen answer has the higher reward. If training accuracy improves without validation accuracy, reduce training or add more varied pairs.

  • Margin is the chosen reward minus the rejected reward. Read it with accuracy to check separation.

  • Chosen reward shows whether preferred answers are becoming more likely relative to the reference. A value far below zero means they are becoming less likely.

Use akka optimize training runs get RUN_ID --settings to read the settings Preference line: reference base model or reference inherited adapter. A dry run shows the same line. A training-state continuation keeps its parent’s reference. A DPO run that started from an inherited adapter cannot use a training-state continuation.

Next steps