-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print the forward's stack when backward op has nan/inf and FLAGS_check_nan_inf_level = 0 #52639
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要添加单测
egr::Controller::Instance().GetOpPythonStackStr() + forward_trace; | ||
try { | ||
PADDLE_ENFORCE( | ||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个PADDLE_ENFORCE
有什么用呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前是通过catch的形式获取当前函数的名称和行数现在不需要了 我删除一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
// Check NaN and Inf if needed | ||
if (FLAGS_check_nan_inf) { | ||
egr::CheckTensorHasNanOrInf("conv2d", api_result); | ||
std::string filename = __FILE__; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
每个manual实现的API都需要添加,重复代码太多了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
@@ -74,6 +74,12 @@ class Controller { | |||
|
|||
void EnableLayoutAutoTune() { tracer_->EnableLayoutAutoTune(); } | |||
|
|||
void SetOpPythonStackStr(std::string stack_str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetOpPythonStackStr
-> SetPythonStack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
std::string filename = __FILE__; | ||
std::string line= std::to_string(__LINE__); | ||
std::string function_name = __FUNCTION__; | ||
pybind11::gil_scoped_acquire gil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
获取python代码调用栈的pybind实现,还是建议放在pybind正式代码里面,尽量不要全部都用代码生成的方式。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
paddle/fluid/eager/grad_node_info.h
Outdated
backward_trace_ = backward_trace; | ||
} | ||
|
||
std::string GetForwardTrace() { return backward_trace_; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward_trace_
-> forward_trace_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
d21bf46
to
b4eb0c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CHECK_NAN_AND_INF_TEMPLATE_BACKWARD = """ | ||
if (FLAGS_check_nan_inf) {{ | ||
try{{ | ||
egr::CheckTensorHasNanOrInf("{}", {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forward_trace
可以直接传入CheckTensorHasNanOrInf
,在CheckTensorHasNanOrInf
里面打印?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那样就需要修改CheckTensorHasNanOrInf了,代码改的比较多了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改CheckTensorHasNanOrInf
是合理的啊,因为打印调用栈本身就是CheckTensorHasNanOrInf
功能的一部分,后面静态图也能服用部分逻辑,可以后续PR再考虑。
std::cout<<forward_trace<<std::endl; | ||
std::rethrow_exception(std::current_exception()); | ||
}} | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意字符串模板中的代码格式,另外为啥要用两个花括号?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是自动代码生成需要用两层花括号
@@ -121,7 +121,10 @@ def FindParsingFunctionFromAttributeType(atype): | |||
NOAMP_DYGRAPH_FUNCTION_TEMPLATE = "decltype({}({})) out = {}({});" | |||
|
|||
|
|||
FUNCTION_SET_DEVICE_TEMPLATE = """{} if (paddle::platform::is_gpu_place(place)) {{ | |||
FUNCTION_SET_DEVICE_TEMPLATE = """{} | |||
LOG(INFO)<<"this is SetPythonStack"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个模板是用于哪里的?LOG(INFO)
会一直输出吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的 这个我下个PR再修改
FUNCTION_SET_DEVICE_TEMPLATE = """{} if (paddle::platform::is_gpu_place(place)) {{ | ||
FUNCTION_SET_DEVICE_TEMPLATE = """{} | ||
LOG(INFO)<<"this is SetPythonStack"; | ||
SetPythonStack(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要加if (FLAGS_check_nan_inf)
判断来限制一下吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要,这个调用里面我加了判断
@@ -141,6 +148,25 @@ def _check_num_nan_inf(use_cuda): | |||
if paddle.fluid.core.is_compiled_with_cuda(): | |||
_check_num_nan_inf(use_cuda=True) | |||
|
|||
def test_check_stack(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个测试其实没有必要再费劲加到这个单测里面了。之所以构造这么一个复杂的测试方式,是因为之前CUDA抛出的异常捕获不到。调用栈报错,应该可以直接用try ... except
捕获到。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不行呀,前向的调用栈是print出来的,无法try... except捕获
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2comments
@@ -1047,11 +1069,15 @@ def GenerateNodeCreationCodes(self, for_backward=False): | |||
|
|||
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" | |||
set_forward_trace = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能否设置FLAGS_check_nan_inf为false时不设置?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以的,后续和上面的临时变量问题统一修改
@@ -484,7 +488,25 @@ class {} : public egr::GradNodeBase {{ | |||
}} | |||
}}""" | |||
|
|||
CHECK_NAN_AND_INF_TEMPLATE = """ if (FLAGS_check_nan_inf) {{ egr::CheckTensorHasNanOrInf("{}", {}); }} | |||
CHECK_NAN_AND_INF_TEMPLATE_FORWARD = """ | |||
std::string forward_trace =""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否可以不使用临时变量减少下平凡的构造和析构开销
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以的 我下个PR统一修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, fix problem in next pr
…k_nan_inf_level = 0 (PaddlePaddle#52639)
…k_nan_inf_level = 0 (PaddlePaddle#52639)
…k_nan_inf_level = 0 (PaddlePaddle#52639)
PR types
Others
PR changes
Others
Describe
新增nan_inf检查工具反向op调用栈打印的支持,效果如下: