Registry / ai-ml / ptflops

ptflops

JSON →
library0.7.5pypypiunverified

A Flops counter for neural networks in PyTorch. It computes the number of floating point operations (FLOPs) and parameters of a model. The current version is 0.7.5, with a slow release cadence.

pip install ptflops
INSTALL
IMPORT
SIG · PTFLOPS
P
ptflops
ai-mlpythonv0.7.5
Install
66.2s avg
Import
Disk
4787MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.5 · 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
✓ 73.6s
py 3.11
✕ build_error
✓ 69.5s
py 3.12
✕ build_error
✓ 65.2s
py 3.13
✕ build_error
✓ 56.3s
py 3.9
✕ build_error
✕ timeout
4787MB installed
● package 4787MB
Code
Verified usage

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

get_model_complexity_info
from ptflops import get_model_complexity_info
from ptflops.flops_counter import get_model_complexity_info
Old import path (pre-0.7) is deprecated.

Compute FLOPs and parameters for ResNet-18 with a 224x224 input.

import torch from ptflops import get_model_complexity_info import torchvision.models as models net = models.resnet18() macs, params = get_model_complexity_info(net, (3, 224, 224), as_strings=True, print_per_layer_stat=True) print('{:<30} {:<8}'.format('Computational complexity: ', macs)) print('{:<30} {:<8}'.format('Number of parameters: ', params))
Debug
Known issues
deprecatedImporting from ptflops.flops_counter directly is deprecated. Use from ptflops import get_model_complexity_info instead.
fix
Change import to 'from ptflops import get_model_complexity_info'.
affects: >=0.7
gotchaThe function returns MACs (multiply-accumulate operations), not FLOPs. MACs are roughly half of FLOPs.
fix
Multiply the returned MACs by 2 to get FLOPs if needed.
affects: all
gotchaFor models with batch normalization, the flops count may be inaccurate if the model is not in eval mode.
fix
Set model.eval() before calling get_model_complexity_info.
affects: all
breakingThe function signature changed in version 0.7. The parameter 'input_res' was removed and replaced with 'input_shape' (tuple).
fix
Pass input_shape=(3, 224, 224) instead of input_res=224.
affects: >=0.7
Upgrade
Version history
0.7.5latest on PyPI · released Aug 20, 2025
Audit
Dependencies
torchrequiredPyTorch is required to define models and run flops computation.
Agent activity
9 hits · last 30 days
node
8
Resources
ptflops — pip install ptflops · libregistry