AI News AI资讯 5h ago Updated 2h ago 更新于 2小时前 49

Finetuning a Reasoning LLM with Supervised or Reinforcement Learning? 使用监督学习或强化学习微调推理型大语言模型?

Supervised Fine-Tuning (SFT) is the recommended starting point for reasoning LLMs when high-quality, correct trajectories are available, rather than immediately resorting to complex reinforcement learning. Internal annotation formats (e.g., `assistant_think`, `assistant_tool`) must be strictly separated from training formats; data must be converted into the target model's specific chat template and tool-calling schema before training. Loss calculation should be selective; typically, loss is appl 明确区分原始轨迹标注格式与目标模型训练格式,避免直接使用自定义角色标签进行监督学习。 强调Chat Template的重要性,需将内部标注转换为模型特定的工具调用和对话结构以匹配预训练分布。 建议仅在拥有可执行工具、Rollout环境和可靠奖励信号时才考虑使用GRPO/RL,否则优先使用SFT和DPO。 在SFT阶段通常不对System Prompt和User消息计算损失,仅对Assistant的特定响应部分(如推理或最终答案)进行监督。

65
Hot 热度
70
Quality 质量
75
Impact 影响力

Analysis 深度分析

TL;DR

  • Supervised Fine-Tuning (SFT) is the recommended starting point for reasoning LLMs when high-quality, correct trajectories are available, rather than immediately resorting to complex reinforcement learning.
  • Internal annotation formats (e.g., assistant_think, assistant_tool) must be strictly separated from training formats; data must be converted into the target model's specific chat template and tool-calling schema before training.
  • Loss calculation should be selective; typically, loss is applied only to assistant responses, with reasoning spans optionally supervised depending on whether visible chain-of-thought is desired.
  • Preference optimization (DPO) is viable if good/bad trajectory pairs can be constructed, while Reinforcement Learning (GRPO/RL) is reserved for scenarios with executable tools, rollout environments, and reliable reward signals.

Why It Matters

This guidance addresses a critical bottleneck in deploying advanced reasoning models: the misalignment between raw annotation data and model-specific training requirements. By clarifying the distinction between internal data structures and the actual chat templates used by frameworks like Hugging Face TRL or vLLM, practitioners can avoid subtle training failures caused by format mismatches. It provides a pragmatic roadmap for choosing between SFT, DPO, and RL based on available infrastructure and data quality, preventing wasted compute on inappropriate optimization methods.

Technical Details

  • Data Representation Strategy: Raw annotations like assistant_think and assistant_tool should be treated as intermediate processing steps. Before training, these must be mapped to the target model's native format, such as standard assistant messages containing reasoning text, tool_calls objects, and tool role messages for results.
  • Tool-Calling Integration: Utilize libraries like TRL’s SFTTrainer which support tool-calling natively. Datasets must include a tools column with JSON schemas, ensuring the tokenizer and chat template correctly render function calls and their outputs.
  • Loss Masking Protocols: Do not apply loss to conditioning context (system prompts, user messages). For assistant responses, loss is generally applied to the final answer. Supervising the "thinking" or reasoning span is optional and depends on whether the goal is to make the model's internal reasoning process visible and reproducible.
  • Template Specificity: Different model families (e.g., Qwen, GPT-OSS) require specific chat templates and parsers. Using generic roles without a corresponding custom chat template that renders them correctly will lead to poor performance, as the model expects specific control tokens and structures it was pre-trained on.

Industry Insight

  • Standardize Data Pipelines Early: Adopt a normalization layer (similar to the Agent Data Protocol concept) that converts heterogeneous raw trajectories into a unified, model-specific schema before any training begins. This reduces friction when switching between base models or updating inference stacks.
  • Evaluate Infrastructure Readiness for RL: Organizations should not jump to Reinforcement Learning for reasoning tasks unless they have robust execution environments and verifiable reward functions. For most cases, high-quality SFT combined with DPO offers a better return on investment and stability.
  • Prioritize Chat Template Fidelity: Treat the chat template as a core component of the model interface, not just a formatting utility. Ensure that preprocessing pipelines strictly adhere to the template requirements of the target model family to maintain compatibility with serving engines like vLLM.

TL;DR

  • 明确区分原始轨迹标注格式与目标模型训练格式,避免直接使用自定义角色标签进行监督学习。
  • 强调Chat Template的重要性,需将内部标注转换为模型特定的工具调用和对话结构以匹配预训练分布。
  • 建议仅在拥有可执行工具、Rollout环境和可靠奖励信号时才考虑使用GRPO/RL,否则优先使用SFT和DPO。
  • 在SFT阶段通常不对System Prompt和User消息计算损失,仅对Assistant的特定响应部分(如推理或最终答案)进行监督。

为什么值得看

本文深入剖析了推理大模型微调中的数据表示陷阱,特别是如何处理思维链(CoT)和工具调用数据,为从业者提供了从数据预处理到损失函数设计的实操指南。它澄清了SFT、DPO和RL在推理模型训练中的适用边界,有助于避免常见的工程错误并优化训练效率。

技术解析

  • 数据格式转换:不应直接将assistant_thinkassistant_tool等作为模型角色训练,而应将其视为内部注释,在预处理阶段转换为目标模型支持的tool_callstool角色消息及JSON Schema格式。
  • Chat Template适配:不同模型家族(如Qwen、GPT-OSS)对工具调用和推理输出的模板要求不同,必须确保训练数据的序列化格式与推理时的apply_chat_template完全一致。
  • 损失函数策略:SFT中通常忽略System和User消息的损失,仅对Assistant生成的内容进行监督;若希望模型学习推理过程,需显式指定对推理文本段计算损失。
  • 算法选择路径:有正确轨迹数据时首选SFT;能构建优劣轨迹对时使用DPO;仅在具备环境交互能力和奖励机制时引入GRPO/RL,避免盲目使用强化学习。

行业启示

  • 数据工程标准化:建立统一的Agent数据协议(如ADP思想),将异构的轨迹数据规范化后再投入训练,是提升模型泛化能力的关键步骤。
  • 微调策略分层:根据数据质量和基础设施能力分层选择微调方法,大多数场景下高质量SFT配合DPO足以达到良好效果,无需过度依赖复杂的RL流程。
  • 模板一致性优先:在推理模型开发中,保持训练数据格式与推理服务框架(如vLLM、Transformers)的严格对齐,比单纯增加数据量更能解决工具调用失败等问题。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

LLM 大模型 Fine-tuning 微调 Training 训练 Alignment 对齐