|
1 | 1 | from ..tensor.functions import rand, zeros |
2 | 2 | from .module import Module, Parameter |
3 | | -from ..backends import fast_conv, fast_ops |
| 3 | +from ..backends import fast_conv |
4 | 4 | from . import init |
5 | | -from ..tensor.tensor import Tensor |
6 | 5 |
|
7 | 6 | try: |
8 | 7 | from ..backends import cuda_conv |
@@ -37,24 +36,19 @@ def __init__(self, in_channels, out_channels, kernel_width, backend, stride=1, i |
37 | 36 | self.kernel_width = kernel_width |
38 | 37 |
|
39 | 38 | def forward(self, input): |
40 | | - # Perform strided convolution manually if stride != 1 |
41 | 39 | batch, in_channels, w = input.shape |
42 | 40 | kw = self.kernel_width |
43 | 41 | stride = self.stride |
44 | 42 | out_channels = self.weights.value.shape[0] |
45 | 43 |
|
46 | | - # Calculate output width with stride |
47 | 44 | out_w = (w - kw) // stride + 1 |
48 | 45 |
|
49 | | - # Create output tensor |
50 | 46 | output = input.zeros((batch, out_channels, out_w)) |
51 | 47 |
|
52 | | - # Perform convolution with stride |
53 | 48 | for b in range(batch): |
54 | 49 | for oc in range(out_channels): |
55 | 50 | for ow in range(out_w): |
56 | 51 | start_w = ow * stride |
57 | | - # Compute convolution for this window |
58 | 52 | total = 0.0 |
59 | 53 | for ic in range(in_channels): |
60 | 54 | for k in range(kw): |
@@ -83,7 +77,6 @@ def __init__(self, in_channels, out_channels, kernel, backend, stride=1, initial |
83 | 77 | self.backend = backend |
84 | 78 |
|
85 | 79 | def forward(self, input): |
86 | | - # Use CUDA conv if backend is CUDA, otherwise use fast conv |
87 | 80 | if self.backend.cuda and cuda_conv is not None: |
88 | 81 | out = cuda_conv.conv2d(input, self.weights.value, self.stride) + self.bias.value |
89 | 82 | else: |
|
0 commit comments