I think the result is expected, since your grid_2d tensor fills the all pixels of the output tensor, which is why it would stretch the input.
I think you can achieve the last output by setting the size in affine_grid to the smaller desired size and place the transformed image in the larger empty output.