Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
3152f3fb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3152f3fb
编写于
4月 04, 2022
作者:
X
xiongkun
提交者:
GitHub
4月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Yaml] add yaml for gather op and elementwise_mod op . (#41348)
* gather op * add mod
上级
fd591ecb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
88 addition
and
39 deletion
+88
-39
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+4
-1
python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_mod_op.py
+9
-2
python/paddle/fluid/tests/unittests/test_gather_op.py
python/paddle/fluid/tests/unittests/test_gather_op.py
+6
-6
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+3
-3
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+24
-26
python/paddle/utils/code_gen/api.yaml
python/paddle/utils/code_gen/api.yaml
+20
-0
python/paddle/utils/code_gen/backward.yaml
python/paddle/utils/code_gen/backward.yaml
+22
-1
未找到文件。
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
3152f3fb
...
...
@@ -2326,7 +2326,7 @@ class TestPow(TestActivation):
def
setUp
(
self
):
self
.
op_type
=
"pow"
self
.
python_api
=
paddle
.
pow
self
.
check_eager
=
Fals
e
self
.
check_eager
=
Tru
e
self
.
init_dtype
()
np
.
random
.
seed
(
1024
)
...
...
@@ -2337,6 +2337,9 @@ class TestPow(TestActivation):
self
.
attrs
=
{
'factor'
:
3.0
}
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
self
.
check_eager
)
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
...
...
python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py
浏览文件 @
3152f3fb
...
...
@@ -29,6 +29,7 @@ class TestElementwiseModOp(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_mod"
self
.
python_api
=
paddle
.
remainder
self
.
axis
=
-
1
self
.
init_dtype
()
self
.
init_input_output
()
...
...
@@ -43,7 +44,10 @@ class TestElementwiseModOp(OpTest):
self
.
outputs
=
{
'Out'
:
self
.
out
}
def
test_check_output
(
self
):
self
.
check_output
()
if
self
.
attrs
[
'axis'
]
==
-
1
:
self
.
check_output
(
check_eager
=
True
)
else
:
self
.
check_output
(
check_eager
=
False
)
def
init_input_output
(
self
):
self
.
x
=
np
.
random
.
uniform
(
0
,
10000
,
[
10
,
10
]).
astype
(
self
.
dtype
)
...
...
@@ -76,7 +80,10 @@ class TestElementwiseModOpFloat(TestElementwiseModOp):
self
.
out
=
np
.
fmod
(
self
.
y
+
np
.
fmod
(
self
.
x
,
self
.
y
),
self
.
y
)
def
test_check_output
(
self
):
self
.
check_output
()
if
self
.
attrs
[
'axis'
]
==
-
1
:
self
.
check_output
(
check_eager
=
True
)
else
:
self
.
check_output
(
check_eager
=
False
)
class
TestElementwiseModOpDouble
(
TestElementwiseModOpFloat
):
...
...
python/paddle/fluid/tests/unittests/test_gather_op.py
浏览文件 @
3152f3fb
...
...
@@ -43,10 +43,10 @@ class TestGatherOp(OpTest):
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
"X"
][
self
.
inputs
[
"Index"
]]}
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
Fals
e
)
self
.
check_output
(
check_eager
=
Tru
e
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
Fals
e
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
Tru
e
)
def
config
(
self
):
"""
...
...
@@ -136,10 +136,10 @@ class TestGatherBF16Op(OpTest):
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
Fals
e
)
self
.
check_output
(
check_eager
=
Tru
e
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
numeric_grad_delta
=
0.5
,
check_eager
=
Fals
e
)
self
.
check_grad
([
'X'
],
'Out'
,
numeric_grad_delta
=
0.5
,
check_eager
=
Tru
e
)
def
config
(
self
):
"""
...
...
@@ -165,10 +165,10 @@ class TestGatherOp1(OpTest):
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
Fals
e
)
self
.
check_output
(
check_eager
=
Tru
e
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
Fals
e
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
Tru
e
)
def
config
(
self
):
"""
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
3152f3fb
...
...
@@ -1391,9 +1391,9 @@ def gather(x, index, axis=None, name=None):
if
axis
is
None
:
axis
=
0
#
if in_dygraph_mode():
#
return _C_ops.final_state_gather(x, index, axis)
if
_
non_static_mode
():
if
in_dygraph_mode
():
return
_C_ops
.
final_state_gather
(
x
,
index
,
axis
)
if
_
in_legacy_dygraph
():
axis
=
axis
.
item
()
if
isinstance
(
axis
,
paddle
.
Tensor
)
else
axis
return
_C_ops
.
gather
(
x
,
index
,
None
,
"axis"
,
axis
,
"overwrite"
,
False
)
...
...
python/paddle/tensor/math.py
浏览文件 @
3152f3fb
...
...
@@ -150,41 +150,38 @@ def pow(x, y, name=None):
"""
# in dynamic graph mode
#if in_dygraph_mode():
#if isinstance(y, (int, float)):
#return _C_ops.final_state_pow(x, y)
#elif isinstance(y, (paddle.Tensor, Variable)):
#return _elementwise_op_in_dygraph(
#x, y, axis=-1, act=None, op_name='elementwise_pow')
#else:
#raise TypeError('y must be scalar or tensor type, but received: %s '% (y.dtype))
#if _in_legacy_dygraph():
if
_non_static_mode
():
if
in_dygraph_mode
():
if
isinstance
(
y
,
(
int
,
float
)):
return
_C_ops
.
pow
(
x
,
'factor'
,
y
)
return
_C_ops
.
final_state_pow
(
x
,
y
)
elif
isinstance
(
y
,
(
paddle
.
Tensor
,
Variable
)):
return
_elementwise_op_in_dygraph
(
x
,
y
,
axis
=-
1
,
act
=
None
,
op_name
=
'elementwise_pow'
)
else
:
raise
TypeError
(
'y must be scalar or tensor type, but received: %s '
%
(
y
.
dtype
))
# in static graph mode
else
:
if
_in_legacy_dygraph
():
if
isinstance
(
y
,
(
int
,
float
)):
helper
=
LayerHelper
(
'pow'
,
**
locals
())
inputs
=
{
'X'
:
x
}
attrs
=
{
'factor'
:
y
}
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
type
=
'pow'
,
inputs
=
inputs
,
outputs
=
{
'Out'
:
out
},
attrs
=
attrs
)
return
out
return
_C_ops
.
pow
(
x
,
'factor'
,
y
)
elif
isinstance
(
y
,
(
paddle
.
Tensor
,
Variable
)):
# TODO A potential speed improvement is supporting different types in C++ and removing the cast ops here
helper
=
LayerHelper
(
'elementwise_pow'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
return
_elementwise_op
(
LayerHelper
(
'elementwise_pow'
,
**
locals
()))
return
_elementwise_op_in_dygraph
(
x
,
y
,
axis
=-
1
,
act
=
None
,
op_name
=
'elementwise_pow'
)
else
:
raise
TypeError
(
'y must be scalar or tensor type, but received: %s '
%
(
type
(
y
)))
raise
TypeError
(
'y must be scalar or tensor type, but received: %s '
%
(
y
.
dtype
))
# in static graph mode
if
isinstance
(
y
,
(
int
,
float
)):
helper
=
LayerHelper
(
'pow'
,
**
locals
())
inputs
=
{
'X'
:
x
}
attrs
=
{
'factor'
:
y
}
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
type
=
'pow'
,
inputs
=
inputs
,
outputs
=
{
'Out'
:
out
},
attrs
=
attrs
)
return
out
elif
isinstance
(
y
,
(
paddle
.
Tensor
,
Variable
)):
# TODO A potential speed improvement is supporting different types in C++ and removing the cast ops here
helper
=
LayerHelper
(
'elementwise_pow'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
return
_elementwise_op
(
LayerHelper
(
'elementwise_pow'
,
**
locals
()))
else
:
raise
TypeError
(
'y must be scalar or tensor type, but received: %s '
%
(
type
(
y
)))
OP_NAMEMAPPING
=
{
...
...
@@ -192,6 +189,7 @@ OP_NAMEMAPPING = {
'elementwise_min'
:
'final_state_minimum'
,
'elementwise_pow'
:
'final_state_elementwise_pow'
,
'elementwise_floordiv'
:
'final_state_floor_divide'
,
'elementwise_mod'
:
'final_state_modulo'
,
}
@
dygraph_only
...
...
python/paddle/utils/code_gen/api.yaml
浏览文件 @
3152f3fb
...
...
@@ -632,6 +632,16 @@
data_type
:
dtype > x
backend
:
place > x
-
api
:
gather
args
:
(Tensor x, Tensor index, Scalar axis=0)
output
:
Tensor(out)
infer_meta
:
func
:
GatherInferMeta
kernel
:
func
:
gather
data_type
:
x
backward
:
gather_grad
-
api
:
gather_nd
args
:
(Tensor x, Tensor index)
output
:
Tensor
...
...
@@ -1220,6 +1230,16 @@
func
:
pool3d
backward
:
pool3d_grad
-
api
:
pow
args
:
(Tensor x, Scalar s)
output
:
Tensor(out)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
pow
backward
:
pow_grad
-
api
:
prelu
args
:
(Tensor x, Tensor alpha, str data_format, str mode)
output
:
Tensor(out)
...
...
python/paddle/utils/code_gen/backward.yaml
浏览文件 @
3152f3fb
...
...
@@ -178,7 +178,7 @@
output
:
Tensor(x_grad), Tensor(filter_grad)
infer_meta
:
func
:
ConvTransposeGradInferMeta
kernel
:
kernel
:
func
:
conv2d_transpose_grad
-
backward_api
:
conv3d_transpose_grad
...
...
@@ -389,6 +389,17 @@
kernel
:
func
:
frobenius_norm_grad
-
backward_api
:
gather_grad
forward
:
gather(Tensor x, Tensor index, Scalar axis=0) -> Tensor(out)
args
:
(Tensor x, Tensor index, Tensor out_grad, Scalar axis=0, bool overwrite=false)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
data_type
:
x
func
:
gather_grad
-
backward_api
:
gather_nd_grad
forward
:
gather_nd (Tensor x, Tensor index) -> Tensor(out)
args
:
(Tensor x, Tensor index, Tensor out_grad)
...
...
@@ -803,6 +814,16 @@
kernel
:
func
:
pool3d_grad
-
backward_api
:
pow_grad
forward
:
pow(Tensor x, Scalar s) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad, Scalar s=-1)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
pow_grad
-
backward_api
:
prelu_grad
forward
:
prelu(Tensor x, Tensor alpha, str data_format, str mode) -> Tensor(out)
args
:
(Tensor x, Tensor alpha, Tensor out_grad, str data_format, str mode)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录