Skip to content

Commit 63d9fe3

Browse files
authored
Merge pull request PaddlePaddle#17034 from seiriosPlus/fix/save_for_selected_rows
fix bug in save, test=develop
2 parents f188b37 + 45136b1 commit 63d9fe3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

paddle/fluid/operators/save_op.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class SaveOp : public framework::OperatorWithKernel {
3131
protected:
3232
framework::OpKernelType GetExpectedKernelType(
3333
const framework::ExecutionContext &ctx) const override {
34-
return framework::OpKernelType(ctx.Input<framework::LoDTensor>("X")->type(),
35-
ctx.GetPlace());
34+
auto data_type = framework::GetDataTypeOfVar(ctx.InputVar("X"));
35+
return framework::OpKernelType(data_type, ctx.device_context());
3636
}
3737
};
3838

paddle/fluid/operators/save_op.h

+15-5
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,22 @@ class SaveOpKernel : public framework::OpKernel<T> {
103103
const platform::Place &place,
104104
const framework::Variable *var) const {
105105
framework::Variable *out_put_var = ctx.OutputVar(LOOKUP_TABLE_PATH);
106-
PADDLE_ENFORCE(
107-
out_put_var != nullptr,
108-
"Can not find variable kLookupTablePath for SaveSelectedRows");
109-
auto *lt_var = out_put_var->GetMutable<std::string>();
110106

111-
std::string filename = lt_var->data();
107+
auto file_path = ctx.Attr<std::string>("file_path");
108+
auto overwrite = ctx.Attr<bool>("overwrite");
109+
110+
std::string filename = file_path;
111+
112+
if (out_put_var != nullptr) {
113+
auto *lt_var = out_put_var->GetMutable<std::string>();
114+
filename = *lt_var;
115+
}
116+
117+
if (FileExists(filename) && !overwrite) {
118+
PADDLE_THROW("%s is existed, cannot save to it when overwrite=false",
119+
filename, overwrite);
120+
}
121+
112122
VLOG(4) << "SaveSelectedRows get File name: " << filename;
113123

114124
MkDirRecursively(DirName(filename).c_str());

0 commit comments

Comments
 (0)