utils.time_helper

time_helper

Please Reference ding/ding/utils/time_helper.py for usage.

build_time_helper

Overview:

Build the timehelper

Arguments:
  • cfg (dict):

    The config file, which is a multilevel dict, have large domain like evaluate, common, model, train etc, and each large domain has it’s smaller domain.

  • wrapper_type (str): The type of wrapper returned, support ['time', 'cuda']

Returns:
  • time_wrapper (TimeWrapper):

    Return the corresponding timewrapper, Reference: ding.utils.timehelper.TimeWrapperTime and ding.utils.timehelper.get_cuda_time_wrapper.

TimeWrapper

class ding.utils.time_helper.TimeWrapper[source]
Overview:

Abstract class method that defines TimeWrapper class

Interface:

wrapper, start_time, end_time

classmethod end_time()[source]
Overview:

Abstract classmethod, stop timing

classmethod start_time()[source]
Overview:

Abstract classmethod, start timing

classmethod wrapper(fn)[source]
Overview:

Classmethod wrapper, wrap a function and automatically return its running time

  • fn (function): The function to be wrap and timed

TimeWrapperTime

class ding.utils.time_helper.TimeWrapperTime[source]
Overview:

A class method that inherit from TimeWrapper class

Interface:

start_time, end_time

classmethod end_time()[source]
Overview:

Implement and overide the end_time method in TimeWrapper class

Returns:
  • time(float): The time between start_time and end_time

classmethod start_time()[source]
Overview:

Implement and overide the start_time method in TimeWrapper class

get_cuda_time_wrapper

Overview:

Return the TimeWrapperCuda class, this wrapper aims to ensure compatibility in no cuda device

Returns:
  • TimeWrapperCuda(class): See TimeWrapperCuda class

Note

Must use torch.cuda.synchronize(), reference: <https://blog.csdn.net/u013548568/article/details/81368019>

EasyTimer

class ding.utils.time_helper.EasyTimer(cuda=True)[source]
Overview:

A decent timer wrapper that can be used easily.

Interface:

__init__, __enter__, __exit__

Example:
>>> wait_timer = EasyTimer()
>>> with wait_timer:
>>>    func(...)
>>> time_ = wait_timer.value  # in second
__enter__()[source]
Overview:

Enter timer, start timing

__exit__(*args)[source]
Overview:

Exit timer, stop timing

__init__(cuda=True)[source]
Overview:

Init class EasyTimer

Arguments:
  • cuda (bool): Whether to build timer with cuda type

WatchDog

class ding.utils.time_helper.WatchDog(timeout: int = 1)[source]
Overview:

Simple watchdog timer to detect timeouts

Arguments:
  • timeout (int): Timeout value of the watchdog [seconds].

Note

If it is not reset before exceeding this value, TimeourError raised.

Interface:

start, stop

Examples:
>>> watchdog = WatchDog(x) # x is a timeout value
>>> ...
>>> watchdog.start()
>>> ... # Some function
__init__(timeout: int = 1)[source]
start()[source]
Overview:

Start watchdog.

stop()[source]
Overview:

Stop watchdog with alarm(0), SIGALRM, and SIG_DFL signals.