-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDirect Preference Optimization
88 lines (76 loc) · 4.28 KB
/
Direct Preference Optimization
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Direct Preference Optimization (DPO) was introduced as an alternative to
Reinforcement Learning from Human Feedback (RLHF) and has gained popularity,
notably used in Zephyr, a leading 7B language model at that time.
DPO is specifically designed for generative language models like GPT, Llama, Zephyr, and T5, with the primary goal of improving
the alignment of language models with human preferences.
Unlike RLHF, DPO doesn't require a reward model and directly optimizes the model based on preference data.
Preference data for DPO consists of triplets (prompt, chosen answer, rejected answer),
where each prompt has an associated better and worse response. These responses, unlike RLHF,
don't need to be sampled from the model being optimized.
The fine-tuning process in DPO involves creating an exact copy of the language model (LM) being trained,
freezing its parameters, and scoring chosen and rejected responses for each data point using both the trained and frozen models.
The scores are calculated as the product of probabilities associated with the desired response token for each generation step
The ratio between the scores from the trained and frozen models is then used to calculate the final loss,
which guides the modification of model weights in the gradient descent update.
The DPO loss equation includes a hyperparameter β and the sigmoid function, ensuring stability and performance.
DPO is praised for being a stable, performant, and computationally lightweight algorithm.
Unlike RLHF, it eliminates the need for fitting a reward model, sampling during fine-tuning, and extensive hyperparameter tuning.
In essence, DPO represents a significant advancement,
simplifying and enhancing the process of building language models that better understand and cater to human needs.
** RLHF vs DPO
## RLHF (Reinforcement Learning from Human Feedback)
1. How it Works:
-1. Phases:
Pre-training, reward model training, and fine-tuning with reinforcement learning.
-2. Reward Model:
Assigns a score to text generated by LLM based on human feedback.
-3. Human Feedback Types:
Numerical ratings, binary preferences, or textual corrections.
-4. Reinforcement Learning:
Guides the model to maximize the score without deviating too far from the original model.
-5. Fine-Tuning:
Requires significant hyperparameter search for stability and convergence.
2. Strengths and Weaknesses:
-1. Strengths:
Handles various types of human feedback.
Can explore new text generation possibilities.
-2. Weaknesses:
More complex and potentially unstable.
Requires more computational resources.
May suffer from convergence, drift, or uncorrelated distribution issues.
## DPO (Direct Policy Optimization)
1. How it Works:
-1. Phase:
Single policy training phase.
-2. Human Feedback Types:
Expressed as binary preferences between two alternatives.
-3. Training:
Solves a classification problem on LLM-generated text directly using human feedback.
-4. Eliminates:
No need for training a reward model, sampling during fine-tuning, or significant hyperparameter search.
-5. Performance:
Offers better or comparable performance to RLHF with fewer computational resources.
2. Strengths and Weaknesses:
-1. Strengths:
Simpler and more efficient.
Better or comparable performance with fewer resources.
Solves reward maximization problem in a single phase.
-2. Weaknesses:
Requires binary preferences as human feedback.
## Most Appropriate Conditions:
1. DPO is Preferable When:
Precise and stable control over LLM behavior is desired.
Human feedback is expressed as binary preferences.
2. RLHF is Suitable When:
Human feedback is expressed as numerical ratings or textual corrections.
Exploration of new text generation possibilities is a priority.
## Conclusion:
1. DPO:
Simplicity and efficiency.
Requires binary preferences.
Precise and stable control over LLM behavior.
2. RLHF:
Flexibility and versatility.
Handles various types of feedback.
Exploration of new possibilities, but more resource-intensive.
The choice between RLHF and DPO depends on the specific application, the type of feedback available, and the desired level of control over the LLM's behavior.