Flopper - A FLOP counter for PyTorch
An FLOP counter based on fvcore with a more extensive support for any (we're trying) PyTorch modules. This tool is a lightweight wrapper around fvcore flop counter, which does all the work under the hood. We provide an easy to use API to count the number of FLOPs of any PyTorch model.
It's going to be a bit slower than fvcore, but more accurate.
Installation
pip install flopper
Usage
The simplest way to use flopper is to use the count_flops function. It takes a model and an input batch as input and prints the total number of FLOPs.
from flopper import count_flops
model = YourRandomModel()
batch = torch.randn(1, 3, 224, 224)
flops = count_flops(model, batch) # This will print the total number of FLOPs
n_flops = flops.total()
To get more detailed information, you can do the following:
print(flops.by_operator())
print(flops.by_module())
print(flops.by_module_and_operator())
print(flops.get_table())
Out API supports also the usage of keyword arguments in the model's forward function. Let's look at an example:
input_1, input_2 = ...
mode = "advanced"
flops = count_flops(model, input_1, input_2, mode=mode)
Adding support for custom new modules
If you want to add support for a new module, you can do so by creating a dictionary with the following structure:
import numpy as np
from fvcore.nn.jit_handles import get_shape
from flopper import count_flops
model = YourRandomModel()
batch = torch.randn(1, 3, 224, 224)
def mean_flop_jit(inputs, outputs):
input_shape = get_shape(inputs[0])
return np.prod(input_shape)
custom_ops = {"aten::mean": mean_flop_jit}
flops = count_flops(model, batch, custom_ops=custom_ops)
Metadata
Release files for flopper 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flopper-0.2.2.tar.gz | 12.0 kB | Without provenance | Details for flopper-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flopper-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for flopper-0.2.2-py3-none-any.whl |
Total release size: 21.1 kB
Release files / flopper-0.2.2.tar.gz
| Download URL | flopper-0.2.2.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
364a83ed558ebd50da9cbee219339cdeec92ccc44d105bd29c472bfa95a69709
|
|
BLAKE2b-256 checksum How to use checksums |
90c81cac086317ae4cefb64dbc0215867a8b0590a1397d8edb2027618707be0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Release files / flopper-0.2.2-py3-none-any.whl
| Download URL | flopper-0.2.2-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
312ffc55aff7e477313675ce7bee21d439f6340571233e86abe446e34d9e9c70
|
|
BLAKE2b-256 checksum How to use checksums |
0977e9c7de712d0874710e582e5bbe4333773fbbd18d5e245588386238c37717
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for flopper 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.