Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added crash tip for the case when SGLogger is None #1799

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading