-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
❌ The PR is not created using PR's template. You can refer to this Demo. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abs
没有必要提升精度来计算吧
There was a problem hiding this comment.
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,替换这里代码
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以直接使用abs,Paddle中对这两种数据类型的abs计算应该都做了重载
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
paddle/phi/common/bfloat16.h
Outdated
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此文件内304行已经有了abs的重载
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改使用abs()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Others
PR changes
Others
Description
huber_loss 算子 fp16/bf16 完善