[C10D] Make _set_pg_timeout work with DeviceMesh PG (#120850)
Fixes #120847
Makes _set_pg_timeout work on nccl and/or gloo backends instead of working only on one backend (gloo) in cases that both backends exist for the group.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120850
Approved by: https://github.com/XilunWu, https://github.com/wanchaol