Torch Pconv
Faster and more memory efficient implementation of the Partial Convolution 2D layer in PyTorch equivalent to the standard Nvidia implementation.
This implementation has numerous advantages:
- It is strictly equivalent in computation to the reference implementation by Nvidia . I made unit tests to assess that all throughout development.
- It's commented and more readable
- It's faster and more memory efficient, which means you can use more layers on smaller GPUs. It's a good thing considering today's GPU prices.
- It's a PyPI-published library. You can
pipinstall it instead of copy/pasting source code, and get the benefit of ( free) bugfixes when someone notice a bug in the implementation.
Getting started
pip3 install torch_pconv
Usage
import torch
from torch_pconv import PConv2d
images = torch.rand(32, 3, 256, 256)
masks = (torch.rand(32, 256, 256) > 0.5).to(torch.float32)
pconv = PConv2d(
in_channels=3,
out_channels=64,
kernel_size=7,
stride=1,
padding=2,
dilation=2,
bias=True
)
output, shrunk_masks = pconv(images, masks)
Performance improvement
Test
You can find the reference implementation by Nvidia here .
I tested their implementation vs mine one the following configuration:
| Parameter | Value |
|---|---|
| in_channels | 64 |
| out_channels | 128 |
| kernel_size | 9 |
| stride | 1 |
| padding | 3 |
| bias | True |
| input height/width | 256 |
The goal here was to produce the most computationally expensive partial convolution operator so that the performance difference is displayed better.
I compute both the forward and the backward pass, in case one consumes more memory than the other.
Results
torch_pconv | Nvidia® (Guilin) | |
|---|---|---|
| Forward only | 813 466 624 | 4 228 120 576 |
| Backward only | 1 588 201 480 | 1 588 201 480 |
| Forward + Backward | 2 405 797 640 | 6 084 757 512 |
Development
To install the latest version from Github, run:
git clone git@github.com:DesignStripe/torch_pconv.git torch_pconv
cd torch_pconv
pip3 install -U .
Release files for torch-pconv 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torch_pconv-0.1.1.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torch_pconv-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / torch_pconv-0.1.1.tar.gz
| Download URL | torch_pconv-0.1.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34ad9badad03bacceb02b8f0b4f825eedcead8f6cc17058716cd81deacdb5819
|
|
BLAKE2b-256 checksum How to use checksums |
86c2fe2dfa3201d96ff378626b33c12c9572cf9d37602cce78238bd757fb1b41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.1
|
Release files / torch_pconv-0.1.1-py3-none-any.whl
| Download URL | torch_pconv-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c846d07e4ea34046f95ec50aeca505317118f7eb0f5eb3f13a362a94bbe0a596
|
|
BLAKE2b-256 checksum How to use checksums |
459c4aa35963c54ab9021e18f39e4dc22f9286b532ab620a0dcbeddd1b59e221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.1
|