From f9d4b9dabfcf33de11154aa5dc67be5537a34bb8 Mon Sep 17 00:00:00 2001 From: tangwei12 Date: Thu, 17 May 2018 22:49:40 +0800 Subject: [PATCH] fix auto serial_num has no initializer --- paddle/fluid/operators/checkpoint_load_op.cc | 8 ++++---- paddle/fluid/operators/checkpoint_save_op.cc | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/operators/checkpoint_load_op.cc b/paddle/fluid/operators/checkpoint_load_op.cc index 0f0d989ccd2..5fd3a7af9cf 100644 --- a/paddle/fluid/operators/checkpoint_load_op.cc +++ b/paddle/fluid/operators/checkpoint_load_op.cc @@ -112,14 +112,14 @@ class CheckpointLoadOp : public framework::OperatorBase { std::string serial_var_name = std::string(SERIAL_VAR); auto *serial_var = scope.FindVar(serial_var_name); - auto *serial_num; + if (serial_var == nullptr) { *serial_var = scope.Var(serial_var_name); - *serial_num = serial_var->GetMutable(); - serial_num->append("0"); + auto *serial_tmp = serial_var->GetMutable(); + serial_tmp->append("0"); } - *serial_num = serial_var->GetMutable(); + auto *serial_num = serial_var->GetMutable(); VLOG(1) << "CheckpointLoadOp set " << SERIAL_NUMBER << " value: " << serial_num; diff --git a/paddle/fluid/operators/checkpoint_save_op.cc b/paddle/fluid/operators/checkpoint_save_op.cc index 3c2cc50ac49..5fccefeed25 100644 --- a/paddle/fluid/operators/checkpoint_save_op.cc +++ b/paddle/fluid/operators/checkpoint_save_op.cc @@ -84,14 +84,13 @@ class CheckpointSaveOp : public framework::OperatorBase { std::string serial_var_name = std::string(SERIAL_VAR); auto *serial_var = scope.FindVar(serial_var_name); - auto *serial_num; + if (serial_var == nullptr) { *serial_var = scope.Var(serial_var_name); - *serial_num = serial_var->GetMutable(); - serial_num->append("0"); + *serial_tmp = serial_var->GetMutable(); + serial_tmp->append("0"); } - - *serial_num = serial_var->GetMutable(); + auto *serial_num = serial_var->GetMutable(); VLOG(1) << "CheckpointSaveOp get " << SERIAL_NUMBER << " value: " << serial_num; -- GitLab