I am new to TorchScript and I was trying to use torch.jit.script for one of my models and when I do so, I get the following:
RuntimeError:
Tried to access nonexistent attribute or method 'forward' of type 'Tensor'.:
File "custom_layers.py", line 32
def forward(self, x):
result = super().forward(x)
~~~~~~~~~~~~~ <--- HERE
if self._padding != 0:
The method that is causing issues is the forward()
method of the nn.Conv1d
instance that is called from the derived class as follows:
class CausalConv1d(nn.Conv1d):
def __init__(self,
in_channels,
out_channels,
kernel_size=1,
stride=1,
dilation=1,
groups=1,
bias=True):
self._padding = (kernel_size - 1) * dilation
super().__init__(
in_channels,
out_channels,
kernel_size=kernel_size,
stride=stride,
padding=self._padding,
dilation=dilation,
groups=groups,
bias=bias
)
def forward(self, x):
result = super().forward(x)
if self._padding != 0:
return result[:, :, : - self._padding]
return result
If I hint the input type x as suggested in this topic I still get an error.
Thanks for your help!