Monitor¶
- class Monitor(reducer: Reducer, module: Module | None = None, prehook: str | None = None, posthook: str | None = None, prehook_kwargs: dict[str, Any] | None = None, posthook_kwargs: dict[str, Any] | None = None, train_update: bool = True, eval_update: bool = True)[source]¶
Bases:
Module
,ContextualHook
Base class for recording input, output, or state of a Module.
- Parameters:
reducer (Reducer) – underlying means for reducing samples over time and storing them.
module (Module | None, optional) – module to register as the target for monitoring, can be modified after construction. Defaults to
None
.prehook (str | None, optional) – name of the prehook method, if any, to execute, no prehook when
None
. Defaults toNone
.posthook (str | None, optional) – name of the posthook method, if any, to execute, no posthook when
None
. Defaults toNone
.prehook_kwargs (dict[str, Any] | None, optional) – keyword arguments passed to
register_forward_pre_hook()
. Defaults toNone
.posthook_kwargs (dict[str, Any] | None, optional) – keyword arguments passed to
register_forward_hook()
. Defaults toNone
.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
.
Important
While
Monitor
can be used directly, it must be subclassed to be used in cases where monitors are constructed automatically.See also
See
register_forward_pre_hook()
andregister_forward_hook()
for keyword arguments that can be passed withprehook_kwargs
andposthook_kwargs
respectively.- property latest: Tensor¶
Return’s the reducer’s current state.
If
peek()
has multiple options, this should be considered as the default. Unless overridden,peek()
is called without arguments.- Returns:
reducer’s current state.
- Return type:
- classmethod partialconstructor(*args, **kwargs) MonitorConstructor [source]¶
Returns a function with a common signature for monitor construction.
- Raises:
NotImplementedError –
partialconstructor
must be implemented by the subclass.- Returns:
partial constructor for monitor.
- Return type:
- property reducer: Reducer¶
Underlying reducer used by the monitor.
- Returns:
underlying reducer.
- Return type:
- register(module: Module | None = None) None [source]¶
Registers the monitor as a forward hook/prehook.
- Parameters:
module (Module | None, optional) – module with which to register, last registered if
None
. Defaults toNone
.- Raises:
RuntimeError – weak reference to the last referenced module is no longer valid or did not exist.