Could you modify your code so that the error is thrown?
I tried your code and it runs just fine:
class Net(nn.Module):
    def __init__(self,):
        super(Net, self).__init__()
        self.activation = nn.Tanh()
        self.image_conv1 = nn.Conv2d(5, 20, 5, padding=2)
        self.image_conv2 = nn.Conv2d(20, 20, 5, padding=2)
        
    def forward(self, x):
        x = self.image_conv1(x)
        x = self.activation(x)
        x = self.image_conv2(x)
        x = self.activation(x)
        return x

model = Net()
x = torch.randn(1, 5, 24, 24)
output = model(x)
output.mean().backward()