AbstractLens#

class monitorch.lens.AbstractLens[source]#

Bases: ABC

Base class for all lenses.

Defines minimal interface that a lens must satisfy to interact with monitorch.inspector.PyTorchInspector and visualizers from monitorch.visualizer.

Lens implementation should allocate and manage all gatherers and preprocessors alone.

abstract detach_from_module()[source]#

Detaches lens from module.

Detaches gatherers and resets inner state.

abstract finalize_epoch()[source]#

Finaizes computations done thorugh epoch.

During finalization data from preprocessors can be transfered to dedicated storages and reorganized in visualizer friendly way.

abstract introduce_tags(visualizer: AbstractVisualizer)[source]#

Introduces lens’s plots to visualizer.

It is a preparation method for the visualizer. Lens should pass all tags to register_tags() with appropriate attributes.

Parameters:

visualzier (AbstractVisualizer) – A visualizer object to pass tag attributes to.

register_foreign_preprocessor(ext_ppr: AbstractPreprocessor, inspector_state)[source]#

Registers preprocessor allocated and managed by external environment.

Gets a week reference to a preprocessor and decides what to do with it. Primary example is monitorch.preprocessor.ExplicitCall, it is usually allocated inside inspector.

Parameters:

ext_ppr (AbstractPreprocessor) – External preprocessor to register (or ignore).

abstract register_leaf_module(module: Module, module_name: str, inspector_state)[source]#

Registers (or ignores) leaf module.

Register module, i.e., create and link gatherers. The lens should ignore the modules it does not interact with not to overcrowd plots with useless information.

Parameters:
  • module (torch.nn.Module) – The module object to hook gatherers onto.

  • module_name (str) – Name of the module, module’s information will be passed to visaulizer under this name.

register_non_leaf_module(module: Module, module_name: str, inspector_state)[source]#

Registers (or ignores) non-leaf module. By default does nothing.

Register module, i.e., create and link gatherers. The lens should ignore the modules it does not interact with not to overcrowd plots with useless information.

Parameters:
  • module (torch.nn.Module) – The module object to hook gatherers onto.

  • module_name (str) – Name of the module, module’s information will be passed to visaulizer under this name.

abstract reset_epoch()[source]#

Resets inner state.

Resets data computed during last epoch and resets preprocessors.

abstract vizualize(visualizer: AbstractVisualizer, epoch: int)[source]#

Passes computed data to visualizer.

Uses plot method from visualizer to pass the data.

Parameters:
  • visualizer (AbstractVisualizer) – The visualizer object responsbile for drawing plots.

  • epoch (int) – Computation’s epoch number.