Skip to main content

Lightweight utilities for inspecting PyTorch model shapes.

Project description

torchinspect

Lightweight utilities for inspecting PyTorch model shapes and common mismatch errors.

Install

From PyPI (recommended):

pip install torch_model_inspector

Local editable install (for development):

pip install -e .

Usage

import torch
import torch.nn as nn
from torchinspect import analyze, count_parameters, print_report

class BadModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(3, 8, kernel_size=3, stride=1, padding=1)
        self.fc = nn.Linear(16, 10)  # intentionally wrong

    def forward(self, x):
        x = self.conv(x)
        return self.fc(x)

m = BadModel()
x = torch.randn(2, 3, 32, 32)

res = analyze(m, x)
print_report(res, last_n=20)

total_params = count_parameters(m)
print("trainable params:", total_params)

What’s included

  • analyze(model, *example_inputs): records per-layer input/output shapes
  • print_report(result): prints a readable summary
  • suggest_fixes(records, error): helpful hints for common shape issues
  • count_parameters(model, trainable_only=True): total parameter count

Import name

The PyPI package is torch_model_inspector, but you import it as:

import torchinspect

License

MIT

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

torch_model_inspector-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

torch_model_inspector-0.1.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file torch_model_inspector-0.1.2.tar.gz.

File metadata

  • Download URL: torch_model_inspector-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torch_model_inspector-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e1cfaf0ec76f709e7757174f207e8af5ded03059e0615d3d9ca6c44a932d9034
MD5 c26ac9357dac33c3757cbaa982c7bd84
BLAKE2b-256 916b98a379b97cd87705bd78f7fac257fab3350f22be3abd4135d30afb4e6ce9

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_model_inspector-0.1.2.tar.gz:

Publisher: publish.yaml on ptkakaeitoe/torchinspect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torch_model_inspector-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_model_inspector-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 43c1d4a617e9e3110d2ed341adba28463ab4f5e547322d7dabc958b065abaa28
MD5 32a51f32dea60a597c9aee7c075e3ac3
BLAKE2b-256 ba895f4cec5198333f61ad58de4bc05e3db19fe72977d44795723bebeedad896

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_model_inspector-0.1.2-py3-none-any.whl:

Publisher: publish.yaml on ptkakaeitoe/torchinspect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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