Implementation of 1D, 2D, and 3D FFT convolutions in PyTorch. Much faster than direct convolutions for large kernel sizes
Project description
FFT Conv PyTorch
This is a fork of fft-conv-pytorch.
I made some modifications to support dilated, strided, and transposed convolution, so it can be a drop-in-replacement of original PyTorch Conv*d modules and conv*d functions, with the same behaviour and interface.
Install
pip install torch-fftconv
Example Usage
import torch
from torch_fftconv import fft_conv1d, FFTConv1d
signal = torch.randn(3, 3, 1024 * 1024)
kernel = torch.randn(2, 3, 128)
bias = torch.randn(2)
# Functional execution. (Easiest for generic use cases.)
out = fft_conv1d(signal, kernel, bias=bias)
# Object-oriented execution.
fft_conv = FFTConv1d(3, 2, 128, bias=True)
out = fft_conv(signal)
# Suppose you want to replace all the existing convolution layers in a neural network with FFTConv, you can do it like this:
m: torch.nn.Module = ... # some existing model
from torch_fftconv.utils import convert_fft_conv
m = convert_fft_conv(m) # this will replace all Conv/TransposedConv layers in m with FFTConv layers, and copy the weights and bias.
Benchmarks
The best situation to use FFTConv is when using large size kernel. The following image shows that when the size of input is fixed, the fft method remains an almost constant cost among all size of kernel, regardless.
For details and benchmarks on other parameters, check this notebook.
Features
[ ] Jittability.- Dilated Convolution.
- Transposed Convolution.
- Support complex input and kernel.
Project details
Release history Release notifications | RSS feed
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 torch_fftconv-1.0.0.tar.gz.
File metadata
- Download URL: torch_fftconv-1.0.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14a7d47c4a2e9aaec6e6beeab2c5d56c45b60fff924a610c014a3d0fa1224bff
|
|
| MD5 |
842d672b9f15a25ce9e74fec3cbde273
|
|
| BLAKE2b-256 |
b3491ce497065fea30bea4675888b51621511bc12f4be29a8d878186fe0d0d9b
|
File details
Details for the file torch_fftconv-1.0.0-py3-none-any.whl.
File metadata
- Download URL: torch_fftconv-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e64edd2c36847c820c9f61b6b0de94652d6017c261e00c59d55f18e32809c145
|
|
| MD5 |
21381eadc6247e936502b7a81c866443
|
|
| BLAKE2b-256 |
4879fb06c196086cccab5da8e1c7b8f385c435084144634fac02c89a97c66560
|