你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

直接首选项优化(预览版)

直接偏好优化 (DPO) 是一种针对大型语言模型的对齐技术,用于根据人类偏好调整模型权重。 它与人类反馈强化学习 (RLHF) 的不同之处在于,它不需要拟合奖励模型,而是使用更简单的二元数据偏好进行训练。 它在计算上比 RLHF 更轻、更快,同时在对齐方面同样有效。

为什么 DPO 有用?

在没有明确的正确答案且语气、风格或特定内容偏好等主观元素很重要的情况下,DPO 特别有用。 这种方法还使模型能够从正面示例(被认为是正确或理想的)和负面示例(不太理想或不正确的)中学习。

DPO 被认为是一种可以让客户更轻松地生成高质量训练数据集的技术。 虽然许多客户很难生成足够大的数据集来进行监督式微调,但他们通常已经根据用户日志、A/B 测试或较少量的手动注释工作收集了偏好数据。

直接偏好优化数据集格式

直接偏好优化文件的格式与监督式微调不同。 客户提供包含系统消息和初始用户消息的“对话”,然后提供带有配对偏好数据的“补全”。 用户只能提供两个补全。

三个顶级字段:inputpreferred_outputnon_preferred_output

  • preferred_output/non_preferred_output 中的每个元素都必须至少包含一条助手消息
  • preferred_output/non_preferred_output 中的每个元素都只能具有 (assistant, tool) 中的角色
{  
  "input": {  
    "messages": {"role": "system", "content": ...},  
    "tools": [...],  
    "parallel_tool_calls": true  
  },  
  "preferred_output": [{"role": "assistant", "content": ...}],  
  "non_preferred_output": [{"role": "assistant", "content": ...}]  
}  

训练数据集必须采用 jsonl 格式:

{{"input": {"messages": [{"role": "system", "content": "You are a chatbot assistant. Given a user question with multiple choice answers, provide the correct answer."}, {"role": "user", "content": "Question: Janette conducts an investigation to see which foods make her feel more fatigued. She eats one of four different foods each day at the same time for four days and then records how she feels. She asks her friend Carmen to do the same investigation to see if she gets similar results. Which would make the investigation most difficult to replicate? Answer choices: A: measuring the amount of fatigue, B: making sure the same foods are eaten, C: recording observations in the same chart, D: making sure the foods are at the same temperature"}]}, "preferred_output": [{"role": "assistant", "content": "A: Measuring The Amount Of Fatigue"}], "non_preferred_output": [{"role": "assistant", "content": "D: making sure the foods are at the same temperature"}]}
}

直接偏好优化模型支持

  • gpt-4o-2024-08-06 在其各自的微调区域中支持直接偏好优化。 模型页中更新了最新的区域可用性

用户可以对基础模型以及已经使用监督式微调进行微调的模型进行偏好微调,只要它们属于受支持的模型/版本即可。

如何使用直接偏好优化微调?

偏好优化微调步骤的 GIF。

  1. jsonl准备 数据集。
  2. 选择模型,然后选择自定义的方法“直接偏好优化”
  3. 上传数据集 – 训练和验证。 根据需要进行预览。
  4. 选择超参数,建议使用默认值进行初始试验。
  5. 查看选择并创建微调作业。

后续步骤