mindspore.mint.distributed.get_rank
- mindspore.mint.distributed.get_rank(group=None)[source]
Get the rank ID for the current device in the specified collective communication group.
Note
This method should be used after
mindspore.mint.distributed.init_process_group()
.- Parameters
group (str, optional) – The communication group to work on. Normally, the group should be created by
mindspore.mint.distributed.new_group()
. IfNone
, which means"hccl_world_group"
in Ascend. Default:None
.- Returns
int, the rank ID of the calling process within the group. return -1, if not part of the group
- Raises
TypeError – If group is not a string.
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> import mindspore as ms >>> from mindspore.mint.distributed import init_process_group, get_rank >>> ms.set_device(device_target="Ascend") >>> init_process_group() >>> rank_id = get_rank() >>> print(rank_id) >>> # the result is the rank_id in world_group