Skip to main content

A plug-and-use python library to monitor learning of PyTorch neural networks

Project description

Monitorch

A plug-and-use python module to monitor learning of PyTorch neural networks. Heavily inspired by an article by Malcolm Lett. Provides easy to use interface to collect and display

  • Loss and custom metrics
  • Layer outputs (activation and norms)
  • Gradients (norms, scalar products and activation)
  • Neural Net's Parameters (norm)

Monitorch manages layer separation, data collection and vizualization with simple exposed methods and classes, so the code is concise and expressive without sacrificing informativness of the vizualizations and broad scope of its application. It also allows user to choose between static matplotlib and dynamic tensorboard plotting to help investigate both small models and keep track of large machines.

Documentation can be found under this link.

Usage

Installation

Install the module using pip dependency manager.

pip install monitorch

Code

Use PyTorchInspector from monitorch.inspector to hook your module and lenses (for example LossMetrics or ParameterGradientGeometry) from monitorch.lens to define vizualizations.

import torch

from monitorch.inspector import PyTorchInspector
from monitorch.lens import LossMetrics, ParameterGradientGeometry

mynet = MyNeuralNet() # torch.nn.Module subclass
loss_fn = MSELoss()
optimizer = torch.optim.Adam(module.parameters())

inspector = PyTorchInspector(
    lenses = [
        LossMetrics(loss_fn=loss_fn),
        ParameterGradientGeometry()
    ],
    module = mynet,
    vizualizer = "matplotlib"
)

for epoch in range(n_epochs):
    # No changes to your training loop
    # Passes through training and validation datasets remain the same

    ...

    # at the end of an epoch inspector must be ticked
    inspector.tick_epoch()

inspector.vizualizer.show_fig()

You can choose other vizualizers by passing "tensorboard", "print" or an instance of vizualizer's class from monitorch.vizualizers. Note that matplotlib vizualier requires show_fig() call to plot.

Currently module supports gradient and parameter collection for arbitrary PyTorch module and output collection for single output architectures (feedforward, convolution, non-transformer autoencoders etc).

Requirments

  • python>=3.10
  • torch>=2.0.0
  • matplotlib>=3.10.0
  • tensorboard>=2.19.0

Tests

Tests can be run with pytest from root project directory. Lens test have no assertions or other critical functionality tests, but are rather smoke tests to catch unhandled exceptions. To run functionality tests run pytest -k "not smoke".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monitorch-0.1.0.2.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monitorch-0.1.0.2-py3-none-any.whl (73.6 kB view details)

Uploaded Python 3

File details

Details for the file monitorch-0.1.0.2.tar.gz.

File metadata

  • Download URL: monitorch-0.1.0.2.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for monitorch-0.1.0.2.tar.gz
Algorithm Hash digest
SHA256 886a78374706403624c87e9cc3639f36f746d3a43c5d96e5f13d821c4ea0dcb4
MD5 a095beebf7051c9098d2565dff807f41
BLAKE2b-256 469762e9f92a81197eafb345cc53834715414c1e754a31a3e6cc4c7c9d055827

See more details on using hashes here.

File details

Details for the file monitorch-0.1.0.2-py3-none-any.whl.

File metadata

  • Download URL: monitorch-0.1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 73.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for monitorch-0.1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 53ee34ef630cd6149c0a1bff70ad6fff21aaf0e0d601c9fd7c2d6afcf09741ef
MD5 b468d7aa02c2a018a9594df0431d136b
BLAKE2b-256 59ecf23098839960acd7b3347fd54d10a8cc56733da58bf7efaa298a261e7a6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page