Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0075a7b0
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看板
提交
0075a7b0
编写于
9月 22, 2020
作者:
S
seiriosPlus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add save delta for large scale kv
上级
20d435b1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
29 deletion
+38
-29
paddle/fluid/operators/distributed/large_scale_kv.h
paddle/fluid/operators/distributed/large_scale_kv.h
+38
-29
未找到文件。
paddle/fluid/operators/distributed/large_scale_kv.h
浏览文件 @
0075a7b0
...
...
@@ -246,6 +246,7 @@ struct VALUE {
std
::
vector
<
std
::
string
>
names_
;
int
count_
;
bool
seen_after_save_
;
int
unseen_days_
;
bool
is_entry_
;
std
::
vector
<
std
::
vector
<
float
>>
values_
;
...
...
@@ -322,6 +323,7 @@ class ValueBlock {
auto
value
=
new
VALUE
(
value_names_
);
value
->
set
(
values
);
value
->
seen_after_save_
=
true
;
value
->
count_
=
count
;
values_
[
id
]
=
value
;
}
...
...
@@ -590,9 +592,9 @@ class SparseVariable {
}
}
void
Save
(
const
std
::
string
&
dirname
)
{
void
Save
(
const
std
::
string
&
dirname
,
const
int
mode
=
0
)
{
rwlock_
->
WRLock
();
VLOG
(
1
)
<<
"save "
<<
meta_
.
name
<<
" in dir: "
<<
dirname
<<
" begin"
;
VLOG
(
3
)
<<
"save "
<<
meta_
.
name
<<
" in dir: "
<<
dirname
<<
" begin"
;
MkDirRecursively
(
dirname
.
c_str
());
...
...
@@ -601,22 +603,15 @@ class SparseVariable {
auto
filename
=
string
::
Sprintf
(
"%s/%s"
,
dirname
,
value_name
);
filenames
.
push_back
(
filename
);
}
SaveToSelectedRows
(
filenames
,
meta_
.
value_names
);
// // save sparse to text
// std::vector<std::string> txt_filenames;
// for (auto &value_name : meta_.value_names) {
// auto filename = string::Sprintf("%s/%s.txt", dirname, value_name);
// txt_filenames.push_back(filename);
// }
// SaveToText(txt_filenames, meta_.value_names);
VLOG
(
1
)
<<
"save "
<<
meta_
.
name
<<
" in dir: "
<<
dirname
<<
" done"
;
SaveToSelectedRows
(
filenames
,
meta_
.
value_names
,
mode
);
VLOG
(
3
)
<<
"save "
<<
meta_
.
name
<<
" in dir: "
<<
dirname
<<
" done"
;
rwlock_
->
UNLock
();
}
void
SaveToSelectedRows
(
const
std
::
vector
<
std
::
string
>
&
filenames
,
const
std
::
vector
<
std
::
string
>
&
valuenames
)
{
const
std
::
vector
<
std
::
string
>
&
valuenames
,
const
int
mode
)
{
for
(
auto
&
value_name
:
valuenames
)
{
auto
it
=
std
::
find
(
meta_
.
value_names
.
begin
(),
meta_
.
value_names
.
end
(),
value_name
);
...
...
@@ -630,14 +625,30 @@ class SparseVariable {
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
auto
&
dev_ctx
=
*
pool
.
Get
(
place
);
int64_t
ids_num
=
0
;
std
::
vector
<
int64_t
>
ids
;
for
(
auto
&
block
:
shard_blocks_
)
{
ids_num
+=
block
->
values_
.
size
();
for
(
auto
value
:
block
->
values_
)
{
bool
id_need_save
=
false
;
// save all params
if
(
mode
==
0
)
{
id_need_save
=
true
;
}
else
{
id_need_save
=
value
.
second
.
seen_after_save_
;
}
if
(
id_need_save
)
{
ids
.
push_back
(
value
.
first
);
}
value
.
second
.
seen_after_save_
=
false
;
}
}
VLOG
(
3
)
<<
"save "
<<
ids
.
size
()
<<
" feasigns for "
<<
meta_
.
name
<<
" with mode: "
<<
mode
;
std
::
vector
<
std
::
shared_ptr
<
framework
::
Variable
>>
variables
;
std
::
vector
<
float
*>
tensors
;
std
::
vector
<
int64_t
>
ids
;
std
::
vector
<
int64_t
>
dims
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
filenames
.
size
());
i
++
)
{
...
...
@@ -646,7 +657,7 @@ class SparseVariable {
auto
*
slr
=
var
->
GetMutable
<
framework
::
SelectedRows
>
();
auto
*
src_t
=
slr
->
mutable_value
();
src_t
->
Resize
({
ids
_num
,
dim
});
src_t
->
Resize
({
ids
.
size
()
,
dim
});
auto
*
value
=
src_t
->
mutable_data
<
float
>
(
place
);
dims
.
push_back
(
dim
);
...
...
@@ -654,20 +665,18 @@ class SparseVariable {
tensors
.
push_back
(
value
);
}
int64_t
offset
=
0
;
for
(
auto
&
block
:
shard_blocks_
)
{
for
(
auto
value
:
block
->
values_
)
{
ids
.
push_back
(
value
.
first
);
std
::
vector
<
std
::
vector
<
float
>
*>
vss
=
value
.
second
->
get
(
valuenames
);
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
vss
.
size
());
i
++
)
{
auto
&
vs
=
vss
[
i
];
std
::
memcpy
(
tensors
[
i
]
+
offset
*
dims
[
i
],
vs
->
data
(),
sizeof
(
float
)
*
dims
[
i
]);
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>
*>>
*
values
;
Get
(
ids
,
variables
,
values
);
offset
+=
1
;
int64_t
offset
=
0
;
for
(
auto
*
value
:
values
)
{
auto
vss
=
value
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
vss
.
size
());
i
++
)
{
auto
&
vs
=
vss
[
i
];
std
::
memcpy
(
tensors
[
i
]
+
offset
*
dims
[
i
],
vs
->
data
(),
sizeof
(
float
)
*
dims
[
i
]);
}
offset
+=
1
;
}
for
(
auto
&
var
:
variables
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录