ultralytics-thop
Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.
What it is and what it does
THOP is a PyTorch operation counter that measures model complexity by counting Multiply-Accumulate Operations and parameters. It runs a single forward pass through your model with example inputs and returns MAC and parameter counts, making it useful for comparing architecture efficiency before training or deployment. The package includes built-in counting rules for common layer types (convolutional, normalization, pooling, activation, linear, recurrent) and allows you to define custom counting rules for unsupported modules via forward hooks.
The package is lightweight and maintained by Ultralytics, with support for modern Python versions (3.8 through 3.14) across Linux, macOS, and Windows. It depends only on numpy and torch, keeping installation friction minimal. For image models, you can pass a stride parameter to estimate MACs from smaller stride-aligned profiles, or omit it for exact single-pass profiling. A helper function (clever_format) converts raw counts into human-readable notation.
Use it for:
- Compare computational complexity of different neural network architectures before training to choose the most efficient design.
- Estimate deployment requirements by profiling model MACs and parameters to predict inference latency and memory usage.
- Analyze custom or third-party layer implementations by registering custom counting rules to understand their computational cost.
- Profile models with variable input sizes using the stride parameter to estimate MACs across different spatial dimensions.
- Convert raw operation counts into human-readable format using clever_format for reporting and documentation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Profiles PyTorch models by counting Multiply-Accumulate Operations (MACs) and parameters in a single forward pass, with built-in rules for common layer types and support for custom counting rules.
Yes. THOP is actively maintained, has no known vulnerabilities, installs with minimal friction (two common dependencies), and solves a concrete problem in model development. The AGPL-3.0 license is a consideration only if you plan to distribute proprietary modifications; for research, internal tools, or open-source projects, it poses no barrier. Install it if you need to profile PyTorch model efficiency.
Install
ultralytics-thop on PyPI
pip
pip install ultralytics-thopuv
uv add ultralytics-thoppoetry
poetry add ultralytics-thopInstalling ultralytics-thop
Before you install
Low friction installation with only numpy and torch as runtime dependencies. Actively maintained by Ultralytics with a recent release (15 days old) and ongoing repository activity.
License in practice
Licensed under AGPL-3.0, which requires derivative works and modifications to remain open-source. An enterprise license is available from Ultralytics for proprietary use without open-source obligations.
Quickstart
pip install ultralytics-thop
import torch
from thop import profile
model = torch.nn.Sequential(torch.nn.Conv2d(3, 64, 3, padding=1))
inputs = (torch.randn(1, 3, 224, 224),)
macs, params = profile(model, inputs=inputs)
print(f"MACs: {macs}, Parameters: {params}")
Requires PyTorch and a compatible model instance; the profile() call executes a forward pass so the model must be in a state ready to accept the provided input tensor shape.
Verify before relying
- Whether custom counting rules for third-party modules are extensible enough for all common modern architectures beyond the built-in layer types.
- Performance overhead of profiling on very large models or when profiling is called repeatedly during training.
- Accuracy of MAC estimates when using the stride parameter for spatial-only models versus actual deployment compute.
Package facts
| License | AGPL-3.0 (agpl) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — numpy, torch |
| Maintenance | actively maintained — 15 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,458,146/month — #1,907 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ultralytics_thop-2.1.6-py3-none-any.whl
Keywords: FLOPs, PyTorch, Model Analysis
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
thopCounts floating-point operations (MACs) and…
permissive · 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
effdetPyTorch implementation of EfficientDet object…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
ultralyticsUltralytics YOLO provides a unified framework…
agpl · top 5,000 on PyPI
pytorchcvProvides a collection of pretrained computer…
unclear · top 15,000 on PyPI
opt-einsum-fxOptimizes PyTorch einsum operations and…
permissive · top 15,000 on PyPI
onnx-toolParse, analyze, optimize, and profile ONNX…
permissive · top 15,000 on PyPI
torchinfoGenerates detailed summaries of PyTorch neural…
permissive · top 15,000 on PyPI