Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#578 Feature/sg 516 support head replacement for local pretrained weights unknown dataset

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-516_support_head_replacement_for_local_pretrained_weights_unknown_dataset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  1. from typing import Union, Callable
  2. from types import TracebackType
  3. from super_gradients.common.crash_handler.crash_tips import get_relevant_crash_tip_message
  4. def register_exceptions(excepthook: Callable) -> Callable:
  5. """Wrap excepthook with a step the saves the exception info to be available in the exit hooks.
  6. :param exc_type: Type of exception
  7. :param exc_value: Exception
  8. :param exc_traceback: Traceback
  9. :return: wrapped exceptook, that register the exception before raising it
  10. """
  11. def excepthook_with_register(exc_type: type, exc_value: Exception, exc_traceback: TracebackType) -> Callable:
  12. ExceptionInfo.register_exception(exc_type, exc_value, exc_traceback)
  13. return excepthook(exc_type, exc_value, exc_traceback)
  14. return excepthook_with_register
  15. class ExceptionInfo:
  16. """Holds information about the session exception (if any)"""
  17. _is_exception_raised = False
  18. exc_type = None
  19. exc_value = None
  20. exc_traceback = None
  21. @staticmethod
  22. def register_exception(exc_type: type, exc_value: Exception, exc_traceback: TracebackType):
  23. """Register the exception information into the class"""
  24. ExceptionInfo._is_exception_raised = True
  25. ExceptionInfo.exc_type = exc_type
  26. ExceptionInfo.exc_value = exc_value
  27. ExceptionInfo.exc_traceback = exc_traceback
  28. @staticmethod
  29. def is_exception_raised():
  30. """Check if an exception was raised in the current process"""
  31. return ExceptionInfo._is_exception_raised
  32. @staticmethod
  33. def get_crash_tip_message() -> Union[None, str]:
  34. return get_relevant_crash_tip_message(ExceptionInfo.exc_type, ExceptionInfo.exc_value, ExceptionInfo.exc_traceback)
Discard
Tip!

Press p or to see the previous file or, n or to see the next file