logging_mixin

Implements LoggingMixin, which can be used easily log from any torch.nn.Module

Example

>>> class MyLayer(torch.nn.Module, LoggingMixin):
>>>     def forward(self, x, y):
>>>         z = x + y
>>>         # easily log intermediate value
>>>         self.log(x=x, z_intermediate=z)
>>>         z = z ** 2
>>>         self.log(z_final=z)
>>>         return z
class LoggingMixin[source]

A mixin class for logging.

Use in your nn.Module to log values during training and validation.

_process_log_dict(log_dict: dict) dict[source]

process a dict of things to be logged: log scalars directly, otherwise compute mean, std, abs_max

activate_logging() None[source]

Activate logging.

deactivate_logging() None[source]

Deactivate logging.

log(**log_dict: dict) None[source]

Log values, if logging was activated.

property log_dict: dict

A dictionary of values to log.

_locate_logging_mixins_generator(module: Module, prefix: str = '')[source]

Recursively locate all LoggingMixin instances in a module and its children.

locate_logging_mixins(module: Module) dict[source]

Locate all LoggingMixin instances in a module and its (named) children.

Parameters:

module – The module to search.

Returns:

A dictionary mapping the dotted ‘paths’ within the module to the LoggingMixin instances.