未验证 提交 63d9fe33 编写于 作者: L lujun 提交者: GitHub

Merge pull request #17034 from seiriosPlus/fix/save_for_selected_rows

fix bug in save, test=develop
...@@ -31,8 +31,8 @@ class SaveOp : public framework::OperatorWithKernel { ...@@ -31,8 +31,8 @@ class SaveOp : 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(ctx.Input<framework::LoDTensor>("X")->type(), auto data_type = framework::GetDataTypeOfVar(ctx.InputVar("X"));
ctx.GetPlace()); return framework::OpKernelType(data_type, ctx.device_context());
} }
}; };
......
...@@ -103,12 +103,22 @@ class SaveOpKernel : public framework::OpKernel<T> { ...@@ -103,12 +103,22 @@ class SaveOpKernel : public framework::OpKernel<T> {
const platform::Place &place, const platform::Place &place,
const framework::Variable *var) const { const framework::Variable *var) const {
framework::Variable *out_put_var = ctx.OutputVar(LOOKUP_TABLE_PATH); framework::Variable *out_put_var = ctx.OutputVar(LOOKUP_TABLE_PATH);
PADDLE_ENFORCE(
out_put_var != nullptr, auto file_path = ctx.Attr<std::string>("file_path");
"Can not find variable kLookupTablePath for SaveSelectedRows"); auto overwrite = ctx.Attr<bool>("overwrite");
std::string filename = file_path;
if (out_put_var != nullptr) {
auto *lt_var = out_put_var->GetMutable<std::string>(); auto *lt_var = out_put_var->GetMutable<std::string>();
filename = *lt_var;
}
if (FileExists(filename) && !overwrite) {
PADDLE_THROW("%s is existed, cannot save to it when overwrite=false",
filename, overwrite);
}
std::string filename = lt_var->data();
VLOG(4) << "SaveSelectedRows get File name: " << filename; VLOG(4) << "SaveSelectedRows get File name: " << filename;
MkDirRecursively(DirName(filename).c_str()); MkDirRecursively(DirName(filename).c_str());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册