Skip to content

Commit

Permalink
Update on "Node.stack_trace should have innermost frame last"
Browse files Browse the repository at this point in the history
Both fx.Tracer and Dynamo should store node.stack_trace in the "innermost frame last" order. 




cc soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
  • Loading branch information
SherlockNoMad committed Feb 27, 2023
1 parent 3e1fe09 commit d757afb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
22 changes: 6 additions & 16 deletions torch/fx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,27 +454,17 @@ def append_stacktrace_summary(node : Node):
# stacktrace should have innermost frame last, so we
# iterate backwards to find the first line that starts
# with 'File '
idx = len(lines) - 1
while idx >= 0:
summary_str = ""
for idx in range(len(lines) - 2, -1, -1):
line = lines[idx].strip()
if line.startswith('File '):
break
idx -= 1

summary_lines = []
if idx >= 0 and idx + 1 < len(lines):
matches = pattern.match(lines[idx].strip())
matches = pattern.match(line)
if matches:
file = matches.group(1)
lineno = matches.group(2)
lineage = f'File: {file}:{lineno}'
summary_lines.append(lineage)

# next line should be the code
code = f"code: {lines[idx + 1].strip()}"
summary_lines.append(code)

summary_str = ', '.join(summary_lines)
code = lines[idx + 1].strip()
summary_str = f'File: {file}:{lineno}, code: {code}'
break
body.append(f'\n# {summary_str}\n')
elif prev_stacktrace != "":
prev_stacktrace = ""
Expand Down
2 changes: 1 addition & 1 deletion torch/fx/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def stack_trace(self) -> Optional[str]:
When traced with dynamo, this property will be populated by default by
`OutputGraph.create_proxy`.
stack_trace would have the innermost frame at the bottom.
stack_trace would have the innermost frame at the end of the string.
"""
return self.meta.get("stack_trace", None)

Expand Down

0 comments on commit d757afb

Please sign in to comment.