Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
3f5705c3
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3f5705c3
编写于
3月 16, 2018
作者:
K
Kexin Zhao
提交者:
GitHub
3月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9148 from kexinzhao/cast_op_fp16
Add float16 support for cast op
上级
02b3cfb1
6ef4f1f8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
3 deletion
+38
-3
paddle/fluid/operators/cast_op.cc
paddle/fluid/operators/cast_op.cc
+3
-1
paddle/fluid/operators/cast_op.cu
paddle/fluid/operators/cast_op.cu
+3
-1
python/paddle/fluid/tests/unittests/test_cast_op.py
python/paddle/fluid/tests/unittests/test_cast_op.py
+32
-1
未找到文件。
paddle/fluid/operators/cast_op.cc
浏览文件 @
3f5705c3
...
@@ -14,6 +14,7 @@ limitations under the License. */
...
@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/fluid/operators/cast_op.h"
#include "paddle/fluid/operators/cast_op.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/platform/float16.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -88,4 +89,5 @@ REGISTER_OP_CPU_KERNEL(cast, ops::CastOpKernel<CPU, float>,
...
@@ -88,4 +89,5 @@ REGISTER_OP_CPU_KERNEL(cast, ops::CastOpKernel<CPU, float>,
ops
::
CastOpKernel
<
CPU
,
double
>
,
ops
::
CastOpKernel
<
CPU
,
double
>
,
ops
::
CastOpKernel
<
CPU
,
int
>
,
ops
::
CastOpKernel
<
CPU
,
int
>
,
ops
::
CastOpKernel
<
CPU
,
int64_t
>
,
ops
::
CastOpKernel
<
CPU
,
int64_t
>
,
ops
::
CastOpKernel
<
CPU
,
bool
>
);
ops
::
CastOpKernel
<
CPU
,
bool
>
,
ops
::
CastOpKernel
<
CPU
,
paddle
::
platform
::
float16
>
);
paddle/fluid/operators/cast_op.cu
浏览文件 @
3f5705c3
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/fluid/operators/cast_op.h"
#include "paddle/fluid/operators/cast_op.h"
#include "paddle/fluid/platform/float16.h"
template
<
typename
T
>
template
<
typename
T
>
using
CastOpKernel
=
using
CastOpKernel
=
...
@@ -20,4 +21,5 @@ using CastOpKernel =
...
@@ -20,4 +21,5 @@ using CastOpKernel =
REGISTER_OP_CUDA_KERNEL
(
cast
,
CastOpKernel
<
float
>
,
CastOpKernel
<
double
>
,
REGISTER_OP_CUDA_KERNEL
(
cast
,
CastOpKernel
<
float
>
,
CastOpKernel
<
double
>
,
CastOpKernel
<
int
>
,
CastOpKernel
<
int64_t
>
,
CastOpKernel
<
int
>
,
CastOpKernel
<
int64_t
>
,
CastOpKernel
<
bool
>
);
CastOpKernel
<
bool
>
,
CastOpKernel
<
paddle
::
platform
::
float16
>
);
python/paddle/fluid/tests/unittests/test_cast_op.py
浏览文件 @
3f5705c3
...
@@ -18,7 +18,7 @@ import numpy as np
...
@@ -18,7 +18,7 @@ import numpy as np
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
class
TestCastOp
(
op_test
.
OpTest
):
class
TestCastOp
1
(
op_test
.
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
ipt
=
np
.
random
.
random
(
size
=
[
10
,
10
])
ipt
=
np
.
random
.
random
(
size
=
[
10
,
10
])
self
.
inputs
=
{
'X'
:
ipt
.
astype
(
'float32'
)}
self
.
inputs
=
{
'X'
:
ipt
.
astype
(
'float32'
)}
...
@@ -36,5 +36,36 @@ class TestCastOp(op_test.OpTest):
...
@@ -36,5 +36,36 @@ class TestCastOp(op_test.OpTest):
self
.
check_grad
([
'X'
],
[
'Out'
])
self
.
check_grad
([
'X'
],
[
'Out'
])
class
TestCastOp2
(
op_test
.
OpTest
):
def
setUp
(
self
):
ipt
=
np
.
random
.
random
(
size
=
[
10
,
10
])
# numpy float16 is binded to fluid float16 via uint16
self
.
inputs
=
{
'X'
:
ipt
.
astype
(
'float16'
).
view
(
np
.
uint16
)}
self
.
outputs
=
{
'Out'
:
ipt
.
astype
(
'float32'
)}
self
.
attrs
=
{
'in_dtype'
:
int
(
core
.
VarDesc
.
VarType
.
FP16
),
'out_dtype'
:
int
(
core
.
VarDesc
.
VarType
.
FP32
)
}
self
.
op_type
=
'cast'
def
test_check_output
(
self
):
self
.
check_output
(
atol
=
1e-3
)
class
TestCastOp3
(
op_test
.
OpTest
):
def
setUp
(
self
):
ipt
=
np
.
random
.
random
(
size
=
[
10
,
10
])
self
.
inputs
=
{
'X'
:
ipt
.
astype
(
'float32'
)}
self
.
outputs
=
{
'Out'
:
ipt
.
astype
(
'float16'
)}
self
.
attrs
=
{
'in_dtype'
:
int
(
core
.
VarDesc
.
VarType
.
FP32
),
'out_dtype'
:
int
(
core
.
VarDesc
.
VarType
.
FP16
)
}
self
.
op_type
=
'cast'
def
test_check_output
(
self
):
self
.
check_output
(
atol
=
1e-3
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录