ms-swift icon indicating copy to clipboard operation
ms-swift copied to clipboard

希望支持train_on_prompt

Open caihuaiguang opened this issue 1 year ago • 8 comments

Describe the feature 在SFT时碰到场景,希望同时学习用户的提问和模型的回复,希望支持和llama factory一样的train_on_prompt功能;或者说SFT的数据格式中user也能增添loss字段,来决定是否参与训练。

Paste any useful information Llama factory实现: https://github.com/hiyouga/LLaMA-Factory/blob/59f2bf1ea369ca91774b99e8d94a578657be6c7c/src/llamafactory/data/processor/supervised.py#L63

caihuaiguang avatar Sep 08 '25 06:09 caihuaiguang

--loss_scale all 就可以对所有内容算loss

Jintao-Huang avatar Sep 08 '25 06:09 Jintao-Huang

试了一下SFT时设置为--loss_scale all,发现的确会对所有内容算loss(也包括template中的system prompt和special token),但我只想训user真实的提问和assistant的回答(将template中的system prompt和special token的设置为loss 为 0),这应该咋做呢? Image

caihuaiguang avatar Sep 08 '25 08:09 caihuaiguang

为什么需要这么训练呢

Jintao-Huang avatar Sep 10 '25 08:09 Jintao-Huang

场景是大模型智能外呼,客户(user)对于大模型的输出会有不同反应,希望在SFT时同时学习user真实的提问和assistant的回答,来让模型更好地预测user的反应。类似于“世界模型”,让模型能够预测客户的下一步反应,从而生成更合适的回答来引导对话走向成功。想试一下效果,但是又不想让模型学会太多模版化的内容(比如system prompt,和某些轮次比较固定的话术)。

caihuaiguang avatar Sep 10 '25 09:09 caihuaiguang

This issue has been inactive for over 3 months and will be automatically closed in 7 days. If this issue is still relevant, please reply to this message.

github-actions[bot] avatar Dec 10 '25 00:12 github-actions[bot]

This issue has been automatically closed due to inactivity. If needed, it can be reopened.

github-actions[bot] avatar Dec 27 '25 00:12 github-actions[bot]

你好,请问你最后是如何实现只对user和assistant计算loss

flownia avatar May 21 '26 14:05 flownia

--loss_scale all

Jintao-Huang avatar May 21 '26 14:05 Jintao-Huang