One-clicked merge convolution and batchnorm to one unified convolution
Project description
Convolution Batchnorm Merge
Only one line of code and we can accelerate your model up to 50% faster!
Installation
$ pip install convbnmerge
Usage
conv-bn-merge is ONLY used in inference time!
from convbnmerge import merge
model = ...
"""
training...
"""
merge(model)
Update
- 2021.18.04: support ConvTranspose2d and ConvTranspose3d
- 2021.02.04: also support Conv3d
How much fast
You usually reach 30++% inferece time reduce. In some cases, the number is more than 50%!
from time import time
import torch
from torchvision.models.resnet import resnet34
from convbnmerge import merge
if __name__ == '__main__':
model = resnet34(pretrained=True)
x = torch.Tensor(2, 3, 32, 32)
with torch.no_grad():
start = time()
for i in range(100):
model(x)
stop = time()
print(stop - start) # Before merge: about 7.9s
merge(model)
with torch.no_grad():
start = time()
for i in range(100):
model(x)
stop = time()
print(stop - start) # After merge: about 4.8s
How we do
Coming soon
Are outputs the same before and after merge?
A small difference caused by round-off error. In almost cases, it doesn't harm the model's result.
import torch
from torchvision.models.resnet import resnet34
from convbnmerge import merge
if __name__ == '__main__':
model = resnet34(pretrained=True)
model.eval()
x = torch.Tensor(1, 3, 32, 32)
out_old = model(x)
merge(model)
out_new = model(x)
print(((out_old-out_new)**2).sum()) #less than 1e-10
License
conv-bn-merge is MIT-licensed.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file convbnmerge-0.1.6.tar.gz.
File metadata
- Download URL: convbnmerge-0.1.6.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7b56c794a7c82b4bcad30a833305ac75c0b89d652dee3f22ee02e10360e8a6b
|
|
| MD5 |
5d43ceb00ecb820129846c9e35472c7d
|
|
| BLAKE2b-256 |
fe18399d811c9d3ac6f0eb9cf348f0eb9ad6901e7a07bf57072c99616eae295b
|
File details
Details for the file convbnmerge-0.1.6-py3-none-any.whl.
File metadata
- Download URL: convbnmerge-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
524cd77909c0aac8587b793589e6bf10d4f5a36daa61c3bccc766f2ac2ef27e4
|
|
| MD5 |
df14ab62c5d3d236f8a6399766f3a99a
|
|
| BLAKE2b-256 |
e96eb61a0fe6d269aaf928cadbbd839518073c46898f5c86ffa0f886a198e63a
|