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

grpo 多任务训练 奖励函数设置返回None 这样的话,如果想要查看单个任务的reward曲线,在tensorboard中会出现nan的情况

Open XQZZK opened this issue 1 year ago • 7 comments

grpo 多任务训练 奖励函数设置返回None 这样的话,如果想要查看单个任务的reward曲线,在tensorboard中会出现nan的情况

具体来说,是在 swift/trainers/rlhf_trainer/grpo_trainer.py(1522) metrics = {key: sum(val) / len(val) for key, val in self._metrics[mode].items()} # average the metrics

如果val中存在一个nan的话,那么sum(val)就会为nan

请问如何处理这种情况

XQZZK avatar Jun 20 '25 09:06 XQZZK

What version of swift are you using?

In swift 3.5, I believe that NaN values have already been excluded by nanstd and nanmean, right?

https://github.com/modelscope/ms-swift/blob/v3.5.1/swift/trainers/rlhf_trainer/grpo_trainer.py#L1050-L1054

hjh0119 avatar Jun 20 '25 09:06 hjh0119

我使用的是3.6.0,是的 https://github.com/modelscope/ms-swift/blob/v3.5.1/swift/trainers/rlhf_trainer/grpo_trainer.py#L1050-L1054 会排除掉nan,但是考虑一种极端情况,

Image

这种情况会将nan这个值给带到swift/trainers/rlhf_trainer/grpo_trainer.py(1522)这里来

XQZZK avatar Jun 20 '25 09:06 XQZZK

What version of swift are you using?

In swift 3.5, I believe that NaN values have already been excluded by nanstd and nanmean, right?

https://github.com/modelscope/ms-swift/blob/v3.5.1/swift/trainers/rlhf_trainer/grpo_trainer.py#L1050-L1054

https://github.com/modelscope/ms-swift/issues/4653#issuecomment-2990473844

XQZZK avatar Jun 20 '25 09:06 XQZZK

So we need to exclude NaN values from the calculations in the log as well, right?

https://github.com/modelscope/ms-swift/blob/v3.5.1/swift/trainers/rlhf_trainer/grpo_trainer.py#L1512-L1518

hjh0119 avatar Jun 20 '25 09:06 hjh0119

So we need to exclude NaN values from the calculations in the log as well, right?

https://github.com/modelscope/ms-swift/blob/v3.5.1/swift/trainers/rlhf_trainer/grpo_trainer.py#L1512-L1518

我认为是这样的,可能需要修改1512到1518行这几个地方,我目前是这样修改的,但是不知道对不对

Image

XQZZK avatar Jun 20 '25 09:06 XQZZK

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 Sep 19 '25 00:09 github-actions[bot]

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

github-actions[bot] avatar Oct 05 '25 00:10 github-actions[bot]