Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
747de082
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看板
提交
747de082
编写于
6月 06, 2023
作者:
J
JZ-LIANG
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add registry
上级
c1545a4b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
72 addition
and
0 deletion
+72
-0
paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc
paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc
+35
-0
paddle/fluid/distributed/auto_parallel/spmd_rules/common.h
paddle/fluid/distributed/auto_parallel/spmd_rules/common.h
+35
-0
paddle/fluid/distributed/auto_parallel/spmd_rules/matmul_spmd_rule.cc
.../distributed/auto_parallel/spmd_rules/matmul_spmd_rule.cc
+2
-0
未找到文件。
paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc
浏览文件 @
747de082
...
...
@@ -148,6 +148,41 @@ std::string GetBroadcastAxes(const int64_t& tenosr_ndim,
.
substr
(
broadcast_ndim
-
tenosr_ndim
,
tenosr_ndim
);
}
// SPMDRuleMap
SPMDRuleMap
&
SPMDRuleMap
::
Instance
();
static
SPMDRuleMap
g_spmd_rule_map
;
return
g_spmd_rule_map
;
}
// TODO enable default replicated spmd rule for op that are NOT registered
// which all tensors of inputs and outputs will be replicated in all ranks of the mesh.
SPMDRuleBase
&
SPMDRuleMap
::
Get
(
const
std
::
string
&
op_type
)
const
{
auto
rule_ptr
=
GetNullable
(
op_type
);
PADDLE_ENFORCE_NOT_NULL
(
rule_ptr
,
platform
::
errors
::
NotFound
(
"NO SPMD Rule has been registered for Operator [%s]."
,
op_type
));
return
*
rule_ptr
;
}
SPMDRuleBase
*
SPMDRuleMap
::
GetNullable
(
const
std
::
string
&
op_type
)
const
{
auto
it
=
map_
.
find
(
op_type
);
if
(
it
==
map_
.
end
())
{
return
nullptr
;
}
else
{
return
it
->
second
.
get
();
}
}
void
SPMDRuleMap
::
Insert
(
const
std
::
string
&
op_type
,
std
::
unique_ptr
<
SPMDRuleBase
>
rule
){
PADDLE_ENFORCE_NE
(
Has
(
op_type
),
true
,
platform
::
errors
::
AlreadyExists
(
"SPMD Rule for Operator [%s] has been registered."
,
type
));
map_
.
insert
({
op_type
,
std
::
move
(
rule
)});
}
}
// namespace auto_parallel
}
// namespace distributed
}
// namespace paddle
paddle/fluid/distributed/auto_parallel/spmd_rules/common.h
浏览文件 @
747de082
...
...
@@ -109,6 +109,41 @@ std::string GetBroadcastAxes(const int64_t& tenosr_ndim,
const
int64_t
&
broadcast_ndim
,
const
std
::
string
&
alphabet
);
// The static map that stores and initializes all the registered SPMD rules.
class
SPMDRuleMap
{
public:
~
SPMDRuleMap
()
=
default
;
// A singleton
static
SPMDRuleMap
&
Instance
();
// Returns the spmd rule for the given op_type
SPMDRuleBase
&
Get
(
const
std
::
string
&
op_type
)
const
;
// Returns the spmd by name or nullptr if not registered
SPMDRuleBase
*
GetNullable
(
const
std
::
string
&
op_type
)
const
;
// Register a spmd for an op_type.
void
Insert
(
const
std
::
string
&
op_type
,
std
::
unique_ptr
<
SPMDRuleBase
>
rule
);
bool
Has
(
const
std
::
string
&
op_type
)
const
{
return
map_
.
find
(
op_type
)
!=
map_
.
end
();
}
private:
SPMDRuleMap
()
=
default
;
paddle
::
flat_hash_map
<
std
::
string
,
std
::
unique_ptr
<
SPMDRuleBase
>>
map_
;
DISABLE_COPY_AND_ASSIGN
(
SPMDRuleMap
);
};
#define REGISTER_SPMDRULE(op_type, rule_class, ...) \
SPMDRuleMap::Instance().Insert( \
op_type, \
std::make_unique<rule_class>(__VA_ARGS__))
}
// namespace auto_parallel
}
// namespace distributed
}
// namespace paddle
paddle/fluid/distributed/auto_parallel/spmd_rules/matmul_spmd_rule.cc
浏览文件 @
747de082
...
...
@@ -204,6 +204,8 @@ std::vector<TensorDistAttr> MatmulSPMDRule::InferBackward(
return
{};
}
REGISTER_SPMDRULE
(
matmul
,
MatmulSPMDRule
);
}
// namespace auto_parallel
}
// namespace distributed
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录