Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
87d24878
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
87d24878
编写于
6月 06, 2023
作者:
H
houj04
提交者:
GitHub
6月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XPU] support approximate for gelu activation. (#54376)
上级
58fe161f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
18 deletion
+59
-18
cmake/external/xpu.cmake
cmake/external/xpu.cmake
+1
-1
paddle/phi/kernels/xpu/gelu_grad_kernel.cc
paddle/phi/kernels/xpu/gelu_grad_kernel.cc
+23
-9
paddle/phi/kernels/xpu/gelu_kernel.cc
paddle/phi/kernels/xpu/gelu_kernel.cc
+18
-8
test/xpu/test_activation_op_xpu.py
test/xpu/test_activation_op_xpu.py
+13
-0
test/xpu/test_rnn_op_xpu.py
test/xpu/test_rnn_op_xpu.py
+4
-0
未找到文件。
cmake/external/xpu.cmake
浏览文件 @
87d24878
...
...
@@ -8,7 +8,7 @@ set(XPU_API_LIB_NAME "libxpuapi.so")
set
(
XPU_RT_LIB_NAME
"libxpurt.so"
)
set
(
XPU_XFT_LIB_NAME
"libxft.so"
)
set
(
XPU_BASE_DATE
"20230
529
"
)
set
(
XPU_BASE_DATE
"20230
602
"
)
set
(
XPU_XCCL_BASE_VERSION
"1.0.49.2"
)
set
(
XPU_XFT_BASE_VERSION
"latest"
)
...
...
paddle/phi/kernels/xpu/gelu_grad_kernel.cc
浏览文件 @
87d24878
...
...
@@ -28,16 +28,30 @@ void GeluGradKernel(const Context& dev_ctx,
bool
approximate
,
DenseTensor
*
x_grad
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
dev_ctx
.
template
Alloc
<
T
>(
x_grad
);
int
r
=
xpu
::
gelu_grad
<
XPUType
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
x
.
data
<
T
>
()),
nullptr
,
reinterpret_cast
<
const
XPUType
*>
(
out_grad
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
x_grad
->
data
<
T
>
()),
x_grad
->
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"gelu_grad"
);
if
(
approximate
)
{
// int approximate_gelu_grad(Context* ctx, const T* x, const T* y, const T*
// dy, T* dx, int64_t len);
int
r
=
xpu
::
approximate_gelu_grad
<
XPUType
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
x
.
data
<
T
>
()),
nullptr
,
reinterpret_cast
<
const
XPUType
*>
(
out_grad
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
x_grad
->
data
<
T
>
()),
x_grad
->
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"approximate_gelu_grad"
);
}
else
{
// int gelu_grad(Context* ctx, const T* x, const T* y, const T* dy, T* dx,
// int64_t len);
int
r
=
xpu
::
gelu_grad
<
XPUType
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
x
.
data
<
T
>
()),
nullptr
,
reinterpret_cast
<
const
XPUType
*>
(
out_grad
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
x_grad
->
data
<
T
>
()),
x_grad
->
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"gelu_grad"
);
}
}
}
// namespace phi
...
...
paddle/phi/kernels/xpu/gelu_kernel.cc
浏览文件 @
87d24878
...
...
@@ -27,16 +27,26 @@ void GeluKernel(const Context& dev_ctx,
const
DenseTensor
&
x
,
bool
approximate
,
DenseTensor
*
out
)
{
if
(
approximate
)
{
LOG_FIRST_N
(
INFO
,
1
)
<<
"XPU does not support gelu with approximate."
;
}
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
dev_ctx
.
template
Alloc
<
T
>(
out
);
int
r
=
xpu
::
gelu
<
XPUType
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
x
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
out
->
data
<
T
>
()),
out
->
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"gelu"
);
if
(
approximate
)
{
// int approximate_gelu(Context* ctx, const T* x, T* y, int64_t len, const
// float* max_x = nullptr, float* max_y = nullptr);
int
r
=
xpu
::
approximate_gelu
<
XPUType
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
x
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
out
->
data
<
T
>
()),
out
->
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"approximate_gelu"
);
}
else
{
// int gelu(Context* ctx, const T* x, T* y, int64_t len, const float* max_x
// = nullptr, float* max_y = nullptr);
int
r
=
xpu
::
gelu
<
XPUType
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
x
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
out
->
data
<
T
>
()),
out
->
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"gelu"
);
}
}
}
// namespace phi
...
...
test/xpu/test_activation_op_xpu.py
浏览文件 @
87d24878
...
...
@@ -377,6 +377,19 @@ class XPUTestGeluOP(XPUOpTestWrapper):
self
.
outputs
=
{
'Out'
:
out
}
self
.
attrs
=
{
"approximate"
:
approximate
,
'use_xpu'
:
True
}
class
XPUTestGeluApproximate
(
TestActivationOPBase
):
def
set_case
(
self
):
self
.
op_type
=
"gelu"
self
.
dtype
=
self
.
in_type
approximate
=
True
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
self
.
dtype
)
out
=
gelu
(
x
,
approximate
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
out
}
self
.
attrs
=
{
"approximate"
:
approximate
,
'use_xpu'
:
True
}
support_types
=
get_xpu_op_support_types
(
'gelu'
)
for
stype
in
support_types
:
...
...
test/xpu/test_rnn_op_xpu.py
浏览文件 @
87d24878
...
...
@@ -11,9 +11,13 @@
# limitations under the License.
import
random
import
sys
import
unittest
import
numpy
as
np
sys
.
path
.
append
(
'../rnn'
)
from
convert
import
get_params_for_net
from
get_test_cover_info
import
(
XPUOpTestWrapper
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录