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)

Backward Analyze

Analyze run time and memory of each layer in backward:

from torchanalyzer import ModelTimeMemAnalyzer

analyzer = ModelTimeMemAnalyzer(model)
info = analyzer.analyze(inputs, with_backward=True)

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.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

torch_analyzer-1.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_analyzer-1.2.tar.gz
  • Upload date:
  • Size: 13.4 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.2.tar.gz
Algorithm Hash digest
SHA256 12c6c8f865ac62d51568717d681407066d06af35323b74879e05bfbfbe664399
MD5 d0c1213ec00e2c177c03ef9b42ae3aef
BLAKE2b-256 781a955f0424158db595c38ac4ea2418db0511418c225d753cd1dcfe0c7da6bf

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: torch_analyzer-1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95c9fec89222e7a70a32d4e335555ae92744f79e2a9365ac4854d6fba59e0da4
MD5 9c7d8b7417d32f5da372588c2bed8856
BLAKE2b-256 547fc593d0cd0dd5770c2a73f5c0f9fb4486afcbee37af53332ad9c5a50bc995

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