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 calflopsVerified import paths — ran on the pinned version, not inferred.
Compute FLOPs, MACs, and parameters for a ResNet-18 model.
Set model.eval() before calling calculate_flops to disable dropout/batchnorm effects.
Pass a callable that returns a tuple of tensors: input_constructor=lambda: (x,).
If using control flow, test with a simple forward pass first and verify counts are reasonable.