Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
3858f458
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
3858f458
编写于
1月 29, 2021
作者:
S
ShenLiang
提交者:
GitHub
1月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rm Singleton of reducer (#30775)
上级
2c974cc3
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
5 addition
and
46 deletion
+5
-46
paddle/fluid/imperative/reducer.cc
paddle/fluid/imperative/reducer.cc
+0
-8
paddle/fluid/imperative/reducer.h
paddle/fluid/imperative/reducer.h
+0
-28
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+5
-10
未找到文件。
paddle/fluid/imperative/reducer.cc
浏览文件 @
3858f458
...
...
@@ -41,8 +41,6 @@ namespace paddle {
namespace
imperative
{
#if defined(PADDLE_WITH_NCCL)
std
::
shared_ptr
<
Reducer
>
Reducer
::
s_instance_
=
NULL
;
template
<
typename
DeviceContext
,
typename
T
>
static
void
ConcatTensorsForAllReduce
(
const
DeviceContext
&
context
,
...
...
@@ -225,14 +223,8 @@ Reducer::Reducer(const std::vector<std::shared_ptr<imperative::VarBase>> &vars,
})));
var_index_map_
[
var
->
GradVarBase
()
->
SharedVar
().
get
()]
=
global_var_index
;
}
std
::
call_once
(
once_flag_
,
[]()
{
std
::
atexit
([]()
{
Reducer
::
GetInstance
()
->
ReleaseReducer
();
});
});
}
void
Reducer
::
ReleaseReducer
()
{
parallel_ctx_
.
reset
();
}
void
Reducer
::
InitializeDenseGroups
(
const
std
::
vector
<
size_t
>
&
variable_indices_
,
Group
*
p_group
)
{
int64_t
all_length
=
0
;
...
...
paddle/fluid/imperative/reducer.h
浏览文件 @
3858f458
...
...
@@ -108,44 +108,16 @@ class Reducer {
void
AddDistHook
(
size_t
var_index
);
// void MarkDenseVarReady(size_t var_index);
// void MarkSparseVarReady(size_t var_index);
void
MarkVarReady
(
const
size_t
var_index
,
const
bool
is_used_var
);
void
MarkGroupReady
(
size_t
group_index
);
void
FinalizeBackward
();
void
ReleaseReducer
();
std
::
vector
<
std
::
vector
<
size_t
>>
RebuildGruops
();
inline
bool
NeedRebuildGroup
()
{
return
!
has_rebuilt_group_
;
}
// Reducer Singleton
static
std
::
shared_ptr
<
Reducer
>
SetInstance
(
const
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>&
vars
,
const
std
::
vector
<
std
::
vector
<
size_t
>>&
group_indices
,
const
std
::
vector
<
bool
>&
is_sparse_gradient
,
std
::
shared_ptr
<
imperative
::
ParallelContext
>
parallel_ctx
,
const
std
::
vector
<
size_t
>&
group_size_limits
,
bool
find_unused_vars
)
{
if
(
NULL
==
s_instance_
)
{
s_instance_
.
reset
(
new
paddle
::
imperative
::
Reducer
(
vars
,
group_indices
,
is_sparse_gradient
,
parallel_ctx
,
group_size_limits
,
find_unused_vars
));
}
return
s_instance_
;
}
static
std
::
shared_ptr
<
Reducer
>
GetInstance
()
{
PADDLE_ENFORCE_EQ
(
s_instance_
!=
NULL
,
true
,
platform
::
errors
::
InvalidArgument
(
"Reducer is not initialized."
));
return
s_instance_
;
}
private:
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
vars_
;
std
::
vector
<
std
::
vector
<
size_t
>>
group_indices_
;
...
...
paddle/fluid/pybind/imperative.cc
浏览文件 @
3858f458
...
...
@@ -1390,16 +1390,11 @@ void BindImperative(py::module *m_ptr) {
py
::
class_
<
imperative
::
Reducer
,
std
::
shared_ptr
<
imperative
::
Reducer
>>
(
m
,
"Reducer"
,
R"DOC()DOC"
)
.
def
(
py
::
init
([](
const
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
&
vars
,
const
std
::
vector
<
std
::
vector
<
size_t
>>
&
group_indices
,
const
std
::
vector
<
bool
>
&
is_sparse_gradient
,
std
::
shared_ptr
<
imperative
::
ParallelContext
>
parallel_ctx
,
const
std
::
vector
<
size_t
>
&
group_size_limits
,
bool
find_unused_vars
)
{
return
imperative
::
Reducer
::
SetInstance
(
vars
,
group_indices
,
is_sparse_gradient
,
parallel_ctx
,
group_size_limits
,
find_unused_vars
);
}))
.
def
(
py
::
init
<
const
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
&
,
const
std
::
vector
<
std
::
vector
<
size_t
>>
&
,
const
std
::
vector
<
bool
>
&
,
std
::
shared_ptr
<
imperative
::
ParallelContext
>
,
const
std
::
vector
<
size_t
>
&
,
bool
>
())
.
def
(
"prepare_for_backward"
,
&
imperative
::
Reducer
::
PrepareForBackward
,
py
::
arg
(
"vars"
),
py
::
call_guard
<
py
::
gil_scoped_release
>
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录