Hi,
I’m currently facing the same issue with customizing nn.conv2d() 's kernel:
Traceback (most recent call last):
  File "/home/Documents/code/EMVD/temp.py", line 21, in forward
    x = self.conv1(x)
  File "/home/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/anaconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 399, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/home/anaconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 395, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
RuntimeError: expected stride to be a single integer value or a list of 1 values to match the convolution dimensions, but got stride=[1, 1]
torch.Size([1, 4, 128, 128])

My code is below:
class MyModel(nn.Module):
    def __init__(self, kernel_stack):
        super(MyModel, self).__init__()
        self.conv1 = nn.Conv2d(in_channels=4, out_channels=4, kernel_size=4, bias=True)
        # Add other layers here

        # Initialize conv1 with custom kernel
        kernel_stack = torch.Tensor(kernel_stack)

        self.conv1.weight = nn.Parameter(kernel_stack)

    def forward(self, x):
        try:
            x = self.conv1(x)
        except:
            traceback.print_exc()

        return x


if __name__ == '__main__':

    # Define your custom kernel
    kernel = [[0.5, 0.5, 0.5, 0.5],
              [-0.5, 0.5, 0.5, -0.5],
              [0.7, 0.1, -0.1, -0.7],
              [-0.1, 0.7, -0.7, 0.1]]
    kernel = np.array(kernel)
    kernel_stack = np.stack([kernel, kernel, kernel, kernel], axis=1)


    model = MyModel(kernel_stack)
    model.eval()

    x = torch.randn(1, 4, 128, 128)

    with torch.no_grad():
        output = model(x)
    print(output.shape)