skillfed

thop

A tool to count the FLOPs of PyTorch model.

thop v0.1.1.post2209072238 1.0M downloads/30d#4,462 on PyPI5,079
Permissive license MIT DORMANT released

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 thop

uv

uv add thop

poetry

poetry add thop

Installing 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

Programming Language :: Python :: 3

Tags

pytorch flop countermodel complexity analysisneural network profilingpytorch operation countercompute cost estimationmodel parameter countingpytorch mac counter
model-profilingpytorch-tools

More Artificial Intelligence packages