Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
50a8b655
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
50a8b655
编写于
1月 09, 2023
作者:
W
wangzhen38
提交者:
GitHub
1月 09, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[0 Tensor support] cumprod (#49550)
上级
1574a862
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
55 addition
and
3 deletion
+55
-3
paddle/fluid/operators/cumprod_op.cc
paddle/fluid/operators/cumprod_op.cc
+1
-1
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+1
-2
paddle/phi/kernels/cpu/cumprod_grad_kernel.cc
paddle/phi/kernels/cpu/cumprod_grad_kernel.cc
+4
-0
paddle/phi/kernels/cpu/cumprod_kernel.cc
paddle/phi/kernels/cpu/cumprod_kernel.cc
+4
-0
paddle/phi/kernels/funcs/cumprod.h
paddle/phi/kernels/funcs/cumprod.h
+12
-0
paddle/phi/kernels/gpu/cumprod_grad_kernel.cu
paddle/phi/kernels/gpu/cumprod_grad_kernel.cu
+4
-0
paddle/phi/kernels/gpu/cumprod_kernel.cu
paddle/phi/kernels/gpu/cumprod_kernel.cu
+4
-0
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
+25
-0
未找到文件。
paddle/fluid/operators/cumprod_op.cc
浏览文件 @
50a8b655
...
...
@@ -82,7 +82,7 @@ class CumprodGradOp : public framework::OperatorWithKernel {
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
cumprod
,
CumprodInferShapeFunctor
,
PD_INFER_META
(
phi
::
UnchangedInferMeta
));
PD_INFER_META
(
phi
::
UnchangedInferMeta
CheckAxis
));
REGISTER_OPERATOR
(
cumprod
,
ops
::
CumprodOp
,
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
50a8b655
...
...
@@ -441,8 +441,7 @@
args
:
(Tensor x, int dim)
output
:
Tensor(out)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
func
:
UnchangedInferMetaCheckAxis
kernel
:
func
:
cumprod
backward
:
cumprod_grad
...
...
paddle/phi/kernels/cpu/cumprod_grad_kernel.cc
浏览文件 @
50a8b655
...
...
@@ -44,6 +44,10 @@ void CumprodGradKernel(const Context& dev_ctx,
size_t
mid_dim
=
1
;
size_t
inner_dim
=
1
;
GetCumprodDimInfo
(
shape
,
dim
,
&
outer_dim
,
&
mid_dim
,
&
inner_dim
);
if
(
shape
.
size
()
==
0
)
{
phi
::
Copy
<
Context
>
(
dev_ctx
,
d_out
,
dev_ctx
.
GetPlace
(),
false
,
d_x
);
return
;
}
size_t
numel
=
outer_dim
*
mid_dim
*
inner_dim
;
// deal with complex
...
...
paddle/phi/kernels/cpu/cumprod_kernel.cc
浏览文件 @
50a8b655
...
...
@@ -37,6 +37,10 @@ void CumprodKernel(const Context& dev_ctx,
size_t
mid_dim
=
1
;
size_t
inner_dim
=
1
;
GetCumprodDimInfo
(
shape
,
dim
,
&
outer_dim
,
&
mid_dim
,
&
inner_dim
);
if
(
shape
.
size
()
==
0
)
{
phi
::
Copy
<
Context
>
(
dev_ctx
,
input
,
dev_ctx
.
GetPlace
(),
false
,
out
);
return
;
}
for
(
size_t
i
=
0
;
i
<
outer_dim
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
mid_dim
;
j
++
)
{
...
...
paddle/phi/kernels/funcs/cumprod.h
浏览文件 @
50a8b655
...
...
@@ -30,6 +30,18 @@ static void GetCumprodDimInfo(const DDim& dim,
"rank of input x which is %d.But received dim=%d"
,
-
dim
.
size
(),
cumprod_dim
));
if
(
dim
.
size
()
==
0
)
{
PADDLE_ENFORCE_LE
(
cumprod_dim
,
dim
.
size
(),
phi
::
errors
::
InvalidArgument
(
"The input dim of CumprodOp should be smaller than the "
"rank of input x which is %d.But received dim=%d"
,
dim
.
size
(),
cumprod_dim
));
return
;
}
PADDLE_ENFORCE_LT
(
cumprod_dim
,
dim
.
size
(),
phi
::
errors
::
InvalidArgument
(
...
...
paddle/phi/kernels/gpu/cumprod_grad_kernel.cu
浏览文件 @
50a8b655
...
...
@@ -136,6 +136,10 @@ void CumprodGradKernel(const Context &dev_ctx,
size_t
outer_dim
,
mid_dim
,
inner_dim
;
GetCumprodDimInfo
(
x
.
dims
(),
dim
,
&
outer_dim
,
&
mid_dim
,
&
inner_dim
);
if
(
x
.
dims
().
size
()
==
0
)
{
phi
::
Copy
<
Context
>
(
dev_ctx
,
dout
,
dev_ctx
.
GetPlace
(),
false
,
dx
);
return
;
}
if
(
outer_dim
==
0
||
mid_dim
==
0
||
inner_dim
==
0
)
return
;
size_t
numel
=
outer_dim
*
mid_dim
*
inner_dim
;
...
...
paddle/phi/kernels/gpu/cumprod_kernel.cu
浏览文件 @
50a8b655
...
...
@@ -32,6 +32,10 @@ void CumprodKernel(const Context &dev_ctx,
auto
*
y
=
out
;
size_t
outer_dim
,
mid_dim
,
inner_dim
;
GetCumprodDimInfo
(
x
->
dims
(),
dim
,
&
outer_dim
,
&
mid_dim
,
&
inner_dim
);
if
(
x
->
dims
().
size
()
==
0
)
{
phi
::
Copy
<
Context
>
(
dev_ctx
,
input
,
dev_ctx
.
GetPlace
(),
false
,
out
);
return
;
}
const
auto
*
x_data
=
x
->
data
<
T
>
();
auto
*
y_data
=
dev_ctx
.
template
Alloc
<
T
>(
y
);
...
...
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
浏览文件 @
50a8b655
...
...
@@ -563,6 +563,18 @@ class TestSundryAPI(unittest.TestCase):
self
.
assertEqual
(
out
.
grad
.
shape
,
[])
self
.
assertEqual
(
x
.
grad
.
shape
,
[])
def
test_cumprod
(
self
):
x
=
paddle
.
full
([],
1.0
,
'float32'
)
x
.
stop_gradient
=
False
out
=
paddle
.
cumprod
(
x
,
0
)
out
.
backward
()
with
self
.
assertRaises
(
ValueError
):
tmp
=
paddle
.
cumprod
(
x
,
2
)
self
.
assertEqual
(
out
.
shape
,
[])
self
.
assertEqual
(
out
.
grad
.
shape
,
[])
self
.
assertEqual
(
x
.
grad
.
shape
,
[])
def
test_clip
(
self
):
x
=
paddle
.
uniform
([],
None
,
-
10
,
10
)
x
.
stop_gradient
=
False
...
...
@@ -994,6 +1006,19 @@ class TestSundryAPIStatic(unittest.TestCase):
res
=
self
.
exe
.
run
(
prog
,
fetch_list
=
[
out
])
self
.
assertEqual
(
res
[
0
].
shape
,
())
@
prog_scope
()
def
test_cumprod
(
self
):
x
=
paddle
.
full
([],
1.0
,
'float32'
)
x
.
stop_gradient
=
False
out
=
paddle
.
cumprod
(
x
,
0
)
paddle
.
static
.
append_backward
(
out
)
prog
=
paddle
.
static
.
default_main_program
()
res
=
self
.
exe
.
run
(
prog
,
fetch_list
=
[
out
])
with
self
.
assertRaises
(
ValueError
):
tmp
=
paddle
.
cumprod
(
x
,
2
)
self
.
assertEqual
(
res
[
0
].
shape
,
())
@
prog_scope
()
def
test_clip
(
self
):
x
=
paddle
.
uniform
([],
None
,
-
10
,
10
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录