OutputMonitor

class OutputMonitor(reducer: Reducer, module: Module = None, train_update: bool = True, eval_update: bool = True, prepend: bool = False, filter_: Callable[[Any], bool] | None = None, map_: Callable[[Any], tuple[Tensor, ...]] | None = None)[source]

Bases: Monitor

Records the outputs returned from a Module.

Parameters:
  • reducer (Reducer) – underlying means for reducing samples over time and storing them.

  • module (Module, optional) – module to register as the target for monitoring, can be modified after construction. Defaults to None.

  • train_update (bool, optional) – if this monitor should be called when the module being monitored is in train mode. Defaults to True.

  • eval_update (bool, optional) – if this monitor should be called when the module being monitored is in eval mode. Defaults to True.

  • prepend (bool, optional) – if this monitor should be called before other registered forward posthooks. Defaults to False.

  • filter (Callable[[Any], bool] | None, optional) – test if the output should be passed to the reducer, ignores None values when None. Defaults to None.

  • map (Callable[[Any], tuple[torch.Tensor, ...]] | None, optional) – modifies the output before being passed to the reducer, wraps with a tuple if not already a tuple if None. Defaults to None.

Note

The output depends on the forward() of the Module being called. If it a single tensor, it will work as expected. Otherwise a map_ must be specified which takes the output and returns a single tensor.

classmethod partialconstructor(reducer: Reducer, train_update: bool = True, eval_update: bool = True, prepend: bool = False, filter_: Callable[[Any], bool] | None = None, map_: Callable[[Any], tuple[Tensor, ...]] | None = None) MonitorConstructor[source]

Returns a function with a common signature for monitor construction.

Parameters:
  • reducer (Reducer) – underlying means for reducing samples over time and storing them.

  • train_update (bool, optional) – if this monitor should be called when the module being monitored is in train mode. Defaults to True.

  • eval_update (bool, optional) – if this monitor should be called when the module being monitored is in eval mode. Defaults to True.

  • prepend (bool, optional) – if this monitor should be called before other registered forward prehooks or posthooks. Defaults to False.

  • filter (Callable[[Any], bool] | None, optional) – test if the output should be passed to the reducer, ignores None values when None. Defaults to None.

  • map (Callable[[Any], tuple[torch.Tensor, ...]] | None, optional) – modifies the output before being passed to the reducer, wraps with a tuple if not already a tuple if None. Defaults to None.

Returns:

partial constructor for monitor.

Return type:

MonitorConstructor