[dynamo][logs] Bug fix (#123606)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/123606
Approved by: https://github.com/jansel, https://github.com/ezyang
diff --git a/torch/_dynamo/convert_frame.py b/torch/_dynamo/convert_frame.py
index f0b55ae..93ff6d9 100644
--- a/torch/_dynamo/convert_frame.py
+++ b/torch/_dynamo/convert_frame.py
@@ -841,14 +841,17 @@
                 # Log this message in the graph break. Also use the string
                 # "skip: " to tell that the whole frame is falling back to
                 # eager.
-                with compile_context(CompileContext(e.compile_id)):  # type: ignore[attr-defined]
-                    user_stack = e.real_stack
-                    user_stack_formatted = "".join(traceback.format_list(user_stack))
-                    graph_break_log.debug(
-                        "Graph break: skip: from user code at:\n%s",
-                        user_stack_formatted,
-                        exc_info=True,
-                    )
+                if hasattr(e, "compile_id"):
+                    with compile_context(CompileContext(e.compile_id)):  # type: ignore[attr-defined]
+                        user_stack = e.real_stack
+                        user_stack_formatted = "".join(
+                            traceback.format_list(user_stack)
+                        )
+                        graph_break_log.debug(
+                            "Graph break: skip: from user code at:\n%s",
+                            user_stack_formatted,
+                            exc_info=True,
+                        )
 
             if not config.suppress_errors and not soft_fail:
                 raise