--- id: ultralytics-thop version: "2.1.6" license: AGPL-3.0 license_treatment: agpl maintenance: active --- # ultralytics-thop — Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters. License: agpl · Maintenance: active · Downloads: 6.5M/mo ## 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 above — 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 pip install ultralytics-thop uv add ultralytics-thop 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_current - Install friction: low - Maintenance: active - Downloads: 6.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytorch model flops counter, mac operations profiler, neural network complexity analyzer, pytorch model parameter counter, deep learning model profiling, compute cost estimation, architecture efficiency comparison, model-profiling, pytorch-tools, performance-analysis [View on SkillFed](https://skillfed.io/packages/ultralytics-thop) · [View on PyPI](https://pypi.org/project/ultralytics-thop/)