skillfed

torchprofile

Count the MACs / FLOPs of PyTorch models

torchprofile v0.1.0 297.6K downloads/30d#7,882 on PyPI645
Permissive license MIT Active released

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 torchprofile

uv

uv add torchprofile

poetry

poetry add torchprofile

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

pytorch model mac counterflop profiler torchneural network operation counterpytorch computation graph profilermodel efficiency analysispytorch mac countingdeep learning profiling tool
profilingpytorchmodel-analysis

More Artificial Intelligence packages