espnet2.gan_codec.shared.quantizer.modules.distrib.world_size
Less than 1 minute
espnet2.gan_codec.shared.quantizer.modules.distrib.world_size
espnet2.gan_codec.shared.quantizer.modules.distrib.world_size()
Get the total number of processes in the current distributed group.
This function checks if the PyTorch distributed environment is initialized. If it is, it returns the total number of processes (world size) that are part of the distributed group. If not, it returns 1, indicating that there is only a single process.
- Returns: The total number of processes in the distributed group. Returns 1 if the distributed environment is not initialized.
- Return type: int
Examples
>>> import torch
>>> if torch.distributed.is_initialized():
... print(world_size())
... else:
... print(world_size()) # Output: 1
NOTE
This function is typically used in conjunction with other distributed utilities to facilitate multi-process training.