expand(5, -1, -1, -1) or repeat(5, 1, 1, 1) should work:
gx = F.conv2d(x, w.expand(5, -1, -1, -1), padding=1, groups=5)

If you want to manipulate w inplace, you should use repeat, since it will allocate new memory, while expand uses the same memory and just changes the stride and size.