Monitorch
A plug-and-use python module to monitor learning of PyTorch neural networks. Provides easy to use interface to collect and display
- Loss and custom metrics
- Layer outputs (activation and norms)
- Gradients (norms, oscilations and activation)
- Neural Net's Parameters Evolution
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 visualizations 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
Documentation can be found here:
https://monitorch.readthedocs.io/en/latest/.
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
Optional:
- matplotlib>=3.10.0
- tensorboard>=2.19.0
Development:
- sphinx>=8.1.3
- pydata-sphinx-theme>=0.16.1
- pytest>=9.0.3
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".
Other repositories
Case studies
- nanochat-monitorch Karpathy's nanochat with viewed using monitorch.
- monitorch-experments Repository with my results using monitorch (including nanochat logs).
Tensorflow
Malcolm Lett has created an excellent Tensorflow library with similar features. So if you prefer Tensorflow, please check it out:
Metadata
Release files for monitorch 0.1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| monitorch-0.1.0.7.tar.gz | 45.7 kB | Without provenance | Details for monitorch-0.1.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| monitorch-0.1.0.7-py3-none-any.whl | Python 3 | none | any | Details for monitorch-0.1.0.7-py3-none-any.whl |
Total release size: 124.7 kB
Release files / monitorch-0.1.0.7.tar.gz
| Download URL | monitorch-0.1.0.7.tar.gz |
|---|---|
| Size | 45.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72cb78fee7456faf5a830e6a457ac60895dbbc48d93894abb918529f742de3fd
|
|
BLAKE2b-256 checksum How to use checksums |
4c2e38d894ccce4594ad26f94ddedd35b543bfa205fab4189edf1deb2a9d8353
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / monitorch-0.1.0.7-py3-none-any.whl
| Download URL | monitorch-0.1.0.7-py3-none-any.whl |
|---|---|
| Size | 79.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef0809cc42fb2dafd6c38e414123861af256e689de8fe822e15b37c8937278b1
|
|
BLAKE2b-256 checksum How to use checksums |
3556c73a2e791abbe5c1072a4ac7ede27472a0145b6dc16df4a277a8fa7a53d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Security for monitorch 0.1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.