Skip to content

能否支持自定义loss function? #8084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
longXboy opened this issue May 16, 2025 · 1 comment
Open
1 task done

能否支持自定义loss function? #8084

longXboy opened this issue May 16, 2025 · 1 comment
Labels
enhancement New feature or request pending This problem is yet to be addressed

Comments

@longXboy
Copy link

longXboy commented May 16, 2025

Reminder

  • I have read the above rules and searched the existing issues.

Description

能否提供一个配置入口能够让用户自定义transformers的Trainer里的compute_loss_func(动态加载自定义的代码)?这个我理解还是一个比较常用的功能

Pull Request

如果觉得有需要的话,我可以贡献pr

No response

@longXboy longXboy added enhancement New feature or request pending This problem is yet to be addressed labels May 16, 2025
@hiyouga
Copy link
Owner

hiyouga commented May 16, 2025

一般来说可以重写这个

def compute_loss(self, model, inputs, *args, **kwargs):
return super().compute_loss(model, inputs, *args, **kwargs)

确实可以加个动态加载函数的机制来读取 loss function,例如
https://github.com/hiyouga/EasyR1/blob/65aad49271849dbe027f4f892fbea924d2fd6e14/verl/workers/reward/function.py#L41-L66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending This problem is yet to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants