Skip to main content

An enterprise-grade PyTorch monitoring and analytics toolkit.

Project description

🔥 GradLens

CI PyPI version

An enterprise-grade PyTorch monitoring and analytics toolkit.


🚀 Quick Start (v0.1)

gradlens provides a lightweight, zero-overhead monitoring engine for your PyTorch training loops.


Installation

pip install gradlens

Usage

Use the gl.watch() context manager to automatically attach hooks to your model. The monitor.log() method captures statistics with near-zero performance impact.

import torch
import torch.nn as nn
import gradlens as gl  # Import the library

# 1. Define your model and data (example)
model = nn.Sequential(nn.Linear(10, 20), nn.ReLU(), nn.Linear(20, 1))
data = torch.randn(16, 10)
target = torch.randn(16, 1)
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
criterion = nn.MSELoss()

# 2. Wrap your training loop with gl.watch()
try:
    with gl.watch(model) as monitor:
        for _ in range(10):  # Example training loop

            # --- Training Step ---
            optimizer.zero_grad()
            output = model(data)
            loss = criterion(output, target)
            loss.backward()  # Hooks capture data here
            optimizer.step()

            # 3. Log the loss
            monitor.log(loss=loss.item())

except Exception as e:
    print(f"Training failed: {e}")

finally:
    # 4. Get the results
    history = monitor.get_history()

    print("\n--- Training History ---")
    print(f"Total steps: {len(history['loss'])}")
    print(f"Final loss: {history['loss'][-1]}")

    # Show stats for the last step
    last_stats = monitor.get_stats()
    print("\n--- Last Step Stats ---")
    print(f"Gradient Norms: {last_stats['grad_norm']}")
    print(f"Dead Neuron %: {last_stats['dead_neuron_pct']}")

This is the v0.1 engine. Visualization and advanced analytics will be added in future versions.


🧑‍💻 Development & Packaging

  1. Set up a virtual environment
    python -m venv .venv && source .venv/bin/activate
    pip install --upgrade pip hatch
    
  2. Run the automated test suite
    hatch run test
    
  3. Build distributable artifacts (wheel + sdist)
    HATCH_HOME=.hatch hatch build
    

    Setting HATCH_HOME keeps Hatch’s build env inside the repo, which works well on locked-down machines/CI runners.

  4. Publish to PyPI (manual invocation)
    HATCH_INDEX_USER="__token__" \
    HATCH_INDEX_AUTH="$PYPI_API_TOKEN" \
    hatch publish pypi
    

Tagging releases as v* lets GitHub Actions (when re-enabled) run the same build/publish pipeline automatically.

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

gradlens-0.1.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

gradlens-0.1.3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file gradlens-0.1.3.tar.gz.

File metadata

  • Download URL: gradlens-0.1.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gradlens-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e1620848a16ecfd6d6f1f803adb895715bc1d64a79ed6cffe63886d0bc3447a8
MD5 b52b4033a3a9fca502c56c19709fd676
BLAKE2b-256 7242fbdef962e16694065a0247696206d961111887e678af8af288c2af030c08

See more details on using hashes here.

File details

Details for the file gradlens-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: gradlens-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gradlens-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6ed6f0867a297f99c6df40005ffc25038e63d0b1689617acfc8e4443460321c0
MD5 050c1ec93990b551f7213df6f35d7fe2
BLAKE2b-256 9d3f1ff14adf3e0cbb115605be4269f9745278ba9ac3bb1957438cf0448e3e9f

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