".github/vscode:/vscode.git/clone" did not exist on "f0a1df315db3c0fdec3d638895f6173809030bba"
Commit f840564d authored by Nathan Ng's avatar Nathan Ng Committed by Facebook Github Bot
Browse files

initial light and dynamic convolution kernels (#547)

Summary:
CUDA code for light/dynamicconv kernels, including pytorch modules. Modules can be built by running setup.py in each respective folder, and can then be imported and used like any other module.
Pull Request resolved: https://github.com/fairinternal/fairseq-py/pull/547

Reviewed By: myleott, shubho

Differential Revision: D15703660

Pulled By: nng555

fbshipit-source-id: e9c913753be3a1cd571965f7200df6678b644520
parent b8704686
from setuptools import setup
from torch.utils.cpp_extension import CUDAExtension, BuildExtension
setup(
name='lightconv_layer',
ext_modules=[
CUDAExtension('lightconv_cuda', [
'lightconv_cuda.cpp',
'lightconv_cuda_kernel.cu',
]),
],
cmdclass={
'build_ext': BuildExtension
})
...@@ -10,6 +10,21 @@ import torch.nn.functional as F ...@@ -10,6 +10,21 @@ import torch.nn.functional as F
from fairseq import utils from fairseq import utils
from fairseq.modules.unfold import unfold1d from fairseq.modules.unfold import unfold1d
def LightweightConv(input_size, kernel_size=1, padding_l=None, num_heads=1,
weight_dropout=0., weight_softmax=False, bias=False):
if torch.cuda.is_available():
try:
from fairseq.modules.lightconv_layer import LightconvLayer
return LightconvLayer(input_size, kernel_size=kernel_size,
padding_l=padding_l, num_heads=num_heads,
weight_dropout=weight_dropout,
weight_softmax=weight_softmax, bias=bias)
except ImportError as e:
print(e)
return LightweightConv1dTBC(input_size, kernel_size=kernel_size,
padding_l=padding_l, num_heads=num_heads,
weight_dropout=weight_dropout,
weight_softmax=weight_softmax, bias=bias)
class LightweightConv1d(nn.Module): class LightweightConv1d(nn.Module):
'''Lightweight Convolution assuming the input is BxCxT '''Lightweight Convolution assuming the input is BxCxT
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import torch.nn.functional as F import torch.nn.functional as F
def unfold1d(x, kernel_size, padding_l, pad_value=0): def unfold1d(x, kernel_size, padding_l, pad_value=0):
'''unfold T x B x C to T x B x C x K''' '''unfold T x B x C to T x B x C x K'''
if kernel_size > 1: if kernel_size > 1:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment