Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
96edcea4
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
96edcea4
编写于
10月 28, 2021
作者:
0
0x45f
提交者:
GitHub
10月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
show paddle traceback after last user code traceback (#36741) (#36765)
show paddle traceback after last user code traceback
上级
7cb7535e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
61 addition
and
32 deletion
+61
-32
python/paddle/fluid/dygraph/dygraph_to_static/error.py
python/paddle/fluid/dygraph/dygraph_to_static/error.py
+61
-32
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/error.py
浏览文件 @
96edcea4
...
@@ -122,7 +122,7 @@ class TraceBackFrameRange(OriginInfo):
...
@@ -122,7 +122,7 @@ class TraceBackFrameRange(OriginInfo):
msg
=
' '
*
BLANK_COUNT_BEFORE_FILE_STR
+
'File "{}", line {}, in {}
\n
'
.
format
(
msg
=
' '
*
BLANK_COUNT_BEFORE_FILE_STR
+
'File "{}", line {}, in {}
\n
'
.
format
(
self
.
location
.
filepath
,
self
.
location
.
lineno
,
self
.
function_name
)
self
.
location
.
filepath
,
self
.
location
.
lineno
,
self
.
function_name
)
# add empty line after range code
# add empty line after range code
return
msg
+
'
\n
'
.
join
(
self
.
source_code
)
+
'
\n
'
return
msg
+
'
\n
'
.
join
(
self
.
source_code
)
class
SuggestionDict
(
object
):
class
SuggestionDict
(
object
):
...
@@ -183,24 +183,39 @@ class ErrorData(object):
...
@@ -183,24 +183,39 @@ class ErrorData(object):
return
'
\n
'
.
join
(
message_lines
)
return
'
\n
'
.
join
(
message_lines
)
# Step2: Optimizes stack information with source code information of dygraph from user.
# Step2: Optimizes stack information with source code information of dygraph from user.
whether_source_range
=
True
user_code_traceback_index
=
[]
for
filepath
,
lineno
,
funcname
,
code
in
self
.
origin_traceback
[::
-
1
]:
for
i
,
(
filepath
,
lineno
,
funcname
,
loc
=
Location
(
filepath
,
lineno
)
code
)
in
enumerate
(
self
.
origin_traceback
):
dygraph_func_info
=
self
.
origin_info_map
.
get
(
loc
.
line_location
,
dygraph_func_info
=
self
.
origin_info_map
.
get
(
(
filepath
,
lineno
)
,
None
)
None
)
if
dygraph_func_info
:
if
dygraph_func_info
:
if
whether_source_range
:
user_code_traceback_index
.
append
(
i
)
# Add user code traceback
for
i
in
user_code_traceback_index
:
filepath
,
lineno
,
funcname
,
code
=
self
.
origin_traceback
[
i
]
dygraph_func_info
=
self
.
origin_info_map
.
get
((
filepath
,
lineno
),
None
)
if
i
==
user_code_traceback_index
[
-
1
]:
traceback_frame
=
TraceBackFrameRange
(
traceback_frame
=
TraceBackFrameRange
(
dygraph_func_info
.
location
,
dygraph_func_info
.
location
,
dygraph_func_info
.
function_name
)
dygraph_func_info
.
function_name
)
whether_source_range
=
False
else
:
else
:
traceback_frame
=
TraceBackFrame
(
traceback_frame
=
TraceBackFrame
(
dygraph_func_info
.
location
,
dygraph_func_info
.
location
,
dygraph_func_info
.
function_name
,
dygraph_func_info
.
function_name
,
dygraph_func_info
.
source_code
)
dygraph_func_info
.
source_code
)
# Two elements already exist in message_lines: "In transformed code:" and "", so insert in index 2
message_lines
.
insert
(
2
,
traceback_frame
.
formated_message
())
message_lines
.
append
(
traceback_frame
.
formated_message
())
message_lines
.
append
(
""
)
# Add paddle traceback after user code traceback
paddle_traceback_start_idnex
=
user_code_traceback_index
[
-
1
]
+
1
if
user_code_traceback_index
else
0
for
filepath
,
lineno
,
funcname
,
code
in
self
.
origin_traceback
[
paddle_traceback_start_idnex
:]:
traceback_frame
=
TraceBackFrame
(
Location
(
filepath
,
lineno
),
funcname
,
code
)
message_lines
.
append
(
traceback_frame
.
formated_message
())
message_lines
.
append
(
""
)
# Step3: Adds error message like "TypeError: dtype must be int32, but received float32".
# Step3: Adds error message like "TypeError: dtype must be int32, but received float32".
# NOTE: `format_exception` is a list, its length is 1 in most cases, but sometimes its length
# NOTE: `format_exception` is a list, its length is 1 in most cases, but sometimes its length
...
@@ -258,8 +273,9 @@ class ErrorData(object):
...
@@ -258,8 +273,9 @@ class ErrorData(object):
bottom_error_message
=
error_value_lines
[
empty_line_idx
+
1
:]
bottom_error_message
=
error_value_lines
[
empty_line_idx
+
1
:]
revise_suggestion
=
self
.
_create_revise_suggestion
(
bottom_error_message
)
revise_suggestion
=
self
.
_create_revise_suggestion
(
bottom_error_message
)
filepath
=
''
user_filepath
=
''
error_from_user_code
=
[]
error_traceback
=
[]
user_code_traceback_index
=
[]
pattern
=
'File "(?P<filepath>.+)", line (?P<lineno>.+), in (?P<function_name>.+)'
pattern
=
'File "(?P<filepath>.+)", line (?P<lineno>.+), in (?P<function_name>.+)'
for
i
in
range
(
0
,
len
(
error_value_lines_strip
),
2
):
for
i
in
range
(
0
,
len
(
error_value_lines_strip
),
2
):
if
error_value_lines_strip
[
i
].
startswith
(
"File "
):
if
error_value_lines_strip
[
i
].
startswith
(
"File "
):
...
@@ -268,22 +284,35 @@ class ErrorData(object):
...
@@ -268,22 +284,35 @@ class ErrorData(object):
code
=
error_value_lines_strip
[
i
+
1
]
if
i
+
1
<
len
(
code
=
error_value_lines_strip
[
i
+
1
]
if
i
+
1
<
len
(
error_value_lines_strip
)
else
''
error_value_lines_strip
)
else
''
if
i
==
0
:
if
i
==
0
:
filepath
=
tmp_filepath
user_filepath
=
tmp_filepath
if
tmp_filepath
==
filepath
:
if
tmp_filepath
==
user_filepath
:
error_from_user_code
.
append
(
user_code_traceback_index
.
append
(
len
(
error_traceback
))
error_traceback
.
append
(
(
tmp_filepath
,
int
(
lineno_str
),
function_name
,
code
))
(
tmp_filepath
,
int
(
lineno_str
),
function_name
,
code
))
error_frame
=
[]
error_frame
=
[]
whether_source_range
=
True
# Add user code traceback
for
filepath
,
lineno
,
funcname
,
code
in
error_from_user_code
[::
-
1
]
:
for
i
in
user_code_traceback_index
:
loc
=
Location
(
filepath
,
lineno
)
filepath
,
lineno
,
funcname
,
code
=
error_traceback
[
i
]
if
whether_source_range
:
if
i
==
user_code_traceback_index
[
-
1
]
:
traceback_frame
=
TraceBackFrameRange
(
loc
,
funcname
)
traceback_frame
=
TraceBackFrameRange
(
whether_source_range
=
False
Location
(
filepath
,
lineno
),
funcname
)
else
:
else
:
traceback_frame
=
TraceBackFrame
(
loc
,
funcname
,
code
)
traceback_frame
=
TraceBackFrame
(
Location
(
filepath
,
lineno
),
funcname
,
code
)
error_frame
.
insert
(
0
,
traceback_frame
.
formated_message
())
error_frame
.
append
(
traceback_frame
.
formated_message
())
error_frame
.
append
(
""
)
# Add paddle traceback after user code traceback
paddle_traceback_start_idnex
=
user_code_traceback_index
[
-
1
]
+
1
if
user_code_traceback_index
else
0
for
filepath
,
lineno
,
funcname
,
code
in
error_traceback
[
paddle_traceback_start_idnex
:]:
traceback_frame
=
TraceBackFrame
(
Location
(
filepath
,
lineno
),
funcname
,
code
)
error_frame
.
append
(
traceback_frame
.
formated_message
())
error_frame
.
append
(
""
)
error_frame
.
extend
(
bottom_error_message
)
error_frame
.
extend
(
bottom_error_message
)
error_frame
.
extend
(
revise_suggestion
)
error_frame
.
extend
(
revise_suggestion
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录