Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
df7cc457
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看板
未验证
提交
df7cc457
编写于
11月 15, 2021
作者:
A
arlesniak
提交者:
GitHub
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added BF16 to mean op (#37104)
* Added BF16 to mean op * fix for CI * fix for CI * fix for CI
上级
83eef6d2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
4 deletion
+36
-4
paddle/fluid/operators/mean_op.cc
paddle/fluid/operators/mean_op.cc
+6
-2
paddle/pten/kernels/cpu/math.cc
paddle/pten/kernels/cpu/math.cc
+2
-1
python/paddle/fluid/tests/book/test_fit_a_line.py
python/paddle/fluid/tests/book/test_fit_a_line.py
+13
-0
python/paddle/fluid/tests/unittests/test_mean_op.py
python/paddle/fluid/tests/unittests/test_mean_op.py
+15
-1
未找到文件。
paddle/fluid/operators/mean_op.cc
浏览文件 @
df7cc457
...
@@ -96,7 +96,11 @@ REGISTER_OPERATOR(mean_grad, ops::MeanGradOp,
...
@@ -96,7 +96,11 @@ REGISTER_OPERATOR(mean_grad, ops::MeanGradOp,
ops
::
MeanGradNoNeedBufferVarsInferer
);
ops
::
MeanGradNoNeedBufferVarsInferer
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
mean
,
ops
::
MeanKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
mean
,
ops
::
MeanKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
MeanKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
);
ops
::
MeanKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
ops
::
MeanKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
bfloat16
>
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
mean_grad
,
ops
::
MeanGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
mean_grad
,
ops
::
MeanGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
MeanGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
);
ops
::
MeanGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
ops
::
MeanGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
bfloat16
>
);
paddle/pten/kernels/cpu/math.cc
浏览文件 @
df7cc457
...
@@ -97,7 +97,8 @@ using complex128 = ::paddle::platform::complex<double>;
...
@@ -97,7 +97,8 @@ using complex128 = ::paddle::platform::complex<double>;
// using bfloat16 = ::paddle::platform::bfloat16;
// using bfloat16 = ::paddle::platform::bfloat16;
PT_REGISTER_KERNEL
(
"sign"
,
CPU
,
ANY
,
pten
::
Sign
,
float
,
double
)
{}
PT_REGISTER_KERNEL
(
"sign"
,
CPU
,
ANY
,
pten
::
Sign
,
float
,
double
)
{}
PT_REGISTER_KERNEL
(
"mean"
,
CPU
,
ANY
,
pten
::
Mean
,
float
,
double
)
{}
PT_REGISTER_KERNEL
(
"mean"
,
CPU
,
ANY
,
pten
::
Mean
,
float
,
double
,
paddle
::
platform
::
bfloat16
)
{}
PT_REGISTER_KERNEL
(
"scale"
,
PT_REGISTER_KERNEL
(
"scale"
,
CPU
,
CPU
,
ANY
,
ANY
,
...
...
python/paddle/fluid/tests/book/test_fit_a_line.py
浏览文件 @
df7cc457
...
@@ -24,10 +24,19 @@ import unittest
...
@@ -24,10 +24,19 @@ import unittest
import
math
import
math
import
sys
import
sys
import
os
import
os
import
struct
paddle
.
enable_static
()
paddle
.
enable_static
()
def
convert_uint16_to_float
(
in_list
):
in_list
=
numpy
.
asarray
(
in_list
)
out
=
numpy
.
vectorize
(
lambda
x
:
struct
.
unpack
(
'<f'
,
struct
.
pack
(
'<I'
,
x
<<
16
))[
0
],
otypes
=
[
numpy
.
float32
])(
in_list
.
flat
)
return
numpy
.
reshape
(
out
,
in_list
.
shape
)
def
train
(
use_cuda
,
save_dirname
,
is_local
,
use_bf16
,
pure_bf16
):
def
train
(
use_cuda
,
save_dirname
,
is_local
,
use_bf16
,
pure_bf16
):
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
13
],
dtype
=
'float32'
)
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
13
],
dtype
=
'float32'
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
1
],
dtype
=
'float32'
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
1
],
dtype
=
'float32'
)
...
@@ -84,6 +93,8 @@ def train(use_cuda, save_dirname, is_local, use_bf16, pure_bf16):
...
@@ -84,6 +93,8 @@ def train(use_cuda, save_dirname, is_local, use_bf16, pure_bf16):
avg_loss_value
,
=
exe
.
run
(
main_program
,
avg_loss_value
,
=
exe
.
run
(
main_program
,
feed
=
feeder
.
feed
(
data
),
feed
=
feeder
.
feed
(
data
),
fetch_list
=
[
avg_cost
])
fetch_list
=
[
avg_cost
])
if
avg_loss_value
.
dtype
==
numpy
.
uint16
:
avg_loss_value
=
convert_uint16_to_float
(
avg_loss_value
)
if
avg_loss_value
[
0
]
<
10.0
:
if
avg_loss_value
[
0
]
<
10.0
:
if
save_dirname
is
not
None
:
if
save_dirname
is
not
None
:
paddle
.
static
.
save_inference_model
(
paddle
.
static
.
save_inference_model
(
...
@@ -154,6 +165,8 @@ def infer(use_cuda, save_dirname=None, use_bf16=False):
...
@@ -154,6 +165,8 @@ def infer(use_cuda, save_dirname=None, use_bf16=False):
results
=
exe
.
run
(
inference_program
,
results
=
exe
.
run
(
inference_program
,
feed
=
{
feed_target_names
[
0
]:
numpy
.
array
(
test_feat
)},
feed
=
{
feed_target_names
[
0
]:
numpy
.
array
(
test_feat
)},
fetch_list
=
fetch_targets
)
fetch_list
=
fetch_targets
)
if
results
[
0
].
dtype
==
numpy
.
uint16
:
results
[
0
]
=
convert_uint16_to_float
(
results
[
0
])
print
(
"infer shape: "
,
results
[
0
].
shape
)
print
(
"infer shape: "
,
results
[
0
].
shape
)
print
(
"infer results: "
,
results
[
0
])
print
(
"infer results: "
,
results
[
0
])
print
(
"ground truth: "
,
test_label
)
print
(
"ground truth: "
,
test_label
)
...
...
python/paddle/fluid/tests/unittests/test_mean_op.py
浏览文件 @
df7cc457
...
@@ -16,7 +16,7 @@ from __future__ import print_function
...
@@ -16,7 +16,7 @@ from __future__ import print_function
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
op_test
import
OpTest
from
op_test
import
OpTest
,
OpTestTool
import
paddle
import
paddle
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
...
@@ -76,6 +76,20 @@ class TestFP16MeanOp(TestMeanOp):
...
@@ -76,6 +76,20 @@ class TestFP16MeanOp(TestMeanOp):
place
,
[
'X'
],
'Out'
,
max_relative_error
=
0.8
)
place
,
[
'X'
],
'Out'
,
max_relative_error
=
0.8
)
@
OpTestTool
.
skip_if_not_cpu_bf16
()
class
TestBF16MeanOp
(
TestMeanOp
):
def
init_dtype_type
(
self
):
self
.
dtype
=
np
.
uint16
def
test_check_output
(
self
):
paddle
.
enable_static
()
self
.
check_output_with_place
(
core
.
CPUPlace
())
def
test_checkout_grad
(
self
):
place
=
core
.
CPUPlace
()
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
)
def
ref_reduce_mean
(
x
,
axis
=
None
,
keepdim
=
False
,
reduce_all
=
False
):
def
ref_reduce_mean
(
x
,
axis
=
None
,
keepdim
=
False
,
reduce_all
=
False
):
if
isinstance
(
axis
,
list
):
if
isinstance
(
axis
,
list
):
axis
=
tuple
(
axis
)
axis
=
tuple
(
axis
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录