Registry / ai-ml / thop
library0.1.1.post2209072238pypypi✓ verified 23d ago

THOP (PyTorch-OpCounter) is a Python library designed to calculate the Multiply-Accumulate Operations (MACs) and parameters of PyTorch models. It provides an intuitive API for deep learning practitioners to evaluate the computational efficiency and memory footprint of their models, aiding in optimization and architecture selection. The current PyPI version is 0.1.1.post2209072238, released in September 2022, indicating a less active maintenance cadence for this specific branch.

pip install thop
INSTALL
IMPORT
SIG · THOP
T
thop
ai-mlpythonv0.1.1.post2209072238
Install
64.7s avg
Import
Disk
4710MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.1.post2209072238 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 74.6s
py 3.11
✕ build_error
✓ 68.2s
py 3.12
✕ build_error
✓ 61.3s
py 3.13
✕ build_error
✓ 54.8s
py 3.9
✕ build_error
✕ timeout
4710MB installed
● package 4710MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

profile
from thop import profile
clever_format
from thop import clever_format

This quickstart demonstrates how to use `thop` to calculate the Multiply-Accumulate Operations (MACs) and parameters of a standard PyTorch model, then format the output for better readability.

import torch import torch.nn as nn from torchvision.models import resnet18 from thop import profile, clever_format # 1. Define a model and a dummy input model = resnet18() dummy_input = torch.randn(1, 3, 224, 224) # 2. Profile the model macs, params = profile(model, inputs=(dummy_input, ), verbose=False) # 3. Format the output for readability macs, params = clever_format([macs, params], "%.3f") print(f"MACs: {macs}") print(f"Parameters: {params}")
Debug
Known issues
gotchaTHOP primarily reports Multiply-Accumulate Operations (MACs). The interpretation of 1 MAC as 1 FLOP or 2 FLOPs (multiplication + addition) varies across literature and tools. Be mindful of this distinction when comparing results with other FLOPs counters.
fix
Understand that `thop`'s 'FLOPs' often refer to MACs. If strict FLOPs (e.g., each multiplication and addition counts as 1 FLOP) are needed, manually multiply `thop`'s MAC count by 2 for comparison, or refer to its internal definitions.
affects: All versions
gotchaFor models containing custom PyTorch modules or third-party layers not natively supported by `thop`, accurate MACs and parameter counting requires defining custom profiling rules via the `custom_ops` argument in the `profile` function.
fix
Refer to the `thop` documentation or examples on how to define `custom_ops` for unsupported module types to ensure comprehensive and accurate profiling.
affects: All versions
deprecatedThe `thop` library at `github.com/Lyken17/pytorch-OpCounter` (and PyPI version 0.1.1.post2209072238) has not been updated since September 2022. A more actively maintained fork, `ultralytics/thop`, exists with newer versions and continuous development.
fix
For active development or newer PyTorch compatibility, consider evaluating `ultralytics/thop` (installed via `pip install ultralytics-thop`) or explicitly checking the `Lyken17` repository for any new activity before relying on this version.
affects: 0.1.1.post2209072238 and earlier.
Upgrade
Version history
0.1.1.post2209072238latest on PyPI · released Sep 7, 2022
Audit
Dependencies
torchrequiredCore dependency for PyTorch model profiling.
Agent activity
27 hits · last 30 days
node
23
OpenAI (training)
1
Resources