For anyone new looking for this issue, an updated function has also been introduced in pytorch - torch.repeat_interleave() 329 to address this issue in a single operation.
So one can use torch.repeat_interleave(z, repeats=3, dim=0) to obtain:
tensor([[1., 2., 3.],
        [1., 2., 3.],
        [1., 2., 3.],
        [4., 5., 6.],
        [4., 5., 6.],
        [4., 5., 6.]])

and similarly can use torch.repeat_interleave(z, repeats=3, dim=1) to obtain:
tensor([[1., 1., 1., 2., 2., 2., 3., 3., 3.],
        [4., 4., 4., 5., 5., 5., 6., 6., 6.]])