Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
61ec75c5
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看板
未验证
提交
61ec75c5
编写于
4年前
作者:
C
chengjuntao
提交者:
GitHub
4年前
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
register fp16 for assign OP, test=release/1.7 (#22842)
上级
26d45137
release/1.7
v1.7.2
v1.7.1
无相关合并请求
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
11 deletion
+24
-11
paddle/fluid/operators/assign_op.cc
paddle/fluid/operators/assign_op.cc
+3
-0
python/paddle/fluid/tests/unittests/test_assign_op.py
python/paddle/fluid/tests/unittests/test_assign_op.py
+21
-11
未找到文件。
paddle/fluid/operators/assign_op.cc
浏览文件 @
61ec75c5
...
@@ -114,6 +114,7 @@ DECLARE_INPLACE_OP_INFERER(AssignOpInplaceInferer, {"X", "Out"});
...
@@ -114,6 +114,7 @@ DECLARE_INPLACE_OP_INFERER(AssignOpInplaceInferer, {"X", "Out"});
}
// namespace paddle
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OPERATOR
(
assign
,
ops
::
AssignOp
,
REGISTER_OPERATOR
(
assign
,
ops
::
AssignOp
,
ops
::
AssignGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
AssignGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
AssignGradMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
AssignGradMaker
<
paddle
::
imperative
::
OpBase
>
,
...
@@ -122,11 +123,13 @@ REGISTER_OPERATOR(assign, ops::AssignOp,
...
@@ -122,11 +123,13 @@ REGISTER_OPERATOR(assign, ops::AssignOp,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
assign
,
float
,
ops
::
AssignKernel
,
double
,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
assign
,
float
,
ops
::
AssignKernel
,
double
,
ops
::
AssignKernel
,
int
,
ops
::
AssignKernel
,
ops
::
AssignKernel
,
int
,
ops
::
AssignKernel
,
int64_t
,
ops
::
AssignKernel
,
bool
,
int64_t
,
ops
::
AssignKernel
,
bool
,
ops
::
AssignKernel
,
plat
::
float16
,
ops
::
AssignKernel
);
ops
::
AssignKernel
);
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
assign
,
float
,
ops
::
AssignKernel
,
double
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
assign
,
float
,
ops
::
AssignKernel
,
double
,
ops
::
AssignKernel
,
int
,
ops
::
AssignKernel
,
ops
::
AssignKernel
,
int
,
ops
::
AssignKernel
,
int64_t
,
ops
::
AssignKernel
,
bool
,
int64_t
,
ops
::
AssignKernel
,
bool
,
ops
::
AssignKernel
,
plat
::
float16
,
ops
::
AssignKernel
);
ops
::
AssignKernel
);
#endif
#endif
This diff is collapsed.
Click to expand it.
python/paddle/fluid/tests/unittests/test_assign_op.py
浏览文件 @
61ec75c5
...
@@ -37,6 +37,20 @@ class TestAssignOp(op_test.OpTest):
...
@@ -37,6 +37,20 @@ class TestAssignOp(op_test.OpTest):
self
.
check_grad
([
'X'
],
'Out'
)
self
.
check_grad
([
'X'
],
'Out'
)
class
TestAssignFP16Op
(
op_test
.
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"assign"
x
=
np
.
random
.
random
(
size
=
(
100
,
10
)).
astype
(
'float16'
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
x
}
def
test_forward
(
self
):
self
.
check_output
()
def
test_backward
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
class
TestAssignOpError
(
unittest
.
TestCase
):
class
TestAssignOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
...
@@ -44,22 +58,18 @@ class TestAssignOpError(unittest.TestCase):
...
@@ -44,22 +58,18 @@ class TestAssignOpError(unittest.TestCase):
x1
=
fluid
.
create_lod_tensor
(
x1
=
fluid
.
create_lod_tensor
(
np
.
array
([[
-
1
]]),
[[
1
]],
fluid
.
CPUPlace
())
np
.
array
([[
-
1
]]),
[[
1
]],
fluid
.
CPUPlace
())
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x1
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x1
)
# When the type of input is Variable, the dtype of input must be float32, float64, int32, int64, bool.
# When the type of input is Variable, the dtype of input must be float
16, float
32, float64, int32, int64, bool.
x3
=
fluid
.
layers
.
data
(
name
=
'x3'
,
shape
=
[
4
],
dtype
=
"
float16
"
)
x3
=
fluid
.
layers
.
data
(
name
=
'x3'
,
shape
=
[
4
],
dtype
=
"
uint8
"
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x3
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x3
)
x4
=
fluid
.
layers
.
data
(
name
=
'x4'
,
shape
=
[
4
],
dtype
=
"uint8"
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x4
)
# When the type of input is numpy.ndarray, the dtype of input must be float32, int32.
# When the type of input is numpy.ndarray, the dtype of input must be float32, int32.
x5
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'bool'
)
x4
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'bool'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x4
)
x5
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'float64'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x5
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x5
)
x6
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'
float16
'
)
x6
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'
int64
'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x6
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x6
)
x7
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'
float64
'
)
x7
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'
uint8
'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x7
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x7
)
x8
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'int64'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x8
)
x9
=
np
.
array
([[
2.5
,
2.5
]],
dtype
=
'uint8'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
assign
,
x9
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
反馈
建议
客服
返回
顶部