pytorch-estimate-flops
Simple pytorch utility that estimates the number of FLOPs for a given network. For now only some basic operations are supported (basically the ones I needed for my models). More will be added soon.
All contributions are welcomed.
Installation
You can install the model using pip:
pip install pthflops
or directly from the github repository:
git clone https://github.com/1adrianb/pytorch-estimate-flops && cd pytorch-estimate-flops
python setup.py install
Note: pytorch 1.8 or newer is recommended.
Example
import torch
from torchvision.models import resnet18
from pthflops import count_ops
# Create a network and a corresponding input
device = 'cuda:0'
model = resnet18().to(device)
inp = torch.rand(1,3,224,224).to(device)
# Count the number of FLOPs
count_ops(model, inp)
Ignoring certain layers:
import torch
from torch import nn
from pthflops import count_ops
class CustomLayer(nn.Module):
def __init__(self):
super(CustomLayer, self).__init__()
self.conv1 = nn.Conv2d(5, 5, 1, 1, 0)
# ... other layers present inside will also be ignored
def forward(self, x):
return self.conv1(x)
# Create a network and a corresponding input
inp = torch.rand(1,5,7,7)
net = nn.Sequential(
nn.Conv2d(5, 5, 1, 1, 0),
nn.ReLU(inplace=True),
CustomLayer()
)
# Count the number of FLOPs, jit mode:
count_ops(net, inp, ignore_layers=['CustomLayer'])
# Note: if you are using python 1.8 or newer with fx instead of jit, the naming convention changed. As such, you will have to pass ['_2_conv1']
# Please check your model definition to account for this.
# Count the number of FLOPs, fx mode:
count_ops(net, inp, ignore_layers=['_2_conv1'])
Metadata
Release files for pthflops 0.4.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 |
|---|---|---|---|---|
| pthflops-0.4.2.tar.gz | 10.9 kB | Without provenance | Details for pthflops-0.4.2.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pthflops-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for pthflops-0.4.2-py3-none-any.whl |
| pthflops-0.4.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pthflops-0.4.2-py2.py3-none-any.whl |
Total release size: 33.1 kB
Release files / pthflops-0.4.2.tar.gz
| Download URL | pthflops-0.4.2.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a64b6d75937e01cf837e3cdc688de1e0fb58a7d6105974956c3bbeaa1c105e8
|
|
BLAKE2b-256 checksum How to use checksums |
51e9610f95556b06a015e70e37bbeee80f8a57e87e5571c6be6c9901551532a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / pthflops-0.4.2-py3-none-any.whl
| Download URL | pthflops-0.4.2-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7211664c4d47032c6859a84d14d8ce3ccd17ac08028389b92c8d66bf6ca2580c
|
|
BLAKE2b-256 checksum How to use checksums |
0c2783eab6b0a3068944d5e52cd64de9339fce58b2c8e33fec08bafa89843881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / pthflops-0.4.2-py2.py3-none-any.whl
| Download URL | pthflops-0.4.2-py2.py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
8551ca3b10538cd6250b3cee8d42ced6c7cc3b955b57909feb849b95d59c45aa
|
|
BLAKE2b-256 checksum How to use checksums |
a0f747983544d6bc6ae37156c1b5a2b5de5ed886bbdeeda9e1eca84b5abd55cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for pthflops 0.4.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.