torchprofile
Count the MACs / FLOPs of PyTorch models
What it is and what it does
TorchProfile is a lightweight profiler that measures the computational cost of PyTorch models by counting multiply-accumulate operations (MACs). It works by tracing the model's computation graph using torch.jit.trace, which is more accurate than hook-based profilers and more general than ONNX-based approaches. The package outputs either a single aggregate MAC count or a per-operator breakdown showing which layers consume the most computation.
You pass a model and sample input tensors to the profile_macs function, and it returns the total MACs or a dictionary mapping operation nodes to their individual MAC counts. This is useful for understanding model efficiency, comparing architectures, and identifying computational bottlenecks without running the model on actual hardware.
Use it for:
- Estimate computational cost of a model before deploying to resource-constrained devices.
- Compare MAC efficiency across different model architectures or hyperparameter choices.
- Identify which layers in a model consume the most computation for optimization targeting.
- Profile models during development to catch unexpectedly expensive operations early.
- Generate per-operator breakdowns for detailed performance analysis and model auditing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Counts multiply-accumulate operations (MACs) in PyTorch models by tracing the computation graph, providing both aggregate and per-operator breakdowns.
Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real need for PyTorch developers who want to profile model efficiency. The MIT license is permissive. Main caveat: your model must be traceable with torch.jit.trace, which excludes models with dynamic control flow.
Install
torchprofile on PyPI
pip
pip install torchprofileuv
uv add torchprofilepoetry
poetry add torchprofileInstalling torchprofile
Before you install
Low friction: pure Python wheel with only torch as a runtime dependency. Active maintenance with recent commits and a moderate user base.
License in practice
MIT license is permissive; you can use, modify, and distribute this package with minimal restrictions.
Quickstart
pip install torchprofile
import torch
from torchprofile import profile_macs
model = torch.nn.Linear(10, 10)
inputs = torch.randn(1, 10)
macs = profile_macs(model, inputs)
print(macs)
Requires Python >= 3.9 and torch installed; models must be traceable with torch.jit.trace.
Verify before relying
- Whether the tracing approach handles dynamic control flow or models with conditional branches accurately.
- Performance characteristics when profiling very large models or batches.
- Compatibility with torch.jit.trace limitations across different PyTorch versions.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — torch |
| Maintenance | actively maintained — 157 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 297,561/month — #7,882 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: torchprofile-0.1.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
ultralytics-thopProfiles PyTorch models by counting…
agpl · top 5,000 on PyPI
thopCounts floating-point operations (MACs) and…
permissive · top 5,000 on PyPI
torch-tb-profilerIntegrates PyTorch profiling data with…
permissive · top 15,000 on PyPI
HolisticTraceAnalysisAnalyzes PyTorch Profiler traces to identify…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnx2torchConverts ONNX models to PyTorch modules with a…
permissive · top 15,000 on PyPI
fvcorefvcore provides shared computer vision…
permissive · top 5,000 on PyPI
torchevalTorchEval provides a collection of PyTorch…
permissive · top 15,000 on PyPI
torchvizGenerates visual diagrams of PyTorch neural…
permissive · top 5,000 on PyPI