mmengine.dist.sync_random_seed β mmengine 0.10.7 documentation (original) (raw)
mmengine.dist.sync_random_seed(group=None)[source]ΒΆ
Synchronize a random seed to all processes.
In distributed sampling, different ranks should sample non-overlapped data in the dataset. Therefore, this function is used to make sure that each rank shuffles the data indices in the same order based on the same seed. Then different ranks could use different indices to select non-overlapped data from the same data list.
Parameters:
group (ProcessGroup , optional) β The process group to work on. If None, the default process group will be used. Defaults to None.
Returns:
Random seed.
Return type:
Examples
import torch import mmengine.dist as dist
non-distributed environment
seed = dist.sync_random_seed() seed # which a random number 587791752
distributed environment
We have 2 process groups, 2 ranks.
seed = dist.sync_random_seed() seed 587791752 # Rank 0 587791752 # Rank 1