StateMonitor

class StateMonitor(reducer: Reducer, attr: str, module: Module = None, as_prehook: bool = False, 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 state of an attribute in a Module.

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

  • attr (str) – attribute or nested attribute to target.

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

  • as_prehook (bool, optional) – if this monitor should be called before the forward call of the module being monitored. Defaults to False.

  • 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 input should be passed to the reducer, ignores None values when None. Defaults to None.

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

Note

The end target of this can be a method name, however map_ will need to be specified in such a way as to call the method with desired arguments.

Note

The nested attribute should be specified with dot notation. For instance, if the observed module has an attribute a which in turn has an attribute b that should be monitored, then attr should be ‘a.b’`. Even with nested attributes, the monitor’s hook will be tied to the module with which it is registered.

classmethod partialconstructor(reducer: Reducer, as_prehook: bool = False, 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.

  • as_prehook (bool, optional) – if this monitor should be called before the forward call of the module being monitored. Defaults to False.

  • 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 input should be passed to the reducer, ignores None values when None. Defaults to None.

  • map (Callable[[Any], tuple[torch.Tensor, ...]] | None, optional) – modifies the input 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