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

Uploaded Source

Built Distribution

torch_analyzer-0.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for torch_analyzer-0.1.tar.gz
Algorithm Hash digest
SHA256 39852e96d7b24170845746ad2a031251e3d8bcd43d08c3e048e478602a0aa674
MD5 e332f63a80c231702e91d3d47881a94c
BLAKE2b-256 db9a581f8c3f793606be26c326bb352410fd6b403e7fa682985140c3a5acd252

See more details on using hashes here.

Provenance

File details

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

File metadata

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

File hashes

Hashes for torch_analyzer-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2a3a6e8047badd00c98ffa9d1a7b285492a59880a9fd7fd909dd048926fb283
MD5 afed9c53d1308012735a82b8f7d26bf9
BLAKE2b-256 59237928c303e5ef1d506c069428e5adfaafa39df521c99fb09af15e7e93c69f

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