未验证 提交 328195d7 编写于 作者: N niuliling123 提交者: GitHub

Delete temp param in eager_gen (#53047)

* Delete temp param in eager_gen
上级 b02687cc
...@@ -56,11 +56,9 @@ paddle::Tensor add_n_ad_func(const std::vector<paddle::Tensor>& x) { ...@@ -56,11 +56,9 @@ paddle::Tensor add_n_ad_func(const std::vector<paddle::Tensor>& x) {
<< "add_n_ad_func"; << "add_n_ad_func";
auto api_result = paddle::experimental::add_n(x); auto api_result = paddle::experimental::add_n(x);
std::string forward_trace = "";
// Check NaN and Inf if needed // Check NaN and Inf if needed
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
egr::CheckTensorHasNanOrInf("add_n", api_result); egr::CheckTensorHasNanOrInf("add_n", api_result);
forward_trace = egr::Controller::Instance().GetPythonStack();
} }
// Get Outputs // Get Outputs
...@@ -89,7 +87,7 @@ paddle::Tensor add_n_ad_func(const std::vector<paddle::Tensor>& x) { ...@@ -89,7 +87,7 @@ paddle::Tensor add_n_ad_func(const std::vector<paddle::Tensor>& x) {
// Set forward's stack // Set forward's stack
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
grad_node->SetForwardTrace(forward_trace); grad_node->SetForwardTrace(egr::Controller::Instance().GetPythonStack());
} }
// SetAttributes if needed // SetAttributes if needed
......
...@@ -110,11 +110,9 @@ paddle::Tensor conv2d_ad_func(const paddle::Tensor& input, ...@@ -110,11 +110,9 @@ paddle::Tensor conv2d_ad_func(const paddle::Tensor& input,
dilations, dilations,
groups, groups,
data_format); data_format);
std::string forward_trace = "";
// Check NaN and Inf if needed // Check NaN and Inf if needed
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
egr::CheckTensorHasNanOrInf("conv2d", api_result); egr::CheckTensorHasNanOrInf("conv2d", api_result);
forward_trace = egr::Controller::Instance().GetPythonStack();
} }
// Get Outputs // Get Outputs
...@@ -143,7 +141,7 @@ paddle::Tensor conv2d_ad_func(const paddle::Tensor& input, ...@@ -143,7 +141,7 @@ paddle::Tensor conv2d_ad_func(const paddle::Tensor& input,
// Set forward's stack // Set forward's stack
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
grad_node->SetForwardTrace(forward_trace); grad_node->SetForwardTrace(egr::Controller::Instance().GetPythonStack());
} }
// SetAttributes if needed // SetAttributes if needed
......
...@@ -172,11 +172,9 @@ sync_batch_norm__ad_func(const paddle::Tensor& x, ...@@ -172,11 +172,9 @@ sync_batch_norm__ad_func(const paddle::Tensor& x,
data_layout, data_layout,
use_global_stats, use_global_stats,
trainable_statistics); trainable_statistics);
std::string forward_trace = "";
// Check NaN and Inf if needed // Check NaN and Inf if needed
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
egr::CheckTensorHasNanOrInf("sync_batch_norm_", api_result); egr::CheckTensorHasNanOrInf("sync_batch_norm_", api_result);
forward_trace = egr::Controller::Instance().GetPythonStack();
} }
// Get Outputs // Get Outputs
...@@ -231,7 +229,7 @@ sync_batch_norm__ad_func(const paddle::Tensor& x, ...@@ -231,7 +229,7 @@ sync_batch_norm__ad_func(const paddle::Tensor& x,
// Set forward's stack // Set forward's stack
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
grad_node->SetForwardTrace(forward_trace); grad_node->SetForwardTrace(egr::Controller::Instance().GetPythonStack());
} }
egr::Controller::Instance().PushBackForceSequentialNodes(grad_node.get()); egr::Controller::Instance().PushBackForceSequentialNodes(grad_node.get());
......
...@@ -299,7 +299,7 @@ FORWARD_BODY_TEMPLATE = """ if(require_any_grad) {{ ...@@ -299,7 +299,7 @@ FORWARD_BODY_TEMPLATE = """ if(require_any_grad) {{
{} {}
// Set for forward trace // Set for forward trace
if (FLAGS_check_nan_inf) {{ if (FLAGS_check_nan_inf) {{
{} grad_node->SetForwardTrace(egr::Controller::Instance().GetPythonStack());
}} }}
// SetAttributes if needed // SetAttributes if needed
{} {}
...@@ -490,10 +490,8 @@ CHECK_BACKWARD_INPLACE_TEMPLATE = """ ...@@ -490,10 +490,8 @@ CHECK_BACKWARD_INPLACE_TEMPLATE = """
}}""" }}"""
CHECK_NAN_AND_INF_TEMPLATE_FORWARD = """ CHECK_NAN_AND_INF_TEMPLATE_FORWARD = """
std::string forward_trace ="";
if (FLAGS_check_nan_inf) {{ if (FLAGS_check_nan_inf) {{
egr::CheckTensorHasNanOrInf("{}", {}); egr::CheckTensorHasNanOrInf("{}", {});
forward_trace = egr::Controller::Instance().GetPythonStack();
}} }}
""" """
...@@ -1070,15 +1068,11 @@ class DygraphFunctionGeneratorBase(FunctionGeneratorBase): ...@@ -1070,15 +1068,11 @@ class DygraphFunctionGeneratorBase(FunctionGeneratorBase):
node_event_name = forward_api_name + " node_creation" node_event_name = forward_api_name + " node_creation"
node_creation_event_str = f"{indent}paddle::platform::RecordEvent node_creation_record_event(\"{node_event_name}\", paddle::platform::TracerEventType::OperatorInner, 1);\n" node_creation_event_str = f"{indent}paddle::platform::RecordEvent node_creation_record_event(\"{node_event_name}\", paddle::platform::TracerEventType::OperatorInner, 1);\n"
set_forward_trace = (
f"{indent} grad_node->SetForwardTrace(forward_trace);"
)
if not for_backward: if not for_backward:
self.node_creation_str = FORWARD_BODY_TEMPLATE.format( self.node_creation_str = FORWARD_BODY_TEMPLATE.format(
node_creation_event_str, node_creation_event_str,
pass_stop_gradient_args_str, pass_stop_gradient_args_str,
node_construction_str, node_construction_str,
set_forward_trace,
set_attributes_str, set_attributes_str,
set_input_tensor_wrappers_str, set_input_tensor_wrappers_str,
set_grad_out_meta_str, set_grad_out_meta_str,
......
...@@ -218,6 +218,7 @@ std::shared_ptr<imperative::VarBase> CastPyArg2VarBase(PyObject* obj, ...@@ -218,6 +218,7 @@ std::shared_ptr<imperative::VarBase> CastPyArg2VarBase(PyObject* obj,
void SetPythonStack() { void SetPythonStack() {
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
VLOG(4) << "this is SetPythonStack";
pybind11::gil_scoped_acquire gil; pybind11::gil_scoped_acquire gil;
PyObject* mod = PyImport_ImportModule("traceback"); PyObject* mod = PyImport_ImportModule("traceback");
PyObject* traceback_list = PyObject_CallMethod(mod, "format_stack", ""); PyObject* traceback_list = PyObject_CallMethod(mod, "format_stack", "");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册