and I want to do convolution operation such that my kernel height is 3 and width is also 3 but kernel moves only in the one direction (in the direction of width). I tried to use 2D convolution with stride 0 for Height but it throws an error as stride should be greater than zero. Any idea how to achieve this in pytorch?

One way could be is to do 1D convolution for each row (1,2,3) and the result of convolution from each row can be put together back in a tensor. Is there any easy way to achieve the same ?

Yes, with 2D convolution in PyTorch, it does whatâ€™s called â€śvalid paddingâ€ť by default. That is, it wonâ€™t go over the edges. And in this case, it wonâ€™t move vertically (up or down). The output you expect to get here, from a 3x9 input with a 3x3 kernel with stride 1, is a 1x7 output