Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0d642d3a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
0d642d3a
编写于
4月 07, 2022
作者:
H
hong
提交者:
GitHub
4月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add norm, segment_pool (#41465)
上级
50ddc0b2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
49 addition
and
12 deletion
+49
-12
python/paddle/fluid/tests/unittests/test_bincount_op.py
python/paddle/fluid/tests/unittests/test_bincount_op.py
+4
-1
python/paddle/fluid/tests/unittests/test_norm_op.py
python/paddle/fluid/tests/unittests/test_norm_op.py
+1
-0
python/paddle/fluid/tests/unittests/test_segment_ops.py
python/paddle/fluid/tests/unittests/test_segment_ops.py
+16
-2
python/paddle/incubate/tensor/math.py
python/paddle/incubate/tensor/math.py
+4
-4
python/paddle/tensor/linalg.py
python/paddle/tensor/linalg.py
+2
-5
python/paddle/utils/code_gen/api.yaml
python/paddle/utils/code_gen/api.yaml
+11
-0
python/paddle/utils/code_gen/backward.yaml
python/paddle/utils/code_gen/backward.yaml
+11
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_bincount_op.py
浏览文件 @
0d642d3a
...
...
@@ -126,6 +126,7 @@ class TestBincountOp(OpTest):
# without weights
def
setUp
(
self
):
self
.
op_type
=
"bincount"
self
.
python_api
=
paddle
.
bincount
self
.
init_test_case
()
self
.
inputs
=
{
"X"
:
self
.
np_input
}
self
.
attrs
=
{
"minlength"
:
self
.
minlength
}
...
...
@@ -137,13 +138,14 @@ class TestBincountOp(OpTest):
self
.
Out
=
np
.
bincount
(
self
.
np_input
,
minlength
=
self
.
minlength
)
def
test_check_output
(
self
):
self
.
check_output
()
self
.
check_output
(
check_eager
=
False
)
class
TestCase1
(
TestBincountOp
):
# with weights(FLOAT32)
def
setUp
(
self
):
self
.
op_type
=
"bincount"
self
.
python_api
=
paddle
.
bincount
self
.
init_test_case
()
self
.
inputs
=
{
"X"
:
self
.
np_input
,
"Weights"
:
self
.
np_weights
}
self
.
attrs
=
{
"minlength"
:
self
.
minlength
}
...
...
@@ -163,6 +165,7 @@ class TestCase2(TestBincountOp):
# with weights(other)
def
setUp
(
self
):
self
.
op_type
=
"bincount"
self
.
python_api
=
paddle
.
bincount
self
.
init_test_case
()
self
.
inputs
=
{
"X"
:
self
.
np_input
,
"Weights"
:
self
.
np_weights
}
self
.
attrs
=
{
"minlength"
:
self
.
minlength
}
...
...
python/paddle/fluid/tests/unittests/test_norm_op.py
浏览文件 @
0d642d3a
...
...
@@ -32,6 +32,7 @@ def l2_norm(x, axis, epsilon):
class
TestNormOp
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"norm"
self
.
python_api
=
paddle
.
fluid
.
layers
.
l2_normalize
self
.
init_test_case
()
self
.
init_dtype
()
x
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
...
...
python/paddle/fluid/tests/unittests/test_segment_ops.py
浏览文件 @
0d642d3a
...
...
@@ -73,6 +73,17 @@ def compute_segment_min_max(x, segment_ids, pooltype="MAX"):
return
results
,
gradient
/
results
.
size
def
segment_pool_split
(
X
,
SegmentIds
,
pooltype
):
if
pooltype
==
"SUM"
:
return
paddle
.
incubate
.
tensor
.
segment_sum
(
X
,
SegmentIds
)
elif
pooltype
==
"MEAN"
:
return
paddle
.
incubate
.
tensor
.
segment_mean
(
X
,
SegmentIds
)
elif
pooltype
==
"MIN"
:
return
paddle
.
incubate
.
tensor
.
segment_min
(
X
,
SegmentIds
)
elif
pooltype
==
"MAX"
:
return
paddle
.
incubate
.
tensor
.
segment_max
(
X
,
SegmentIds
)
class
TestSegmentOps
(
OpTest
):
def
set_data
(
self
):
x
=
np
.
random
.
uniform
(
-
1
,
1
,
self
.
shape
).
astype
(
self
.
dtype
)
...
...
@@ -90,6 +101,8 @@ class TestSegmentOps(OpTest):
def
prepare
(
self
):
self
.
op_type
=
"segment_pool"
self
.
python_api
=
segment_pool_split
self
.
python_out_sig
=
[
"Out"
]
self
.
dtype
=
np
.
float64
self
.
shape
=
[
30
,
15
]
self
.
attrs
=
{
"pooltype"
:
"SUM"
}
...
...
@@ -105,10 +118,10 @@ class TestSegmentOps(OpTest):
self
.
outputs
=
{
'Out'
:
result
.
astype
(
self
.
dtype
)}
def
test_check_output
(
self
):
self
.
check_output
()
self
.
check_output
(
check_eager
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
([
"X"
],
"Out"
)
self
.
check_grad
([
"X"
],
"Out"
,
check_eager
=
True
)
class
TestSegmentSum2
(
TestSegmentOps
):
...
...
@@ -259,4 +272,5 @@ class API_SegmentOpsTest(unittest.TestCase):
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
unittest
.
main
()
python/paddle/incubate/tensor/math.py
浏览文件 @
0d642d3a
...
...
@@ -52,7 +52,7 @@ def segment_sum(data, segment_ids, name=None):
"""
if
in_dygraph_mode
():
return
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
m
,
"SUM"
)[
0
]
return
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
,
"SUM"
)[
0
]
if
_in_legacy_dygraph
():
out
,
tmp
=
_C_ops
.
segment_pool
(
data
,
segment_ids
,
'pooltype'
,
"SUM"
)
return
out
...
...
@@ -109,7 +109,7 @@ def segment_mean(data, segment_ids, name=None):
"""
if
in_dygraph_mode
():
return
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
m
,
"MEAN"
)[
0
]
return
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
,
"MEAN"
)[
0
]
if
_non_static_mode
():
out
,
tmp
=
_C_ops
.
segment_pool
(
data
,
segment_ids
,
'pooltype'
,
"MEAN"
)
return
out
...
...
@@ -165,7 +165,7 @@ def segment_min(data, segment_ids, name=None):
"""
if
in_dygraph_mode
():
return
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
m
,
"MIN"
)[
0
]
return
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
,
"MIN"
)[
0
]
if
_non_static_mode
():
out
,
tmp
=
_C_ops
.
segment_pool
(
data
,
segment_ids
,
'pooltype'
,
"MIN"
)
...
...
@@ -222,7 +222,7 @@ def segment_max(data, segment_ids, name=None):
"""
if
in_dygraph_mode
():
out
,
tmp
=
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
,
"MAX"
)[
0
]
out
=
_C_ops
.
final_state_segment_pool
(
data
,
segment_ids
,
"MAX"
)[
0
]
return
out
if
_non_static_mode
():
...
...
python/paddle/tensor/linalg.py
浏览文件 @
0d642d3a
...
...
@@ -17,7 +17,7 @@ from ..fluid.layer_helper import LayerHelper
from
..framework
import
_varbase_creator
,
_dygraph_tracer
from
..fluid.data_feeder
import
check_variable_and_dtype
,
check_type
,
check_dtype
from
..static
import
Variable
from
..fluid.framework
import
_in_legacy_dygraph
,
in_dygraph_mode
from
..fluid.framework
import
_in_legacy_dygraph
,
in_dygraph_mode
,
_non_static_mode
from
..fluid.layers
import
transpose
,
cast
# noqa: F401
from
..fluid
import
layers
import
paddle
...
...
@@ -1487,10 +1487,7 @@ def bincount(x, weights=None, minlength=0, name=None):
if
x
.
dtype
not
in
[
paddle
.
int32
,
paddle
.
int64
]:
raise
TypeError
(
"Elements in Input(x) should all be integers"
)
# if in_dygraph_mode():
# return _C_ops.final_state_bincount(x, weights, minlength)
if
_in_legacy_dygraph
():
if
_non_static_mode
():
return
_C_ops
.
bincount
(
x
,
weights
,
"minlength"
,
minlength
)
helper
=
LayerHelper
(
'bincount'
,
**
locals
())
...
...
python/paddle/utils/code_gen/api.yaml
浏览文件 @
0d642d3a
...
...
@@ -1363,6 +1363,16 @@
optional
:
weight
backward
:
nll_loss_grad
-
api
:
norm
args
:
(Tensor x, int axis, float epsilon, bool is_test)
output
:
Tensor(out), Tensor(norm)
infer_meta
:
func
:
NormInferMeta
kernel
:
func
:
norm
intermediate
:
norm
backward
:
norm_grad
-
api
:
not_equal
args
:
(Tensor x, Tensor y, int axis = -1)
output
:
Tensor
...
...
@@ -1669,6 +1679,7 @@
func
:
SegmentPoolInferMeta
kernel
:
func
:
segment_pool
data_type
:
x
backward
:
segment_pool_grad
# selu
...
...
python/paddle/utils/code_gen/backward.yaml
浏览文件 @
0d642d3a
...
...
@@ -980,6 +980,16 @@
data_type
:
input
optional
:
weight
-
backward_api
:
norm_grad
forward
:
norm (Tensor x, int axis, float epsilon, bool is_test) -> Tensor(out), Tensor(norm)
args
:
(Tensor x, Tensor norm, Tensor out_grad, int axis, float epsilon, bool is_test)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
norm_grad
-
backward_api
:
p_norm_grad
forward
:
p_norm(Tensor x, float porder, int axis, float epsilon, bool keepdim, bool asvector=false) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad, float porder, int axis, float epsilon, bool keepdim, bool asvector)
...
...
@@ -1211,6 +1221,7 @@
param
:
[
x
]
kernel
:
func
:
segment_pool_grad
optional
:
summed_ids
-
backward_api
:
selu_grad
forward
:
selu (Tensor x, float scale, float alpha) -> Tensor(out)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录