From 29d6c4c9d61e348f87bf996f4e81baae1886c1ad Mon Sep 17 00:00:00 2001 From: shayaharon Date: Sun, 28 Jan 2024 15:02:09 +0200 Subject: [PATCH] added crash tip --- .../common/crash_handler/crash_tips.py | 23 ++++++++++++++++--- tests/unit_tests/crash_tips_test.py | 5 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/super_gradients/common/crash_handler/crash_tips.py b/src/super_gradients/common/crash_handler/crash_tips.py index b4b2c59333..16fb1f366e 100644 --- a/src/super_gradients/common/crash_handler/crash_tips.py +++ b/src/super_gradients/common/crash_handler/crash_tips.py @@ -7,7 +7,6 @@ from super_gradients.common.crash_handler.utils import indent_string, fmt_txt, json_str_to_dict from super_gradients.common.abstractions.abstract_logger import get_logger - logger = get_logger(__name__) @@ -75,7 +74,7 @@ def get_message(cls, exc_type: type, exc_value: Exception, exc_traceback: Traceb def format_tip(tip_index: int, tip: str): first_sentence, *following_sentences = tip.split("\n") - first_sentence = f"{tip_index+1}. {first_sentence}" + first_sentence = f"{tip_index + 1}. {first_sentence}" following_sentences = [f" {sentence}" for sentence in following_sentences] return "\n".join([first_sentence] + following_sentences) @@ -88,7 +87,7 @@ def format_tip(tip_index: int, tip: str): " ╚═════════════════════════╝ \n" f"{fmt_txt('Something went wrong!', color='red', bold=True)} You can find below potential solution(s) to this error: \n\n" f"{formatted_tips}\n" - f"{len(tips)+1}. If the proposed solution(s) did not help, feel free to contact the SuperGradient team or to open a ticket on " + f"{len(tips) + 1}. If the proposed solution(s) did not help, feel free to contact the SuperGradient team or to open a ticket on " f"https://github.com/Deci-AI/super-gradients/issues/new/choose\n\n" "see the trace above...\n" "══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════\n" @@ -119,6 +118,24 @@ def _get_tips(cls, exc_type: type, exc_value: Exception, exc_traceback: Tracebac return [tip] +class SGLoggerIsNoneTip(CrashTip): + @classmethod + def is_relevant(cls, exc_type: type, exc_value: Exception, exc_traceback: TracebackType) -> bool: + pattern = "AttributeError: 'NoneType' object has no attribute 'add_scalar'" + return isinstance(exc_value, AttributeError) and pattern in str(exc_value) + + @classmethod + def _get_tips(cls, exc_type: type, exc_value: Exception, exc_traceback: TracebackType) -> List[str]: + tip = ( + "SG logger is not available on non-master nodes in DDP.\n" + "Please either decorate the method you don't want to call on those nodes with the" + "super_gradients.common.environment.ddp_utils.multi_process_safe decorator, or check that " + "context.sg_logger is not" + " None inside the method implementation." + ) + return [tip] + + class RecipeFactoryFormatTip(CrashTip): @classmethod def is_relevant(cls, exc_type: type, exc_value: Exception, exc_traceback: TracebackType) -> bool: diff --git a/tests/unit_tests/crash_tips_test.py b/tests/unit_tests/crash_tips_test.py index e2bc8b0683..218de79d2c 100644 --- a/tests/unit_tests/crash_tips_test.py +++ b/tests/unit_tests/crash_tips_test.py @@ -11,6 +11,7 @@ DDPNotInitializedTip, WrongHydraVersionTip, InterpolationKeyErrorTip, + SGLoggerIsNoneTip, ) @@ -52,6 +53,10 @@ def setUp(self) -> None: exc_value=omegaconf.errors.InterpolationKeyError("omegaconf.errors.InterpolationKeyError: Interpolation key 'x' not found"), expected_crash_tip=InterpolationKeyErrorTip, ), + DocumentedException( + exc_value=AttributeError("AttributeError: 'NoneType' object has no attribute 'add_scalar'"), + expected_crash_tip=SGLoggerIsNoneTip, + ), ] def test_found_exceptions(self):