Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
02f66747
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
02f66747
编写于
3月 05, 2023
作者:
2
201716010711
提交者:
GitHub
3月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[AMP OP&Test] Fix scale kernel and perfect unit test (#50998)
上级
ad92a5c1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
12 addition
and
14 deletion
+12
-14
paddle/phi/kernels/gpu/scale_kernel.cu
paddle/phi/kernels/gpu/scale_kernel.cu
+10
-8
python/paddle/fluid/tests/unittests/test_scale_op.py
python/paddle/fluid/tests/unittests/test_scale_op.py
+2
-6
未找到文件。
paddle/phi/kernels/gpu/scale_kernel.cu
浏览文件 @
02f66747
...
...
@@ -21,22 +21,22 @@ limitations under the License. */
namespace
phi
{
template
<
typename
In
T
>
template
<
typename
DataT
,
typename
Param
T
>
struct
ScaleFunctor
{
In
T
bias
;
In
T
scale
;
Param
T
bias
;
Param
T
scale
;
bool
bias_after_scale
;
ScaleFunctor
(
InT
scale_data
,
In
T
bias_data
,
bool
is_bias_after_sacle
)
ScaleFunctor
(
ParamT
scale_data
,
Param
T
bias_data
,
bool
is_bias_after_sacle
)
:
bias
(
bias_data
),
scale
(
scale_data
),
bias_after_scale
(
is_bias_after_sacle
)
{}
__device__
__forceinline__
InT
operator
()(
const
In
T
x
)
const
{
__device__
__forceinline__
DataT
operator
()(
const
Data
T
x
)
const
{
if
(
bias_after_scale
)
{
return
s
cale
*
x
+
bias
;
return
s
tatic_cast
<
DataT
>
(
scale
*
static_cast
<
ParamT
>
(
x
)
+
bias
)
;
}
else
{
return
s
cale
*
(
x
+
bias
);
return
s
tatic_cast
<
DataT
>
(
scale
*
(
static_cast
<
ParamT
>
(
x
)
+
bias
)
);
}
}
};
...
...
@@ -48,6 +48,7 @@ void ScaleKernel(const Context& dev_ctx,
float
bias
,
bool
bias_after_scale
,
DenseTensor
*
out
)
{
using
MT
=
typename
phi
::
dtype
::
MPTypeTrait
<
T
>::
Type
;
std
::
vector
<
const
DenseTensor
*>
inputs
;
std
::
vector
<
DenseTensor
*>
outputs
;
inputs
.
emplace_back
(
&
x
);
...
...
@@ -60,7 +61,8 @@ void ScaleKernel(const Context& dev_ctx,
dev_ctx
,
inputs
,
&
outputs
,
ScaleFunctor
<
T
>
(
scale
.
to
<
T
>
(),
static_cast
<
T
>
(
bias
),
bias_after_scale
));
ScaleFunctor
<
T
,
MT
>
(
scale
.
to
<
MT
>
(),
static_cast
<
MT
>
(
bias
),
bias_after_scale
));
}
}
// namespace phi
...
...
python/paddle/fluid/tests/unittests/test_scale_op.py
浏览文件 @
02f66747
...
...
@@ -149,15 +149,11 @@ class TestScaleFp16Op(TestScaleOp):
def
test_check_output
(
self
):
place
=
core
.
CUDAPlace
(
0
)
if
core
.
is_float16_supported
(
place
):
self
.
check_output_with_place
(
place
,
atol
=
0.002
,
check_eager
=
True
)
self
.
check_output_with_place
(
place
,
check_eager
=
True
)
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
if
core
.
is_float16_supported
(
place
):
self
.
check_grad_with_place
(
place
,
[
"X"
],
"Out"
,
max_relative_error
=
0.05
,
check_eager
=
True
)
self
.
check_grad_with_place
(
place
,
[
"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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录