write checkpoint_load code simply

shanyi15-patch-3
tangwei12 7 years ago
parent c80125f286
commit 2e25e739f3

@ -36,14 +36,6 @@ static bool FileExists(const std::string &filepath) {
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,

@ -16,6 +16,7 @@ limitations under the License. */
#include "paddle/fluid/framework/op_registry.h"
USE_NO_KERNEL_OP(checkpoint_save)
USE_NO_KERNEL_OP(checkpoint_load)
TEST(CheckpointSaveOp, CPU) {
paddle::framework::Scope scope;
@ -37,10 +38,27 @@ TEST(CheckpointSaveOp, CPU) {
expect[i] = static_cast<float>(paddle::platform::float16(i));
}
scope.Var("SERIAL_NUMBER");
paddle::framework::AttributeMap attrs;
attrs.insert({"dir", std::string("tensor/ckpt")});
attrs.insert({"dir", std::string("ckpt")});
auto save_op = paddle::framework::OpRegistry::CreateOp(
"checkpoint_save", {{"X", {"test_var"}}}, {}, attrs);
"checkpoint_save", {{"X", {"test_var"}}}, {{"Serial", {"SERIAL_NUMBER"}}},
attrs);
save_op->Run(scope, place);
}
TEST(CheckpointLoadOp, CPU) {
paddle::framework::Scope scope;
paddle::platform::CPUPlace place;
scope.Var("test_var");
paddle::framework::AttributeMap attrs;
attrs.insert({"dir", std::string("ckpt")});
auto save_op =
paddle::framework::OpRegistry::CreateOp("checkpoint_load", {}, {}, attrs);
save_op->Run(scope, place);
}

Loading…
Cancel
Save