-
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
【PaddlePaddle Hackathon 2】9、为 Paddle 新增 logspace API #41261
【PaddlePaddle Hackathon 2】9、为 Paddle 新增 logspace API #41261
Conversation
PR格式检查通过,你的PR将接受Paddle专家以及开源社区的review,请及时关注PR动态。 |
CI挂了很多,需要调整代码,待CI大部分通过后开启review |
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.
代码规范,单测case考虑周全。几处细节改一下即可。
framework::OpKernelType GetKernelTypeForVar( | ||
const std::string &var_name, const framework::Tensor &tensor, | ||
const framework::OpKernelType &expected_kernel_type) const override { | ||
return expected_kernel_type; |
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.
返回的OpKernelType应该是由expected_kernel_type.data_type_和tensor的place、layout所构造的,不能直接返回expected_kernel_type。
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.
完成
limitations under the License. */ | ||
|
||
#include <string> | ||
#include "paddle/fluid/framework/infershape_utils.h" |
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.
C++基础头文件和项目自身的头文件之间空一行,方便区分。
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.
完成
// limitations under the License. | ||
|
||
#include <cmath> | ||
#include "paddle/phi/kernels/logspace_kernel.h" |
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.
C++基础头文件和项目自身的头文件之间空一行,方便区分。
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.
完成
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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.
完成
out_data[i] = static_cast<T>(std::pow( | ||
base_data, start_data + step * i)); | ||
} else { | ||
out_data[i] = static_cast<T>(std::pow( |
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.
这里注明一下:当pow的结果非整数,dytpe为int时,会采用去尾法,对齐numpy。
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.
我在paddle/fluid/operators/logspace_op.cc
中增加了相关说明,这样可以吗?
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.
可以。
e3992c9
to
3e2e62a
Compare
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
python/paddle/fluid/layers/tensor.py
Outdated
def logspace(start, stop, num, base=10.0, dtype=None, name=None): | ||
r""" | ||
This OP return fixed number of logarithmical-evenly spaced values within a given interval. | ||
Args: |
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.
此处用Parameters 较好
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.
args也可以,不需要重新跑CI。
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.
英文模板中是args,这边应该不需要改。但是英文文档预览报错,这里需要检查一下~
需要添加对应的中文文档,提交PR到PaddlePaddle/docs仓库。并参考文档预览方法,生成该API的中英文文档预览链接,以供检查。 |
已经在此PR的描述中提到中文文档的PR。 |
你的PR有最新反馈,请及时修改。 |
python/paddle/fluid/layers/tensor.py
Outdated
@@ -1583,6 +1584,121 @@ def linspace(start, stop, num, dtype=None, name=None): | |||
return out | |||
|
|||
|
|||
def logspace(start, stop, num, base=10.0, dtype=None, name=None): | |||
r""" | |||
This OP return fixed number of logarithmical-evenly spaced values within a given interval. |
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.
- 与中文文档保持一致,去掉 this OP的描述,尽量在第一句话里描述清楚这个API的作用
- 若中文文档要加note,则英文也需要增加
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/fluid/layers/tensor.py
Outdated
def logspace(start, stop, num, base=10.0, dtype=None, name=None): | ||
r""" | ||
This OP return fixed number of logarithmical-evenly spaced values within a given interval. | ||
Args: |
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.
英文模板中是args,这边应该不需要改。但是英文文档预览报错,这里需要检查一下~
python/paddle/fluid/layers/tensor.py
Outdated
Tensor: the output data type will be float32, float64. The 1-D tensor with | ||
fixed number of evenly spaced values, the data shape of this tensor | ||
is :math:`[num]` . If the :attr:`num` is set 1, the output tensor just | ||
has the value with exponential of :attr:`start` with base :attr:`base`. |
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.
完成
e72bcfd
e72bcfd
to
fee242f
Compare
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 for docs
@@ -0,0 +1,80 @@ | |||
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
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.
license的格式有点问题,缺失空行和缩进,可以参考其他文件修改一下
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.
完成
ctx.GetPlace()); | ||
} | ||
|
||
framework::OpKernelType GetKernelTypeForVar( |
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.
完成
#include "paddle/phi/backends/cpu/cpu_context.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/funcs/data_type_transform.h" | ||
#include "paddle/phi/kernels/logspace_kernel.h" |
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.
头文件的include顺序需要调整下,可以参考说明:https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/headers/#include
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.
完成
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h" |
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.
同上哈,麻烦也调整下,#include "paddle/phi/kernels/logspace_kernel.h"
在最前面,用空行隔开
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/fluid/layers/tensor.py
Outdated
@@ -1614,6 +1615,130 @@ def linspace(start, stop, num, dtype=None, name=None): | |||
return out | |||
|
|||
|
|||
def logspace(start, stop, num, base=10.0, dtype=None, name=None): |
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.
为什么新增API是在fluid下面的,fluid后面是要移除的,这个是不是加到python/paddle/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.
任务的issue #40326 说放在这里。我看linspace
已经被移到了python/paddle/tensor/creation.py
,那就把logspace
也放到这里吗?
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.
是的,任务issue描述有误,已更新
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.
完成
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h" |
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.
这里gpu_primitives.h看起来好像没有使用?是否可以移除?
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.
LGTM
@@ -0,0 +1,27 @@ | |||
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
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.
这里的license格式好像还是有点问题,可以后续再完善下
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
Describe
增加了
paddle.logspace
。具体地,paddle.logspace(start, stop, num, base)
能产生一个以base**start
为首项、以base**end
为末项、共有num
项的等比数列。Issue:#40326
设计文档:PaddlePaddle/community#56
中文文档:PaddlePaddle/docs#4497