Skip to content

Commit

Permalink
added crash tip (#1799)
Browse files Browse the repository at this point in the history
Co-authored-by: Louis-Dupont <35190946+Louis-Dupont@users.noreply.github.com>
  • Loading branch information
shaydeci and Louis-Dupont committed Jan 31, 2024
1 parent 8ea4062 commit 5feb788
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/super_gradients/common/crash_handler/crash_tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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)

Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/crash_tips_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
DDPNotInitializedTip,
WrongHydraVersionTip,
InterpolationKeyErrorTip,
SGLoggerIsNoneTip,
)


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5feb788

Please sign in to comment.