Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
468c17ff
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看板
未验证
提交
468c17ff
编写于
3月 07, 2023
作者:
C
ccrrong
提交者:
GitHub
3月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add stack composite rule (#50861)
* add stack composite rule * add float16 datatype test
上级
39a9abaa
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
35 addition
and
4 deletion
+35
-4
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+1
-0
python/paddle/fluid/tests/unittests/test_stack_op.py
python/paddle/fluid/tests/unittests/test_stack_op.py
+10
-3
python/paddle/incubate/autograd/composite_rules.py
python/paddle/incubate/autograd/composite_rules.py
+14
-0
python/paddle/incubate/autograd/primitives.py
python/paddle/incubate/autograd/primitives.py
+2
-0
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+8
-1
未找到文件。
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
468c17ff
...
...
@@ -1207,6 +1207,7 @@ set(TEST_CINN_OPS
test_expand_v2_op
test_reduce_op
test_slice_op
test_stack_op
test_activation_op
test_full_like_op
test_fill_any_like_op
...
...
python/paddle/fluid/tests/unittests/test_stack_op.py
浏览文件 @
468c17ff
...
...
@@ -44,6 +44,7 @@ class TestStackOpBase(OpTest):
self
.
initDefaultParameters
()
self
.
initParameters
()
self
.
op_type
=
'stack'
self
.
prim_op_type
=
"comp"
self
.
python_api
=
paddle
.
stack
self
.
x
=
[]
for
i
in
range
(
self
.
num_inputs
):
...
...
@@ -61,10 +62,12 @@ class TestStackOpBase(OpTest):
self
.
attrs
=
{
'axis'
:
self
.
axis
}
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
True
)
self
.
check_output
(
check_eager
=
True
,
check_prim
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
(
self
.
get_x_names
(),
'Y'
,
check_eager
=
True
)
self
.
check_grad
(
self
.
get_x_names
(),
'Y'
,
check_eager
=
True
,
check_prim
=
True
)
class
TestStackOp1
(
TestStackOpBase
):
...
...
@@ -100,6 +103,7 @@ class TestStackOp6(TestStackOpBase):
class
TestStackOp_ZeroDim
(
TestStackOpBase
):
def
initParameters
(
self
):
self
.
input_dim
=
()
self
.
enable_cinn
=
False
class
TestStackBF16Op
(
OpTest
):
...
...
@@ -122,6 +126,8 @@ class TestStackBF16Op(OpTest):
self
.
initDefaultParameters
()
self
.
initParameters
()
self
.
op_type
=
'stack'
self
.
prim_op_type
=
"comp"
self
.
enable_cinn
=
False
self
.
python_api
=
paddle
.
stack
self
.
x
=
[]
for
i
in
range
(
self
.
num_inputs
):
...
...
@@ -141,9 +147,10 @@ class TestStackBF16Op(OpTest):
self
.
attrs
=
{
'axis'
:
self
.
axis
}
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
True
)
self
.
check_output
(
check_eager
=
True
,
check_prim
=
True
)
def
test_check_grad
(
self
):
# concat_grad unspport bfloat16 dtype, skip check_prim
self
.
check_grad
(
self
.
get_x_names
(),
'Y'
,
check_eager
=
True
)
...
...
python/paddle/incubate/autograd/composite_rules.py
浏览文件 @
468c17ff
...
...
@@ -192,6 +192,20 @@ def mean_composite(x, axis, keepdim):
return
divide
(
sum_x
,
norm
)
@
REGISTER_COMPOSITE
(
'stack'
)
def
stack_composite
(
x
,
axis
):
"""
define composite rule of op stack
unsqueeze each dimension of the input (use reshape), and then concat
"""
x_shape
=
x
[
0
].
shape
if
axis
<
0
:
axis
+=
len
(
x_shape
)
+
1
out_shape
=
x_shape
[:
axis
]
+
(
1
,)
+
x_shape
[
axis
:]
out
=
concat
([
reshape
(
item
,
out_shape
)
for
item
in
x
],
axis
)
return
out
@
REGISTER_COMPOSITE
(
'flatten_contiguous_range'
)
def
flatten_contiguous_range_composite
(
x
,
start_axis
,
stop_axis
):
"""
...
...
python/paddle/incubate/autograd/primitives.py
浏览文件 @
468c17ff
...
...
@@ -22,6 +22,7 @@ from paddle.tensor import atan # noqa: F401
from
paddle.tensor
import
atanh
# noqa: F401
from
paddle.tensor
import
broadcast_shape
# noqa: F401
from
paddle.tensor
import
broadcast_to
# noqa: F401
from
paddle.tensor
import
concat
# noqa: F401
from
paddle.tensor
import
cos
# noqa: F401
from
paddle.tensor
import
cosh
# noqa: F401
from
paddle.tensor
import
cumprod
# noqa: F401
...
...
@@ -122,6 +123,7 @@ others = [
'fill_constant',
'reshape',
'full',
'concat',
'uniform',
'greater_equal',
]
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
468c17ff
...
...
@@ -1855,7 +1855,14 @@ def stack(x, axis=0, name=None):
check_variable_and_dtype
(
i
,
'x'
,
[
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
[
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
,
'uint16'
,
],
'stack'
,
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录