skillfed

ultralytics-thop

Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.

ultralytics-thop v2.1.6 6.5M downloads/30d#1,907 on PyPI151
AGPL license AGPL-3.0 Active released

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-thop

uv

uv add ultralytics-thop

poetry

poetry add ultralytics-thop

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: EducationIntended Audience :: Science/ResearchLicense :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)Operating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Scientific/Engineering :: Image RecognitionTopic :: Software Development

Tags

pytorch model flops countermac operations profilerneural network complexity analyzerpytorch model parameter counterdeep learning model profilingcompute cost estimationarchitecture efficiency comparison
model-profilingpytorch-toolsperformance-analysis

More Software Development packages