A profiler for matrix math, not milliseconds
THOP tallies the MACs, FLOPs, and parameters of a PyTorch model so you can size up a network before it hits silicon.

What it does
THOP profiles PyTorch models by tallying multiply-accumulate operations (MACs), floating-point operations (FLOPs), and trainable parameters for a given input shape. It also publishes a reference table of classic torchvision CNNs—from AlexNet to ShuffleNet—so you can stack your own model against familiar baselines.
The interesting bit
The library exposes a custom_ops hook that lets you define counting rules for third-party or bespoke modules, preventing oddball layers from silently dropping out of the total. It also includes a clever_format utility to turn raw integer counts into readable strings, because staring at ten-digit numbers is nobody’s idea of fun.
Key highlights
- Returns both MACs/FLOPs and parameter count from a single
profilecall. - Supports custom counting functions for unsupported modules via a dictionary hook.
- Formats output cleanly with
clever_formatinstead of dumping raw integers. - Bundles a benchmark script and results table for standard CNNs adapted from
torchvision.
Verdict Useful if you need a quick, architecture-level sanity check on model complexity. Skip it if your work is already covered by a lower-level profiler that traces kernel execution times.
Frequently asked
- What is Lyken17/pytorch-OpCounter?
- THOP tallies the MACs, FLOPs, and parameters of a PyTorch model so you can size up a network before it hits silicon.
- Is pytorch-OpCounter open source?
- Yes — Lyken17/pytorch-OpCounter is open source, released under the MIT license.
- What language is pytorch-OpCounter written in?
- Lyken17/pytorch-OpCounter is primarily written in Python.
- How popular is pytorch-OpCounter?
- Lyken17/pytorch-OpCounter has 5.1k stars on GitHub.
- Where can I find pytorch-OpCounter?
- Lyken17/pytorch-OpCounter is on GitHub at https://github.com/Lyken17/pytorch-OpCounter.