-
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 No.17】为 Paddle 新增 paddle.nn.CosineEmbeddingLoss 和 paddle.nn.functional.cosine_embedding_loss API #41680
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
请先通过CI检测噢~ |
scalar的问题貌似是之前的一个pr有问题,已经revert了,重新merge一下develop分支即可 |
PR格式检查通过,你的PR将接受Paddle专家以及开源社区的review,请及时关注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.
当前CI有几个问题仍然需要关注:
- Coverage:单测提示超时。请在保证覆盖率的前提下,适当减少功能重复或不必要的单测用例
- Static: 代码风格报错,请按提示修改,或者用pre-commit刷下格式
from __future__ import print_function | ||
|
||
import paddle | ||
import paddle.fluid as fluid |
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.
因为fluid目前是非公开API并在逐步清理退场中。这里请不要使用fluid API,避免增加后续清理工作。静态图下相关API请参考paddle.static,设备相关检查请换用paddle.device.is_compiled_with_cuda()
,paddle.CPUPlace
等等
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.
已修改
python/paddle/nn/functional/loss.py
Outdated
elif reduction == 'sum': | ||
return paddle.sum(scores) | ||
|
||
fluid.data_feeder.check_variable_and_dtype( |
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.
同单测文件,这里也请不要显式使用fluid API。在文件开始引用了check_variable_and_dtype
,这里直接使用这个就行,方便后续清理工作
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.
已修改
python/paddle/nn/functional/loss.py
Outdated
shape=[label.shape[0]], | ||
dtype='{}'.format(label.dtype).replace("paddle.", ""), | ||
value=0) | ||
check_zero = fluid.layers.fill_constant( |
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.
同上,这里也请换用static下的api
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.
已修改
|
||
class TestFunctionCosineEmbeddingLoss(unittest.TestCase): | ||
def setUp(self): | ||
self.input1_np = np.random.random(size=(3, 3)).astype(np.float64) |
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.
- 单测中需要覆盖rfc设计文档中写到的测试用例,包括所有支持的dtype等
- size可以适当设计一些不一样的case以及稍大的case
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.
python/paddle/nn/functional/loss.py
Outdated
@@ -2229,3 +2229,105 @@ def hinge_embedding_loss(input, label, margin=1.0, reduction='mean', name=None): | |||
return paddle.sum(loss, name=name) | |||
elif reduction == 'none': | |||
return loss | |||
|
|||
|
|||
def cosine_embedding_loss(input1, input2, label, margin=0, reduction='mean'): |
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.
The parameters of x1, x2, target
in paddle.nn.functional.cosine_embedding_loss
's RFC must be same with parameters here.
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.
According to the design requirements, our API requires the name
parameter like other loss API.
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.
Now changing parameters will lead to the modification of code and document. Can I just change x1, x2, target
to input1, input2, label
in RFC?
python/paddle/nn/layer/loss.py
Outdated
|
||
""" | ||
|
||
def __init__(self, margin=0, reduction='mean'): |
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.
According to the design requirements, our API requires the name
parameter like other loss API.
95217b8
已修改rfc,并且添加name参数及相关代码 |
@Patrick-Star125 Code Style 检查还是错了,需要用 pre-commit ~ |
已修改 |
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
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
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
APIs
Describe