I simplified your code below:
import torch
import torch.nn.functional as F
import numpy as np

img = torch.rand(1, 1, 512, 512)

kx, ky = 5, 5

# Goes from 1 channel to 1 channel
weight_h = torch.rand(1, 1, ky, 1)
weight_w = torch.rand(1, 1, 1, kx)

padx = kx // 2
pady = ky // 2

convY = F.conv2d(img, weight_h, padding=(pady, 0))
convX = F.conv2d(convY, weight_w, padding=(0, padx))

print(img.size())
print(convY.size())
print(convX.size())