{"id":5731,"library":"thop","title":"THOP: PyTorch-OpCounter","description":"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.","status":"maintenance","version":"0.1.1.post2209072238","language":"en","source_language":"en","source_url":"https://github.com/Lyken17/pytorch-OpCounter/","tags":["pytorch","flops","macs","model-profiling","deep-learning","computational-efficiency"],"install":[{"cmd":"pip install thop","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core dependency for PyTorch model profiling.","package":"torch","optional":false}],"imports":[{"symbol":"profile","correct":"from thop import profile"},{"symbol":"clever_format","correct":"from thop import clever_format"}],"quickstart":{"code":"import torch\nimport torch.nn as nn\nfrom torchvision.models import resnet18\nfrom thop import profile, clever_format\n\n# 1. Define a model and a dummy input\nmodel = resnet18()\ndummy_input = torch.randn(1, 3, 224, 224)\n\n# 2. Profile the model\nmacs, params = profile(model, inputs=(dummy_input, ), verbose=False)\n\n# 3. Format the output for readability\nmacs, params = clever_format([macs, params], \"%.3f\")\n\nprint(f\"MACs: {macs}\")\nprint(f\"Parameters: {params}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"THOP 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the `thop` documentation or examples on how to define `custom_ops` for unsupported module types to ensure comprehensive and accurate profiling.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":"0.1.1.post2209072238 and earlier."}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}