Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
613a3ffe
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2310
Star
20933
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
613a3ffe
编写于
2月 22, 2023
作者:
H
houj04
提交者:
GitHub
2月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XPU] add fp16 support for assign. update xccl to 1.0.9. (#50702)
上级
d8845735
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
66 deletion
+72
-66
cmake/external/xpu.cmake
cmake/external/xpu.cmake
+1
-1
paddle/phi/backends/xpu/xpu2_op_list.cc
paddle/phi/backends/xpu/xpu2_op_list.cc
+1
-0
paddle/phi/kernels/assign_kernel.cc
paddle/phi/kernels/assign_kernel.cc
+2
-1
python/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py
...on/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py
+68
-64
未找到文件。
cmake/external/xpu.cmake
浏览文件 @
613a3ffe
...
...
@@ -8,7 +8,7 @@ set(XPU_API_LIB_NAME "libxpuapi.so")
set
(
XPU_RT_LIB_NAME
"libxpurt.so"
)
set
(
XPU_BASE_DATE
"20230220"
)
set
(
XPU_XCCL_BASE_VERSION
"1.0.
8
"
)
set
(
XPU_XCCL_BASE_VERSION
"1.0.
9
"
)
if
(
NOT DEFINED XPU_BASE_URL
)
set
(
XPU_BASE_URL_WITHOUT_DATE
...
...
paddle/phi/backends/xpu/xpu2_op_list.cc
浏览文件 @
613a3ffe
...
...
@@ -46,6 +46,7 @@ XPUOpMap& get_kl2_ops() {
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
,
phi
::
DataType
::
FLOAT64
,
phi
::
DataType
::
INT32
,
phi
::
DataType
::
FLOAT16
,
phi
::
DataType
::
INT64
,
phi
::
DataType
::
BOOL
})},
{
"assign_value"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
...
...
paddle/phi/kernels/assign_kernel.cc
浏览文件 @
613a3ffe
...
...
@@ -179,5 +179,6 @@ PD_REGISTER_KERNEL(assign_value,
bool
,
int
,
float
,
int64_t
)
{}
int64_t
,
phi
::
dtype
::
float16
)
{}
#endif
python/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py
浏览文件 @
613a3ffe
# Copyright (c) 20
18
PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 20
23
PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
...
...
@@ -13,72 +13,76 @@
# limitations under the License.
import
sys
import
unittest
import
numpy
as
np
sys
.
path
.
append
(
".."
)
import
unittest
from
op_test_xpu
import
XPUOpTest
from
xpu.get_test_cover_info
import
(
XPUOpTestWrapper
,
create_test_class
,
get_xpu_op_support_types
,
)
import
paddle
'''
class TestAssignOp(op_test.OpTest):
def setUp(self):
self.op_type = "assign"
x = np.random.random(size=(100, 10)).astype('float32')
self.inputs = {'X': x}
self.outputs = {'Out': x}
def test_forward(self):
if paddle.is_compiled_with_xpu():
place = paddle.XPUPlace(0)
self.check_output_with_place(place)
def test_backward(self):
if paddle.is_compiled_with_xpu():
place = paddle.XPUPlace(0)
self.check_grad_with_place(place, ['X'], 'Out')
class TestAssignOpWithLoDTensorArray(unittest.TestCase):
def test_assign_LoDTensorArray(self):
main_program = Program()
startup_program = Program()
with program_guard(main_program):
x = fluid.data(name='x', shape=[100, 10], dtype='float32')
x.stop_gradient = False
y = fluid.layers.fill_constant(
shape=[100, 10], dtype='float32', value=1)
z = paddle.add(x=x, y=y)
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=0)
init_array = paddle.tensor.array_write(x=z, i=i)
array = fluid.layers.assign(init_array)
sums = paddle.tensor.array_read(array=init_array, i=i)
mean = paddle.mean(sums)
append_backward(mean)
place = fluid.CUDAPlace(0) if core.is_compiled_with_cuda(
) else fluid.CPUPlace()
exe = fluid.Executor(place)
feed_x = np.random.random(size=(100, 10)).astype('float32')
ones = np.ones((100, 10)).astype('float32')
feed_add = feed_x + ones
res = exe.run(main_program,
feed={'x': feed_x},
fetch_list=[sums.name, x.grad_name])
np.testing.assert_allclose(res[0], feed_add)
np.testing.assert_allclose(res[1], ones / 1000.0)
class TestAssignOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The type of input must be Variable or numpy.ndarray.
x1 = fluid.create_lod_tensor(
np.array([[-1]]), [[1]], fluid.XPUPlace(0))
self.assertRaises(TypeError, fluid.layers.assign, x1)
x2 = np.array([[2.5, 2.5]], dtype='uint8')
self.assertRaises(TypeError, fluid.layers.assign, x2)
'''
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
paddle
.
enable_static
()
class
XPUTestAssignOP
(
XPUOpTestWrapper
):
def
__init__
(
self
):
self
.
op_name
=
'assign'
self
.
use_dynamic_create_class
=
False
class
TestAssignOPBase
(
XPUOpTest
):
def
setUp
(
self
):
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
init_dtype
()
self
.
set_case
()
def
set_case
(
self
):
self
.
op_type
=
'assign'
self
.
init_config
()
x
=
np
.
random
.
random
(
size
=
self
.
input_shape
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
'X'
:
x
}
self
.
attrs
=
{}
self
.
outputs
=
{
'Out'
:
x
}
def
init_dtype
(
self
):
self
.
dtype
=
self
.
in_type
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
def
init_config
(
self
):
self
.
input_shape
=
(
2
,
5
)
class
XPUTestAssign1
(
TestAssignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
2
,
768
]
class
XPUTestAssign2
(
TestAssignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
3
,
8
,
4096
]
class
XPUTestAssign3
(
TestAssignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
1024
]
class
XPUTestAssign4
(
TestAssignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
2
,
2
,
255
]
support_types
=
get_xpu_op_support_types
(
'assign'
)
for
stype
in
support_types
:
create_test_class
(
globals
(),
XPUTestAssignOP
,
stype
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录