Exemple #1
0
def add(*args, **kwargs):
    """
    This has multiple overloads

    .. function:: add(values: Dict[str, any])
        :noindex:

    .. function:: add(name: str, value: any)
        :noindex:

    .. function:: add(**kwargs: any)
        :noindex:
    """
    assert len(args) <= 2

    if len(args) == 0:
        _add_dict(kwargs)
    elif len(args) == 1:
        assert not kwargs
        assert isinstance(args[0], dict)
        _add_dict(args[0])
    elif len(args) == 2:
        assert not kwargs
        assert isinstance(args[0], str)
        _internal().store(args[0], args[1])
Exemple #2
0
def log(*args, is_new_line: bool = True, is_reset: bool = True):
    r"""
    This has multiple overloads

    .. function:: log(message: str, *, is_new_line=True)
        :noindex:

    .. function:: log(message: str, color: StyleCode, *, is_new_line=True)
        :noindex:

    .. function:: log(message: str, colors: List[StyleCode], *, is_new_line=True)
        :noindex:

    .. function:: log(messages: List[Union[str, Tuple[str, StyleCode]]], *, is_new_line=True)
        :noindex:

    .. function:: log(*args: Union[str, Tuple[str, StyleCode]], is_new_line: bool = True)
        :noindex:

    Arguments:
        message (str): string to be printed
        color (StyleCode): color/style of the message
        colors (List[StyleCode]): list of colors/styles for the message
        args (Union[str, Tuple[str, StyleCode]]): list of messages
            Each element should be either a string or a tuple of string and styles.
        messages (List[Union[str, Tuple[str, StyleCode]]]): a list of messages.
            Each element should be either a string or a tuple of string and styles.

    Keyword Arguments:
        is_new_line (bool): whether to print a new line at the end

    Example::
        >>> logger.log("test")
    """
    from labml.internal.logger import logger_singleton as _internal

    if len(args) == 0:
        assert is_new_line
        _internal().log([], is_new_line=is_new_line, is_reset=is_reset)
    elif len(args) == 1:
        message = args[0]
        if isinstance(message, str):
            _internal().log([(message, None)],
                            is_new_line=is_new_line,
                            is_reset=is_reset)
        elif isinstance(message, list):
            _internal().log(message,
                            is_new_line=is_new_line,
                            is_reset=is_reset)
        else:
            raise TypeError(f'Unrecognized type: {type(message)}', message)
    elif len(args) == 2 and isinstance(args[0], str) and isinstance(
            args[1], StyleCode):
        _internal().log([(args[0], args[1])],
                        is_new_line=is_new_line,
                        is_reset=is_reset)
    else:
        _internal().log(args, is_new_line=is_new_line, is_reset=is_reset)
Exemple #3
0
def enum(name,
         iterable: Sized,
         *,
         is_silent: bool = False,
         is_timed: bool = True):
    return _internal().enum(name,
                            iterable,
                            is_silent=is_silent,
                            is_timed=is_timed)
Exemple #4
0
def inspect(*args, **kwargs):
    """
    Pretty prints a set of values.

    This has multiple overloads

    .. function:: inspect(items: Dict)
        :noindex:

    .. function:: inspect(items: List)
        :noindex:

    .. function:: inspect(*items: any)
        :noindex:
    """

    from labml.internal.logger import logger_singleton as _internal

    _internal().info(*args, **kwargs)
Exemple #5
0
def loop(iterator_: Union[range, int],
         *,
         is_print_iteration_time: bool = True):
    """
        This has multiple overloads

        .. function:: loop(iterator_: range, *,is_print_iteration_time=True)
            :noindex:

        .. function:: loop(iterator_: int, *,is_print_iteration_time=True)
            :noindex:
        """

    if type(iterator_) == int:
        return _internal().loop(
            range(iterator_), is_print_iteration_time=is_print_iteration_time)
    else:
        return _internal().loop(
            iterator_, is_print_iteration_time=is_print_iteration_time)
Exemple #6
0
def iterate(name,
            iterable: Union[Iterable, Sized, int],
            total_steps: Optional[int] = None,
            *,
            is_silent: bool = False,
            is_timed: bool = True):
    return _internal().iterate(name,
                               iterable,
                               total_steps,
                               is_silent=is_silent,
                               is_timed=is_timed)
Exemple #7
0
def section(name,
            *,
            is_silent: bool = False,
            is_timed: bool = True,
            is_partial: bool = False,
            is_new_line: bool = True,
            total_steps: float = 1.0):
    return _internal().section(name,
                               is_silent=is_silent,
                               is_timed=is_timed,
                               is_partial=is_partial,
                               total_steps=total_steps,
                               is_new_line=is_new_line)
Exemple #8
0
def save(*args, **kwargs):
    r"""
    This has multiple overloads

    .. function:: save()
        :noindex:

    .. function:: save(global_step: int)
        :noindex:

    .. function:: save(values: Dict[str, any])
        :noindex:

    .. function:: save(name: str, value: any)
        :noindex:

    .. function:: save(**kwargs: any)
        :noindex:

    .. function:: save(global_step: int, values: Dict[str, any])
        :noindex:

    .. function:: save(global_step: int, name: str, value: any)
        :noindex:

    .. function:: save(global_step: int, **kwargs: any)
        :noindex:
    """
    if len(args) > 0 and type(args[0]) == int:
        _internal().set_global_step(args[0])
        args = args[1:]

    if len(args) > 0 or len(kwargs.keys()) > 0:
        add(*args, **kwargs)

    _internal().write()
Exemple #9
0
def set_scalar(name: str, is_print: bool = False):
    from labml.internal.logger.store.indicators.numeric import Scalar
    _internal().add_indicator(Scalar(name, is_print))
Exemple #10
0
def reset():
    r"""
    Reset indicators, for a new experiment
    """
    _internal().reset_store()
Exemple #11
0
def set_histogram(name: str, is_print: bool = False):
    from labml.internal.logger.store.indicators.numeric import Histogram
    _internal().add_indicator(Histogram(name, is_print))
Exemple #12
0
def set_tensor(name: str):
    from labml.internal.logger.store.artifacts import Tensor
    _internal().add_artifact(Tensor(name))
Exemple #13
0
def namespace(name: str):
    r"""
    Set a namespace for tracking
    """
    return _internal().store_namespace(name)
Exemple #14
0
def progress(steps: float):
    _internal().progress(steps)
Exemple #15
0
def set_indexed_text(name: str,
                     title: Optional[str] = None,
                     is_print: bool = False):
    from labml.internal.logger.store.indicators.artifacts import IndexedText
    _internal().add_indicator(IndexedText(name, title, is_print))
Exemple #16
0
def set_tensor(name: str, is_once: bool = False):
    from labml.internal.logger.store.indicators.artifacts import Tensor
    _internal().add_indicator(Tensor(name, is_once=is_once))
Exemple #17
0
def set_indexed_scalar(name: str):
    from labml.internal.logger.store.indicators.indexed import IndexedScalar
    _internal().add_indicator(IndexedScalar(name))
Exemple #18
0
def fail():
    _internal().set_successful(False)
Exemple #19
0
def set_text(name: str, is_print: bool = False):
    from labml.internal.logger.store.indicators.artifacts import Text
    _internal().add_indicator(Text(name, is_print))
Exemple #20
0
def finish_loop():
    _internal().finish_loop()
Exemple #21
0
def set_global_step(global_step: Optional[int]):
    _internal().set_global_step(global_step)
Exemple #22
0
def get_global_step() -> int:
    return _internal().global_step
Exemple #23
0
def _add_dict(values: Dict[str, any]):
    for k, v in values.items():
        _internal().store(k, v)
Exemple #24
0
def set_queue(name: str, queue_size: int = 10, is_print: bool = False):
    from labml.internal.logger.store.indicators.numeric import Queue
    _internal().add_indicator(Queue(name, queue_size, is_print))
Exemple #25
0
def add_global_step(increment_global_step: int = 1):
    _internal().add_global_step(int(increment_global_step))
Exemple #26
0
def set_image(name: str, is_print: bool = False):
    from labml.internal.logger.store.artifacts import Image
    _internal().add_artifact(Image(name, is_print))