--- id: thop version: "0.1.1.post2209072238" license: MIT license_treatment: permissive maintenance: dormant --- # thop — A tool to count the FLOPs of PyTorch model. License: permissive · Maintenance: dormant · Downloads: 1.0M/mo ## 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 above — 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 pip install thop uv add thop 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 1.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytorch flop counter, model complexity analysis, neural network profiling, pytorch operation counter, compute cost estimation, model parameter counting, pytorch mac counter, model-profiling, pytorch-tools [View on SkillFed](https://skillfed.io/packages/thop) · [View on PyPI](https://pypi.org/project/thop/)