Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e4fbb286
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看板
未验证
提交
e4fbb286
编写于
2月 28, 2023
作者:
L
LoneRanger
提交者:
GitHub
2月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[fp16] suppot fp16 in tensordot (#50938)
* fix fp16 bug of tensordot * fix fp16 of tensordot * fix fp16 of tensordot
上级
b69af7ad
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
29 addition
and
2 deletion
+29
-2
python/paddle/fluid/tests/unittests/test_tensordot.py
python/paddle/fluid/tests/unittests/test_tensordot.py
+27
-0
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+2
-2
未找到文件。
python/paddle/fluid/tests/unittests/test_tensordot.py
浏览文件 @
e4fbb286
...
@@ -224,6 +224,33 @@ class TestTensordotAPI(unittest.TestCase):
...
@@ -224,6 +224,33 @@ class TestTensordotAPI(unittest.TestCase):
np_res
=
tensordot_np
(
self
.
x
,
self
.
y
,
axes
)
np_res
=
tensordot_np
(
self
.
x
,
self
.
y
,
axes
)
np
.
testing
.
assert_allclose
(
paddle_res
[
0
],
np_res
,
rtol
=
1e-6
)
np
.
testing
.
assert_allclose
(
paddle_res
[
0
],
np_res
,
rtol
=
1e-6
)
def
test_fp16_with_gpu
(
self
):
paddle
.
enable_static
()
if
paddle
.
fluid
.
core
.
is_compiled_with_cuda
():
for
axes
in
self
.
all_axes
:
place
=
paddle
.
CUDAPlace
(
0
)
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()
):
input_x
=
np
.
random
.
random
([
5
,
5
,
5
,
5
]).
astype
(
"float16"
)
x
=
paddle
.
static
.
data
(
name
=
"x"
,
shape
=
[
5
,
5
,
5
,
5
],
dtype
=
"float16"
)
input_y
=
np
.
random
.
random
([
5
,
5
,
5
,
5
]).
astype
(
"float16"
)
y
=
paddle
.
static
.
data
(
name
=
"y"
,
shape
=
[
5
,
5
,
5
,
5
],
dtype
=
"float16"
)
z
=
paddle
.
tensordot
(
x
,
y
,
axes
)
exe
=
paddle
.
static
.
Executor
(
place
)
paddle_res
=
exe
.
run
(
feed
=
{
'x'
:
input_x
,
'y'
:
input_y
},
fetch_list
=
[
z
]
)
np_res
=
tensordot_np
(
input_x
,
input_y
,
axes
)
np
.
testing
.
assert_allclose
(
paddle_res
[
0
],
np_res
,
rtol
=
1
)
class
TestTensordotAPIFloat64
(
TestTensordotAPI
):
class
TestTensordotAPIFloat64
(
TestTensordotAPI
):
def
set_dtype
(
self
):
def
set_dtype
(
self
):
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
e4fbb286
...
@@ -3940,7 +3940,7 @@ def tensordot(x, y, axes=2, name=None):
...
@@ -3940,7 +3940,7 @@ def tensordot(x, y, axes=2, name=None):
This function computes a contraction, which sum the product of elements from two tensors along the given axes.
This function computes a contraction, which sum the product of elements from two tensors along the given axes.
Args:
Args:
x (Tensor): The left tensor for contraction with data type ``float32`` or ``float64``.
x (Tensor): The left tensor for contraction with data type ``float
16`` or ``float
32`` or ``float64``.
y (Tensor): The right tensor for contraction with the same data type as ``x``.
y (Tensor): The right tensor for contraction with the same data type as ``x``.
axes (int|tuple|list|Tensor, optional): The axes to contract for ``x`` and ``y``, defaulted to integer ``2``.
axes (int|tuple|list|Tensor, optional): The axes to contract for ``x`` and ``y``, defaulted to integer ``2``.
...
@@ -4048,7 +4048,7 @@ def tensordot(x, y, axes=2, name=None):
...
@@ -4048,7 +4048,7 @@ def tensordot(x, y, axes=2, name=None):
# [28312230., 30496530., 32680830., 34865130.]]
# [28312230., 30496530., 32680830., 34865130.]]
"""
"""
op_type
=
'tensordot'
op_type
=
'tensordot'
input_dtype
=
[
'float32'
,
'float64'
]
input_dtype
=
[
'float
16'
,
'float
32'
,
'float64'
]
check_variable_and_dtype
(
x
,
'x'
,
input_dtype
,
op_type
)
check_variable_and_dtype
(
x
,
'x'
,
input_dtype
,
op_type
)
check_variable_and_dtype
(
y
,
'y'
,
input_dtype
,
op_type
)
check_variable_and_dtype
(
y
,
'y'
,
input_dtype
,
op_type
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录