colossalai.utils.timer

class colossalai.utils.timer.Timer[source]

A timer object which helps to log the execution times, and provides different tools to assess the times.

start()[source]

Firstly synchronize cuda, reset the clock and then start the timer.

lap()[source]

lap time and return elapsed time

stop(keep_in_history=False)[source]

Stop the timer and record the start-stop time interval.

Parameters:

keep_in_history (bool, optional) – Whether does it record into history each start-stop interval, defaults to False.

Returns:

Start-stop interval.

Return type:

int

get_history_mean()[source]

Mean of all history start-stop time intervals.

Returns:

Mean of time intervals

Return type:

int

get_history_sum()[source]

Add up all the start-stop time intervals.

Returns:

Sum of time intervals.

Return type:

int

get_elapsed_time()[source]

Return the last start-stop time interval.

Returns:

The last time interval.

Return type:

int

Note

Use it only when timer is not in progress

reset()[source]

Clear up the timer and its history

class colossalai.utils.timer.MultiTimer(on=True)[source]

An object contains multiple timers.

Parameters:

on (bool, optional) – Whether the timer is enabled. Default is True.

start(name)[source]

Start namely one of the timers.

Parameters:

name (str) – Timer’s key.

stop(name, keep_in_history)[source]

Stop namely one of the timers.

Parameters:
  • name (str) – Timer’s key.

  • keep_in_history (bool) – Whether does it record into history each start-stop interval.

get_timer(name)[source]

Get timer by its name (from multitimer)

Parameters:

name (str) – Timer’s key.

Returns:

Timer with the name you give correctly.

Return type:

colossalai.utils.Timer

reset(name=None)[source]

Reset timers.

Parameters:

name (str, optional) – If name is designated, the named timer will be reset and others will not, defaults to None.