Revert "Update gm.print_readable to include Annotation (#165397)"

This reverts commit 7a657700131f31577544e93587eb339618677e97.

Reverted https://github.com/pytorch/pytorch/pull/165397 on behalf of https://github.com/malfet due to I don't know how/why, but it breaks windows tests, see 2e22b1a61e/1 ([comment](https://github.com/pytorch/pytorch/pull/165397#issuecomment-3417428128))
This commit is contained in:
PyTorch MergeBot
2025-10-17 22:35:50 +00:00
parent 2e22b1a61e
commit e50dc40d28
7 changed files with 63 additions and 30 deletions

View File

@ -606,31 +606,29 @@ class CodeGen:
else:
body.append("\n")
prev_summary_str = None
prev_stacktrace = None
def append_stacktrace_summary(node: Node):
"""
Append a summary of the stacktrace to the generated code. This is
useful for debugging.
"""
nonlocal prev_summary_str
nonlocal prev_stacktrace
if node.op not in {"placeholder", "output"}:
annotation_str = ""
annotation = node.meta.get("custom", {})
if annotation:
annotation_str = f" Annotation: {annotation}"
stack_trace_str = "No stacktrace found for following nodes"
if stack_trace := node.stack_trace:
if parsed_stack_trace := _parse_stack_trace(stack_trace):
stack_trace_str = parsed_stack_trace.get_summary_str()
summary_str = f"\n{dim(f'#{annotation_str} {stack_trace_str}')}\n"
if summary_str != prev_summary_str:
prev_summary_str = summary_str
body.append(summary_str)
stack_trace = node.stack_trace
if stack_trace:
if stack_trace != prev_stacktrace:
prev_stacktrace = stack_trace
if parsed_stack_trace := _parse_stack_trace(stack_trace):
summary_str = parsed_stack_trace.get_summary_str()
else:
summary_str = ""
body.append(f"\n {dim(f'# {summary_str}')}\n")
elif prev_stacktrace != "":
prev_stacktrace = ""
no_stacktrace_msg = "# No stacktrace found for following nodes"
body.append(f"\n{dim(no_stacktrace_msg)}\n")
def stringify_shape(shape: Iterable) -> str:
return f"[{', '.join([str(x) for x in shape])}]"