What is the reason you are using new_group? New group should be used only if you want to use the subset of processes. Otherwise you can just do dist.gather(cosine_tensor) with the default group size of the world_size.
The problem in your code is that world_size is 2 and you specify [0, 2] to new_group. new_group should contain a list of ranks between [0, world_size - 1]. So [0, 1], [1] or [0] are valid arguments. However, if you want to just use [0, 1] that is actually the entire world_size and you don’t really need new_group API for that and can just use the default group.