Skip to content
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

【Hackathon】64. huber_loss 算子 fp16/bf16 完善 #53535

Merged
merged 2 commits into from
May 16, 2023

Conversation

co63oc
Copy link
Contributor

@co63oc co63oc commented May 5, 2023

PR types

Others

PR changes

Others

Description

huber_loss 算子 fp16/bf16 完善

图片

@paddle-bot
Copy link

paddle-bot bot commented May 5, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels May 5, 2023
@paddle-bot
Copy link

paddle-bot bot commented May 5, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

Copy link
Contributor

@ZzSean ZzSean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -25,7 +26,10 @@ struct HuberLossForward {
HOSTDEVICE HuberLossForward(const T& delta) : delta(delta) {}

HOSTDEVICE T operator()(const T& val) const {
T abs_val = std::abs(val);
using MPType = typename phi::dtype::MPTypeTrait<T>::Type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abs没有必要提升精度来计算吧

Copy link
Contributor Author

@co63oc co63oc May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::abs 没有float16类型参数,需要增加MPType转换
如果val, delta都使用MPType计算,delta也需要转换,这样减少delta的转换
以后可以对std::abs封装float16,替换这里代码

@co63oc
Copy link
Contributor Author

co63oc commented May 10, 2023

T abs_val = std::abs(val);
using MPType = typename phi::dtype::MPTypeTrait<T>::Type;
MPType mt_val = static_cast<MPType>(val);
MPType mt_abs_val = std::abs(mt_val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以直接使用abs,Paddle中对这两种数据类型的abs计算应该都做了重载

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@@ -401,4 +401,8 @@ struct numeric_limits<phi::dtype::bfloat16> {
}
};

HOSTDEVICE inline phi::dtype::bfloat16 abs(const phi::dtype::bfloat16& a) {
return phi::dtype::abs(a);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此文件内304行已经有了abs的重载

Copy link
Contributor Author

@co63oc co63oc May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改使用abs()

Copy link
Contributor

@ZzSean ZzSean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1 luotao1 merged commit 74b91bc into PaddlePaddle:develop May 16, 2023
@co63oc co63oc deleted the huber branch May 18, 2023 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants