Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
701d3fa0
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
提交
701d3fa0
编写于
5月 29, 2023
作者:
L
liangjianzhong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
broadcast func
上级
ed0c31e6
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
39 addition
and
10 deletion
+39
-10
paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc
paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc
+21
-5
paddle/fluid/distributed/auto_parallel/spmd_rules/common.h
paddle/fluid/distributed/auto_parallel/spmd_rules/common.h
+18
-5
未找到文件。
paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc
浏览文件 @
701d3fa0
...
...
@@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <glog/logging.h>
#include "paddle/fluid/distributed/auto_parallel/spmd_rules/common.h"
namespace
paddle
{
...
...
@@ -42,7 +44,7 @@ std::unordered_map<std::string, int64_t> ShardingMergeForTensors(
int64_t
merge_dim
;
for
(
auto
&
pair
:
tensor_axes_to_dim_pairs
)
{
for
(
int
i
=
0
;
i
<
pair
.
second
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
pair
.
second
.
size
();
++
i
)
{
auto
tensor_axis
=
pair
.
first
.
substr
(
i
,
1
);
auto
mesh_dim
=
pair
.
second
[
i
];
...
...
@@ -71,7 +73,7 @@ std::unordered_map<std::string, int64_t> ShardingMergeForTensors(
VLOG
(
4
)
<<
"Sharding Conflict: Mesh_Dim ["
<<
it
.
first
<<
"] are Sharding Multiple Tensor Axis: ["
<<
it
.
second
<<
"]. The Axis: ["
<<
it
.
second
[
0
]
<<
"] is Picked."
;
for
(
int
i
=
1
;
i
<
it
.
second
.
size
();
i
++
)
{
for
(
size_t
i
=
1
;
i
<
it
.
second
.
size
();
++
i
)
{
axis_to_dim_map
[
it
.
second
.
substr
(
i
,
1
)]
=
-
1
;
}
}
...
...
@@ -113,7 +115,7 @@ TensorDistAttr CopyTensorDistAttrForOutput(
new_dist_attr
.
set_process_mesh
(
src_dist_attr
.
process_mesh
());
new_dist_attr
.
set_batch_dim
(
src_dist_attr
.
batch_dim
());
new_dist_attr
.
set_dynamic_dims
(
src_dist_attr
.
dynamic_dims
());
new_dist_attr
.
set_annotated
(
false
);
// new_dist_attr.set_annotated(false); TODO unset field is false by default.
return
new_dist_attr
;
}
...
...
@@ -122,8 +124,8 @@ std::vector<int64_t> ResoluteOutputPartialDimension(
const
std
::
string
&
tensor_axes
)
{
std
::
vector
<
int64_t
>
partial_on_dims
;
for
(
auto
&
it
:
in_
axis_to_dim_map
)
{
if
(
out_axis
.
find
(
it
.
first
)
!
=
std
::
string
::
npos
)
{
for
(
auto
&
it
:
axis_to_dim_map
)
{
if
(
tensor_axes
.
find
(
it
.
first
)
=
=
std
::
string
::
npos
)
{
if
(
it
.
second
>
-
1
)
{
partial_on_dims
.
push_back
(
it
.
second
);
}
...
...
@@ -132,6 +134,20 @@ std::vector<int64_t> ResoluteOutputPartialDimension(
return
partial_on_dims
;
}
std
::
string
GetBroadcastAxes
(
const
int64_t
&
tenosr_ndim
,
const
int64_t
&
broadcast_ndim
,
const
std
::
string
&
alphabet
)
{
PADDLE_ENFORCE_GE
(
alphabet
.
size
(),
broadcast_ndim
,
phi
::
errors
::
InvalidArgument
(
"size of alphabet [%d] is less than broadcast ndim [%d]"
,
alphabet
.
size
(),
broadcast_ndim
));
return
alphabet
.
substr
(
0
,
broadcast_ndim
)
.
substr
(
broadcast_ndim
-
tenosr_ndim
,
tenosr_ndim
);
}
}
// namespace auto_parallel
}
// namespace distributed
}
// namespace paddle
paddle/fluid/distributed/auto_parallel/spmd_rules/common.h
浏览文件 @
701d3fa0
...
...
@@ -19,14 +19,18 @@ limitations under the License. */
#include <string>
#include <vector>
#include "paddle/fluid/distributed/auto_parallel/spmd_rules/dist_tensor_spec.h"
#include "paddle/fluid/framework/type_defs.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/phi/core/distributed/auto_parallel/dist_attr.h"
#include "paddle/fluid/distributed/auto_parallel/spmd_rules/dist_tensor_spec.h"
namespace
paddle
{
namespace
distributed
{
namespace
auto_parallel
{
using
paddle
::
framework
::
Attribute
;
class
SPMDRuleBase
{
public:
virtual
~
SPMDRuleBase
()
{}
...
...
@@ -64,10 +68,10 @@ class SPMDRuleBase {
const
Attribute
&
GetAttr
(
const
std
::
string
&
name
,
const
paddle
::
framework
::
AttributeMap
&
attrs
)
const
{
auto
iter
=
attrs
.
find
(
name
);
PADDLE_ENFORCE_NE
(
iter
,
PADDLE_ENFORCE_NE
(
iter
,
attrs
.
end
(),
platform
::
errors
::
NotFound
(
"(%s) is not found in AttributeMap."
));
paddle
::
platform
::
errors
::
NotFound
(
"(%s) is not found in AttributeMap."
));
return
iter
->
second
;
}
};
...
...
@@ -96,6 +100,15 @@ std::vector<int64_t> ResoluteOutputPartialDimension(
const
std
::
unordered_map
<
std
::
string
,
int64_t
>&
axis_to_dim_map
,
const
std
::
string
&
tensor_axes
);
// Generate the axis notation of tensor for the einsum notation of a broadcast
// operation(alignment star from the rightmost axis). tenosr_ndim: the size of
// the tensor. broadcast_ndim: the maxium size of tensors in this broadcast
// operation. alphabet: the characters used to represent the axes of tensor.
// length of alphabet should >= broadcast_ndim.
std
::
string
GetBroadcastAxes
(
const
int64_t
&
tenosr_ndim
,
const
int64_t
&
broadcast_ndim
,
const
std
::
string
&
alphabet
);
}
// namespace auto_parallel
}
// namespace distributed
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录