Shortcuts

mmengine.dist.sync_random_seed

mmengine.dist.sync_random_seed(group=None)[源代码]

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.

参数

group (ProcessGroup, optional) – The process group to work on. If None, the default process group will be used. Defaults to None.

返回

Random seed.

返回类型

int

实际案例

>>> 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
Read the Docs v: v0.2.0
Versions
latest
stable
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.