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

#643 PPYolo-E

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-344-PP-Yolo-E-Training-Replicate-Recipe
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  1. def deci_func_logger(_func=None, *, name: str = "abstract_decorator"):
  2. """
  3. This decorator is used to wrap our functions with logs.
  4. It will log every enter and exit of the functon with the equivalent parameters as extras.
  5. It will also log exceptions that raises in the function.
  6. It will also log the exception time of the function.
  7. How it works:`
  8. First it will check if the decorator called with name keyword.
  9. If so it will return a new decorator that its logger is the name parameter.
  10. If not it will return a new decorator that its logger is the wrapped function name.
  11. Then the return decorator will return a new function that warps the original function with the new logs.
  12. For further understanding advise real-python "fancy decorators documentation"
  13. Args:
  14. _func (): used when called without name specify. dont pass it directly
  15. name (): The name of the logger to save logs by.
  16. Returns:
  17. a decorator that wraps function with logs logic.
  18. """
  19. # TODO: Not Working - Breaks the code, tests does not pass (s3 connector, platform...)
  20. # TODO: Fix problem with ExplicitParamValidation error (arguments not passed)
  21. # TODO: Run ALL test suite of deci2 (NOT circieCI test suite, but ALL the tests under tests folders)
  22. # TODO: Delete/Update all failing tests.
  23. # def deci_logger_decorator(fn):
  24. #
  25. # @functools.wraps(fn)
  26. # def wrapper_func(*args, **kwargs):
  27. # try:
  28. #
  29. # try:
  30. # logger.debug(f"Start: {fn.__name__}", extra={"args": args, "kwargs": kwargs})
  31. # time1 = time.perf_counter()
  32. # except Exception:
  33. # # failed to write log - continue.
  34. # pass
  35. #
  36. # result = fn(*args, **kwargs)
  37. #
  38. # try:
  39. # time2 = time.perf_counter()
  40. # logger.debug(f"End: {fn.__name__}",
  41. # extra={'duration': (time2 - time1) * 1000.0, 'return_value': result})
  42. # except Exception:
  43. # # failed to write log - continue.
  44. # pass
  45. #
  46. # return result
  47. #
  48. # except Exception as ex:
  49. # # This exception was raised from inside the function call
  50. # logger.error(f"Exception: {ex}", exc_info=ex)
  51. # raise ex
  52. #
  53. # return wrapper_func
  54. # if _func is None:
  55. # logger = get_logger(name)
  56. # return deci_logger_decorator
  57. # else:
  58. # logger = get_logger(_func.__name__)
  59. # return deci_logger_decorator(_func)
  60. return _func
  61. def deci_class_logger():
  62. """
  63. This decorator wraps every class method with deci_func_logger decorator.
  64. It works by checking if class method is callable and if so it will set a new decorated method as the same method name.
  65. """
  66. def wrapper(cls):
  67. # TODO: Not Working - Breaks the code, tests does not pass (s3 connector, platform...)
  68. # TODO: Fix problem with ExplicitParamValidation error (arguments not passed)
  69. # TODO: Run ALL test suite of deci2 (NOT circieCI test suite, but ALL the tests under tests folders)
  70. # TODO: Delete/Update all failing tests.
  71. # for attr in cls.__dict__:
  72. # if callable(getattr(cls, attr)) and attr != '__init__':
  73. # decorated_function = deci_func_logger(name=cls.__name__)(getattr(cls, attr))
  74. # if type(cls.__dict__[attr]) is staticmethod:
  75. # decorated_function = staticmethod(decorated_function)
  76. # setattr(cls, attr, decorated_function)
  77. return cls
  78. return wrapper
Discard
Tip!

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