Skip to main content

A torch model analyzer

Project description

Torch Analyzer

This tool can be used to analyze the model run time, GPU memory usage, input/output information of each layer, and FLOPs of each layer in PyTorch models.

The run time, GPU memory usage, and FLOPs are analyzed at the cuda operator level, which is more accurate than the existing module-based analysis. Even model with custom operators can be analyzed.

example1

Installation

Install from pip:

pip install torch-analyzer

Install from source:

git clone https://github.com/IrisRainbowNeko/torch-analyzer.git
cd torch-analyzer
pip install -e .

Usage

Example:

import torch
import torchvision.models as models
from torchanalyzer import ModelTimeMemAnalyzer, TorchViser

model = models.resnet18().cuda()
inputs = torch.randn(1, 3, 224, 224).cuda()

analyzer = ModelTimeMemAnalyzer(model)
info = analyzer.analyze(inputs)
TorchViser().show(model, info)

Analyze model

Analyze run time of each layer:

from torchanalyzer import ModelTimeMemAnalyzer

analyzer = ModelTimeMemAnalyzer(model)
info = analyzer.analyze(inputs)

Analyze input/output information of each layer:

from torchanalyzer import ModelIOAnalyzer

analyzer = ModelIOAnalyzer(model)
info = analyzer.analyze(inputs)

Analyze flops of each layer:

from torchanalyzer import ModelFlopsAnalyzer

analyzer = ModelFlopsAnalyzer(model)
info = analyzer.analyze(inputs)

Show Analyzed Information

Show with the style like print(model) in torch:

from torchanalyzer import TorchViser
TorchViser().show(model, info)

Show with table style:

from torchanalyzer import TableViser
TableViser().show(model, info)

Show with flow style:

from torchanalyzer import FlowViser
FlowViser().show(model, info)

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_analyzer-1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

torch_analyzer-1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file torch_analyzer-1.0.tar.gz.

File metadata

  • Download URL: torch_analyzer-1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for torch_analyzer-1.0.tar.gz
Algorithm Hash digest
SHA256 9da81aa0675add8225c3527fe917f37a261418f893dd01bee348a46767879713
MD5 d305fa86eda6ca66fceece89ac0c0588
BLAKE2b-256 c78786871c93fbfcef512d31635b07c38127772c8b8be51d4de15abfa2bcc160

See more details on using hashes here.

Provenance

File details

Details for the file torch_analyzer-1.0-py3-none-any.whl.

File metadata

  • Download URL: torch_analyzer-1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for torch_analyzer-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cb72e9de5db59a557d609c7ffb5a39c15e986e58ee2219739e257e685b283f9
MD5 a7e6dab255472a9ba26ca16be5d910f4
BLAKE2b-256 b2f17596dce2d2ab6cd6a4869c66799a2706816c33c70d523b8762ebaf6dccbe

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page