-
Notifications
You must be signed in to change notification settings - Fork 5.8k
【Paddle Tensor 第二期 API鲁棒性增强】解决paddle.max、paddle.min在输入存在nan时传播不正确问题 #70049
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
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.
添加单测
test/legacy_test/test_min_op.py
Outdated
def _test_with_nan(self, func, shape, on_gpu, dtype=np.float32): | ||
with dygraph_guard(): | ||
x_np = np.arange(np.prod(shape), dtype=dtype).reshape(shape) | ||
x_np[0, 0] = np.nan | ||
x = paddle.to_tensor(x_np) | ||
if on_gpu: | ||
if not paddle.is_compiled_with_cuda(): | ||
return | ||
x = x.cuda() | ||
out = func(x) | ||
self.assertTrue(paddle.isnan(out), "Result should be NaN") |
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.
这个逻辑不用这么复杂吧
def _test_with_nan(self, func, shape, on_gpu, dtype=np.float32): | |
with dygraph_guard(): | |
x_np = np.arange(np.prod(shape), dtype=dtype).reshape(shape) | |
x_np[0, 0] = np.nan | |
x = paddle.to_tensor(x_np) | |
if on_gpu: | |
if not paddle.is_compiled_with_cuda(): | |
return | |
x = x.cuda() | |
out = func(x) | |
self.assertTrue(paddle.isnan(out), "Result should be NaN") | |
def _test_with_nan(self, func, shape, place, dtype=np.float32): | |
with dygraph_guard(): | |
x_np = np.arange(np.prod(shape), dtype=dtype).reshape(shape) | |
x_np[0, 0] = np.nan | |
x = paddle.to_tensor(x_np, place=place) | |
out = func(x) | |
self.assertTrue(paddle.isnan(out), "Result should be NaN") |
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.
已更改
@aquagull 用SFINAE合并下int32/int64两种模板 |
好的 |
PR Category
User ExperiencePR Types
Bug fixesDescription
解决了paddle.max、paddle.min在gpu、cpu环境下输入存在nan时传播不正确问题.
测试代码