Decorators
save_code(obj)
A decorator function which save the code of the class/function in a file (to be kept along with the training logs) File name will be according to the class/function name
usage:
@save_code MyClass(): ...
def foo():
...
@save_code
def do_something():
...
This example will generate two files named MyClass.py and do_something.py, that will be saved in the checkpoint directory and uploaded to remote storage (if defined). the text of the class and the function will also be added to the tensorboard (or any other tracking service)
Source code in V3_2/src/super_gradients/common/decorators/code_save_decorator.py
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 |
|
save_file(obj)
A decorator function which save the code of the entire file (to be kept along with the training logs). one call to this decorator in the file is enough to save the entire file
usage:
@save_file MyClass(): ...
def foo():
...
def do_something():
...
This example will save the file containing this code in the checkpoint directory and uploaded to remote storage (if defined). the content of the file will also be added to the tensorboard (or any other tracking service)
Source code in V3_2/src/super_gradients/common/decorators/code_save_decorator.py
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 |
|
deci_class_logger()
This decorator wraps every class method with deci_func_logger decorator. It works by checking if class method is callable and if so it will set a new decorated method as the same method name.
Source code in V3_2/src/super_gradients/common/decorators/deci_logger.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
deci_func_logger(_func=None, *, name='abstract_decorator')
This decorator is used to wrap our functions with logs. It will log every enter and exit of the functon with the equivalent parameters as extras. It will also log exceptions that raises in the function. It will also log the exception time of the function.
How it works:` First it will check if the decorator called with name keyword. If so it will return a new decorator that its logger is the name parameter. If not it will return a new decorator that its logger is the wrapped function name. Then the return decorator will return a new function that warps the original function with the new logs. For further understanding advise real-python "fancy decorators documentation"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_func |
used when called without name specify. dont pass it directly |
None
|
|
name |
str
|
The name of the logger to save logs by. |
'abstract_decorator'
|
Returns:
Type | Description |
---|---|
a decorator that wraps function with logs logic. |
Source code in V3_2/src/super_gradients/common/decorators/deci_logger.py
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 |
|
resolve_param(param_name, factory)
A decorator function which resolves a specific named parameter using a defined Factory usage: @resolve_param(my_param_name, MyFactory()) def foo(self, a, my_param_name, b, c) ...
this will use MyFactory to generate an object from the provided value of my_param_name
Source code in V3_2/src/super_gradients/common/decorators/factory_decorator.py
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 |
|
SingletonMeta
Bases: type
A Singleton meta class. A class that derives from this class will have only 1 instance of that type for the process.
Source code in V3_2/src/super_gradients/common/decorators/singleton.py
1 2 3 4 5 6 7 8 9 10 11 12 |
|
singleton(cls)
A singleton decorator. Returns a wrapper objects. A call on that object returns a single instance object of decorated class. Use the wrapped attribute to access decorated class directly in unit tests
Source code in V3_2/src/super_gradients/common/decorators/singleton.py
32 33 34 35 36 37 38 |
|