-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 4th No.12】为 Paddle 新增 Cauchy API #52999
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
from paddle.fluid.data_feeder import check_type, convert_dtype | ||
from paddle.fluid.framework import _non_static_mode | ||
from paddle.fluid.layers import tensor | ||
|
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.
导入规范遵循pep8,不意见直接导入函数、类
'scale', | ||
(float, tensor.Variable), | ||
'Cauchy', | ||
) |
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.
直接使用 isinstance(loc, (numbers.Real, framework.Variable)) 进行类型检查没,不需要if not _non_static_mode()判断
python/paddle/distribution/cauchy.py
Outdated
self.scale = scale | ||
self.dtype = convert_dtype(loc.dtype) | ||
else: | ||
[self.loc, self.scale] = self._to_tensor(loc, scale) |
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.
distribution._validate_args, distribution._to_tensor是遗留API,存在缺陷,建议参考 gumbel.py 写法
python/paddle/distribution/cauchy.py
Outdated
if _non_static_mode(): | ||
"""Not use `paddle.any` in static mode, which always be `True`.""" | ||
if paddle.any(self.scale <= 0): | ||
raise ValueError("The arg of `scale` must be positive.") |
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.
为了避免性能问题,建议移除此判断;后续 distribution全面支持参数校验,再进行此判断
python/paddle/distribution/cauchy.py
Outdated
raise ValueError("The arg of `scale` must be positive.") | ||
|
||
super().__init__( | ||
batch_shape=(self.loc + self.scale).shape, event_shape=() |
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.
此处为什么需要加法
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.
利用broadcast获取到batch shape,有问题吗?
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.
我根据 gumbel.py 把初始化重新写一下吧~ :)
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.
可以用 broadcast_shape
,加法会有开销
刚看到
请帮忙看看,谢谢!:) |
|
@cxxly 刚才看了一下,好象是所有的测试用例目录变了,导致我的测试用例应该是没加进去。 原来是:home/aistudio/Paddle/python/paddle/fluid/tests/unittests/distribution 我把我的用例移过去重新commit吧~ |
CI 基本都通过了,就是这个 CheckPRTemplate 不知道为啥失败了~ 请评审,谢谢!:) |
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
New features
PR changes
APIs
Description
[used AI Studio]
__init__.py
: 将 Cauchy 添加到 distribution 目录下其他说明:
@luotao1 @cxxly @Ligoml @dasenCoding
谢谢评审!
中文文档:PaddlePaddle/docs#5807
RFC:@dasenCoding
p.s. 2023-4-25 Update
to_tensor
默认0D
而不是1D
的行为。请评审,谢谢!:)
p.s. 2023-4-21 Update
__init__
方法。check_type
,改用isinstance
做类型检查。请评审,谢谢!:)