Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
4bb492e7
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看板
提交
4bb492e7
编写于
2月 11, 2018
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pass tiny data
上级
bb3ae206
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
7 deletion
+26
-7
paddle/operators/nccl_op.cc
paddle/operators/nccl_op.cc
+20
-4
python/paddle/v2/fluid/backward.py
python/paddle/v2/fluid/backward.py
+6
-3
未找到文件。
paddle/operators/nccl_op.cc
浏览文件 @
4bb492e7
...
@@ -19,6 +19,8 @@ limitations under the License. */
...
@@ -19,6 +19,8 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
static
constexpr
char
kParallelScopes
[]
=
"parallel_scopes"
;
// NCCLinitOp
// NCCLinitOp
class
NCCLInitOp
:
public
framework
::
OperatorBase
{
class
NCCLInitOp
:
public
framework
::
OperatorBase
{
public:
public:
...
@@ -29,24 +31,37 @@ class NCCLInitOp : public framework::OperatorBase {
...
@@ -29,24 +31,37 @@ class NCCLInitOp : public framework::OperatorBase {
void
Run
(
const
framework
::
Scope
&
scope
,
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
Place
&
place
)
const
override
{
const
platform
::
Place
&
place
)
const
override
{
PADDLE_ENFORCE_NOT_NULL
(
scope
.
FindVar
(
Input
(
kParallelScopes
)),
"Can not find variable '%s' in the scope."
,
kParallelScopes
);
const
auto
&
name
=
Output
(
"Communicator"
);
const
auto
&
name
=
Output
(
"Communicator"
);
PADDLE_ENFORCE_NOT_NULL
(
scope
.
FindVar
(
name
),
PADDLE_ENFORCE_NOT_NULL
(
scope
.
FindVar
(
name
),
"Can not find variable '%s' in the scope."
,
name
);
"Can not find variable '%s' in the scope."
,
name
);
// A parallel do may not use all the gpus. For example, the batch size is 7
int
count
=
platform
::
GetCUDADeviceCount
();
// in the last batch while we have 8 gpu. In this case, parallel_do will
std
::
vector
<
int
>
gpus
(
count
);
// create 7 parallel scopes, so should ncclInitOp create 7 gpu peers
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
LOG
(
INFO
)
<<
"---------------"
;
auto
&
parallel_scopes
=
scope
.
FindVar
(
Input
(
kParallelScopes
))
->
Get
<
std
::
vector
<
framework
::
Scope
*>>
();
LOG
(
INFO
)
<<
"---------------"
;
std
::
vector
<
int
>
gpus
(
parallel_scopes
.
size
());
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
parallel_scopes
.
size
());
++
i
)
{
gpus
[
i
]
=
i
;
gpus
[
i
]
=
i
;
}
}
LOG
(
INFO
)
<<
"---------------"
;
PADDLE_ENFORCE
(
!
gpus
.
empty
(),
"NCCL init with 0 gpus."
);
PADDLE_ENFORCE
(
!
gpus
.
empty
(),
"NCCL init with 0 gpus."
);
LOG
(
INFO
)
<<
"---------------"
;
if
(
scope
.
FindVar
(
name
)
==
nullptr
)
{
if
(
scope
.
FindVar
(
name
)
==
nullptr
)
{
PADDLE_THROW
(
"Output(Communicator) is needed for ncclInit operator."
);
PADDLE_THROW
(
"Output(Communicator) is needed for ncclInit operator."
);
}
}
LOG
(
INFO
)
<<
"---------------"
;
platform
::
Communicator
*
comm
=
platform
::
Communicator
*
comm
=
scope
.
FindVar
(
name
)
->
GetMutable
<
platform
::
Communicator
>
();
scope
.
FindVar
(
name
)
->
GetMutable
<
platform
::
Communicator
>
();
LOG
(
INFO
)
<<
"---------------"
;
comm
->
InitAll
(
gpus
);
comm
->
InitAll
(
gpus
);
LOG
(
INFO
)
<<
"---------------"
;
}
}
};
};
...
@@ -70,6 +85,7 @@ class NCCLInitOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -70,6 +85,7 @@ class NCCLInitOpMaker : public framework::OpProtoAndCheckerMaker {
public:
public:
NCCLInitOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
NCCLInitOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
kParallelScopes
,
"The working place of parallel do."
);
AddOutput
(
"Communicator"
,
AddOutput
(
"Communicator"
,
"Create Communicator for communicating between gpus"
);
"Create Communicator for communicating between gpus"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
...
...
python/paddle/v2/fluid/backward.py
浏览文件 @
4bb492e7
...
@@ -223,9 +223,10 @@ def _callback_lookup_(op):
...
@@ -223,9 +223,10 @@ def _callback_lookup_(op):
param_grad_names
=
[
n
+
"@GRAD"
for
n
in
param_names
]
param_grad_names
=
[
n
+
"@GRAD"
for
n
in
param_names
]
class
ParallelDoCallBack
(
object
):
class
ParallelDoCallBack
(
object
):
def
__init__
(
self
,
param_grad_names
):
def
__init__
(
self
,
param_grad_names
,
parallel_scopes_name
):
self
.
has_inserted_nccl_init
=
False
self
.
has_inserted_nccl_init
=
False
self
.
param_grad_names
=
param_grad_names
self
.
param_grad_names
=
param_grad_names
self
.
parallel_scopes_name
=
parallel_scopes_name
def
__call__
(
self
,
block
,
context
):
def
__call__
(
self
,
block
,
context
):
if
not
self
.
has_inserted_nccl_init
:
if
not
self
.
has_inserted_nccl_init
:
...
@@ -242,7 +243,8 @@ def _callback_lookup_(op):
...
@@ -242,7 +243,8 @@ def _callback_lookup_(op):
# inputs={},
# inputs={},
# outputs={'Communicator': [self.nccl_com]})
# outputs={'Communicator': [self.nccl_com]})
op_desc
=
_create_op_desc_
(
op_desc
=
_create_op_desc_
(
"ncclInit"
,
{},
"ncclInit"
,
{
"parallel_scopes"
:
self
.
parallel_scopes_name
},
{
"Communicator"
:
[
'nccl_com__do_not_change_'
]},
{})
{
"Communicator"
:
[
'nccl_com__do_not_change_'
]},
{})
# block.desc.append_op().copy_from(op_desc)
# block.desc.append_op().copy_from(op_desc)
print
(
serialize_op_decs
(
op_desc
))
print
(
serialize_op_decs
(
op_desc
))
...
@@ -281,7 +283,8 @@ def _callback_lookup_(op):
...
@@ -281,7 +283,8 @@ def _callback_lookup_(op):
{
"Out"
:
[
o_argu
]},
{})
{
"Out"
:
[
o_argu
]},
{})
block
.
desc
.
append_op
().
copy_from
(
op_desc
)
block
.
desc
.
append_op
().
copy_from
(
op_desc
)
return
ParallelDoCallBack
(
param_grad_names
)
return
ParallelDoCallBack
(
param_grad_names
,
op
.
output
(
"parallel_scopes"
))
else
:
else
:
return
None
return
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录