Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

conv_tbc.py 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  1. # Copyright (c) 2017-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the LICENSE file in
  5. # the root directory of this source tree. An additional grant of patent rights
  6. # can be found in the PATENTS file in the same directory.
  7. import torch
  8. from torch.nn.modules.utils import _single
  9. class ConvTBC(torch.nn.Module):
  10. """1D convolution over an input of shape (time x batch x channel)
  11. The implementation uses gemm to perform the convolution. This implementation
  12. is faster than cuDNN for small kernel sizes.
  13. """
  14. def __init__(self, in_channels, out_channels, kernel_size, padding=0):
  15. super(ConvTBC, self).__init__()
  16. self.in_channels = in_channels
  17. self.out_channels = out_channels
  18. self.kernel_size = _single(kernel_size)
  19. self.padding = _single(padding)
  20. self.weight = torch.nn.Parameter(torch.Tensor(
  21. self.kernel_size[0], in_channels, out_channels))
  22. self.bias = torch.nn.Parameter(torch.Tensor(out_channels))
  23. def forward(self, input):
  24. return input.contiguous().conv_tbc(self.weight, self.bias, self.padding[0])
  25. def __repr__(self):
  26. s = ('{name}({in_channels}, {out_channels}, kernel_size={kernel_size}'
  27. ', padding={padding}')
  28. if self.bias is None:
  29. s += ', bias=False'
  30. s += ')'
  31. return s.format(name=self.__class__.__name__, **self.__dict__)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...