Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
1e6047f1
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看板
未验证
提交
1e6047f1
编写于
2月 11, 2022
作者:
Z
zhangbo9674
提交者:
GitHub
2月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bf16] add bf16 kernel: transpose & unbind (#39457)
* add transpose unbind * add unittest * refine transpose unittest
上级
89aa8b1a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
87 addition
and
8 deletion
+87
-8
paddle/fluid/operators/transpose_op.cc
paddle/fluid/operators/transpose_op.cc
+12
-4
paddle/fluid/operators/transpose_op.cu
paddle/fluid/operators/transpose_op.cu
+9
-0
paddle/fluid/operators/unbind_op.cc
paddle/fluid/operators/unbind_op.cc
+2
-1
paddle/fluid/operators/unbind_op.cu.cc
paddle/fluid/operators/unbind_op.cu.cc
+2
-1
python/paddle/fluid/tests/unittests/test_transpose_op.py
python/paddle/fluid/tests/unittests/test_transpose_op.py
+35
-1
python/paddle/fluid/tests/unittests/test_unbind_op.py
python/paddle/fluid/tests/unittests/test_unbind_op.py
+27
-1
未找到文件。
paddle/fluid/operators/transpose_op.cc
浏览文件 @
1e6047f1
...
...
@@ -356,7 +356,9 @@ REGISTER_OP_CPU_KERNEL(
ops
::
TransposeKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
double
>>
);
paddle
::
platform
::
complex
<
double
>>
,
ops
::
TransposeKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
bfloat16
>
);
REGISTER_OP_CPU_KERNEL
(
transpose_grad
,
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
...
...
@@ -365,7 +367,9 @@ REGISTER_OP_CPU_KERNEL(
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
double
>>
);
paddle
::
platform
::
complex
<
double
>>
,
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
bfloat16
>
);
REGISTER_OPERATOR
(
transpose2
,
ops
::
Transpose2Op
,
ops
::
Transpose2OpMaker
,
ops
::
Transpose2GradMaker
<
paddle
::
framework
::
OpDesc
>
,
...
...
@@ -383,7 +387,9 @@ REGISTER_OP_CPU_KERNEL(
ops
::
TransposeKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
double
>>
);
paddle
::
platform
::
complex
<
double
>>
,
ops
::
TransposeKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
bfloat16
>
);
REGISTER_OP_CPU_KERNEL
(
transpose2_grad
,
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
...
...
@@ -394,4 +400,6 @@ REGISTER_OP_CPU_KERNEL(
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
double
>>
);
paddle
::
platform
::
complex
<
double
>>
,
ops
::
TransposeGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
bfloat16
>
);
paddle/fluid/operators/transpose_op.cu
浏览文件 @
1e6047f1
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/fluid/operators/transpose_op.cu.h"
#include "paddle/fluid/operators/transpose_op.h"
#include "paddle/fluid/platform/bfloat16.h"
#include "paddle/fluid/platform/float16.h"
namespace
paddle
{
...
...
@@ -87,6 +88,8 @@ REGISTER_OP_CUDA_KERNEL(
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
float16
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
bfloat16
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
...
...
@@ -98,6 +101,8 @@ REGISTER_OP_CUDA_KERNEL(
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
float16
>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
bfloat16
>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
...
...
@@ -111,6 +116,8 @@ REGISTER_OP_CUDA_KERNEL(
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
float16
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
bfloat16
>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
...
...
@@ -124,6 +131,8 @@ REGISTER_OP_CUDA_KERNEL(
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
float16
>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
bfloat16
>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
TransposeGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
...
...
paddle/fluid/operators/unbind_op.cc
浏览文件 @
1e6047f1
...
...
@@ -85,4 +85,5 @@ REGISTER_OP_CPU_KERNEL(
ops
::
UnbindOpKernel
<
plat
::
CPUDeviceContext
,
float
>
,
ops
::
UnbindOpKernel
<
plat
::
CPUDeviceContext
,
int64_t
>
,
ops
::
UnbindOpKernel
<
plat
::
CPUDeviceContext
,
int
>
,
ops
::
UnbindOpKernel
<
plat
::
CPUDeviceContext
,
plat
::
float16
>
);
ops
::
UnbindOpKernel
<
plat
::
CPUDeviceContext
,
plat
::
float16
>
,
ops
::
UnbindOpKernel
<
plat
::
CPUDeviceContext
,
plat
::
bfloat16
>
);
paddle/fluid/operators/unbind_op.cu.cc
浏览文件 @
1e6047f1
...
...
@@ -20,4 +20,5 @@ REGISTER_OP_CUDA_KERNEL(
ops
::
UnbindOpKernel
<
plat
::
CUDADeviceContext
,
float
>
,
ops
::
UnbindOpKernel
<
plat
::
CUDADeviceContext
,
int64_t
>
,
ops
::
UnbindOpKernel
<
plat
::
CUDADeviceContext
,
int
>
,
ops
::
UnbindOpKernel
<
plat
::
CUDADeviceContext
,
plat
::
float16
>
);
ops
::
UnbindOpKernel
<
plat
::
CUDADeviceContext
,
plat
::
float16
>
,
ops
::
UnbindOpKernel
<
plat
::
CUDADeviceContext
,
plat
::
bfloat16
>
);
python/paddle/fluid/tests/unittests/test_transpose_op.py
浏览文件 @
1e6047f1
...
...
@@ -16,10 +16,11 @@ from __future__ import print_function
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
from
op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid
import
Program
,
program_guard
import
paddle.fluid.core
as
core
paddle
.
enable_static
()
...
...
@@ -113,6 +114,39 @@ class TestCase9(TestTransposeOp):
self
.
axis
=
(
6
,
1
,
3
,
5
,
0
,
2
,
4
,
7
)
class
TestTransposeBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
init_op_type
()
self
.
initTestCase
()
self
.
dtype
=
np
.
uint16
x
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
x
)}
self
.
attrs
=
{
'axis'
:
list
(
self
.
axis
),
'use_mkldnn'
:
self
.
use_mkldnn
,
}
self
.
outputs
=
{
'XShape'
:
convert_float_to_uint16
(
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)),
'Out'
:
self
.
inputs
[
'X'
].
transpose
(
self
.
axis
)
}
def
init_op_type
(
self
):
self
.
op_type
=
"transpose2"
self
.
use_mkldnn
=
False
def
test_check_output
(
self
):
self
.
check_output
(
no_check_set
=
[
'XShape'
])
def
test_check_grad
(
self
):
pass
def
initTestCase
(
self
):
self
.
shape
=
(
3
,
2
)
self
.
axis
=
(
1
,
0
)
class
TestTransposeOpBool
(
TestTransposeOp
):
def
test_check_grad
(
self
):
pass
...
...
python/paddle/fluid/tests/unittests/test_unbind_op.py
浏览文件 @
1e6047f1
...
...
@@ -16,7 +16,7 @@ from __future__ import print_function
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
from
op_test
import
OpTest
,
convert_float_to_uint16
import
paddle.fluid
as
fluid
import
paddle.tensor
as
tensor
from
paddle.fluid
import
compiler
,
Program
,
program_guard
,
core
...
...
@@ -154,6 +154,32 @@ class TestUnbindOp4(TestUnbindOp):
self
.
out
[
1
]
=
self
.
out
[
1
].
reshape
((
3
,
2
))
class
TestUnbindBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
_set_op_type
()
self
.
dtype
=
self
.
get_dtype
()
self
.
axis
=
0
self
.
num
=
3
x
=
np
.
arange
(
12
).
reshape
(
3
,
2
,
2
).
astype
(
self
.
dtype
)
self
.
out
=
np
.
split
(
x
,
self
.
num
,
self
.
axis
)
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
x
)}
self
.
attrs
=
{
'axis'
:
self
.
axis
}
self
.
outputs
=
{
'Out'
:
[(
'out%d'
%
i
,
convert_float_to_uint16
(
self
.
out
[
i
]))
\
for
i
in
range
(
len
(
self
.
out
))]}
def
get_dtype
(
self
):
return
np
.
uint16
def
_set_op_type
(
self
):
self
.
op_type
=
"unbind"
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
pass
class
TestUnbindAxisError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录