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.
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)
Metadata
Release files for torch-analyzer 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torch_analyzer-1.4.2.tar.gz | 14.5 kB | Without provenance | Details for torch_analyzer-1.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torch_analyzer-1.4.2-py3-none-any.whl | Python 3 | none | any | Details for torch_analyzer-1.4.2-py3-none-any.whl |
Total release size: 32.9 kB
Release files / torch_analyzer-1.4.2.tar.gz
| Download URL | torch_analyzer-1.4.2.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f7892173486f11df5d4bc0e5b0b8eafa1d2aa2f1994450fb745597ccc33e879
|
|
BLAKE2b-256 checksum How to use checksums |
214c936d9641c04e0e64c952fb13491bd2fa7cabd5dbdcc2ca72569a9e29d2e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / torch_analyzer-1.4.2-py3-none-any.whl
| Download URL | torch_analyzer-1.4.2-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
028c6e4d02f425bf3fa07126368c296caf699c8141319c86c81f0b3f7fb1c95b
|
|
BLAKE2b-256 checksum How to use checksums |
e1258a91b96a541e100ece70378b077876c53a3b335492e7d559b8f87a807058
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for torch-analyzer 1.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.