Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f04b23ad
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看板
提交
f04b23ad
编写于
5月 15, 2018
作者:
T
tangwei12
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add checkpoint_load, update checkpoint save
上级
3c820064
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
103 addition
and
8 deletion
+103
-8
paddle/fluid/operators/CMakeLists.txt
paddle/fluid/operators/CMakeLists.txt
+2
-1
paddle/fluid/operators/checkpoint_load_op.cc
paddle/fluid/operators/checkpoint_load_op.cc
+87
-0
paddle/fluid/operators/checkpoint_op_test.cc
paddle/fluid/operators/checkpoint_op_test.cc
+0
-0
paddle/fluid/operators/checkpoint_save_op.cc
paddle/fluid/operators/checkpoint_save_op.cc
+14
-7
未找到文件。
paddle/fluid/operators/CMakeLists.txt
浏览文件 @
f04b23ad
...
@@ -243,6 +243,7 @@ op_library(load_op DEPS lod_tensor)
...
@@ -243,6 +243,7 @@ op_library(load_op DEPS lod_tensor)
op_library
(
save_combine_op DEPS lod_tensor
)
op_library
(
save_combine_op DEPS lod_tensor
)
op_library
(
load_combine_op DEPS lod_tensor
)
op_library
(
load_combine_op DEPS lod_tensor
)
op_library
(
checkpoint_save_op DEPS lod_tensor
)
op_library
(
checkpoint_save_op DEPS lod_tensor
)
op_library
(
checkpoint_load_op DEPS lod_tensor
)
op_library
(
concat_op DEPS concat
)
op_library
(
concat_op DEPS concat
)
# FIXME(thuan): Move CSP operators to paddle/fluid/framework/operators/concurrency
# FIXME(thuan): Move CSP operators to paddle/fluid/framework/operators/concurrency
...
@@ -278,6 +279,6 @@ cc_test(beam_search_op_test SRCS beam_search_op_test.cc DEPS lod_tensor beam_sea
...
@@ -278,6 +279,6 @@ cc_test(beam_search_op_test SRCS beam_search_op_test.cc DEPS lod_tensor beam_sea
cc_test
(
strided_memcpy_test SRCS strided_memcpy_test.cc DEPS tensor memory
)
cc_test
(
strided_memcpy_test SRCS strided_memcpy_test.cc DEPS tensor memory
)
cc_test
(
save_load_op_test SRCS save_load_op_test.cc DEPS save_op load_op
)
cc_test
(
save_load_op_test SRCS save_load_op_test.cc DEPS save_op load_op
)
cc_test
(
save_load_combine_op_test SRCS save_load_combine_op_test.cc DEPS save_combine_op load_combine_op
)
cc_test
(
save_load_combine_op_test SRCS save_load_combine_op_test.cc DEPS save_combine_op load_combine_op
)
cc_test
(
checkpoint_
save_op_test SRCS checkpoint_save_op_test.cc DEPS checkpoint_save
_op
)
cc_test
(
checkpoint_
op_test SRCS checkpoint_op_test.cc DEPS checkpoint_save_op checkpoint_load
_op
)
nv_test
(
nccl_op_test SRCS nccl_op_test.cu.cc DEPS nccl_op gpu_info device_context
)
nv_test
(
nccl_op_test SRCS nccl_op_test.cu.cc DEPS nccl_op gpu_info device_context
)
nv_test
(
dropout_op_test SRCS dropout_op_test.cc DEPS dropout_op tensor
)
nv_test
(
dropout_op_test SRCS dropout_op_test.cc DEPS dropout_op tensor
)
paddle/fluid/operators/checkpoint_load_op.cc
0 → 100644
浏览文件 @
f04b23ad
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <stdint.h>
#include <sys/stat.h>
#include <fstream>
#include <numeric>
#include <sstream>
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/data_type_transform.h"
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/platform/device_context.h"
namespace
paddle
{
namespace
operators
{
constexpr
char
kSEP
=
'/'
;
// write empty file named _SUCCESS
const
char
SUCCESS
[]
=
"_SUCCESS"
;
static
bool
FileExists
(
const
std
::
string
&
filepath
)
{
struct
stat
buffer
;
return
(
stat
(
filepath
.
c_str
(),
&
buffer
)
==
0
);
}
static
std
::
string
DirName
(
const
std
::
string
&
filepath
)
{
auto
pos
=
filepath
.
rfind
(
kSEP
);
if
(
pos
==
std
::
string
::
npos
)
{
return
""
;
}
return
filepath
.
substr
(
0
,
pos
);
}
class
CheckpointLoadOp
:
public
framework
::
OperatorBase
{
public:
CheckpointLoadOp
(
const
std
::
string
&
type
,
const
framework
::
VariableNameMap
&
inputs
,
const
framework
::
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{}
private:
void
RunImpl
(
const
framework
::
Scope
&
scope
,
const
platform
::
Place
&
place
)
const
override
{
auto
dir
=
Attr
<
std
::
string
>
(
"dir"
);
bool
is_present
=
FileExists
(
dir
);
if
(
!
is_present
)
{
return
;
}
// UPDATE LATER ...
}
};
class
CheckpointLoadOpProtoMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
CheckpointLoadOpProtoMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddAttr
<
std
::
string
>
(
"dir"
,
"(string)"
"The
\"
file_path
\"
where the LoDTensor variables will be saved."
)
.
AddCustomChecker
(
[](
const
std
::
string
&
path
)
{
return
!
path
.
empty
();
});
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
checkpoint_load
,
ops
::
CheckpointLoadOp
,
ops
::
CheckpointLoadOpProtoMaker
);
paddle/fluid/operators/checkpoint_
save_
op_test.cc
→
paddle/fluid/operators/checkpoint_op_test.cc
浏览文件 @
f04b23ad
文件已移动
paddle/fluid/operators/checkpoint_save_op.cc
浏览文件 @
f04b23ad
...
@@ -27,8 +27,6 @@ limitations under the License. */
...
@@ -27,8 +27,6 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
// TODO(sidgoyal78): These function are needed by other files (save_op), move
// them to paddle::filesystem namespace. (as noted by yuyang18 in save_op).
constexpr
char
kSEP
=
'/'
;
constexpr
char
kSEP
=
'/'
;
// write empty file named _SUCCESS
// write empty file named _SUCCESS
const
char
SUCCESS
[]
=
"_SUCCESS"
;
const
char
SUCCESS
[]
=
"_SUCCESS"
;
...
@@ -82,7 +80,14 @@ class CheckpointSaveOp : public framework::OperatorBase {
...
@@ -82,7 +80,14 @@ class CheckpointSaveOp : public framework::OperatorBase {
// overwrite=false",
// overwrite=false",
// dir, overwrite);
// dir, overwrite);
}
}
MkDirRecursively
(
dir
.
c_str
());
auto
serial_var_name
=
Output
(
"Serial"
);
auto
*
serial_var
=
scope
.
FindVar
(
serial_var_name
);
std
::
string
*
serial_num
=
serial_var
->
GetMutable
<
std
::
string
>
();
serial_num
->
append
(
"0"
);
dir
.
append
(
"/"
);
dir
.
append
(
serial_num
);
MkDirRecursively
(
dir
.
c_str
());
MkDirRecursively
(
dir
.
c_str
());
auto
inp_var_names
=
Inputs
(
"X"
);
auto
inp_var_names
=
Inputs
(
"X"
);
...
@@ -93,6 +98,7 @@ class CheckpointSaveOp : public framework::OperatorBase {
...
@@ -93,6 +98,7 @@ class CheckpointSaveOp : public framework::OperatorBase {
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
auto
&
dev_ctx
=
*
pool
.
Get
(
place
);
auto
&
dev_ctx
=
*
pool
.
Get
(
place
);
// todo (tangwei) made it async
for
(
size_t
i
=
0
;
i
<
inp_var_names
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
inp_var_names
.
size
();
i
++
)
{
auto
*
var
=
scope
.
FindVar
(
inp_var_names
[
i
]);
auto
*
var
=
scope
.
FindVar
(
inp_var_names
[
i
]);
std
::
string
var_file
;
std
::
string
var_file
;
...
@@ -132,19 +138,20 @@ class CheckpointSaveOpProtoMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -132,19 +138,20 @@ class CheckpointSaveOpProtoMaker : public framework::OpProtoAndCheckerMaker {
"X"
,
"X"
,
"(vector) Input LoDTensors that need to be saved together in a file."
)
"(vector) Input LoDTensors that need to be saved together in a file."
)
.
AsDuplicable
();
.
AsDuplicable
();
AddOutput
(
"Serial"
,
"the serial number"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
SaveCombin
e operator
CheckpointSav
e operator
This operator will serialize and write a list of input LoDTensor variables
This operator will serialize and write a list of input LoDTensor variables
to a file on disk.
to a file on disk.
)DOC"
);
)DOC"
);
AddAttr
<
bool
>
(
"overwrite"
,
AddAttr
<
bool
>
(
"overwrite"
,
"(boolean, default
tru
e)"
"(boolean, default
fals
e)"
"
Overwrite the output file
if it exists."
)
"
Delete the output dir
if it exists."
)
.
SetDefault
(
tru
e
);
.
SetDefault
(
fals
e
);
AddAttr
<
std
::
string
>
(
AddAttr
<
std
::
string
>
(
"
file_path
"
,
"
dir
"
,
"(string)"
"(string)"
"The
\"
file_path
\"
where the LoDTensor variables will be saved."
)
"The
\"
file_path
\"
where the LoDTensor variables will be saved."
)
.
AddCustomChecker
(
.
AddCustomChecker
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录