Skip to main content

Implementation of 1D, 2D, and 3D FFT convolutions in PyTorch. Much faster than direct convolutions for large kernel sizes

Project description

FFT Conv PyTorch

Python package Upload Python Package PyPI version

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_fftconv-1.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_fftconv-1.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

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

Hashes for torch_fftconv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 14a7d47c4a2e9aaec6e6beeab2c5d56c45b60fff924a610c014a3d0fa1224bff
MD5 842d672b9f15a25ce9e74fec3cbde273
BLAKE2b-256 b3491ce497065fea30bea4675888b51621511bc12f4be29a8d878186fe0d0d9b

See more details on using hashes here.

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

Hashes for torch_fftconv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e64edd2c36847c820c9f61b6b0de94652d6017c261e00c59d55f18e32809c145
MD5 21381eadc6247e936502b7a81c866443
BLAKE2b-256 4879fb06c196086cccab5da8e1c7b8f385c435084144634fac02c89a97c66560

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page