hiyouga / LLaMA-Factory

Unified Efficient Fine-Tuning of 100+ LLMs (ACL 2024)
https://arxiv.org/abs/2403.13372
Apache License 2.0
32.32k stars 3.96k forks source link

如何自定义加权损失函数 #5033

Closed WentseChen closed 2 months ago

WentseChen commented 2 months ago

Reminder

System Info

作者您好,我目前正在进行SFT任务,想要对原有的损失函数进行加权后求平均。我已经继承了SeqTrainer的compute_loss并做出了一些修改,但不确定如何将权重从dataset传递到该函数中。可以请您告知应该对哪些地方进行修改吗?非常感谢您的回复!

以下是我的dataset,其中ratio是损失函数的权重: { "messages": [ { "role": "system", "content": "xxx" }, { "role": "human", "content": "xxx" }, { "role": "assistant", "content": "xxx" } ], "ratio": "0.51" }

Reproduction

NA

Expected behavior

No response

Others

No response

codemayq commented 2 months ago

这个改动会很大,需要从dataset 的加载开始改造,然后重载 trainner 的loss 计算。目前无法直接支持,建议仔细阅读源码,然后自行改造。

WentseChen commented 2 months ago

好的,谢谢您的回复