View a markdown version of this page

DPO - Amazon SageMaker AI

DPO

Description

Direct Preference Optimization (DPO) aligns a model with human preferences by training on pairs of chosen (preferred) and rejected (non-preferred) responses to the same prompt.

When to use

  • You have preference data showing which responses are better

  • Improve response quality beyond what SFT achieves

  • Model needs to avoid specific undesirable behaviors

What it achieves

Model learns to prefer generating responses similar to chosen examples and avoid rejected examples, without requiring a separate reward model.

Dataset format

DPO requires pairs of chosen (preferred) and rejected (non-preferred) responses for the same prompt. DPO supports two dataset formats. All datasets must be in JSONL format (one JSON object per line). A system message is optional in both formats.

Format 1: messages

Provide chosen and rejected as full message lists. If included, the system message must be the first element and must be the same in both chosen and rejected.

{ "chosen": [ {"role": "system", "content": "..."}, {"role": "user", "content": "..."}, {"role": "assistant", "content": "..."} ], "rejected": [ {"role": "system", "content": "..."}, {"role": "user", "content": "..."}, {"role": "assistant", "content": "..."} ] }

Format 2: prompt/chosen/rejected

Provide the prompt and both responses as separate string fields, with an optional top-level system field.

{ "system": "...", "prompt": "...", "chosen": "...", "rejected": "..." }

Guidance

  • Chosen and rejected responses should differ meaningfully in quality

  • Use the same prompt for both chosen and rejected

  • The system message is optional

Hyperparameters - DPO LoRA

Note

The tables below show the hyperparameters available when you use serverless model customization. Other hyperparameters are preset by Amazon SageMaker AI using optimized defaults. When you use SageMaker AI Training Jobs or HyperPod, you can access the full list of hyperparameters available in the recipes. See the SageMaker AI Recipes repository to get a recipe and access all hyperparameters.

Parameter Type Required? Range / Values Description
max_epochsintegerRequired1–100Number of complete passes through the training dataset.
global_batch_sizeintegerRequired16, 32, 64, 128Total samples processed per optimizer step across all instances.
learning_ratefloatRequired5e-07–1e-04Step size for weight updates during optimization.
lr_schedulerstringRequiredcosine, constantLearning rate decay schedule over training.
lr_warmup_steps_ratiofloatRequired0–1Fraction of total steps spent ramping learning rate from 0.
weight_decayfloatRequired0.0–1.0L2 regularization coefficient. Helps prevent overfitting.
gradient_clippingbooleanRequiredtrue, falseScale down gradients if norm exceeds threshold.
gradient_clipping_thresholdfloatRequired0.0–5.0Maximum allowed gradient norm.
dataset_max_lenintegerRequired256–131072Maximum sequence length in tokens. Longer sequences are truncated.
seedintegerRequired0–2147483647Random seed for reproducibility.
logging_stepsintegerRequired1–100Frequency of metric logging in optimizer steps.
lora_rankintegerRequired8, 16, 32, 64, 128Dimensionality of low-rank matrices. Lower = fewer trainable parameters.
lora_dropoutfloatRequired0.0–1.0Dropout probability for LoRA adapter layers.
lora_alphaintegerRequired16, 32, 64, 128, 256LoRA scaling factor. Effective LR scales as alpha/rank.
merge_weightsbooleanRequiredtrue, falseMerge LoRA weights into base model after training.
train_val_split_ratiofloatOptional0.0–1.0Fraction allocated to training vs validation.
temperaturefloatRequired0.0–2.0Sampling temperature for evaluation.
adam_betafloatRequired1e-03–0.1DPO inverse temperature. Controls how strongly the model enforces preference rankings.

Hyperparameters - DPO FFT

Parameter Type Required? Range / Values Description
max_epochsintegerRequired1–100Number of complete passes through the training dataset.
global_batch_sizeintegerRequired16, 32, 64, 128Total samples processed per optimizer step.
learning_ratefloatRequired5e-07–1e-04Step size for weight updates.
lr_schedulerstringRequiredcosine, constantLearning rate decay schedule.
lr_warmup_steps_ratiofloatRequired0–1Fraction of steps for LR warmup.
weight_decayfloatRequired0.0–1.0L2 regularization coefficient.
gradient_clippingbooleanRequiredtrue, falseScale down gradients if norm exceeds threshold.
gradient_clipping_thresholdfloatRequired0.0–5.0Maximum allowed gradient norm.
dataset_max_lenintegerRequired256–131072Maximum sequence length in tokens.
max_response_lengthintegerRequired100–200000Maximum tokens for generated response.
seedintegerRequired0–2147483647Random seed for reproducibility.
logging_stepsintegerRequired1–100Frequency of metric logging.
train_val_split_ratiofloatOptional0.0–1.0Fraction allocated to training vs validation.
temperaturefloatRequired0.0–2.0Sampling temperature for evaluation.
adam_betafloatRequired1e-03–0.1DPO inverse temperature. Controls how strongly the model enforces preference rankings.