Skip to main content

Enhanced model analysis tool for PyTorch models

Project description

TorchInsight

TorchInsight is an enhanced PyTorch model analysis tool that provides functionality similar to torchinfo but with custom formatting and additional features.

Features

  • Detailed model structure visualization
  • Automatic FLOPS calculation with appropriate unit selection (K, M, G)
  • Support for input dimension specification without batch dimension
  • Support for long dtype specification for specific inputs
  • Analysis of various model architectures (CNN, Attention, Recommendation systems, etc.)
  • Colorized output for improved readability

Installation

pip install torchinsight

Quick Start

import torch
import torch.nn as nn
from torchinsight import analyze_model

# Create a simple model
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1)
        self.pool = nn.MaxPool2d(2, 2)
        self.fc = nn.Linear(16 * 16 * 16, 10)
        
    def forward(self, x):
        x = self.pool(torch.relu(self.conv1(x)))
        x = x.view(-1, 16 * 16 * 16)
        x = self.fc(x)
        return x

# Create model instance
model = SimpleModel()

# Analyze model
summary = analyze_model(
    model,
    model_name="SimpleModel",
    input_dims=(3, 32, 32),  # Input dimensions (channels, height, width)
    batch_size=64,  # Batch size
)

# Print analysis results
print(summary)

Advanced Usage

TorchInsight supports multiple input formats and data types:

# Analyze model with multiple inputs
summary = analyze_model(
    model,
    model_name="ComplexModel",
    input_dims=[(13,), (5,)],  # Two inputs with dimensions (13,) and (5,)
    long_indices=[1],  # Second input (index 1) should be torch.long
    batch_size=128,  # Batch size
)

For more examples, see the examples directory.

Documentation

For complete documentation, visit:

Contributing

Contributions are welcome! Feel free to submit Pull Requests or create Issues.

License

This project is licensed under the MIT License - see the LICENSE file for details.

中文

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

torchinsight-0.1.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

torchinsight-0.1.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file torchinsight-0.1.1.tar.gz.

File metadata

  • Download URL: torchinsight-0.1.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for torchinsight-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0dec632027c32fe4a457b22b8a93ebac4313b13f3621b4c310adf107424cf301
MD5 259858114b8f8e34b824882195a65ad4
BLAKE2b-256 b547c1fc70a28186a227a4b9c3607e234f8fa6aeff324a0e135503eaa7368238

See more details on using hashes here.

File details

Details for the file torchinsight-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: torchinsight-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for torchinsight-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f2a820fd6bb0afad6eb96e40bd7bff4448f33b010b4c85d0a02e92b59ee334e
MD5 b7c425db7a0de34cae9ad172a050a15c
BLAKE2b-256 7a3034a2cabe3dac3b339b7d5ea2a4ec9e3b3d23ff8e490f2c1b345342e92d99

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