Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
37fcf03a
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看板
未验证
提交
37fcf03a
编写于
4月 10, 2020
作者:
Z
zhongpu
提交者:
GitHub
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Op (Save/Load) error message enhancement, test=develop (#23650)
上级
c6d14bc8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
36 addition
and
28 deletion
+36
-28
paddle/fluid/operators/load_op.h
paddle/fluid/operators/load_op.h
+13
-10
paddle/fluid/operators/save_op.h
paddle/fluid/operators/save_op.h
+23
-18
未找到文件。
paddle/fluid/operators/load_op.h
浏览文件 @
37fcf03a
...
@@ -34,26 +34,29 @@ class LoadOpKernel : public framework::OpKernel<T> {
...
@@ -34,26 +34,29 @@ class LoadOpKernel : public framework::OpKernel<T> {
// it to save an output stream.
// it to save an output stream.
auto
filename
=
ctx
.
Attr
<
std
::
string
>
(
"file_path"
);
auto
filename
=
ctx
.
Attr
<
std
::
string
>
(
"file_path"
);
std
::
ifstream
fin
(
filename
,
std
::
ios
::
binary
);
std
::
ifstream
fin
(
filename
,
std
::
ios
::
binary
);
PADDLE_ENFORCE
(
static_cast
<
bool
>
(
fin
),
"Cannot open file %s for load op"
,
PADDLE_ENFORCE_EQ
(
static_cast
<
bool
>
(
fin
),
true
,
filename
);
platform
::
errors
::
Unavailable
(
"Load operator fail to open file %s, please check "
"whether the model file is complete or damaged."
,
filename
));
auto
out_var_name
=
ctx
.
OutputNames
(
"Out"
).
data
();
auto
out_var_name
=
ctx
.
OutputNames
(
"Out"
).
data
();
auto
*
out_var
=
ctx
.
OutputVar
(
"Out"
);
auto
*
out_var
=
ctx
.
OutputVar
(
"Out"
);
PADDLE_ENFORCE
(
out_var
!=
nullptr
,
"Output variable %s cannot be found "
,
PADDLE_ENFORCE
_NOT_NULL
(
out_var_name
);
out_var
,
platform
::
errors
::
InvalidArgument
(
PADDLE_ENFORCE
(
out_var
!=
nullptr
,
"Output variable cannot be found "
);
"The variable %s to be loaded cannot be found."
,
out_var_name
)
);
if
(
out_var
->
IsType
<
framework
::
LoDTensor
>
())
{
if
(
out_var
->
IsType
<
framework
::
LoDTensor
>
())
{
LoadLodTensor
(
fin
,
place
,
out_var
,
ctx
);
LoadLodTensor
(
fin
,
place
,
out_var
,
ctx
);
}
else
if
(
out_var
->
IsType
<
framework
::
SelectedRows
>
())
{
}
else
if
(
out_var
->
IsType
<
framework
::
SelectedRows
>
())
{
LoadSelectedRows
(
fin
,
place
,
out_var
);
LoadSelectedRows
(
fin
,
place
,
out_var
);
}
else
{
}
else
{
PADDLE_
ENFORCE
(
PADDLE_
THROW
(
platform
::
errors
::
InvalidArgument
(
false
,
"Load operator only supports loading LoDTensor and SelectedRows "
"
Load only support LoDTensor and SelectedRows
, %s has wrong type"
,
"
variable
, %s has wrong type"
,
out_var_name
);
out_var_name
)
)
;
}
}
}
}
...
...
paddle/fluid/operators/save_op.h
浏览文件 @
37fcf03a
...
@@ -41,18 +41,19 @@ class SaveOpKernel : public framework::OpKernel<T> {
...
@@ -41,18 +41,19 @@ class SaveOpKernel : public framework::OpKernel<T> {
auto
*
input_var
=
ctx
.
InputVar
(
"X"
);
auto
*
input_var
=
ctx
.
InputVar
(
"X"
);
auto
iname
=
ctx
.
InputNames
(
"X"
).
data
();
auto
iname
=
ctx
.
InputNames
(
"X"
).
data
();
PADDLE_ENFORCE
(
input_var
!=
nullptr
,
"Cannot find variable %s for save_op"
,
PADDLE_ENFORCE_NOT_NULL
(
iname
);
input_var
,
platform
::
errors
::
InvalidArgument
(
"The variable %s to be saved cannot be found."
,
iname
));
if
(
input_var
->
IsType
<
framework
::
LoDTensor
>
())
{
if
(
input_var
->
IsType
<
framework
::
LoDTensor
>
())
{
SaveLodTensor
(
ctx
,
place
,
input_var
);
SaveLodTensor
(
ctx
,
place
,
input_var
);
}
else
if
(
input_var
->
IsType
<
framework
::
SelectedRows
>
())
{
}
else
if
(
input_var
->
IsType
<
framework
::
SelectedRows
>
())
{
SaveSelectedRows
(
ctx
,
place
,
input_var
);
SaveSelectedRows
(
ctx
,
place
,
input_var
);
}
else
{
}
else
{
PADDLE_
ENFORCE
(
PADDLE_
THROW
(
platform
::
errors
::
InvalidArgument
(
false
,
"Save operator only supports saving LoDTensor and SelectedRows "
"
SaveOp only support LoDTensor and SelectedRows
, %s has wrong type"
,
"
variable
, %s has wrong type"
,
iname
);
iname
)
)
;
}
}
}
}
...
@@ -62,10 +63,11 @@ class SaveOpKernel : public framework::OpKernel<T> {
...
@@ -62,10 +63,11 @@ class SaveOpKernel : public framework::OpKernel<T> {
auto
filename
=
ctx
.
Attr
<
std
::
string
>
(
"file_path"
);
auto
filename
=
ctx
.
Attr
<
std
::
string
>
(
"file_path"
);
auto
overwrite
=
ctx
.
Attr
<
bool
>
(
"overwrite"
);
auto
overwrite
=
ctx
.
Attr
<
bool
>
(
"overwrite"
);
if
(
FileExists
(
filename
)
&&
!
overwrite
)
{
PADDLE_ENFORCE_EQ
(
PADDLE_THROW
(
"%s is existed, cannot save to it when overwrite=false"
,
FileExists
(
filename
)
&&
!
overwrite
,
false
,
filename
,
overwrite
);
platform
::
errors
::
PreconditionNotMet
(
}
"%s exists!, cannot save to it when overwrite is set to false."
,
filename
,
overwrite
));
MkDirRecursively
(
DirName
(
filename
).
c_str
());
MkDirRecursively
(
DirName
(
filename
).
c_str
());
...
@@ -78,8 +80,9 @@ class SaveOpKernel : public framework::OpKernel<T> {
...
@@ -78,8 +80,9 @@ class SaveOpKernel : public framework::OpKernel<T> {
// FIXME(yuyang18): We save variable to local file now, but we should change
// FIXME(yuyang18): We save variable to local file now, but we should change
// it to save an output stream.
// it to save an output stream.
std
::
ofstream
fout
(
filename
,
std
::
ios
::
binary
);
std
::
ofstream
fout
(
filename
,
std
::
ios
::
binary
);
PADDLE_ENFORCE
(
static_cast
<
bool
>
(
fout
),
"Cannot open %s to write"
,
PADDLE_ENFORCE_EQ
(
static_cast
<
bool
>
(
fout
),
true
,
filename
);
platform
::
errors
::
Unavailable
(
"Cannot open %s to save variables."
,
filename
));
auto
save_as_fp16
=
ctx
.
Attr
<
bool
>
(
"save_as_fp16"
);
auto
save_as_fp16
=
ctx
.
Attr
<
bool
>
(
"save_as_fp16"
);
auto
in_dtype
=
tensor
.
type
();
auto
in_dtype
=
tensor
.
type
();
...
@@ -117,10 +120,11 @@ class SaveOpKernel : public framework::OpKernel<T> {
...
@@ -117,10 +120,11 @@ class SaveOpKernel : public framework::OpKernel<T> {
}
}
}
}
if
(
FileExists
(
filename
)
&&
!
overwrite
)
{
PADDLE_ENFORCE_EQ
(
PADDLE_THROW
(
"%s is existed, cannot save to it when overwrite=false"
,
FileExists
(
filename
)
&&
!
overwrite
,
false
,
filename
,
overwrite
);
platform
::
errors
::
PreconditionNotMet
(
}
"%s exists!, cannot save to it when overwrite is set to false."
,
filename
,
overwrite
));
VLOG
(
4
)
<<
"SaveSelectedRows get File name: "
<<
filename
;
VLOG
(
4
)
<<
"SaveSelectedRows get File name: "
<<
filename
;
...
@@ -135,8 +139,9 @@ class SaveOpKernel : public framework::OpKernel<T> {
...
@@ -135,8 +139,9 @@ class SaveOpKernel : public framework::OpKernel<T> {
// FIXME(yuyang18): We save variable to local file now, but we should change
// FIXME(yuyang18): We save variable to local file now, but we should change
// it to save an output stream.
// it to save an output stream.
std
::
ofstream
fout
(
filename
,
std
::
ios
::
binary
);
std
::
ofstream
fout
(
filename
,
std
::
ios
::
binary
);
PADDLE_ENFORCE
(
static_cast
<
bool
>
(
fout
),
"Cannot open %s to write"
,
PADDLE_ENFORCE_EQ
(
static_cast
<
bool
>
(
fout
),
true
,
filename
);
platform
::
errors
::
Unavailable
(
"Cannot open %s to save variables."
,
filename
));
framework
::
SerializeToStream
(
fout
,
selectedRows
,
dev_ctx
);
framework
::
SerializeToStream
(
fout
,
selectedRows
,
dev_ctx
);
fout
.
close
();
fout
.
close
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录