Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
5bcabf78
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看板
未验证
提交
5bcabf78
编写于
8月 16, 2022
作者:
H
houj04
提交者:
GitHub
8月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XPU] add truncated_gaussian_random op. (#45152)
上级
e2b924bf
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
90 addition
and
9 deletion
+90
-9
paddle/fluid/platform/device/xpu/xpu2_op_list.h
paddle/fluid/platform/device/xpu/xpu2_op_list.h
+2
-0
python/paddle/fluid/tests/unittests/xpu/test_truncated_gaussian_random_op_xpu.py
...ts/unittests/xpu/test_truncated_gaussian_random_op_xpu.py
+88
-9
未找到文件。
paddle/fluid/platform/device/xpu/xpu2_op_list.h
浏览文件 @
5bcabf78
...
@@ -558,6 +558,8 @@ XPUOpMap& get_kl2_ops() {
...
@@ -558,6 +558,8 @@ XPUOpMap& get_kl2_ops() {
{
"transpose"
,
{
"transpose"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
())})},
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
())})},
{
"truncated_gaussian_random"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
())})},
{
"top_k"
,
{
"top_k"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
())})},
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
())})},
...
...
python/paddle/fluid/tests/unittests/xpu/test_truncated_gaussian_random_op_xpu.py
浏览文件 @
5bcabf78
# Copyright (c) 202
0
PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 202
2
PaddlePaddle Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
...
@@ -18,24 +18,103 @@ import sys
...
@@ -18,24 +18,103 @@ import sys
sys
.
path
.
append
(
".."
)
sys
.
path
.
append
(
".."
)
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.op
import
Operator
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.executor
import
Executor
from
test_truncated_gaussian_random_op
import
TestTrunctedGaussianRandomOp
from
op_test_xpu
import
XPUOpTest
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
,
XPUOpTestWrapper
paddle
.
enable_static
()
paddle
.
enable_static
()
class
TestXPUTrunctedGaussianRandomOp
(
TestTrunctedGaussianRandomOp
):
class
XPUTestTruncatedGaussianRandomOp
(
XPUOpTestWrapper
):
def
__init__
(
self
):
self
.
op_name
=
'truncated_gaussian_random'
self
.
use_dynamic_create_class
=
False
class
TestTruncatedGaussianRandomOp
(
XPUOpTest
):
def
init
(
self
):
self
.
dtype
=
self
.
in_type
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
__class__
.
op_type
=
"truncated_gaussian_random"
def
setUp
(
self
):
self
.
init
()
self
.
inputs
=
{}
self
.
set_attrs
()
self
.
attrs
=
{
"shape"
:
self
.
shape
,
"mean"
:
self
.
mean
,
"std"
:
self
.
std
,
"seed"
:
10
,
}
self
.
outputs
=
{
'Out'
:
np
.
zeros
(
self
.
shape
,
dtype
=
self
.
dtype
)}
def
test_xpu
(
self
):
def
set_attrs
(
self
):
if
paddle
.
is_compiled_with_xpu
():
self
.
shape
=
[
10000
]
self
.
mean
=
0.0
self
.
std
=
1.0
def
test_check_output
(
self
):
self
.
gaussian_random_test
(
place
=
fluid
.
XPUPlace
(
0
))
self
.
gaussian_random_test
(
place
=
fluid
.
XPUPlace
(
0
))
def
gaussian_random_test
(
self
,
place
):
program
=
fluid
.
Program
()
block
=
program
.
global_block
()
vout
=
block
.
create_var
(
name
=
"Out"
)
op
=
block
.
append_op
(
type
=
self
.
op_type
,
outputs
=
{
"Out"
:
vout
},
attrs
=
self
.
attrs
)
op
.
desc
.
infer_var_type
(
block
.
desc
)
op
.
desc
.
infer_shape
(
block
.
desc
)
fetch_list
=
[]
for
var_name
in
self
.
outputs
:
fetch_list
.
append
(
block
.
var
(
var_name
))
exe
=
Executor
(
place
)
outs
=
exe
.
run
(
program
,
fetch_list
=
fetch_list
)
tensor
=
outs
[
0
]
np
.
testing
.
assert_allclose
(
np
.
mean
(
tensor
),
self
.
mean
,
atol
=
0.05
)
np
.
testing
.
assert_allclose
(
np
.
var
(
tensor
),
0.773
,
atol
=
0.05
)
class
TestTruncatedGaussianRandomOp_1
(
TestTruncatedGaussianRandomOp
):
def
set_attrs
(
self
):
self
.
shape
=
[
4096
,
2
]
self
.
mean
=
5.0
self
.
std
=
1.0
class
TestTruncatedGaussianRandomOp_2
(
TestTruncatedGaussianRandomOp
):
def
set_attrs
(
self
):
self
.
shape
=
[
1024
]
self
.
mean
=
-
2.0
self
.
std
=
1.0
class
TestTruncatedGaussianRandomOp_3
(
TestTruncatedGaussianRandomOp
):
def
set_attrs
(
self
):
self
.
shape
=
[
11
*
13
*
17
]
self
.
mean
=
-
1.0
self
.
std
=
1.0
class
TestTruncatedGaussianRandomOp_4
(
TestTruncatedGaussianRandomOp
):
def
set_attrs
(
self
):
self
.
shape
=
[
2049
]
self
.
mean
=
5.1234
self
.
std
=
1.0
support_types
=
get_xpu_op_support_types
(
'truncated_gaussian_random'
)
for
stype
in
support_types
:
create_test_class
(
globals
(),
XPUTestTruncatedGaussianRandomOp
,
stype
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录