Skip to content

Utilities

danling.runner.utils

RunnerMode

Bases: LowercaseStrEnum

RunnerMode is an enumeration of running modes.

Attributes:

Name Type Description
train

Training mode.

eval

Evaluation mode.

inf

Inference mode.

Source code in danling/runner/utils.py
Python
class RunnerMode(StrEnum):  # pylint: disable=too-few-public-methods
    r"""
    `RunnerMode` is an enumeration of running modes.

    Attributes:
        train: Training mode.
        eval: Evaluation mode.
        inf: Inference mode.
    """

    train = auto()
    eval = auto()
    inf = auto()

on_main_process

Python
on_main_process(func)

Decorator to run func only on main process.

Source code in danling/runner/utils.py
Python
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/runner/utils.py
Python
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