Registry / ai-ml / calflops

calflops

JSON →
library0.3.2pypypiunverified

CalFlops is a PyTorch-based FLOPs, MACs, and parameter counter for neural networks including CNNs, RNNs, GCNs, and Transformers (e.g., BERT, LLaMA). Version 0.3.2 supports custom models. Released as needed on GitHub.

pip install calflops
INSTALL
IMPORT
SIG · CALFLOPS
C
calflops
ai-mlpythonv0.3.2
Install
69.2s avg
Import
—
Disk
4890MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.3.2 · 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
✓ 80.6s
py 3.11
✕ build_error
✓ 73s
py 3.12
✕ build_error
✓ 63.5s
py 3.13
✕ build_error
✓ 59.7s
py 3.9
✕ build_error
✕ timeout
4890MB installed
● package 4890MB
Code
Verified usage

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

calculate_flops
✓ from calflops import calculate_flops
✗ from calflops import calculate_flops

Compute FLOPs, MACs, and parameters for a ResNet-18 model.

import torch import torchvision.models as models from calflops import calculate_flops model = models.resnet18() batch_size = 1 input_shape = (batch_size, 3, 224, 224) flops, macs, params = calculate_flops( model=model, input_shape=input_shape, output_as_string=True, output_precision=4 ) print(f"FLOPs: {flops}, MACs: {macs}, Params: {params}")
Debug
Known issues
gotchaTorchvision models may include non-parameter operations (like softmax) that are counted differently. Ensure model is in eval mode.
fix
Set model.eval() before calling calculate_flops to disable dropout/batchnorm effects.
affects: all
gotchaIf model has multiple inputs (e.g., encoders), use input_constructor instead of input_shape.
fix
Pass a callable that returns a tuple of tensors: input_constructor=lambda: (x,).
affects: all
gotchaFLOPs counting for dynamic architectures (e.g., with torch.where) may be inaccurate due to static graph assumption.
fix
If using control flow, test with a simple forward pass first and verify counts are reasonable.
affects: all
Upgrade
Version history
0.3.2latest on PyPI · released Jun 7, 2024
Audit
Dependencies
torchrequiredCore dependency for model definitions and tensors.
Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
calflops — pip install calflops · libregistry