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

Fix div zero in fake quantize op #22966

Merged
merged 5 commits into from
Mar 19, 2020
Merged

Conversation

slf12
Copy link
Contributor

@slf12 slf12 commented Mar 11, 2020

Fix div zero in fake quantize op

@@ -58,11 +58,12 @@ struct ClipAndFakeQuantFunctor<platform::CPUDeviceContext, T> {
const framework::Tensor& in, const framework::Tensor& scale,
const int bin_cnt, framework::Tensor* out) {
T s = scale.data<T>()[0];
T inv_s = s - 0 <= 1e-30 ? 0 : 1.0 / s;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. s是否可能为负数,如果可能为负数建议用abs,不会为负数-0建议不要
  2. 1e-30多处用到,建议作为全局常量放在.h里面

Copy link
Contributor

Choose a reason for hiding this comment

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

建议在.h里面抽象一个HOSTDEVICE static inlineinverse函数

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@slf12 slf12 closed this Mar 17, 2020
@slf12 slf12 reopened this Mar 17, 2020
@ceci3 ceci3 merged commit 915b892 into PaddlePaddle:develop Mar 19, 2020
@slf12 slf12 deleted the fix_div_zero branch March 19, 2020 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants