How do the two virtual machines connect to each other and run GPUs from another machine parallelly?

Once the two machines forms a process group, you can use collective APIs like allreduce for communication.

Out of two virtual machine, on which machine should I run the below distribution command?

You should run these commands on two virtual machines, respectively. There is no “out of two virtual machine”.