Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
668e235c
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看板
未验证
提交
668e235c
编写于
5月 27, 2022
作者:
X
xiongkun
提交者:
GitHub
5月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change einsum_v2 as default and add new flags: FLAG_einsum_opt=1|0 (#43010)
上级
905d857c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
3 deletion
+21
-3
paddle/fluid/platform/flags.cc
paddle/fluid/platform/flags.cc
+13
-0
paddle/phi/kernels/impl/einsum_impl.h
paddle/phi/kernels/impl/einsum_impl.h
+4
-2
python/paddle/fluid/tests/unittests/test_einsum.py
python/paddle/fluid/tests/unittests/test_einsum.py
+3
-0
python/paddle/tensor/einsum.py
python/paddle/tensor/einsum.py
+1
-1
未找到文件。
paddle/fluid/platform/flags.cc
浏览文件 @
668e235c
...
@@ -848,3 +848,16 @@ PADDLE_DEFINE_EXPORTED_bool(nccl_blocking_wait, false, "nccl blocking wait");
...
@@ -848,3 +848,16 @@ PADDLE_DEFINE_EXPORTED_bool(nccl_blocking_wait, false, "nccl blocking wait");
* Example:
* Example:
*/
*/
PADDLE_DEFINE_EXPORTED_bool
(
use_autotune
,
false
,
"Whether enable autotune."
);
PADDLE_DEFINE_EXPORTED_bool
(
use_autotune
,
false
,
"Whether enable autotune."
);
/**
* Preformance related FLAG
* Name: einsum_opt
* Since Version: 2.3.0
* Value Range: bool, default=false
* Example:
* Note: If True, EinsumOp will be optimimzed by innercache reuse, which
* uses more gpu memory.
*/
PADDLE_DEFINE_EXPORTED_bool
(
einsum_opt
,
false
,
"EinsumOp backward will be speedup at the expense of more gpu memory."
);
paddle/phi/kernels/impl/einsum_impl.h
浏览文件 @
668e235c
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
#include "paddle/phi/kernels/transpose_kernel.h"
#include "paddle/phi/kernels/transpose_kernel.h"
#include "paddle/utils/string/string_helper.h"
#include "paddle/utils/string/string_helper.h"
DECLARE_bool
(
einsum_opt
);
namespace
phi
{
namespace
phi
{
// check the validation of the Einsum equation.
// check the validation of the Einsum equation.
...
@@ -456,7 +458,7 @@ DenseTensor PerformContraction(
...
@@ -456,7 +458,7 @@ DenseTensor PerformContraction(
}
}
// reduction
// reduction
DenseTensor
trans_t
;
DenseTensor
trans_t
;
if
(
use_cache
&&
cache
[
operand_idx
]
!=
nullptr
&&
if
(
FLAGS_einsum_opt
&&
use_cache
&&
cache
[
operand_idx
]
!=
nullptr
&&
cache
[
operand_idx
]
->
IsInitialized
())
{
cache
[
operand_idx
]
->
IsInitialized
())
{
trans_t
.
ShareBufferWith
(
*
(
cache
[
operand_idx
]));
trans_t
.
ShareBufferWith
(
*
(
cache
[
operand_idx
]));
VLOG
(
5
)
<<
"Cache Used!"
;
VLOG
(
5
)
<<
"Cache Used!"
;
...
@@ -465,7 +467,7 @@ DenseTensor PerformContraction(
...
@@ -465,7 +467,7 @@ DenseTensor PerformContraction(
dev_ctx
,
t
,
perm
,
all_labels
,
ellipsis
,
label2type
);
dev_ctx
,
t
,
perm
,
all_labels
,
ellipsis
,
label2type
);
trans_t
=
PerformTranspose
<
T
,
Context
>
(
trans_t
=
PerformTranspose
<
T
,
Context
>
(
dev_ctx
,
reduct_t
,
perm
,
reordered_all_labels
,
ellipsis
,
label2type
);
dev_ctx
,
reduct_t
,
perm
,
reordered_all_labels
,
ellipsis
,
label2type
);
if
(
cache
[
operand_idx
]
!=
nullptr
)
if
(
FLAGS_einsum_opt
&&
cache
[
operand_idx
]
!=
nullptr
)
cache
[
operand_idx
]
->
ShareBufferWith
(
trans_t
);
cache
[
operand_idx
]
->
ShareBufferWith
(
trans_t
);
}
}
auto
mul_dims
=
GetShapeByType
<
int
>
(
all_labels
,
auto
mul_dims
=
GetShapeByType
<
int
>
(
all_labels
,
...
...
python/paddle/fluid/tests/unittests/test_einsum.py
浏览文件 @
668e235c
...
@@ -18,6 +18,9 @@ import unittest
...
@@ -18,6 +18,9 @@ import unittest
import
paddle
import
paddle
from
paddle.fluid
import
core
from
paddle.fluid
import
core
import
os
os
.
environ
[
'FLAGS_new_einsum'
]
=
"0"
class
TestErrors
(
unittest
.
TestCase
):
class
TestErrors
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
python/paddle/tensor/einsum.py
浏览文件 @
668e235c
...
@@ -983,7 +983,7 @@ def einsum(equation, *operands):
...
@@ -983,7 +983,7 @@ def einsum(equation, *operands):
# [0.51476848, 0.23367381, 0.39229113]]])
# [0.51476848, 0.23367381, 0.39229113]]])
"""
"""
import
os
import
os
if
int
(
os
.
environ
.
get
(
'FLAGS_new_einsum'
,
"
0
"
)):
if
int
(
os
.
environ
.
get
(
'FLAGS_new_einsum'
,
"
1
"
)):
return
einsum_v2
(
equation
,
*
operands
)
return
einsum_v2
(
equation
,
*
operands
)
nop
=
len
(
operands
)
nop
=
len
(
operands
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录