Skip to content
New issue

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

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

Already on GitHub? # to your account

use cumprod fix bug of prod_grad #64127

Merged
merged 42 commits into from
May 31, 2024

Conversation

YibinLiu666
Copy link
Contributor

@YibinLiu666 YibinLiu666 commented May 8, 2024

PR Category

Others

PR Types

Bug fixes

Description

使用双向cumprod修复prod_grad在x有0的时候出现nan的bug
测试代码:

import paddle
paddle.framework.core.set_prim_eager_enabled(True)
a=paddle.to_tensor([[1,2,3,0,5],[6,7,8,9,0]])
a.stop_gradient=False
a = a.to("float32")
b=paddle.prod(a,0)
da = paddle.grad(b, a, create_graph=False, retain_graph=False)
print(da)

修复前:
image
修复后:
image

Important

单测会挂在老动态图+CPU配置上,所以禁用了单测的CPU测试

Copy link

paddle-bot bot commented May 8, 2024

你的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 the contributor External developers label May 8, 2024
self.check_grad(
['X'],
'Out',
check_pir=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
check_pir=True,
check_pir=True,
check_prim_pir=True,

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

self.check_grad(
['X'],
'Out',
check_pir=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
check_pir=True,
check_pir=True,
check_prim_pir=True,

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

)
return x_cotangent[0]

x = np.random.random((5, 6, 10)).astype(self.data_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

建议增大shape

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

@@ -88,6 +96,7 @@ void CumprodKernel(const Context& dev_ctx,
}
}
}
memcpy(out_ptr, out_data, out->numel() * sizeof(T));
Copy link
Contributor

Choose a reason for hiding this comment

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

建议加上判断:if (x_data == out_ptr)

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

cyber-pioneer
cyber-pioneer previously approved these changes May 30, 2024
Copy link
Contributor

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

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

LGTM

@HydrogenSulfate HydrogenSulfate merged commit cb72d52 into PaddlePaddle:develop May 31, 2024
32 checks passed
co63oc pushed a commit to co63oc/Paddle that referenced this pull request Jun 3, 2024
* add reverse and exclusive

* support reverse and exclusive

* fix inplace test

* fix make on xpu

* remove print

* update test time

* fix prod_grad use cumprod

* add 1-5D test

* speed up test

* mul out_grad

* update test

* Update CMakeLists.txt

* update op_version

* update detail.h

* update composite

* update detail.h

* stage

* update test

* only test on gpu

* update details.h

* CI

* Update composite_backward_api.h

* Update details.h

* update test

* update

* Update test_reduce_op.py

* fix cumprod cpu bug

* update test

* update test

* update

* update

* ci

* ci

* remove comment

* CI

* Your commit message

* CI

* update
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants