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

希望在RL和SFT中支持ptx loss

Open caihuaiguang opened this issue 1 year ago • 4 comments

Describe the feature 在Kimi K2报告中提到,为了防止RL过程对预训练知识的遗忘,采用和InstructGPT中PPO-ptx一样的策略:在RL的目标函数中添加了额外的一项PT的loss,kimi k2中说对模型的泛化性很有帮助(“ This augmentation substantially improves the model’s generalization across a broader range of domains”)。因此希望添加对PTX的支持。

Paste any useful information Kimi ptx loss: https://arxiv.org/pdf/2507.20534 的13页 InstructGPT ptx loss: https://arxiv.org/pdf/2203.02155 第9页

Additional context ms-swift已实现CHORD算法,在RL目标函数中添加了额外的一项SFT的loss,将其换成PT loss即可。此外,也希望支持SFT时添加PT loss,应该也能提升SFT时的泛化性。

caihuaiguang avatar Sep 15 '25 08:09 caihuaiguang

请问有计划支持SFT和RL时加入ptx loss训练么?

caihuaiguang avatar Oct 07 '25 08:10 caihuaiguang

You can easily implement it in both SFT and GRPO, as DFT/CHORD is encapsulated within a separate function:

https://github.com/modelscope/ms-swift/blob/011676992ee33805b0f3a32f75294d508c47f58f/swift/trainers/utils.py#L94-L109

https://github.com/modelscope/ms-swift/blob/011676992ee33805b0f3a32f75294d508c47f58f/swift/trainers/rlhf_trainer/utils.py#L484-L526

hjh0119 avatar Oct 09 '25 08:10 hjh0119

@hjh0119 感谢指出路径,后续我自己尝试实现一下吧:)

caihuaiguang avatar Oct 09 '25 09:10 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 Jan 08 '26 00:01 github-actions[bot]