Skip to content

Commit ded1202

Browse files
committed
change save code to run instruction
1 parent 68e5102 commit ded1202

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc

-41
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "paddle/fluid/framework/details/nan_inf_utils.h"
2121
#include "paddle/fluid/framework/executor_gc_helper.h"
2222
#include "paddle/fluid/framework/framework.pb.h"
23-
#include "paddle/fluid/framework/io/save_load_tensor.h"
2423
#include "paddle/fluid/framework/new_executor/instruction/instruction_base.h"
2524
#include "paddle/fluid/framework/new_executor/interpreter/data_transfer.h"
2625
#include "paddle/fluid/framework/new_executor/interpreter/execution_config.h"
@@ -50,8 +49,6 @@
5049

5150
PHI_DECLARE_bool(use_mkldnn);
5251
PHI_DECLARE_bool(check_nan_inf);
53-
PHI_DECLARE_string(static_runtime_data_save_path);
54-
PHI_DECLARE_bool(save_static_runtime_data);
5552

5653
namespace paddle {
5754
namespace framework {
@@ -966,44 +963,6 @@ void BuildOpFuncList(const platform::Place& place,
966963
std::rethrow_exception(std::current_exception());
967964
}
968965

969-
if (FLAGS_save_static_runtime_data) {
970-
VLOG(6) << "start to save paddle variable";
971-
auto root_path = FLAGS_static_runtime_data_save_path;
972-
for (auto& vname : op->InputVars()) {
973-
auto* var = local_scope->FindVar(vname);
974-
if (var == nullptr) continue;
975-
const phi::DenseTensor* tensor{nullptr};
976-
if (var->IsType<phi::DenseTensor>()) {
977-
tensor = &var->Get<phi::DenseTensor>();
978-
} else {
979-
VLOG(6) << vname << " is not DenseTensor";
980-
continue;
981-
}
982-
if (!tensor->IsInitialized()) continue;
983-
paddle::framework::SaveTensor(
984-
*tensor,
985-
root_path + "/saved_tensors/" + op_type + "-input-" + vname,
986-
false);
987-
}
988-
for (auto& vname : op->OutputVars(true)) {
989-
auto* var = local_scope->FindVar(vname);
990-
if (var == nullptr) continue;
991-
const phi::DenseTensor* tensor{nullptr};
992-
if (var->IsType<phi::DenseTensor>()) {
993-
tensor = &var->Get<phi::DenseTensor>();
994-
} else {
995-
VLOG(6) << vname << " is not DenseTensor";
996-
continue;
997-
}
998-
if (!tensor->IsInitialized()) continue;
999-
paddle::framework::SaveTensor(
1000-
*tensor,
1001-
root_path + "/saved_tensors/" + op_type + "-output-" + vname,
1002-
false);
1003-
}
1004-
VLOG(6) << "end save paddle variable";
1005-
}
1006-
1007966
if (FLAGS_check_nan_inf) {
1008967
VLOG(4) << "Check nan/inf";
1009968
try {

paddle/fluid/framework/new_executor/program_interpreter.cc

+41-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "paddle/fluid/platform/cuda_graph_with_memory_pool.h"
3434
#include "paddle/phi/backends/device_manager.h"
3535
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
36+
#include "paddle/fluid/framework/io/save_load_tensor.h"
3637
#include "paddle/fluid/platform/device/gpu/nccl_helper.h"
3738
#include "paddle/phi/core/distributed/comm_context_manager.h"
3839
#include "paddle/phi/core/distributed/nccl_comm_context.h"
@@ -42,7 +43,8 @@ PHI_DECLARE_bool(dynamic_static_unified_comm);
4243

4344
PD_DECLARE_bool(enable_host_event_recorder_hook);
4445
PD_DECLARE_bool(log_memory_stats);
45-
46+
PHI_DECLARE_string(static_runtime_data_save_path);
47+
PHI_DECLARE_bool(save_static_runtime_data);
4648
namespace paddle {
4749
namespace framework {
4850

@@ -1053,6 +1055,44 @@ void ProgramInterpreter::RunOperator(const Instruction& instr_node) {
10531055
}
10541056
}
10551057

1058+
if (op_with_kernel != nullptr && FLAGS_save_static_runtime_data) {
1059+
VLOG(6) << "start to save paddle variable";
1060+
auto root_path = FLAGS_static_runtime_data_save_path;
1061+
for (auto& vname : op->InputVars()) {
1062+
auto* var = local_scope->FindVar(vname);
1063+
if (var == nullptr) continue;
1064+
const phi::DenseTensor* tensor{nullptr};
1065+
if (var->IsType<phi::DenseTensor>()) {
1066+
tensor = &var->Get<phi::DenseTensor>();
1067+
} else {
1068+
VLOG(6) << vname << " is not DenseTensor";
1069+
continue;
1070+
}
1071+
if (!tensor->IsInitialized()) continue;
1072+
paddle::framework::SaveTensor(
1073+
*tensor,
1074+
root_path + "/saved_tensors/" + op->Type() + "-input-" + vname,
1075+
false);
1076+
}
1077+
for (auto& vname : op->OutputVars(true)) {
1078+
auto* var = local_scope->FindVar(vname);
1079+
if (var == nullptr) continue;
1080+
const phi::DenseTensor* tensor{nullptr};
1081+
if (var->IsType<phi::DenseTensor>()) {
1082+
tensor = &var->Get<phi::DenseTensor>();
1083+
} else {
1084+
VLOG(6) << vname << " is not DenseTensor";
1085+
continue;
1086+
}
1087+
if (!tensor->IsInitialized()) continue;
1088+
paddle::framework::SaveTensor(
1089+
*tensor,
1090+
root_path + "/saved_tensors/" + op->Type() + "-output-" + vname,
1091+
false);
1092+
}
1093+
VLOG(6) << "end save paddle variable";
1094+
}
1095+
10561096
// for debug nan/inf
10571097
if (op_with_kernel != nullptr && FLAGS_check_nan_inf) {
10581098
VLOG(4) << "Check nan/inf";

0 commit comments

Comments
 (0)