Skip to content

Utils

danling.runners.utils

RunnerMode

Bases: LowercaseStrEnum

RunnerMode is an enumeration of running modes.

Attributes:

Name Type Description
train

Training mode.

evaluate

Evaluation mode.

infer

Inference mode.

Source code in danling/runners/utils.py
Python
40
41
42
43
44
45
46
47
48
49
50
51
52
class RunnerMode(StrEnum):  # pylint: disable=too-few-public-methods
    r"""
    `RunnerMode` is an enumeration of running modes.

    Attributes:
        train: Training mode.
        evaluate: Evaluation mode.
        infer: Inference mode.
    """

    train = auto()
    evaluate = auto()
    infer = auto()

on_main_process

Python
on_main_process(func)

Decorator to run func only on main process.

Source code in danling/runners/utils.py
Python
144
145
146
147
148
149
150
151
152
153
154
155
def on_main_process(func):
    """
    Decorator to run func only on main process.
    """

    @wraps(func)
    def wrapper(self, *args, **kwargs) -> Any | None:
        if self.is_main_process or not self.distributed:
            return func(self, *args, **kwargs)
        return None

    return wrapper

on_local_main_process

Python
on_local_main_process(func)

Decorator to run func only on local main process.

Source code in danling/runners/utils.py
Python
158
159
160
161
162
163
164
165
166
167
168
169
def on_local_main_process(func):
    """
    Decorator to run func only on local main process.
    """

    @wraps(func)
    def wrapper(self, *args, **kwargs) -> Any | None:
        if self.is_local_main_process or not self.distributed:
            return func(self, *args, **kwargs)
        return None

    return wrapper