Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
90cb9a0d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
90cb9a0d
编写于
3月 20, 2023
作者:
2
201716010711
提交者:
GitHub
3月 20, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[AMP OP&Test] Norm bf16 (#51083)
上级
4c9e34dc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
10 deletion
+42
-10
paddle/phi/kernels/gpu/norm_grad_kernel.cu
paddle/phi/kernels/gpu/norm_grad_kernel.cu
+2
-1
paddle/phi/kernels/gpu/norm_kernel.cu
paddle/phi/kernels/gpu/norm_kernel.cu
+5
-5
python/paddle/fluid/tests/unittests/test_norm_op.py
python/paddle/fluid/tests/unittests/test_norm_op.py
+33
-0
python/paddle/fluid/tests/unittests/test_scale_op.py
python/paddle/fluid/tests/unittests/test_scale_op.py
+2
-4
未找到文件。
paddle/phi/kernels/gpu/norm_grad_kernel.cu
浏览文件 @
90cb9a0d
...
...
@@ -116,4 +116,5 @@ PD_REGISTER_KERNEL(norm_grad,
phi
::
NormGradKernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{}
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{}
paddle/phi/kernels/gpu/norm_kernel.cu
浏览文件 @
90cb9a0d
...
...
@@ -43,7 +43,7 @@ __global__ void Normalize(const T* x,
const
int
pre
,
const
int
axis_n
,
// dim in axis
const
int
post
,
const
T
eps
,
const
float
eps
,
T
*
y
,
T
*
out_norm
)
{
using
MT
=
typename
phi
::
dtype
::
MPTypeTrait
<
T
>::
Type
;
...
...
@@ -86,7 +86,6 @@ void NormKernel(const Context& ctx,
auto
xdim
=
in_x
->
dims
();
if
(
axis
<
0
)
axis
=
xdim
.
size
()
+
axis
;
T
eps
=
static_cast
<
T
>
(
epsilon
);
DenseTensor
*
out_norm
;
DenseTensor
out_norm_tmp
;
...
...
@@ -117,8 +116,8 @@ void NormKernel(const Context& ctx,
int
max_threads
=
ctx
.
GetMaxPhysicalThreadCount
();
const
int
max_blocks
=
std
::
max
(
max_threads
/
block
,
1
);
int
grid
=
std
::
min
(
max_blocks
,
pre
*
post
);
Normalize
<
T
,
block
>
<<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
x_ptr
,
pre
,
n
,
post
,
eps
,
y
,
norm_ptr
);
Normalize
<
T
,
block
>
<<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
x_ptr
,
pre
,
n
,
post
,
epsilon
,
y
,
norm_ptr
);
}
}
// namespace phi
...
...
@@ -129,4 +128,5 @@ PD_REGISTER_KERNEL(norm,
phi
::
NormKernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{}
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{}
python/paddle/fluid/tests/unittests/test_norm_op.py
浏览文件 @
90cb9a0d
...
...
@@ -16,9 +16,11 @@ import unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
,
skip_check_grad_ci
from
op_test
import
convert_float_to_uint16
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
def
l2_norm
(
x
,
axis
,
epsilon
):
...
...
@@ -157,6 +159,37 @@ class TestNormTestOp(OpTest):
self
.
epsilon
=
1e-8
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
(),
"core is not compiled with CUDA and not support the bfloat16"
,
)
class
TestNormBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"norm"
self
.
python_api
=
norm_wrapper
self
.
init_test_case
()
self
.
dtype
=
"float32"
x
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
y
,
norm
=
l2_norm
(
x
,
self
.
axis
,
self
.
epsilon
)
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
x
)}
self
.
attrs
=
{
'epsilon'
:
self
.
epsilon
,
'axis'
:
self
.
axis
}
self
.
outputs
=
{
'Out'
:
convert_float_to_uint16
(
y
),
'Norm'
:
norm
}
self
.
python_out_sig
=
[
'Out'
]
def
test_check_output
(
self
):
self
.
check_output_with_place
(
core
.
CUDAPlace
(
0
),
atol
=
1e-1
)
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
core
.
CUDAPlace
(
0
),
[
'X'
],
'Out'
,
max_relative_error
=
1e-2
)
def
init_test_case
(
self
):
self
.
shape
=
[
2
,
3
,
4
,
5
]
self
.
axis
=
1
self
.
epsilon
=
1e-8
class
API_NormTest
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
fluid
.
program_guard
(
fluid
.
Program
()):
...
...
python/paddle/fluid/tests/unittests/test_scale_op.py
浏览文件 @
90cb9a0d
...
...
@@ -148,12 +148,10 @@ class TestScaleFp16Op(TestScaleOp):
self
.
dtype
=
np
.
float16
def
test_check_output
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_output_with_place
(
place
,
check_eager
=
True
)
self
.
check_output
(
check_eager
=
True
)
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
"X"
],
"Out"
,
check_eager
=
True
)
self
.
check_grad
([
"X"
],
"Out"
,
check_eager
=
True
)
class
TestScaleBF16Op
(
OpTest
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录