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.0.tar.gz (21.1 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.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torchinsight-0.1.0.tar.gz
  • Upload date:
  • Size: 21.1 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.0.tar.gz
Algorithm Hash digest
SHA256 78eb5355a265296c344649ec798669148af522ee3991be2b88b9316db04d065f
MD5 560bb802726bad62f9a423e84ec0dca7
BLAKE2b-256 61cec6dae5d59d46fb6c7c3f624964af3aedf42055c502b4161564ae434b1929

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchinsight-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71b756fce95052ca96e7e22fa14b10ec1c488f3add451a5ed47bf014b2c1eed7
MD5 77601c52d988c701b10f798dd0316f64
BLAKE2b-256 1f98ed1a2a4943972f1f37e7750e550b6aa635981c7aece015f43a16d7adc095

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