Skip to content

Commit

Permalink
Interpollation crash tip (#616)
Browse files Browse the repository at this point in the history
* first version

* fix doc

* improve txt

* improve txt

* add test

* fix txt
  • Loading branch information
Louis-Dupont authored Jan 17, 2023
1 parent e1fe52b commit 79418ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/super_gradients/common/crash_handler/crash_tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Union, Tuple, List, Type
from types import TracebackType

import omegaconf

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

Expand Down Expand Up @@ -197,6 +199,28 @@ def _get_tips(cls, exc_type: type, exc_value: Exception, exc_traceback: Tracebac
return [tip]


class InterpolationKeyErrorTip(CrashTip):
@classmethod
def is_relevant(cls, exc_type: type, exc_value: Exception, exc_traceback: TracebackType):
expected_str = "Interpolation key "
return isinstance(exc_value, omegaconf.errors.InterpolationKeyError) and expected_str in str(exc_value)

@classmethod
def _get_tips(cls, exc_type: type, exc_value: Exception, exc_traceback: TracebackType) -> List[str]:
variable = re.search("'(.*?)'", str(exc_value)).group(1)
tip = (
f"It looks like you encountered an error related to interpolation of the variable '{variable}'.\n"
"It's possible that this error is caused by not using the full path of the variable in your subfolder configuration.\n"
f"Please make sure that you are referring to the variable using the "
f"{fmt_txt('full path starting from the main configuration file', color='green')}.\n"
f"Try to replace '{fmt_txt(f'${{{variable}}}', color='red')}' with '{fmt_txt(f'${{full.path.to.{variable}}}', color='green')}', \n"
f" where 'full.path.to' is the actual path to reach '{variable}', starting from the root configuration file.\n"
f"Example: '{fmt_txt('${dataset_params.train_dataloader_params.batch_size}', color='green')}' "
f"instead of '{fmt_txt('${train_dataloader_params.batch_size}', color='red')}'.\n"
)
return [tip]


def get_relevant_crash_tip_message(exc_type: type, exc_value: Exception, exc_traceback: TracebackType) -> Union[None, str]:
"""Get a CrashTip class if relevant for input exception"""
for crash_tip in CrashTip.get_sub_classes():
Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/crash_tips_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import unittest
import dataclasses
from typing import Type
import omegaconf
from super_gradients.common.crash_handler.crash_tips import (
get_relevant_crash_tip_message,
CrashTip,
TorchCudaMissingTip,
RecipeFactoryFormatTip,
DDPNotInitializedTip,
WrongHydraVersionTip,
InterpolationKeyErrorTip,
)


Expand Down Expand Up @@ -46,6 +48,10 @@ def setUp(self) -> None:
exc_value=TypeError("__init__() got an unexpected keyword argument 'version_base'"),
expected_crash_tip=WrongHydraVersionTip,
),
DocumentedException(
exc_value=omegaconf.errors.InterpolationKeyError("omegaconf.errors.InterpolationKeyError: Interpolation key 'x' not found"),
expected_crash_tip=InterpolationKeyErrorTip,
),
]

def test_found_exceptions(self):
Expand Down

0 comments on commit 79418ef

Please sign in to comment.