Monitor

Here is a tutorial on Google Colab that shows how to use the monitor module

Basic

labml.monit.section(name, *, is_silent: bool = False, is_timed: bool = True, is_partial: bool = False, is_new_line: bool = True, is_children_silent: bool = False, is_track: bool = False, is_not_in_loop: bool = False, total_steps: float = 1.0)[source]

This creates a monitored with block.

Parameters

name (str) – Name of the section

Keyword Arguments
  • is_silent (bool, optional) – Whether not to print time taken. Defaults to False.

  • is_timed (bool, optional) – Whether to measure time. Default to True.

  • is_partial (bool, optional) – Whether it’s a partial excution where it gets called repeatedly. Defaults to False.

  • is_new_line (bool, optional) – Whether to print a new line. Defaults to True.

  • is_children_silent (bool, optional) – Whether to make child sections silent. Defaults to True.

  • is_track (bool, optional) – Whether to track the time. Defaults to False.

  • is_not_in_loop (bool, optional) – Whether to forcefully track this outside loop(). Defaults to False.

  • total_steps (float, optional) – Total number of steps. This is used to measure progress when progress() gets called. Defaults to 1.

labml.monit.func(name, *, is_silent: bool = False, is_timed: bool = True, is_partial: bool = False, is_new_line: bool = True, is_children_silent: bool = False, is_track: bool = False, is_not_in_loop: bool = False, total_steps: float = 1.0)[source]

This is similar to section() but can be used as a decorator.

Parameters

name (str) – Name of the function

Keyword Arguments
  • is_silent (bool, optional) – Whether not to print time taken. Defaults to False.

  • is_timed (bool, optional) – Whether to measure time. Default to True.

  • is_partial (bool, optional) – Whether it’s a partial excution where it gets called repeatedly. Defaults to False.

  • is_new_line (bool, optional) – Whether to print a new line. Defaults to True.

  • is_children_silent (bool, optional) – Whether to make child sections silent. Defaults to True.

  • is_track (bool, optional) – Whether to track the time. Defaults to False.

  • is_not_in_loop (bool, optional) – Whether to forcefully track this outside loop(). Defaults to False.

  • total_steps (float, optional) – Total number of steps. This is used to measure progress when progress() gets called. Defaults to 1.

labml.monit.progress(steps: float)[source]

Set the progress of the section.

Parameters

steps (float) – Current progress

labml.monit.fail()[source]

Mark the current section as failed.

Iterators

labml.monit.iterate(name, iterable: Union[Iterable, Sized, int], total_steps: Optional[int] = None, *, is_silent: bool = False, is_children_silent: bool = False, is_timed: bool = True, is_track: bool = False, is_not_in_loop: bool = False, context=None)[source]

This creates a monitored iterator.

Parameters
  • name (str) – Name of the iterator

  • iterable (Union[Iterable, Sized, int]) – The iterable

  • total_steps (int, optional) – Total number of steps. If not provided this is calculated from iterable.

Keyword Arguments
  • is_silent (bool, optional) – Whether not to print time taken. Defaults to False.

  • is_timed (bool, optional) – Whether to measure time. Default to True.

  • is_children_silent (bool, optional) – Whether to make child sections silent. Defaults to True.

  • is_track (bool, optional) – Whether to track the time. Defaults to False.

  • is_not_in_loop (bool, optional) – Whether to forcefully track this outside loop(). Defaults to False.

  • context (optional) – Reference to another section that will be used for monitoring the iteration.

labml.monit.enum(name, iterable: Sized, *, is_silent: bool = False, is_children_silent: bool = False, is_timed: bool = True, is_track: bool = False, is_not_in_loop: bool = False, context=None)[source]

This creates a monitored enumerator.

Parameters
  • name (str) – Name of the iterator

  • iterable (Sized]) – The iterable

Keyword Arguments
  • is_silent (bool, optional) – Whether not to print time taken. Defaults to False.

  • is_timed (bool, optional) – Whether to measure time. Default to True.

  • is_children_silent (bool, optional) – Whether to make child sections silent. Defaults to True.

  • is_track (bool, optional) – Whether to track the time. Defaults to False.

  • is_not_in_loop (bool, optional) – Whether to forcefully track this outside loop(). Defaults to False.

  • context (optional) – Reference to another section that will be used for monitoring the iteration.

labml.monit.mix(*iterators: Tuple[Union[str, Callable[[Any], None]], Union[Sized, int]], is_monit: bool = True)[source]
labml.monit.mix(total_iterations: int, *iterators: Tuple[Union[str, Callable[[Any], None]], Union[Sized, int]], is_monit: bool = True)

This has two overloads

labml.monit.mix(*iterators: Tuple[Union[str, Callable[[Any], None]], Union[Sized, int]], is_monit: bool = True)[source]
labml.monit.mix(total_iterations: int, *iterators: Tuple[Union[str, Callable[[Any], None]], Union[Sized, int]], is_monit: bool = True)[source]

This will iterate through a list of iterators while mixing among them. This is useful, for instance, when you want to mix training, validation, sampling steps within an epoch.

You can give it tuples of iterator names and iterators. It will yield the names along with the iterator values.

If you pass a function instead of a name it will call that function with the iterator value, instead of yielding it.

Parameters
  • total_iterations (Union[Collection, range, int]) – The number of times to mix

  • iterators (Tuple[Union[str, Callable[[Any], None]], Union[Sized, int]]) – Are iterators and their names or callback function

  • is_monit (bool, optional) – Whether to monitor the iterations, when inside loop(). Default to True.

Loop

labml.monit.loop(iterator_: int, *, is_track: bool = True, is_print_iteration_time: bool = True)[source]
labml.monit.loop(iterator_: range, *, is_track: bool = True, is_print_iteration_time: bool = True)
labml.monit.loop(iterator_: Collection, *, is_track: bool = True, is_print_iteration_time: bool = True)

This has multiple overloads

labml.monit.loop(iterator_: range, *, is_track=True, is_print_iteration_time=True)[source]
labml.monit.loop(iterator_: int, *, is_track=True, is_print_iteration_time=True)[source]
labml.monit.loop(iterator_: Collection, *, is_track=True, is_print_iteration_time=True)[source]

This creates a monitored loop. This is designed for training loops. It has better monitoring than using iterate() or enum().

Parameters

iterator (Union[Collection, range, int]) – The iterator

Keyword Arguments
  • is_track (bool, optional) – Whether track the loop time using labml.tracker. Default to True.

  • is_print_iteration_time (bool, optional) – Whether to print iteration time. Default to True.

labml.monit.finish_loop() None[source]

Finish the loop and flush all the loop related monitoring stats.