Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
38f9b71b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
38f9b71b
编写于
7月 03, 2020
作者:
C
Chengmo
提交者:
GitHub
7月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] fix fluid.embedding (#25328)
* test=release/1.8, cherry fix fluid.embedding
上级
b69d0647
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
88 addition
and
45 deletion
+88
-45
paddle/fluid/operators/distributed/parameter_prefetch.cc
paddle/fluid/operators/distributed/parameter_prefetch.cc
+8
-4
paddle/fluid/operators/distributed_ops/distributed_lookup_table_op.cc
.../operators/distributed_ops/distributed_lookup_table_op.cc
+41
-8
python/paddle/fluid/tests/unittests/dist_simnet_bow.py
python/paddle/fluid/tests/unittests/dist_simnet_bow.py
+15
-12
python/paddle/fluid/tests/unittests/test_dist_simnet_bow.py
python/paddle/fluid/tests/unittests/test_dist_simnet_bow.py
+4
-4
python/paddle/fluid/transpiler/distribute_transpiler.py
python/paddle/fluid/transpiler/distribute_transpiler.py
+20
-17
未找到文件。
paddle/fluid/operators/distributed/parameter_prefetch.cc
浏览文件 @
38f9b71b
...
@@ -209,16 +209,20 @@ void prefetchs(const std::vector<std::string>& id_var_names,
...
@@ -209,16 +209,20 @@ void prefetchs(const std::vector<std::string>& id_var_names,
TableAndEndpoints
tables
;
TableAndEndpoints
tables
;
for
(
auto
&
id_name
:
id_var_names
)
{
for
(
auto
&
id_name
:
id_var_names
)
{
auto
&
id_tensor
=
scope
.
FindVar
(
id_name
)
->
Get
<
framework
::
LoDTensor
>
();
auto
*
id_tensor
=
auto
*
id_data
=
id_tensor
.
data
<
int64_t
>
();
scope
.
FindVar
(
id_name
)
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
id_dims
=
id_tensor
->
dims
();
id_tensor
->
Resize
(
framework
::
make_ddim
(
{
static_cast
<
int64_t
>
(
id_dims
[
0
]
*
id_dims
[
1
]),
1
}));
auto
*
id_data
=
id_tensor
->
data
<
int64_t
>
();
std
::
vector
<
int64_t
>
ids
;
std
::
vector
<
int64_t
>
ids
;
for
(
int64_t
i
=
0
;
i
<
id_tensor
.
numel
();
++
i
)
{
for
(
int64_t
i
=
0
;
i
<
id_tensor
->
numel
();
++
i
)
{
ids
.
push_back
(
id_data
[
i
]);
ids
.
push_back
(
id_data
[
i
]);
ids_union
.
push_back
(
id_data
[
i
]);
ids_union
.
push_back
(
id_data
[
i
]);
}
}
ids_group
.
push_back
(
ids
);
ids_group
.
push_back
(
ids
);
ids_lods
.
push_back
(
id_tensor
.
lod
());
ids_lods
.
push_back
(
id_tensor
->
lod
());
}
}
std
::
unordered_set
<
int64_t
>
s
(
ids_union
.
begin
(),
ids_union
.
end
());
std
::
unordered_set
<
int64_t
>
s
(
ids_union
.
begin
(),
ids_union
.
end
());
...
...
paddle/fluid/operators/distributed_ops/distributed_lookup_table_op.cc
浏览文件 @
38f9b71b
...
@@ -26,7 +26,7 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
...
@@ -26,7 +26,7 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
public:
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInputs
(
"Ids"
),
PADDLE_ENFORCE
(
ctx
->
HasInputs
(
"Ids"
),
"Input(Ids) of LookupTableOp should not be null."
);
"Input(Ids) of LookupTableOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"W"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"W"
),
...
@@ -40,11 +40,9 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
...
@@ -40,11 +40,9 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
table_dims
.
size
(),
2
,
PADDLE_ENFORCE_EQ
(
table_dims
.
size
(),
2
,
"Only 2 dimensions of the 'Embedding' is supported."
);
"Only 2 dimensions of the 'Embedding' is supported."
);
for
(
auto
&
ids_dim
:
ids_dims
)
{
for
(
auto
&
ids_dim
:
ids_dims
)
{
PADDLE_ENFORCE_EQ
(
ids_dim
.
size
(),
2
,
PADDLE_ENFORCE_EQ
(
ids_dim
.
size
(),
2
,
"The dimension of the 'Ids' tensor must be 2."
);
"The dimension of the 'Ids' tensor must be 2."
);
PADDLE_ENFORCE_EQ
(
ids_dim
[
1
],
1
,
"The last dimension of the 'Ids' tensor must be 1."
);
}
}
auto
lookup_tables
=
auto
lookup_tables
=
...
@@ -52,6 +50,8 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
...
@@ -52,6 +50,8 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
auto
height_sections
=
auto
height_sections
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int64_t
>>
(
"height_sections"
);
ctx
->
Attrs
().
Get
<
std
::
vector
<
int64_t
>>
(
"height_sections"
);
auto
endpoints
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
std
::
string
>>
(
"endpoints"
);
auto
endpoints
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
std
::
string
>>
(
"endpoints"
);
auto
lookup_table_version
=
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"lookup_table_version"
);
PADDLE_ENFORCE
(
lookup_tables
.
size
()
==
height_sections
.
size
()
&&
PADDLE_ENFORCE
(
lookup_tables
.
size
()
==
height_sections
.
size
()
&&
lookup_tables
.
size
()
==
endpoints
.
size
()
&&
lookup_tables
.
size
()
==
endpoints
.
size
()
&&
...
@@ -61,8 +61,15 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
...
@@ -61,8 +61,15 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
auto
outputs_dims
=
std
::
vector
<
framework
::
DDim
>
();
auto
outputs_dims
=
std
::
vector
<
framework
::
DDim
>
();
for
(
auto
&
ids_dim
:
ids_dims
)
{
for
(
auto
&
ids_dim
:
ids_dims
)
{
outputs_dims
.
push_back
(
framework
::
make_ddim
({
ids_dim
[
0
],
table_dims
[
1
]}));
if
(
lookup_table_version
==
"lookup_table"
)
{
outputs_dims
.
push_back
(
framework
::
make_ddim
({
ids_dim
[
0
],
table_dims
[
1
]}));
}
else
if
(
lookup_table_version
==
"lookup_table_v2"
)
{
outputs_dims
.
push_back
(
framework
::
make_ddim
(
{
static_cast
<
int64_t
>
(
ids_dim
[
0
]),
static_cast
<
int64_t
>
(
ids_dim
[
1
]),
static_cast
<
int64_t
>
(
table_dims
[
1
])}));
}
}
}
ctx
->
SetOutputsDim
(
"Outputs"
,
outputs_dims
);
ctx
->
SetOutputsDim
(
"Outputs"
,
outputs_dims
);
...
@@ -71,7 +78,7 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
...
@@ -71,7 +78,7 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
protected:
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
framework
::
OpKernelType
(
return
framework
::
OpKernelType
(
framework
::
proto
::
VarType
::
Type
(
ctx
.
Attr
<
int
>
(
"dtype"
)),
framework
::
proto
::
VarType
::
Type
(
ctx
.
Attr
<
int
>
(
"dtype"
)),
ctx
.
GetPlace
());
ctx
.
GetPlace
());
...
@@ -81,7 +88,7 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
...
@@ -81,7 +88,7 @@ class DistributedLookupTableOp : public framework::OperatorWithKernel {
template
<
typename
T
>
template
<
typename
T
>
class
DistributedLookupTableKernel
:
public
framework
::
OpKernel
<
T
>
{
class
DistributedLookupTableKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
ids_vars
=
context
.
MultiInputVar
(
"Ids"
);
auto
ids_vars
=
context
.
MultiInputVar
(
"Ids"
);
auto
emb_vars
=
context
.
MultiOutput
<
framework
::
Tensor
>
(
"Embeddings"
);
auto
emb_vars
=
context
.
MultiOutput
<
framework
::
Tensor
>
(
"Embeddings"
);
...
@@ -93,10 +100,30 @@ class DistributedLookupTableKernel : public framework::OpKernel<T> {
...
@@ -93,10 +100,30 @@ class DistributedLookupTableKernel : public framework::OpKernel<T> {
auto
height_sections
=
auto
height_sections
=
context
.
Attr
<
std
::
vector
<
int64_t
>>
(
"height_sections"
);
context
.
Attr
<
std
::
vector
<
int64_t
>>
(
"height_sections"
);
auto
endpoints
=
context
.
Attr
<
std
::
vector
<
std
::
string
>>
(
"endpoints"
);
auto
endpoints
=
context
.
Attr
<
std
::
vector
<
std
::
string
>>
(
"endpoints"
);
auto
lookup_table_version
=
context
.
Attr
<
std
::
string
>
(
"lookup_table_version"
);
operators
::
distributed
::
prefetchs
(
operators
::
distributed
::
prefetchs
(
id_names
,
out_names
,
embedding_name
,
false
,
lookup_tables
,
endpoints
,
id_names
,
out_names
,
embedding_name
,
false
,
lookup_tables
,
endpoints
,
height_sections
,
context
,
context
.
scope
());
height_sections
,
context
,
context
.
scope
());
if
(
lookup_table_version
==
"lookup_table_v2"
)
{
auto
&
scope
=
context
.
scope
();
auto
emb_dim
=
scope
.
FindVar
(
embedding_name
)
->
Get
<
framework
::
LoDTensor
>
().
dims
()[
1
];
for
(
size_t
i
=
0
;
i
<
id_names
.
size
();
++
i
)
{
auto
*
id_var
=
scope
.
FindVar
(
id_names
[
i
]);
auto
*
out_var
=
scope
.
FindVar
(
out_names
[
i
]);
auto
*
id_tensor
=
id_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
out_tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
id_dims
=
id_tensor
->
dims
();
out_tensor
->
Resize
(
framework
::
make_ddim
(
{
static_cast
<
int64_t
>
(
id_dims
[
0
]),
static_cast
<
int64_t
>
(
id_dims
[
1
]),
static_cast
<
int64_t
>
(
emb_dim
)}));
}
}
}
}
};
};
...
@@ -134,6 +161,12 @@ class DistributedLookupTableOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -134,6 +161,12 @@ class DistributedLookupTableOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr
<
int
>
(
"trainer_id"
,
"trainer id from 0 ~ worker_num."
).
SetDefault
(
0
);
AddAttr
<
int
>
(
"trainer_id"
,
"trainer id from 0 ~ worker_num."
).
SetDefault
(
0
);
AddAttr
<
std
::
string
>
(
"lookup_table_version"
,
"(string, default lookup_table) "
"To distinguish between different versions of embedding OP"
)
.
SetDefault
(
std
::
string
(
"lookup_table"
));
AddAttr
<
int64_t
>
(
"padding_idx"
,
AddAttr
<
int64_t
>
(
"padding_idx"
,
"(int64, default -1) "
"(int64, default -1) "
"If the value is -1, it makes no effect to lookup. "
"If the value is -1, it makes no effect to lookup. "
...
...
python/paddle/fluid/tests/unittests/dist_simnet_bow.py
浏览文件 @
38f9b71b
...
@@ -92,8 +92,8 @@ def train_network(batch_size,
...
@@ -92,8 +92,8 @@ def train_network(batch_size,
# query
# query
q
=
fluid
.
layers
.
data
(
q
=
fluid
.
layers
.
data
(
name
=
"query_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"query_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
#
#
embedding
# embedding
q_emb
=
fluid
.
layers
.
embedding
(
q_emb
=
fluid
.
embedding
(
input
=
q
,
input
=
q
,
is_distributed
=
is_distributed
,
is_distributed
=
is_distributed
,
size
=
[
dict_dim
,
emb_dim
],
size
=
[
dict_dim
,
emb_dim
],
...
@@ -104,10 +104,11 @@ def train_network(batch_size,
...
@@ -104,10 +104,11 @@ def train_network(batch_size,
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.01
),
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.01
),
name
=
"__emb__"
),
name
=
"__emb__"
),
is_sparse
=
is_sparse
)
is_sparse
=
is_sparse
)
## vsum
q_emb
=
fluid
.
layers
.
reshape
(
q_emb
,
[
-
1
,
emb_dim
])
# vsum
q_sum
=
fluid
.
layers
.
sequence_pool
(
input
=
q_emb
,
pool_type
=
'sum'
)
q_sum
=
fluid
.
layers
.
sequence_pool
(
input
=
q_emb
,
pool_type
=
'sum'
)
q_ss
=
fluid
.
layers
.
softsign
(
q_sum
)
q_ss
=
fluid
.
layers
.
softsign
(
q_sum
)
#
#
fc layer after conv
# fc layer after conv
q_fc
=
fluid
.
layers
.
fc
(
q_fc
=
fluid
.
layers
.
fc
(
input
=
q_ss
,
input
=
q_ss
,
size
=
hid_dim
,
size
=
hid_dim
,
...
@@ -120,8 +121,8 @@ def train_network(batch_size,
...
@@ -120,8 +121,8 @@ def train_network(batch_size,
# pt
# pt
pt
=
fluid
.
layers
.
data
(
pt
=
fluid
.
layers
.
data
(
name
=
"pos_title_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"pos_title_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
#
#
embedding
# embedding
pt_emb
=
fluid
.
layers
.
embedding
(
pt_emb
=
fluid
.
embedding
(
input
=
pt
,
input
=
pt
,
is_distributed
=
is_distributed
,
is_distributed
=
is_distributed
,
size
=
[
dict_dim
,
emb_dim
],
size
=
[
dict_dim
,
emb_dim
],
...
@@ -132,10 +133,11 @@ def train_network(batch_size,
...
@@ -132,10 +133,11 @@ def train_network(batch_size,
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.01
),
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.01
),
name
=
"__emb__"
),
name
=
"__emb__"
),
is_sparse
=
is_sparse
)
is_sparse
=
is_sparse
)
## vsum
pt_emb
=
fluid
.
layers
.
reshape
(
pt_emb
,
[
-
1
,
emb_dim
])
# vsum
pt_sum
=
fluid
.
layers
.
sequence_pool
(
input
=
pt_emb
,
pool_type
=
'sum'
)
pt_sum
=
fluid
.
layers
.
sequence_pool
(
input
=
pt_emb
,
pool_type
=
'sum'
)
pt_ss
=
fluid
.
layers
.
softsign
(
pt_sum
)
pt_ss
=
fluid
.
layers
.
softsign
(
pt_sum
)
#
#
fc layer
# fc layer
pt_fc
=
fluid
.
layers
.
fc
(
pt_fc
=
fluid
.
layers
.
fc
(
input
=
pt_ss
,
input
=
pt_ss
,
size
=
hid_dim
,
size
=
hid_dim
,
...
@@ -147,8 +149,8 @@ def train_network(batch_size,
...
@@ -147,8 +149,8 @@ def train_network(batch_size,
# nt
# nt
nt
=
fluid
.
layers
.
data
(
nt
=
fluid
.
layers
.
data
(
name
=
"neg_title_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"neg_title_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
#
#
embedding
# embedding
nt_emb
=
fluid
.
layers
.
embedding
(
nt_emb
=
fluid
.
embedding
(
input
=
nt
,
input
=
nt
,
is_distributed
=
is_distributed
,
is_distributed
=
is_distributed
,
size
=
[
dict_dim
,
emb_dim
],
size
=
[
dict_dim
,
emb_dim
],
...
@@ -159,10 +161,11 @@ def train_network(batch_size,
...
@@ -159,10 +161,11 @@ def train_network(batch_size,
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.01
),
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.01
),
name
=
"__emb__"
),
name
=
"__emb__"
),
is_sparse
=
is_sparse
)
is_sparse
=
is_sparse
)
## vsum
nt_emb
=
fluid
.
layers
.
reshape
(
nt_emb
,
[
-
1
,
emb_dim
])
# vsum
nt_sum
=
fluid
.
layers
.
sequence_pool
(
input
=
nt_emb
,
pool_type
=
'sum'
)
nt_sum
=
fluid
.
layers
.
sequence_pool
(
input
=
nt_emb
,
pool_type
=
'sum'
)
nt_ss
=
fluid
.
layers
.
softsign
(
nt_sum
)
nt_ss
=
fluid
.
layers
.
softsign
(
nt_sum
)
#
#
fc layer
# fc layer
nt_fc
=
fluid
.
layers
.
fc
(
nt_fc
=
fluid
.
layers
.
fc
(
input
=
nt_ss
,
input
=
nt_ss
,
size
=
hid_dim
,
size
=
hid_dim
,
...
...
python/paddle/fluid/tests/unittests/test_dist_simnet_bow.py
浏览文件 @
38f9b71b
...
@@ -46,7 +46,7 @@ class TestDistSimnetBow2x2DenseAsync(TestDistBase):
...
@@ -46,7 +46,7 @@ class TestDistSimnetBow2x2DenseAsync(TestDistBase):
self
.
_sync_mode
=
False
self
.
_sync_mode
=
False
self
.
_enforce_place
=
"CPU"
self
.
_enforce_place
=
"CPU"
#FIXME(typhoonzero): fix async tests later
#
FIXME(typhoonzero): fix async tests later
def
notest_simnet_bow
(
self
):
def
notest_simnet_bow
(
self
):
need_envs
=
{
need_envs
=
{
"IS_DISTRIBUTED"
:
'0'
,
"IS_DISTRIBUTED"
:
'0'
,
...
@@ -107,7 +107,7 @@ class TestDistSimnetBow2x2LookupTableSync(TestDistBase):
...
@@ -107,7 +107,7 @@ class TestDistSimnetBow2x2LookupTableSync(TestDistBase):
def
test_simnet_bow
(
self
):
def
test_simnet_bow
(
self
):
need_envs
=
{
need_envs
=
{
"IS_DISTRIBUTED"
:
'
1
'
,
"IS_DISTRIBUTED"
:
'
0
'
,
"IS_SPARSE"
:
'1'
,
"IS_SPARSE"
:
'1'
,
'IS_SELF_CONTAINED_LR'
:
'1'
'IS_SELF_CONTAINED_LR'
:
'1'
}
}
...
@@ -126,7 +126,7 @@ class TestDistSimnetBow2x2LookupTableAsync(TestDistBase):
...
@@ -126,7 +126,7 @@ class TestDistSimnetBow2x2LookupTableAsync(TestDistBase):
def
test_simnet_bow
(
self
):
def
test_simnet_bow
(
self
):
need_envs
=
{
need_envs
=
{
"IS_DISTRIBUTED"
:
'
1
'
,
"IS_DISTRIBUTED"
:
'
0
'
,
"IS_SPARSE"
:
'1'
,
"IS_SPARSE"
:
'1'
,
'IS_SELF_CONTAINED_LR'
:
'1'
'IS_SELF_CONTAINED_LR'
:
'1'
}
}
...
@@ -145,7 +145,7 @@ class TestDistSimnetBow2x2LookupTableNotContainLRSync(TestDistBase):
...
@@ -145,7 +145,7 @@ class TestDistSimnetBow2x2LookupTableNotContainLRSync(TestDistBase):
def
test_simnet_bow
(
self
):
def
test_simnet_bow
(
self
):
need_envs
=
{
need_envs
=
{
"IS_DISTRIBUTED"
:
'
1
'
,
"IS_DISTRIBUTED"
:
'
0
'
,
"IS_SPARSE"
:
'1'
,
"IS_SPARSE"
:
'1'
,
'IS_SELF_CONTAINED_LR'
:
'0'
'IS_SELF_CONTAINED_LR'
:
'0'
}
}
...
...
python/paddle/fluid/transpiler/distribute_transpiler.py
浏览文件 @
38f9b71b
...
@@ -50,8 +50,8 @@ from .details import delete_ops, find_op_by_output_arg
...
@@ -50,8 +50,8 @@ from .details import delete_ops, find_op_by_output_arg
from
..distribute_lookup_table
import
find_distributed_lookup_table
from
..distribute_lookup_table
import
find_distributed_lookup_table
from
.
import
collective
from
.
import
collective
LOOKUP_TABLE_TYPE
=
"lookup_table"
LOOKUP_TABLE_TYPE
=
[
"lookup_table"
,
"lookup_table_v2"
]
LOOKUP_TABLE_GRAD_TYPE
=
"lookup_table_grad"
LOOKUP_TABLE_GRAD_TYPE
=
[
"lookup_table_grad"
,
"lookup_table_v2_grad"
]
OP_NAME_SCOPE
=
"op_namescope"
OP_NAME_SCOPE
=
"op_namescope"
CLIP_OP_NAME_SCOPE
=
"@CLIP"
CLIP_OP_NAME_SCOPE
=
"@CLIP"
OP_ROLE_VAR_ATTR_NAME
=
core
.
op_proto_and_checker_maker
.
kOpRoleVarAttrName
()
OP_ROLE_VAR_ATTR_NAME
=
core
.
op_proto_and_checker_maker
.
kOpRoleVarAttrName
()
...
@@ -199,10 +199,10 @@ class DistributeTranspilerConfig(object):
...
@@ -199,10 +199,10 @@ class DistributeTranspilerConfig(object):
geo_sgd_need_push_nums
=
100
geo_sgd_need_push_nums
=
100
nccl_comm_num
=
1
nccl_comm_num
=
1
#The picture here illustrates the principle:
#
The picture here illustrates the principle:
#https://github.com/PaddlePaddle/Paddle/pull/17263#discussion_r285411396
#
https://github.com/PaddlePaddle/Paddle/pull/17263#discussion_r285411396
use_hierarchical_allreduce
=
False
use_hierarchical_allreduce
=
False
#Nccl ranks in a node when use hierarchical allreduce, it's set to gpu cards' number in most cases.
#
Nccl ranks in a node when use hierarchical allreduce, it's set to gpu cards' number in most cases.
hierarchical_allreduce_inter_nranks
=
0
hierarchical_allreduce_inter_nranks
=
0
# if mode is collective
# if mode is collective
...
@@ -445,7 +445,7 @@ class DistributeTranspiler(object):
...
@@ -445,7 +445,7 @@ class DistributeTranspiler(object):
def
_get_all_remote_sparse_update_op
(
self
,
main_program
):
def
_get_all_remote_sparse_update_op
(
self
,
main_program
):
sparse_update_ops
=
[]
sparse_update_ops
=
[]
sparse_update_op_types
=
[
"lookup_table"
,
"nce"
]
sparse_update_op_types
=
[
"lookup_table"
,
"nce"
,
"lookup_table_v2"
]
for
op
in
main_program
.
global_block
().
ops
:
for
op
in
main_program
.
global_block
().
ops
:
if
op
.
type
in
sparse_update_op_types
and
op
.
attr
(
if
op
.
type
in
sparse_update_op_types
and
op
.
attr
(
'remote_prefetch'
)
is
True
:
'remote_prefetch'
)
is
True
:
...
@@ -475,7 +475,7 @@ class DistributeTranspiler(object):
...
@@ -475,7 +475,7 @@ class DistributeTranspiler(object):
ops
.
append
(
op
)
ops
.
append
(
op
)
used_ops
.
append
(
idx
)
used_ops
.
append
(
idx
)
if
op_type
==
"lookup_table"
:
if
op_type
in
LOOKUP_TABLE_TYPE
:
all_ops
=
program
.
global_block
().
ops
all_ops
=
program
.
global_block
().
ops
op_idxs
=
[
all_ops
.
index
(
op
)
for
op
in
ops
]
op_idxs
=
[
all_ops
.
index
(
op
)
for
op
in
ops
]
inputs
=
[
inputs
=
[
...
@@ -521,7 +521,8 @@ class DistributeTranspiler(object):
...
@@ -521,7 +521,8 @@ class DistributeTranspiler(object):
"height_sections"
:
height_sections
,
"height_sections"
:
height_sections
,
"endpoints"
:
endpoints
,
"endpoints"
:
endpoints
,
"padding_idx"
:
padding_idx
,
"padding_idx"
:
padding_idx
,
"trainer_id"
:
self
.
trainer_id
"trainer_id"
:
self
.
trainer_id
,
"lookup_table_version"
:
op_type
})
})
else
:
else
:
raise
ValueError
(
raise
ValueError
(
...
@@ -609,10 +610,12 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
...
@@ -609,10 +610,12 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
)
)
assert
trainers_num
>
self
.
config
.
hierarchical_allreduce_inter_nranks
,
\
assert
trainers_num
>
self
.
config
.
hierarchical_allreduce_inter_nranks
,
\
"trainers_num:{} < hierarchical_allreduce_inter_nranks:{}"
.
format
(
trainers_num
,
self
.
config
.
hierarchical_allreduce_inter_nranks
)
"trainers_num:{} < hierarchical_allreduce_inter_nranks:{}"
.
format
(
trainers_num
,
self
.
config
.
hierarchical_allreduce_inter_nranks
)
assert
trainers_num
%
self
.
config
.
hierarchical_allreduce_inter_nranks
==
0
,
\
assert
trainers_num
%
self
.
config
.
hierarchical_allreduce_inter_nranks
==
0
,
\
"trainers_num:{} mod hierarchical_allreduce_inter_nranks:{} != 0"
.
format
(
trainers_num
,
self
.
config
.
hierarchical_allreduce_inter_nranks
)
"trainers_num:{} mod hierarchical_allreduce_inter_nranks:{} != 0"
.
format
(
trainers_num
,
self
.
config
.
hierarchical_allreduce_inter_nranks
)
self
.
origin_program
.
_hierarchical_allreduce_inter_nranks
=
\
self
.
origin_program
.
_hierarchical_allreduce_inter_nranks
=
\
int
(
self
.
config
.
hierarchical_allreduce_inter_nranks
)
int
(
self
.
config
.
hierarchical_allreduce_inter_nranks
)
...
@@ -778,7 +781,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
...
@@ -778,7 +781,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
decay_dummy_output
=
program
.
global_block
().
create_var
(
decay_dummy_output
=
program
.
global_block
().
create_var
(
name
=
framework
.
generate_control_dev_var_name
())
name
=
framework
.
generate_control_dev_var_name
())
if
self
.
config
.
runtime_split_send_recv
:
if
self
.
config
.
runtime_split_send_recv
:
#
#
async mode, using communicator to merge and send
# async mode, using communicator to merge and send
send_varnames
=
[
self
.
counter_var
.
name
]
send_varnames
=
[
self
.
counter_var
.
name
]
else
:
else
:
send_varnames
=
[]
send_varnames
=
[]
...
@@ -1072,7 +1075,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
...
@@ -1072,7 +1075,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
sparse_table_names
=
self
.
_get_sparse_table_names
()
sparse_table_names
=
self
.
_get_sparse_table_names
()
# self._fake_init_sparsetable(sparse_table_names)
# self._fake_init_sparsetable(sparse_table_names)
#self._delete_trainer_optimizer(is_startup=True)
#
self._delete_trainer_optimizer(is_startup=True)
for
varname
,
splited_var
in
six
.
iteritems
(
self
.
param_var_mapping
):
for
varname
,
splited_var
in
six
.
iteritems
(
self
.
param_var_mapping
):
if
varname
in
sparse_table_names
:
if
varname
in
sparse_table_names
:
...
@@ -2692,7 +2695,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
...
@@ -2692,7 +2695,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler
return
opt_ops
,
params_grads
return
opt_ops
,
params_grads
def
_get_distribute_update_vars
(
self
):
def
_get_distribute_update_vars
(
self
):
#TODO(chengmo): find more powerful and simple way to deal with these special situation
#
TODO(chengmo): find more powerful and simple way to deal with these special situation
"""
"""
This Function is used for a special model, like PyramidDnn which has pyramid hash op.
This Function is used for a special model, like PyramidDnn which has pyramid hash op.
Some Parameters don't use optimizing op to update its value, but updated in its BP process.
Some Parameters don't use optimizing op to update its value, but updated in its BP process.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录