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:
MonitorRecords 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 toNone.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 toNone.
Note
The output depends on the
forward()of theModulebeing called. If it a single tensor, it will work as expected. Otherwise amap_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
Nonevalues whenNone. Defaults toNone.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 toNone.
- Returns:
partial constructor for monitor.
- Return type: