thop
A tool to count the FLOPs of PyTorch model.
What it is and what it does
THOP is a PyTorch profiling tool that measures the computational cost of neural network models by counting multiply-accumulate operations (MACs) and model parameters. It works by instrumenting torch models during a forward pass to track operations, then reporting aggregate statistics.
The package is designed for model developers and researchers who need to understand the computational footprint of their networks—useful when comparing architectures, optimizing for deployment, or working within compute budgets. It includes built-in counting rules for standard layers and allows custom counting logic for third-party modules. The `clever_format` utility provides readable output formatting.
Use it for:
- Compare computational complexity across different neural network architectures before training.
- Profile existing models to identify bottlenecks and guide optimization efforts.
- Estimate deployment feasibility by checking MACs and parameter counts against hardware constraints.
- Benchmark model efficiency for resource-constrained deployment scenarios.
- Validate custom layers by defining counting rules for non-standard torch modules.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Counts floating-point operations (MACs) and parameters in PyTorch neural network models to profile computational complexity.
Yes, if you are actively profiling torch models and can tolerate dormant maintenance. The package is stable for its narrow use case and has no known vulnerabilities, but verify compatibility with your torch version before relying on it in production. Consider alternatives if you need ongoing support or features for very recent model architectures.
Install
thop on PyPI
pip
pip install thopuv
uv add thoppoetry
poetry add thopInstalling thop
Before you install
Low friction installation via pip; dormant maintenance status with last commit in July 2024 and no releases since September 2022, though the repository remains active with 5079 stars.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal legal constraints.
Quickstart
pip install thop
from thop import profile, clever_format
import torch
model = resnet50()
input_tensor = torch.randn(1, 3, 224, 224)
macs, params = profile(model, inputs=(input_tensor,))
macs, params = clever_format([macs, params], "%.3f")
Requires torch as a runtime dependency; model must be a valid PyTorch nn.Module.
Verify before relying
- Whether the package works correctly with recent PyTorch versions given the dormant maintenance status since September 2022.
- Support for modern model architectures beyond those listed in the benchmark results.
- Compatibility with Python versions beyond the unspecified support declaration.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — torch |
| Maintenance | dormant — 1,437 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,035,556/month — #4,462 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: thop-0.1.1.post2209072238-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
torchprofileCounts multiply-accumulate operations (MACs) in…
permissive · top 15,000 on PyPI
torchsummaryDisplays a Keras-style summary of PyTorch…
unclear · top 15,000 on PyPI
opt-einsum-fxOptimizes PyTorch einsum operations and…
permissive · top 15,000 on PyPI
torch-tb-profilerIntegrates PyTorch profiling data with…
permissive · top 15,000 on PyPI
timmTimm provides a large collection of pretrained…
permissive · top 5,000 on PyPI
retinaface-pyDetects and localizes faces in images using a…
permissive · top 15,000 on PyPI
pretrainedmodelsProvides a unified interface to load pretrained…
permissive · top 15,000 on PyPI
pnnxExports and converts PyTorch neural network…
permissive · top 15,000 on PyPI
pygountPygount counts source lines of code (SLOC)…
permissive · top 15,000 on PyPI