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

Added fmax and fmin operators #37826

Merged
merged 16 commits into from
Dec 16, 2021
Merged

Conversation

lijiaqi0612
Copy link
Contributor

@lijiaqi0612 lijiaqi0612 commented Dec 3, 2021

PR types

New features

PR changes

OPs

Describe

Added fmax and fmin operators, and added documentation and unit tests for comparison with competing products.

example:

import numpy as np
import paddle

x = paddle.to_tensor([2, 3, np.nan], dtype='float32')
y = paddle.to_tensor([1, np.nan, 5], dtype='float32')

# fmax
res_fmax = paddle.fmax(x, y)
print(res_fmax)
#    [ 2., 3., 5.]
 
# fmin
res_fmin = paddle.fmin(x, y)
print(res_fmin)
#    [ 1., 3., 5.]

The reason for the need to modify the 'no_grad_set_white_list.py' file is that because there are two inputs, the reverse of one of them needs to be tested separately, and the operator name needs to be added to the whitelist.

@paddle-bot-old
Copy link

paddle-bot-old bot commented Dec 3, 2021

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@paddle-bot-old
Copy link

paddle-bot-old bot commented Dec 3, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@lijiaqi0612 lijiaqi0612 changed the title Fmax fmin Added fmax and fmin operators Dec 3, 2021
ops::ElementwiseFMaxGradKernel<paddle::platform::CPUDeviceContext, int>,
ops::ElementwiseFMaxGradKernel<paddle::platform::CPUDeviceContext, int64_t>);

REGISTER_OP_VERSION(elementwise_fmax)

Choose a reason for hiding this comment

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

这一段不需要,这是用于 op 兼容性升级的。

The equation is:

.. math::
out = fmax(x, y)

Choose a reason for hiding this comment

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

文档里面最好写明 nan 的传播机制。亦即 nan 被认为小于任何值。

out = fmin(x, y)

**Note**:
``paddle.fmin`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .

Choose a reason for hiding this comment

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

文档里面最好写明 nan 的传播机制。亦即 nan 被认为大于任何值。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK 已经添加了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK 已经添加了

import paddle.fluid.core as core


class ApiFMaxTest(unittest.TestCase):
Copy link

@iclementine iclementine Dec 3, 2021

Choose a reason for hiding this comment

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

还缺少 OpTest。
需要继承 OpTest 写 Op 单元测试。可以参考 python/paddle/fluid/tests/unittests/test_elementwise_add_op.py

fmin 也是一样

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok 已经添加了

@@ -295,6 +297,8 @@
'maximum',
'min',
'minimum',
'fmax',
'fmin',
Copy link
Contributor

Choose a reason for hiding this comment

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

这里需要把函数加入此文件的tensor_method_func列表

@@ -437,6 +439,8 @@
'pow',
'zeros_like',
'maximum',
'fmax',
'fmin',
Copy link
Contributor

Choose a reason for hiding this comment

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

需要加入此文件的all 列表

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经加了呀

dingjiaweiww
dingjiaweiww previously approved these changes Dec 10, 2021
Comment on lines 70 to 71
return "Compare two tensors and returns a new tensor containing the "
"element-wise maxima.";
Copy link
Contributor

Choose a reason for hiding this comment

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

what's different between fmax and max, shall we describe it more detailed?

Comment on lines 70 to 71
return "Compare two tensors and returns a new tensor containing the "
"element-wise minima.";
Copy link
Contributor

Choose a reason for hiding this comment

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

what's different between fmin and min, shall we describe it more detailed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

jeff41404
jeff41404 previously approved these changes Dec 14, 2021
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

lgtm

lanxianghit
lanxianghit previously approved these changes Dec 15, 2021
Shixiaowei02
Shixiaowei02 previously approved these changes Dec 15, 2021
Copy link
Contributor

@Shixiaowei02 Shixiaowei02 left a comment

Choose a reason for hiding this comment

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

approve for no_grad_set_white_list

Copy link

@iclementine iclementine left a comment

Choose a reason for hiding this comment

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

LGTM

@iclementine iclementine merged commit dd3afc9 into PaddlePaddle:develop Dec 16, 2021
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.

6 participants